geometric primitives used in open gl drawing triangles glbegin(gl_triangels); glvertex2i(p0);...

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

If you can't read please download the document

Upload: liliana-grant

Post on 17-Jan-2018

219 views

Category:

Documents


0 download

DESCRIPTION

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

TRANSCRIPT

Geometric Primitives Used in Open GL 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 Drawing Triangles 1.GL_TRIANGELS 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 Drawing Triangles 2.GL_TRIANGEL_STRIP 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. Drawing Triangles 3.GL_TRIANGEL_FAN 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. 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 Drawing Quads 1.GL_QUADS 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 Drawing Quads 2.GL_QUADS_STRIP Drawing Rectangle with the method GL_Rect*( ) Drawing Rectangle with GL_Rect*( ) Just take the code of first program, e.g.code of Drawing Point #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(); } We just modify a little in a function: void myInit(void) 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); } 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(); } Geometric Primitives Used in Open GL Geometric Primitives Used in Open GL, Cont. Geometric Primitives Used in Open GL Summery The End