Presentation is loading. Please wait.

Presentation is loading. Please wait.

OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.

Similar presentations


Presentation on theme: "OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects."— Presentation transcript:

1 OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.

2 OpenGL ● OpenGL – Hardware independent, only specifies graphics output low level, no GUI operations (events, windows, menu’s) ●OpenGL Utility (GLU) – Higher level graphics primitives (spheres, curves, curved surfaces) ●OpenGL Utility Toolkit (GLUT) – Primitive window setup & event handling. enables truly window system independent applications

3 OpenGL Basic Syntax (C Language Binding) ●Functions: glXXXX – glBegin, glEnd, glPolygonMode ●Constants: GL_XXXX – GL_2D, GL_RGB, GL_CCW ●Types: GLxxx – GLbyte, GLshort, GLint, GLfloat, GLdouble, GLboolean

4 OpenGL Header Files #include However, If using GLUT to handle window- managing operations #include

5 Display-Window Management Using GLUT Step1 : GLUT Initialization glut Init (&argc, argv); Step2 : Display window is created on the screen with the function glutCreateWindow ( “ An Example OpenGL Program”); Other functions such as : glutDisplayFunc ( lineSegment); //displaying any object glutInitWindowPosition (50, 100); // set the position of window

6 Display-Window Management Using GLUT.. glutInitWindowSize (400, 300); //set the size of the window glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); //options for buffering and color modes Final Step : All display windows are activated and displayed glutMainLoop ( ); This function completes the window- processing operations.

7 OpenGL Program Example #include void init (void) { glClearColor (1.0, 1.0, 1.0, 0.0); //Set Display-window color to white glMatrixMode (GL_PROJECTION); // Set projection parameters gluOrtho2D (0.0, 200.0, 0.0, 150.0); }

8 Continued.. void lineSegment (void) { glClear (GL_COLOR_BUFFER_BIT); // Clear display window glColor3f (1.0, 0.0, 0.0); //Set line segment color to red glBegin (GL_LINES); glVertex2i (180, 15); //Specify line- segment geometry glVertex2i (10, 145); glEnd (); glFlush (); // Process all OpenGL routines as quickly as possible }

9 Continued.. void main (int argc, char** argv) { glutInit (&argc, argv);// Initialize GLUT glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Set display mode glutInitWindowPosition (50, 100); //Set top-left display-window position glutInitWindowSize (400,300); //Set display-window width and height

10 Continued.. glutCreateWindow ("An Example OpenGL Program");// Create display window init (); // Execute initialization procedure glutDisplayFunc (lineSegment); // Send graphics to display window glutMainLoop (); }

11 OpenGL Geometric Output Primitives ●Types: GL_POINTS, GL_LINES, GL_LINE_LOOP, GL_LINE_STRIP, GL_POLYGON, GL_QUADS, GL_QUAD_STRIP, GL_TRIANGLE, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN ●Basic Syntax: glBegin (PrimitiveConstant); glVertex3f (x1,y1,z1) glVertex3f (x2,y2,z2) …. glEnd(); glVertex(2|3|4)(s|i|d|f)[v]

12 Points & Lines v0 v1 v2 v3 glBegin (PrimitiveConstant); glVertex3f (x1,y1,z1) glVertex3f (x2,y2,z2) …. glEnd(); v0 v1 v2 v3 v4 v5 GL_POINTS GL_LINES GL_LINE_STRIP v0 v1 v2 v3 v4 GL_LINE_LOOP

13 Polygons glBegin (PrimitiveConstant); glVertex3f (x1,y1,z1) glVertex3f (x2,y2,z2) …. glEnd(); GL_POLYGON v0 v1 v2 v3 v4 v0 v1 v2 v3 v4 v5 v6 v7 GL_QUADS v0 v1 v2 v3 v4 v5 v6 v7 GL_QUAD_STRIP

14 Polygons (2) glBegin (PrimitiveConstant); glVertex3f (x1,y1,z1) glVertex3f (x2,y2,z2) …. glEnd(); v0 v1 v2 v3 v4 v5 GL_TRIANGLES GL_TRIANGLE_STRIP v0 v1 v2 v3 v4 v5 GL_TRIANGLE_FAN v0 v1 v2 v3 v4 v5 N vertices N/3 Triangles N+2 vertices N Triangles N+2 vertices N Triangles

15 References Computer Graphics with OpenGL :H & B RedBook : www.opengl.orgwww.opengl.org Tutorials : www.nehe.gamedev.netwww.nehe.gamedev.net ITCS 4120 class notes


Download ppt "OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects."

Similar presentations


Ads by Google