SlideShare a Scribd company logo
1 of 12
///////////////////////////////////
// square.cpp
//
// OpenGL program to draw a square.
//
// Sumanta Guha.
///////////////////////////////////
#include <GL/freeglut.h>
#include <cmath>
#define PI 3.14
void drawDisc(float R, float X, float Y, float Z) {
static int N = 100; // #vertices.
float t = 0.0;
glBegin(GL_LINE_LOOP);
for (int i = 0; i <= N; ++i) {
glVertex3f(X + R * cos(t), Y + R * sin(t), Z);
t += 2 * PI / N;
}
glEnd();
}
void drawDiamond() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(50, 26, 0);
glVertex3f(56, 20, 0);
glVertex3f(50, 14, 0);
glVertex3f(44, 20, 0);
glEnd();
}
void drawCoss() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(73, 51, 0);
glVertex3f(85, 51, 0);
glVertex3f(85, 49, 0);
glVertex3f(73, 49, 0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(78, 56, 0);
glVertex3f(80, 56, 0);
glVertex3f(80, 44, 0);
glVertex3f(78, 44, 0);
glEnd();
}
void drawTriangle() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(50, 86, 0);
glVertex3f(56, 74, 0);
glVertex3f(44, 74, 0);
glEnd();
}
void drawArrow() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(50, 68, 0);
glVertex3f(44, 63, 0);
glVertex3f(56, 63, 0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(46, 63, 0);
glVertex3f(54, 63, 0);
glVertex3f(54, 32, 0);
glVertex3f(46, 32, 0);
glEnd();
}
void drawPiont(float R, float X, float Y, float Z) {
static int N = 200; // #vertices.
float t = 0.0;
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(X, Y, 0); //center point
for (int i = 0; i < N + 1; i++)
{
glVertex3f(X + R * cos(t), Y + R * sin(t), 0.0);
t += 2 * PI / N;
}
glEnd();
}
void drawStar() {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glBegin(GL_POLYGON);
glVertex3f(15, 51, 0);
glVertex3f(27, 51, 0);
glVertex3f(21, 46, 0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(21, 56, 0);
glVertex3f(21, 46, 0);
glVertex3f(17, 44, 0);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(21, 56, 0);
glVertex3f(21, 46, 0);
glVertex3f(25, 44, 0);
glEnd();
}
// Drawing routine.
void drawScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
//glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
//glEnable(GL_DEPTH_TEST);
glColor3ub(190, 190, 190);
for (float i = 0; i < 400; i++) {
float n = i * 0.01;
drawDisc(42.0-n, 50.0, 50.0, 0.0);
i += i * 0.01;
}
glColor3ub(225, 225, 0);
drawDiamond();
glColor3ub(255, 0, 0);
drawCoss();
glColor3ub(65, 105, 225);
drawTriangle();
glColor3ub(205, 104, 57);
drawArrow();
glColor3f(0, 0, 0);
drawPiont(1, 50.0, 50.0, 0.0);
glColor3ub(50, 205, 50);
drawStar();
//glDisable(GL_DEPTH_TEST);
glFlush();
}
// Initialization routine.
void setup(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
// OpenGL window reshape routine.
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// Keyboard input processing routine.
void keyInput(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
default:
break;
}
}
// g++ -framework OpenGL -lGLUT -lGLEW -I
/opt/X11/include -L /opt/X11/lib -w -o out squareEx.cpp
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitContextVersion(4, 3);
glutInitContextProfile(GLUT_COMPATIBILITY_PROFIL
E);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
//glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA |
GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("square.cpp");
glutDisplayFunc(drawScene);
glutReshapeFunc(resize);
glutKeyboardFunc(keyInput);
setup();
glutMainLoop();
}

More Related Content

Similar to square.cpp Open

Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.pptadil104135
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source codeBrian Goggins
 
Togo National Flag
Togo National FlagTogo National Flag
Togo National FlagSH Rajøn
 
Graphics programs
Graphics programsGraphics programs
Graphics programsNAVYA RAO
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184Mahmoud Samir Fayed
 
animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfambritgames
 
Ghana National Flag
Ghana National FlagGhana National Flag
Ghana National FlagSH Rajøn
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210Mahmoud Samir Fayed
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wireRené Domínguez
 
Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)Robi Parvez
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flagRobi Parvez
 

Similar to square.cpp Open (20)

Komputer Grafik
Komputer GrafikKomputer Grafik
Komputer Grafik
 
opengl.ppt
opengl.pptopengl.ppt
opengl.ppt
 
Intro to Computer Graphics.ppt
Intro to Computer Graphics.pptIntro to Computer Graphics.ppt
Intro to Computer Graphics.ppt
 
