Escolar Documentos
Profissional Documentos
Cultura Documentos
Advantages
May be coded in small programs, saves space
Disadvantages
Limited flexibility for use, as only attributes can be used as
control parameters
Elementary Drawing Tools
moveto(1,1) 2
lineto(2,1)
lineto(2,2) 1
lineto(1,2)
lineto(1,1)
moveto(0,0) (0,0) 1 2
Elementary Drawing Tools
Disadvantages
“Pixelation”
Pixels are too large to represent the smallest features
in the image
Curves are represented as jagged, discontinuous
lines
Questions?
So, what do we need to start drawing?
Application Graphics
Hardware
Program Library (API)
Graphics Architectures: Pipeline
Display process
Refresh the display continuously
INPUT OUTPUT
Instruction Instruction Instruction
(3D geometry) 1 2 3 (pixels)
Device Independent Programming
When the same code can be compiled and run on a
variety of graphics environments and produce nearly
identical graphical output
Porting is now simply installing appropriate libraries on a new
machine
Event-driven program
Programmer writes callback functions, to be executed
(called) when a certain event occurs
Upon completion, application resumes where it left off
Event-Driven Programming
This is how OpenGL functions
init_function(…) {…}
display_callback(…) {
// Drawing happens here
}
keyboard_callback(…) {…}
other_callback(…) {…}
main(…) {
init_function(…)
// Register callbacks
main_loop()
}
Initialization
(0,479)
Name
(0,0) (639,0)
x
Basic Graphic Primitives in OpenGL
Recall graphic primitives
Points, lines, polylines, polygons…
Most of these are defined by vertices (corners)
glVertex2i(…)
type of
argument
gl
basic number of
library
command arguments
OpenGL Data Types
Specific data types defined for internal OpenGL functions
Variations in data types exist between systems
e.g. 16 bit or 32 bit integers
e.g. no standard size for float or double
…
Line Drawings
Simple OpenGL constant
glBegin(GL_LINES);
glVertex2i(40, 100);
glVertex2i(200, 97);
glEnd();
glBegin(GL_LINES);
glVertex2i( 10, 20 ); // first line
glVertex2i( 40, 20 ); // first line
glVertex2i( 20, 10 ); // second line
glVertex2i( 20, 40 ); // second line
glEnd();
glBegin(GL_LINE_STRIP);
glVertex2i( 20, 10 );
glVertex2i( 50, 10 ); GL_LINE_STRIP
glVertex2i( 20, 80 );
glVertex2i( 50, 80 );
glEnd();
glFlush();
GL_QUADS
Takes vertices 4 at a time,
counterclockwise
GL_TRIANGLE_STRIP
Draws triangles based on triplets of
vertices
v0, v1, v2; v2, v1, v3; v2, v3, v4; …
All traversed in same order
(counterclockwise)
GL_QUAD_STRIP
Draws quads based on
foursomes of vertices
v0, v1, v3, v2; v2, v3, v5, v4;
v4, v5, v7, v6; …
All traversed in same order
(counterclockwise)
Questions?
In-Class Exercise