Introduction to OpenGL Introduction to OpenGL ► What is OpenGL? What is OpenGL? Computer-graphics API (application Computer-graphics API (application programming interface) programming interface) ► Efficient, streaming interface Efficient, streaming interface ► Hardware independent Hardware independent ► Operating system independent Operating system independent
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Introduction to OpenGLIntroduction to OpenGL
►What is OpenGL?What is OpenGL? Computer-graphics API (application Computer-graphics API (application
programming interface)programming interface)►Efficient, streaming interfaceEfficient, streaming interface►Hardware independentHardware independent►Operating system independentOperating system independent
Uses of OpenGLUses of OpenGL► CADCAD► LightingLighting► ShadingShading► Texture mappingTexture mapping► TransparencyTransparency► AnimationAnimation► Wire frame modelWire frame model► AntialiasingAntialiasing► ShadowingShadowing► Can work access a networkCan work access a network► Content creationContent creation► EntertainmentEntertainment► Game developmentGame development► ManufacturingManufacturing► MedicalMedical
How OpenGL works?How OpenGL works?
► OpenGL is a procedural rather than a OpenGL is a procedural rather than a descriptive graphics APIdescriptive graphics API
► Include more than 200 (250) commands and Include more than 200 (250) commands and functions by using which Open GL primitives( or functions by using which Open GL primitives( or graphic primitives) like points, lines, triangles graphic primitives) like points, lines, triangles and polygons in 2D and 3D can be drawnand polygons in 2D and 3D can be drawn
► It keep track of many state variables, such as It keep track of many state variables, such as the current size of a point, the current color of the current size of a point, the current color of drawing, the current background etcdrawing, the current background etc
► The value of the state variable remains active The value of the state variable remains active until a new value is givenuntil a new value is given
Software( or generic ) Software( or generic ) implementation of Open GLimplementation of Open GL
Application program
OSservices
I/Oservices
GDI OpenGL
Display/Windowing system Software Rasterizer
Hardware implementation of Hardware implementation of Open GLOpen GL
Application program
OSservices
I/Oservices
GDI OpenGL
Display/Windowing system Hardware Driver
PipelinePipeline
► It is used to describe a process that It is used to describe a process that can take two or more distinct stages or can take two or more distinct stages or stepssteps
►The OpenGL pipeline is the following The OpenGL pipeline is the following fig:fig:
OpenGL Data typesOpenGL Data types( ISO C implementations of open ( ISO C implementations of open
GL) GL) ►GLbyte-8 bit integer-signed char-bGLbyte-8 bit integer-signed char-b►GLshort-16 bit integer-short-sGLshort-16 bit integer-short-s►GLint-32 bit integer-long-lGLint-32 bit integer-long-l►GLfloat-32 bit floating point-float-fGLfloat-32 bit floating point-float-f►GLdouble-64 bit floating point-double-GLdouble-64 bit floating point-double-
dd►GLubyte,GLboolean-8 bit unsigned GLubyte,GLboolean-8 bit unsigned
glColor3f(0.0,0.0,0.0); displays black colorglColor3f(0.0,0.0,0.0); displays black color
glVertex2i(1,2); plot a point (1,2)glVertex2i(1,2); plot a point (1,2)
glBegin(GL_POINTS);glBegin(GL_POINTS);
glEnd();glEnd();
ColorColor
► Color Color values Displayed Command usedvalues Displayed Command used► 000 Black glColor3f(0.0,0.0,0.0)000 Black glColor3f(0.0,0.0,0.0)► 001 Blue glColor3f(0.0,0.0,1.0)001 Blue glColor3f(0.0,0.0,1.0)► 010 Green glColor3f(0.0,1.0,0.0)010 Green glColor3f(0.0,1.0,0.0)► 011 Cyan glColor3f(0.0,1.0,1.0)011 Cyan glColor3f(0.0,1.0,1.0)► 100 Red glColor3f(1.0,0.0,0.0)100 Red glColor3f(1.0,0.0,0.0)► 101 Magenta glColor3f(1.0,0.0,1.0)101 Magenta glColor3f(1.0,0.0,1.0)► 110 Yellow glColor3f(1.0,1.0,0.0) 110 Yellow glColor3f(1.0,1.0,0.0) ► 111 White glColor3f(1.0,1.0,1.0)111 White glColor3f(1.0,1.0,1.0)
►OpenGL primitives are described by OpenGL primitives are described by
glBegin() and glEnd() pairsglBegin() and glEnd() pairs
->gl Begin() marks the beginning of a vertex ->gl Begin() marks the beginning of a vertex data list that describes a geometric primitivedata list that describes a geometric primitive
->gl end() marks the end of a vertex data list->gl end() marks the end of a vertex data list
->The argument of the glBegin() may be the ->The argument of the glBegin() may be the following values( given in the next slide)following values( given in the next slide)
Cont.Cont.
► Value MeaningValue Meaning► GL_POINTS Individual pointsGL_POINTS Individual points► GL_LINES Pair of vertices interpreted as GL_LINES Pair of vertices interpreted as ► individual line segments individual line segments ► GL_LINE-STRIP Series of connected lineGL_LINE-STRIP Series of connected line► segmentssegments► GL_LINE_LOOP same as above, with a segmentGL_LINE_LOOP same as above, with a segment► added between between last andadded between between last and► first vertices first vertices ► GL_TRIANGLES Triples of vertices interpreted asGL_TRIANGLES Triples of vertices interpreted as► triangle triangle
Cont.Cont.
► Value MeaningValue Meaning► GL_TRIANGLE_STRIP Linked strip of triangleGL_TRIANGLE_STRIP Linked strip of triangle► GL_TRIANGLE_FAN Linked fan of trianglesGL_TRIANGLE_FAN Linked fan of triangles► GL_QUADS Quadruple of vertices GL_QUADS Quadruple of vertices ► interpreted as 4 sided polygonsinterpreted as 4 sided polygons► GL_QUAD_STRIP Linked strip of GL_QUAD_STRIP Linked strip of ► quadrilateralsquadrilaterals► GL_POLYGON Boundary of a simple , GL_POLYGON Boundary of a simple , ► convex polygonconvex polygon
► GLU (OpenGL Utility Library)GLU (OpenGL Utility Library) part of OpenGLpart of OpenGL NURBS, tessellators, quadric shapes, etc…NURBS, tessellators, quadric shapes, etc…
► GLUT (OpenGL Utility Toolkit)GLUT (OpenGL Utility Toolkit) portable windowing APIportable windowing API not officially part of OpenGLnot officially part of OpenGL
►Application StructureApplication Structure Configure and open windowConfigure and open window Initialize OpenGL stateInitialize OpenGL state Register input callback functionsRegister input callback functions
►renderrender►resizeresize►input: keyboard, mouse, etc.input: keyboard, mouse, etc.
Enter event processing loopEnter event processing loop
Header files available in a gl Header files available in a gl subdirectorysubdirectory
►Routine to call when something Routine to call when something happenshappens window resized, user input, window needs window resized, user input, window needs
drawing, etc…drawing, etc…►““Register” callbacks with GLUTRegister” callbacks with GLUT