Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.

Similar presentations


Presentation on theme: "Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave."— Presentation transcript:

1

2 Geometric Primitives Used in Open GL

3 Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave.

4 Examples of polygons

5 The Gl_POLYGON Argument The Gl_POLYGON argument : draw close convex polygon which has n points and n>=3. To draw a graphic with internal angles greater than 180 degree: we need to separate it to many convex polygons.

6 Drawing Polygon glBegin(GL_POLYGON); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glVertex2i(p5); glVertex2i(p6); glVertex2i(p7); glEnd( ); There are one glBegin () arguments to draw polygons:

7 Graphic with Internal Angles Greater than 180 Internal Angels Bigger Than 180

8 Graphic with Internal Angles Greater than 180,Cont.

9 Example Tree Polygons #include void myInit(void); void myDisplay(void); void main(int argc,char** argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(200,200); glutInitWindowPosition(100,100); glutCreateWindow(”Tree"); glutDisplayFunc(myDisplay); myInit(); glutMainLoop(); } void myInit(void) { glClearColor(1.0,1.0,1.0,1.0); gluOrtho2D(0,600,0,600); } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); دالة رسم المضلع ويمثل رأس الشجرة الأخضر // glColor3f(0.0,0.5,0.2) glBegin(GL_POLYGON); glVertex2i(40,80); glVertex2i(60,80); glVertex2i(80,60); glVertex2i(60,40); glVertex2i(40,40); glVertex2i(20,60); glEnd(); دالة رسم المضلع وهو جذع الشجرة البني // glColor3f(0.3,0.2,0.2) glBegin(GL_POLYGON); glVertex2i(60,40); glVertex2i(40,40); glVertex2i(40,10); glVertex2i(60,10); glEnd(); glFlush(); }

10 Output Tree Polygons

11 Just take the code of first program, e.g.code of Drawing Point

12 #include void myInit(void); void myDisplay(void); void main(int argc,char** argv) { glutInit(&argc,argv); //argc= arg count, specifies no. of arguments //argv= arg values, specifies values of those arguments glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600,600); glutInitWindowPosition(100,100); glutCreateWindow("My first program"); glutDisplayFunc(myDisplay); myInit(); glutMainLoop(); } void myInit(void) { glClearColor(1.0,1.0,1.0,1.0); glColor3f(0.0,0.0, 0.0); glPointSize(50.0); gluOrtho2D(0,600,0,600); } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2i(300,300); glEnd(); glFlush(); }

13 We just modify a little in a function: void myInit(void)

14 Code for point void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2i(300,300); glEnd(); glFlush(); } Code for simple triangle void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex2i(0,0); glVertex2i(300,600); glVertex2i(600,0); glEnd(); glFlush(); } Code for drawing a pointCode for simple triangle void myInit(void) { glClearColor(1.0,1.0,1.0, 1.0); glColor3f(0.0,0.0, 0.0); glPointSize(50); gluOrtho2D(0,600,0,600); } void myInit(void) { glClearColor(1.0,1.0,1.0, 1.0); glColor3f(0.0,0.0, 0.0); nothing gluOrtho2D(0,600,0,600); }

15 Code for point void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POINTS); glVertex2i(300,300); glEnd(); glFlush(); } Code for simple triangle void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex2i(0,0); glVertex2i(300,600); glVertex2i(600,0); glEnd(); glFlush(); } Code for drawing a pointCode for simple line void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT) ; glBegin(GL_POINTS); glVertex2i(300,300); glEnd(); glFlush(); } void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT) ; glBegin(GL_POLYGON); glVertex2i(P1); : glVertex2i(Pn); glEnd(); glFlush(); }

16 Geometric Primitives Used in Open GL, Cont.

17 Geometric Primitives Used in Open GL Summery

18 The End


Download ppt "Geometric Primitives Used in Open GL Polygons Polygon is : Flat shape with three or more straight sides. It could be either : convex or concave."

Similar presentations


Ads by Google