Robot Motion Source code
Robot Motion Source codeRobot Motion Source code
Robot Motion Source code
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
Robot by gulnaz
Robot by gulnazRobot by gulnaz
Robot by gulnaz
 
Togo National Flag
Togo National FlagTogo National Flag
Togo National Flag
 
Graphics programs
Graphics programsGraphics programs
Graphics programs
 
Practicing 2d drawing primitives
Practicing 2d drawing primitivesPracticing 2d drawing primitives
Practicing 2d drawing primitives
 
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.3 book - Part 65 of 184
 
animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdf
 
Ghana National Flag
Ghana National FlagGhana National Flag
Ghana National Flag
 
Open GL Tutorial10
Open GL Tutorial10Open GL Tutorial10
Open GL Tutorial10
 
Slc math series
Slc math seriesSlc math series
Slc math series
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
Programa de objetos 3 d wire
Programa de objetos 3 d wirePrograma de objetos 3 d wire
Programa de objetos 3 d wire
 
Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)Ass day2 2_rotating my name (robi)
Ass day2 2_rotating my name (robi)
 
Ass day3 1_bd flag
Ass day3 1_bd flagAss day3 1_bd flag
Ass day3 1_bd flag
 
Practica
PracticaPractica
Practica
 

More from MikeEly930

Building on the Report Analysis you completed in Week 4, create a 10.docx
Building on the Report Analysis you completed in Week 4, create a 10.docxBuilding on the Report Analysis you completed in Week 4, create a 10.docx
Building on the Report Analysis you completed in Week 4, create a 10.docxMikeEly930
 
