7.module II OpenGL
7.module II OpenGL
► What is OpenGL?
Computer-graphics API (application
programming interface)
►Efficient,
streaming interface
►Hardware independent
►Operating system independent
► CAD Uses of OpenGL
► Lighting
► Shading
► Texture mapping
► Transparency
► Animation
► Wire frame model
► Antialiasing
► Shadowing
► Can work access a network
► Content creation
► Entertainment
► Game development
► Manufacturing
► Medical
How OpenGL works?
► OpenGL is a procedural rather than a descriptive
graphics API
► Include more than 200 (250) commands and
functions by using which Open GL primitives( or
graphic primitives) like points, lines, triangles and
polygons in 2D and 3D can be drawn
► It keep track of many state variables, such as the
current size of a point, the current color of drawing,
the current background etc
► The value of the state variable remains active until
a new value is given
Software( or generic )
implementation of Open GL
Application program
OS I/O OpenGL
GDI
services services
Application program
OS I/O OpenGL
GDI
services services
Transform and
lighting
Open Gl Frame buffer
Rasterization
command
buffer
OpenGL Command Formats
glVertex3fv( v )
Prefix
Initial capital letters
Examples:
glColor3f(0.0,0.0,0.0); displays black color
glVertex2i(1,2); plot a point (1,2)
glBegin(GL_POINTS);
glEnd();
Color
► Color
values Displayed Command used
► 000 Black glColor3f(0.0,0.0,0.0)
► 001 Blue glColor3f(0.0,0.0,1.0)
► 010 Green glColor3f(0.0,1.0,0.0)
► 011 Cyan glColor3f(0.0,1.0,1.0)
► 100 Red glColor3f(1.0,0.0,0.0)
► 101 Magenta glColor3f(1.0,0.0,1.0)
► 110 Yellow glColor3f(1.0,1.0,0.0)
► 111 White glColor3f(1.0,1.0,1.0)
OpenGL Geometric Primitives
► Allgeometric primitives are specified by
vertices
GL_LINES
GL_POINTS GL_POLYGON
GL_LINE_STRIP GL_LINE_LOOP
GL_TRIANGLES
GL_TRIANGLE_STRIP GL_QUADS GL_QUAD_STRIP
GL_TRIANGLE_FAN
Cont.
► OpenGL primitives are described by
glBegin() and glEnd() pairs
->gl Begin() marks the beginning of a vertex
data list that describes a geometric primitive
->gl end() marks the end of a vertex data list
->The argument of the glBegin() may be the
following values( given in the next slide)
Cont.
► Value Meaning
► GL_POINTS Individual points
► GL_LINES Pair of vertices interpreted as
► individual line segments
► GL_LINE-STRIP Series of connected line
► segments
► GL_LINE_LOOP same as above, with a segment
► added between between last and
► first vertices
► GL_TRIANGLES Triples of vertices interpreted as
► triangle
Cont.
► Value Meaning
► GL_TRIANGLE_STRIP Linked strip of triangle
► GL_TRIANGLE_FAN Linked fan of triangles
► GL_QUADS Quadruple of vertices
► interpreted as 4 sided polygons
► GL_QUAD_STRIP Linked strip of
► quadrilaterals
► GL_POLYGON Boundary of a simple ,
► convex polygon
OpenGL Drawing Functions
glBegin (GL_POINTS);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_LINES);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_LINE_STRIP);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_LINE_LOOP);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_POLYGON);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_TRIANGLES);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p4); P1 P4
glVertex2iv (p5);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_TRIANGLES_STRIP);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p6);
glVertex2iv (p3);
glVertex2iv (p5); P1 P4
glVertex2iv (p4);
glEnd();
P2 P3
If N is odd, order: n, n+1, n+2
If N is even, order: n+1, n, n+2
OpenGL Drawing Functions
glBegin (GL_TRIANGLES_FAN);
glVertex2iv (p1);
P6 P5
glVertex2iv (p2);
glVertex2iv (p3);
glVertex2iv (p4);
glVertex2iv (p5); P1 P4
glVertex2iv (p6);
glEnd();
P2 P3
OpenGL Drawing Functions
glBegin (GL_QUADS);
glVertex2iv (p1); P8
glVertex2iv (p2);
P1
glVertex2iv (p3); P4 P5
glVertex2iv (p4);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p7);
glVertex2iv (p8); P2 P6
P3 P7
glEnd();
OpenGL Drawing Functions
glBegin (GL_QUADS_STRIP);
glVertex2iv (p1); P8
glVertex2iv (p2);
P1
glVertex2iv (p4); P4 P5
glVertex2iv (p3);
glVertex2iv (p5);
glVertex2iv (p6);
glVertex2iv (p8);
glVertex2iv (p7); P2 P6
P3 P7