0% found this document useful (0 votes)
95 views

7.module II OpenGL

OpenGL is a cross-language API for 3D graphics rendering. It allows creation of CAD models, lighting, shading, textures, transparency and animation. OpenGL uses a pipeline where commands are sent to the graphics card for hardware-accelerated rasterization and display. It includes functions for drawing basic geometric primitives like points, lines and polygons in 2D and 3D. Related libraries like GLUT provide windowing and input handling functionality.

Uploaded by

pradiptart
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

7.module II OpenGL

OpenGL is a cross-language API for 3D graphics rendering. It allows creation of CAD models, lighting, shading, textures, transparency and animation. OpenGL uses a pipeline where commands are sent to the graphics card for hardware-accelerated rasterization and display. It includes functions for drawing basic geometric primitives like points, lines and polygons in 2D and 3D. Related libraries like GLUT provide windowing and input handling functionality.

Uploaded by

pradiptart
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 28

Introduction to 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

Display/Windowing system Software Rasterizer


Hardware implementation of
Open GL

Application program

OS I/O OpenGL
GDI
services services

Display/Windowing system Hardware Driver


Pipeline
► Itis used to describe a process that can
take two or more distinct stages or steps
► The OpenGL pipeline is the following fig:

Transform and
lighting
Open Gl Frame buffer
Rasterization
command
buffer
OpenGL Command Formats

glVertex3fv( v )
Prefix
Initial capital letters

Number of Data Type Vector


components b - byte omit “v” for
ub - unsigned byte
2 - (x,y) scalar form
s - short
3 - (x,y,z)
us - unsigned short
4 - (x,y,z,w) glVertex2f( x, y )
i - int
ui - unsigned int
f - float
d - double
l -long
OpenGL Data types
( ISO C implementations of open GL)
► GLbyte-8 bit integer-signed char-b
► GLshort-16 bit integer-short-s
► GLint-32 bit integer-long-l
► GLfloat-32 bit floating point-float-f
► GLdouble-64 bit floating point-double-d
► GLubyte,GLboolean-8 bit unsigned integer-
unsigned char- ub
Open GL function
► Syntax:
<Library prefix> <Root command> <optional argument count><optional argument type>;

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

glEnd(); Order: 2n-1, 2n, 2n+2, 2n+1


OpenGL-Related Libraries

► GLU (OpenGL Utility Library)


 part of OpenGL
 NURBS, tessellators, quadric shapes, etc…
► GLUT (OpenGL Utility Toolkit)
 portable windowing API
 not officially part of OpenGL
GLUT: OpenGL Utility Toolkit
► Application Structure
 Configure and open window
 Initialize OpenGL state
 Register input callback functions
►render
►resize
►input: keyboard, mouse, etc.
 Enter event processing loop
Header files available in a gl
subdirectory
► #include<gl/gl.h>
► #include<gl/glu.h>
► #include<gl/glut.h>
► #include<windows.h>
GLUT Callback Functions
► Routine to call when something happens
 window resized, user input, window needs
drawing, etc…
► “Register” callbacks with GLUT
glutDisplayFunc( display );
glutIdleFunc( idle );
glutKeyboardFunc( keyboard );
glutMouseFunc( mouse );

You might also like