Unit I: Raphics Primitives and Scan Conversion Algorithm
Unit I: Raphics Primitives and Scan Conversion Algorithm
Moveto(100,50) - device/lib 2
Lineto(150,100)
(150, 100)
Commands may either be accumulated in display lists, or processed immediately
through the pipeline. Display lists allow for greater optimization and command
reuse, but not all commands can be put in display lists.
The first stage in the pipeline is the evaluator. This stage effectively takes any
polynomial evaluator commands and evaluates them into their corresponding vertex
and attribute commands.
The third stage is rasterization. This stage produces fragments, which are series
of framebuffer addresses and values, from the viewport-mapped primitives as well
as bitmaps and pixel rectangles.
Parts of the framebuffer may be fed back into the pipeline as pixel rectangles.
Texture memory may be used in the rasterization process when texture mapping is
enabled.
OpenGL Basics
• OpenGL’s primary function –
Rendering
• Rendering? – converting
geometric/mathematical object descriptions
into frame buffer values
• OpenGL can render:
– Geometric primitives
• Lines, points, polygons, etc…
– Bitmaps and Images
• Images and geometry linked through
texture mapping
OpenGL Geometric Primitives
• The geometry is specified by vertices.
• The primitive types:
OpenGL Command Format
glVertex3fv
Vertices and Primitives
• Primitives are specified using
glBegin( primType );
…
glEnd();
glBegin(GL_POINTS);
glColor3fv( color );
glVertex2f( P0.x, P0.y );
glVertex2f( P1.x, P1.y );
glVertex2f( P2.x, P2.y );
glVertex2f( P3.x, P3.y );
glVertex2f( P4.x, P4.y );
glVertex2f( P5.x, P5.y );
glVertex2f( P6.x, P6.y );
glVertex2f( P7.x, P7.y );
glEnd();
Vertices and Primitives
• Lines, GL_LINES
– Pairs of vertices interpreted as individual line segments
– Can specify line width using:
• glLineWidth (float width)
glBegin(GL_LINES);
glColor3fv( color );
glVertex2f( P0.x, P0.y );
glVertex2f( P1.x, P1.y );
glVertex2f( P2.x, P2.y );
glVertex2f( P3.x, P3.y );
glVertex2f( P4.x, P4.y );
glVertex2f( P5.x, P5.y );
glVertex2f( P6.x, P6.y );
glVertex2f( P7.x, P7.y );
glEnd();
Vertices and Primitives
• Line Strip, GL_LINE_STRIP
– series of connected line segments
Vertices and Primitives
• Line Loop, GL_LINE_LOOP
– Line strip with a segment added between last and first
vertices
Vertices and Primitives
• Polygon , GL_POLYGON
– boundary of a simple, convex polygon
Vertices and Primitives
• Triangles , GL_TRIANGLES
– triples of vertices interpreted as triangles
Vertices and Primitives
• Triangle Strip , GL_TRIANGLE_STRIP
– linked strip of triangles
v0 v1
v2 v3
v4 v5
v7
v6
Vertices and Primitives
• Triangle Fan ,
GL_TRIANGLE_FAN
– linked fan of triangles
v1 v2
v3
v4
v0
v5
Vertices and Primitives
• Quads , GL_QUADS
– quadruples of vertices interpreted as four-sided polygons
Vertices and Primitives
H&B 5-1:130
Attributes 2
Example:
glLineWidth(width);
glEnable(GL_LINE_STIPPLE);
glLineStipple(repeatfactor, pattern);
// draw stippled lines
...
glDisable(GL_LINE_STIPPLE);
H&B 5-7:141-143
Color 1
RGB mode :
• color = (red, green, blue)
• glColor[34][bisf]: set color of vertex
• For example:
– glColor4f(red, green, blue, alpha)
– alpha: opacity (1−transparantie)
H&B 5-2:130-131
Use GLUT (OpenGL Utility Toolkit)
• For fast prototyping, we can use GLUT to interface
with different window systems
#include <GL/glut.h>
#include <GL/gl.h>
Keyboar
Event queue d ….
MainLoop( Mouse
)
Window