Bullet In the BrainHow to date a brown girl (black girl, white.docx
Bullet In the BrainHow to date a brown girl (black girl, white.docxBullet In the BrainHow to date a brown girl (black girl, white.docx
Bullet In the BrainHow to date a brown girl (black girl, white.docxMikeEly930
 
Budgeting and Financial ManagementPart 1There is a mounting publ.docx
Budgeting and Financial ManagementPart 1There is a mounting publ.docxBudgeting and Financial ManagementPart 1There is a mounting publ.docx
Budgeting and Financial ManagementPart 1There is a mounting publ.docxMikeEly930
 
Building aswimmingpoolTaskWorkerCategoryPerson.docx
Building aswimmingpoolTaskWorkerCategoryPerson.docxBuilding aswimmingpoolTaskWorkerCategoryPerson.docx
Building aswimmingpoolTaskWorkerCategoryPerson.docxMikeEly930
 
Bringing about Change in the Public Sector Please respond to the.docx
Bringing about Change in the Public Sector Please respond to the.docxBringing about Change in the Public Sector Please respond to the.docx
Bringing about Change in the Public Sector Please respond to the.docxMikeEly930
 
Briefly share with the class the  issue analysis paper written in .docx
Briefly share with the class the  issue analysis paper written in .docxBriefly share with the class the  issue analysis paper written in .docx
Briefly share with the class the  issue analysis paper written in .docxMikeEly930
 
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docx
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docxBronsen acquired a biblical manuscript in 1955.In 1962, he told .docx
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docxMikeEly930
 
BrochureInclude the following in your resource (Hyperten.docx
BrochureInclude the following in your resource (Hyperten.docxBrochureInclude the following in your resource (Hyperten.docx
BrochureInclude the following in your resource (Hyperten.docxMikeEly930
 
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docx
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docxBSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docx
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docxMikeEly930
 
Briefly provide an overview of Sir Robert Peel’s contributions to po.docx
Briefly provide an overview of Sir Robert Peel’s contributions to po.docxBriefly provide an overview of Sir Robert Peel’s contributions to po.docx
Briefly provide an overview of Sir Robert Peel’s contributions to po.docxMikeEly930
 
Brain-Based Innovative Teaching and Learning Strategies Chapter .docx
Brain-Based Innovative Teaching and Learning Strategies Chapter .docxBrain-Based Innovative Teaching and Learning Strategies Chapter .docx
Brain-Based Innovative Teaching and Learning Strategies Chapter .docxMikeEly930
 
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docxBrief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docxMikeEly930
 
Both Germany and Finland, among a large number of other nation state.docx
Both Germany and Finland, among a large number of other nation state.docxBoth Germany and Finland, among a large number of other nation state.docx
Both Germany and Finland, among a large number of other nation state.docxMikeEly930
 
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docx
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docxBrief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docx
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docxMikeEly930
 
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docxBrief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docxMikeEly930
 
Briefly describe how the following tools can be Applied to a psychol.docx
Briefly describe how the following tools can be Applied to a psychol.docxBriefly describe how the following tools can be Applied to a psychol.docx
Briefly describe how the following tools can be Applied to a psychol.docxMikeEly930
 
Branding ConceptsBranding is one of the marketing-orig.docx
Branding ConceptsBranding is one of the marketing-orig.docxBranding ConceptsBranding is one of the marketing-orig.docx
Branding ConceptsBranding is one of the marketing-orig.docxMikeEly930
 
Briefly discuss the key phases of the SDLC methodology.Discuss the.docx
Briefly discuss the key phases of the SDLC methodology.Discuss the.docxBriefly discuss the key phases of the SDLC methodology.Discuss the.docx
Briefly discuss the key phases of the SDLC methodology.Discuss the.docxMikeEly930
 
Briefly describe a time when you received a job description and fe.docx
Briefly describe a time when you received a job description and fe.docxBriefly describe a time when you received a job description and fe.docx
Briefly describe a time when you received a job description and fe.docxMikeEly930
 
Briefly discuss the meaning of the so-called social contract. In.docx
Briefly discuss the meaning of the so-called social contract. In.docxBriefly discuss the meaning of the so-called social contract. In.docx
Briefly discuss the meaning of the so-called social contract. In.docxMikeEly930
 

More from MikeEly930 (20)

Building on the Report Analysis you completed in Week 4, create a 10.docx
Building on the Report Analysis you completed in Week 4, create a 10.docxBuilding on the Report Analysis you completed in Week 4, create a 10.docx
Building on the Report Analysis you completed in Week 4, create a 10.docx
 
Bullet In the BrainHow to date a brown girl (black girl, white.docx
Bullet In the BrainHow to date a brown girl (black girl, white.docxBullet In the BrainHow to date a brown girl (black girl, white.docx
Bullet In the BrainHow to date a brown girl (black girl, white.docx
 
Budgeting and Financial ManagementPart 1There is a mounting publ.docx
Budgeting and Financial ManagementPart 1There is a mounting publ.docxBudgeting and Financial ManagementPart 1There is a mounting publ.docx
Budgeting and Financial ManagementPart 1There is a mounting publ.docx
 
Building aswimmingpoolTaskWorkerCategoryPerson.docx
Building aswimmingpoolTaskWorkerCategoryPerson.docxBuilding aswimmingpoolTaskWorkerCategoryPerson.docx
Building aswimmingpoolTaskWorkerCategoryPerson.docx
 
Bringing about Change in the Public Sector Please respond to the.docx
Bringing about Change in the Public Sector Please respond to the.docxBringing about Change in the Public Sector Please respond to the.docx
Bringing about Change in the Public Sector Please respond to the.docx
 
Briefly share with the class the  issue analysis paper written in .docx
Briefly share with the class the  issue analysis paper written in .docxBriefly share with the class the  issue analysis paper written in .docx
Briefly share with the class the  issue analysis paper written in .docx
 
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docx
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docxBronsen acquired a biblical manuscript in 1955.In 1962, he told .docx
Bronsen acquired a biblical manuscript in 1955.In 1962, he told .docx
 
BrochureInclude the following in your resource (Hyperten.docx
BrochureInclude the following in your resource (Hyperten.docxBrochureInclude the following in your resource (Hyperten.docx
BrochureInclude the following in your resource (Hyperten.docx
 
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docx
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docxBSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docx
BSBMKG607B Manage market researchAssessment Task 1Procedure Fr.docx
 
Briefly provide an overview of Sir Robert Peel’s contributions to po.docx
Briefly provide an overview of Sir Robert Peel’s contributions to po.docxBriefly provide an overview of Sir Robert Peel’s contributions to po.docx
Briefly provide an overview of Sir Robert Peel’s contributions to po.docx
 
Brain-Based Innovative Teaching and Learning Strategies Chapter .docx
Brain-Based Innovative Teaching and Learning Strategies Chapter .docxBrain-Based Innovative Teaching and Learning Strategies Chapter .docx
Brain-Based Innovative Teaching and Learning Strategies Chapter .docx
 
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docxBrief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000 a.docx
 
Both Germany and Finland, among a large number of other nation state.docx
Both Germany and Finland, among a large number of other nation state.docxBoth Germany and Finland, among a large number of other nation state.docx
Both Germany and Finland, among a large number of other nation state.docx
 
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docx
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docxBrief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docx
Brief Exercise 5-2Koch Corporation’s adjusted trial balance contai.docx
 
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docxBrief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docx
Brief Exercise 4-2Brisky Corporation had net sales of $2,400,000.docx
 
Briefly describe how the following tools can be Applied to a psychol.docx
Briefly describe how the following tools can be Applied to a psychol.docxBriefly describe how the following tools can be Applied to a psychol.docx
Briefly describe how the following tools can be Applied to a psychol.docx
 
Branding ConceptsBranding is one of the marketing-orig.docx
Branding ConceptsBranding is one of the marketing-orig.docxBranding ConceptsBranding is one of the marketing-orig.docx
Branding ConceptsBranding is one of the marketing-orig.docx
 
Briefly discuss the key phases of the SDLC methodology.Discuss the.docx
Briefly discuss the key phases of the SDLC methodology.Discuss the.docxBriefly discuss the key phases of the SDLC methodology.Discuss the.docx
Briefly discuss the key phases of the SDLC methodology.Discuss the.docx
 
Briefly describe a time when you received a job description and fe.docx
Briefly describe a time when you received a job description and fe.docxBriefly describe a time when you received a job description and fe.docx
Briefly describe a time when you received a job description and fe.docx
 
Briefly discuss the meaning of the so-called social contract. In.docx
Briefly discuss the meaning of the so-called social contract. In.docxBriefly discuss the meaning of the so-called social contract. In.docx
Briefly discuss the meaning of the so-called social contract. In.docx
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

square.cpp Open

  • 1. /////////////////////////////////// // square.cpp // // OpenGL program to draw a square. // // Sumanta Guha. /////////////////////////////////// #include <GL/freeglut.h> #include <cmath> #define PI 3.14 void drawDisc(float R, float X, float Y, float Z) { static int N = 100; // #vertices. float t = 0.0; glBegin(GL_LINE_LOOP);
  • 2. for (int i = 0; i <= N; ++i) { glVertex3f(X + R * cos(t), Y + R * sin(t), Z); t += 2 * PI / N; } glEnd(); } void drawDiamond() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); glVertex3f(50, 26, 0); glVertex3f(56, 20, 0); glVertex3f(50, 14, 0); glVertex3f(44, 20, 0); glEnd(); }
  • 3. void drawCoss() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); glVertex3f(73, 51, 0); glVertex3f(85, 51, 0); glVertex3f(85, 49, 0); glVertex3f(73, 49, 0); glEnd(); glBegin(GL_POLYGON); glVertex3f(78, 56, 0); glVertex3f(80, 56, 0); glVertex3f(80, 44, 0); glVertex3f(78, 44, 0); glEnd(); } void drawTriangle() {
  • 4. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); glVertex3f(50, 86, 0); glVertex3f(56, 74, 0); glVertex3f(44, 74, 0); glEnd(); } void drawArrow() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); glVertex3f(50, 68, 0); glVertex3f(44, 63, 0); glVertex3f(56, 63, 0); glEnd(); glBegin(GL_POLYGON); glVertex3f(46, 63, 0); glVertex3f(54, 63, 0);
  • 5. glVertex3f(54, 32, 0); glVertex3f(46, 32, 0); glEnd(); } void drawPiont(float R, float X, float Y, float Z) { static int N = 200; // #vertices. float t = 0.0; glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_TRIANGLE_FAN); glVertex3f(X, Y, 0); //center point for (int i = 0; i < N + 1; i++) { glVertex3f(X + R * cos(t), Y + R * sin(t), 0.0); t += 2 * PI / N; } glEnd(); }
  • 6. void drawStar() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_POLYGON); glVertex3f(15, 51, 0); glVertex3f(27, 51, 0); glVertex3f(21, 46, 0); glEnd(); glBegin(GL_POLYGON); glVertex3f(21, 56, 0); glVertex3f(21, 46, 0); glVertex3f(17, 44, 0); glEnd(); glBegin(GL_POLYGON); glVertex3f(21, 56, 0); glVertex3f(21, 46, 0); glVertex3f(25, 44, 0); glEnd();
  • 7. } // Drawing routine. void drawScene(void) { glClear(GL_COLOR_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glEnable(GL_DEPTH_TEST); glColor3ub(190, 190, 190); for (float i = 0; i < 400; i++) { float n = i * 0.01; drawDisc(42.0-n, 50.0, 50.0, 0.0); i += i * 0.01; }
  • 8. glColor3ub(225, 225, 0); drawDiamond(); glColor3ub(255, 0, 0); drawCoss(); glColor3ub(65, 105, 225); drawTriangle(); glColor3ub(205, 104, 57); drawArrow(); glColor3f(0, 0, 0); drawPiont(1, 50.0, 50.0, 0.0); glColor3ub(50, 205, 50); drawStar();
  • 9. //glDisable(GL_DEPTH_TEST); glFlush(); } // Initialization routine. void setup(void) { glClearColor(1.0, 1.0, 1.0, 0.0); } // OpenGL window reshape routine. void resize(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity();
  • 10. glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // Keyboard input processing routine. void keyInput(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } }
  • 11. // g++ -framework OpenGL -lGLUT -lGLEW -I /opt/X11/include -L /opt/X11/lib -w -o out squareEx.cpp int main(int argc, char** argv) { glutInit(&argc, argv); glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFIL E); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("square.cpp");