1 / 15

OpenGL (Graphics Library)

OpenGL (Graphics Library). Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects. OpenGL. ● OpenGL – Hardware independent, only specifies graphics output low level, no GUI operations (events, windows, menu’s)

calla
Download Presentation

OpenGL (Graphics Library)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 <windows.h> #include <GL/gl.h> #include <GL/glu.h> However, If using GLUT to handle window- managing operations #include <GL/glut.h>

  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 • 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 <GL/glut.h> 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 GL_LINE_STRIP GL_LINES v1 GL_POINTS v0 v1 v2 v3 v0 v5 v2 v3 v4 v1 GL_LINE_LOOP v0 v2 v3 v4 glBegin (PrimitiveConstant); glVertex3f (x1,y1,z1) glVertex3f (x2,y2,z2) …. glEnd();

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

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

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

More Related