Presentation is loading. Please wait.

Presentation is loading. Please wait.

Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);

Similar presentations


Presentation on theme: "Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);"— Presentation transcript:

1

2 Geometric Primitives Used in Open GL

3 Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glVertex2i(p5); glEnd( ); There are three glBegin () arguments to draw triangles: 1

4 Drawing Triangles 1.GL_TRIANGELS

5 Drawing Triangles 2.GL_TRIANGEL_STRIP 2 glBegin(GL_TRIANGEL_ST RIP); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glVertex2i(p5); glEnd( );  Last two points(vertices) in the first triangle are the first two points (vertices) in the second and it keep going like this.  If n : number of points, the number of triangles is : n-2

6 Drawing Triangles 2.GL_TRIANGEL_STRIP

7 Drawing Triangles 3.GL_TRIANGEL_FAN 3 glBegin(GL_TRIANGEL_FAN); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glEnd( );  All the triangles have the same beginning point( vertices)  The second triangle got from the first triangle the beginning and end points and match it with the following new point (vertices) and it keep going like this.

8 Drawing Triangles 3.GL_TRIANGEL_FAN

9 Drawing Quadrilateral Quadrilateral just means "four sides" (quad means four, lateral means side). Any four-sided shape is a Quadrilateral. But the sides have to be straight, and it has to be 2-dimensional.

10 Drawing Quads 1 glBegin(GL_Quads); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glVertex2i(p5); glVertex2i(p6); glVertex2i(p7); glEnd( ); There are two glBegin () arguments to draw quads: If n : number of points (vertices), the number of quads drawn with this argumenta is : n /4

11 Drawing Quads 1.GL_QUADS

12 Drawing Quads 2.GL_QUADS_STRIP 1 glBegin(GL_Quads_STRIP); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4); glVertex2i(p5); glVertex2i(p6); glVertex2i(p7); glEnd( );  The last two points (vertices) in the first quads are the first two points in the second quads and it keep going like this.  If n : number of points (vertices), the number of quads drawn with this argumenta is : (n /2)-1

13 Drawing Quads 2.GL_QUADS_STRIP

14 Drawing Rectangle with the method GL_Rect*( )

15 Drawing Rectangle with GL_Rect*( )

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

17 #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(); }

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

19 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); }

20 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( …………………. ); glVertex2i(P1); : glVertex2i(Pn); glEnd(); glFlush(); }

21 Geometric Primitives Used in Open GL

22 Geometric Primitives Used in Open GL, Cont.

23 Geometric Primitives Used in Open GL Summery

24 The End


Download ppt "Geometric Primitives Used in Open GL Drawing Triangles glBegin(GL_TRIANGELS); glVertex2i(p0); glVertex2i(p1); glVertex2i(p2); glVertex2i(p3); glVertex2i(p4);"

Similar presentations


Ads by Google