Mod 1
Mod 1
Output device
Input devices
Image formed in FB
• Wireframe graphics
Draw only lines
• Sketchpad
• Display Processors
• Storage tube
wireframe representation
of sun object
• Created by Tektronix
Did not require constant refresh
Standard interface to computers
• Allowed for standard software
• Plot3D in Fortran
Relatively inexpensive
• Opened door to use of computer graphics for CAD
community
• Raster Graphics
• Beginning of graphics standards
IFIPS
• GKS: European effort
– Becomes ISO 2D standard
• Core: North American effort
– 3D but fails to become ISO standard
• Workstations and PCs
• OpenGL API
• Completely computer-generated feature-
length movies (Toy Story) are successful
• New hardware capabilities
Texture mapping
Blending
Accumulation, stencil buffers
• Photorealism
• Graphics cards for PCs dominate market
Nvidia, ATI
• Game boxes and game players determine
direction of market
• Computer graphics routine in movie
industry: Maya, Lightwave
• Programmable pipelines
• Objects
• Viewer
• Light source(s)
projector
p
image plane
projection of p
center of projection
application program
OpenGL Motif
widget or similar GLUT
GLX, AGL
or WGL GLU
function name
dimensions
glVertex3f(x,y,z)
glVertex3fv(p)
p is a pointer to an array
• Unix/linux
Include files usually in …/include/GL
Compile with –lglut –lglu –lgl loader flags
May have to add –L flag for X libraries
Mesa implementation included with most linux
distributions
Check web for latest versions of Mesa and glut
• Visual C++
Get glut.h, glut32.lib and glut32.dll from web
Create a console application
Add opengl32.lib, glut32.lib, glut32.lib to project
settings (under link tab)
• Borland C similar
• Cygwin (linux under Windows)
Can use gcc and similar makefile to linux
Use –lopengl32 –lglu32 –lglut32 flags
enter event
loop
GLUT functions
black clear
color
void init() opaque
{ window
glClearColor (0.0, 0.0, 0.0, 1.0);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
viewing volume
Programming with OpenGL
Part 2: Complete Programs
• Simple viewing
Two-dimensional viewing as a special case of
three-dimensional viewing
• Fundamental OpenGL primitives
• Attributes
z=0
z=0
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
GL_POINTS GL_POLYGON
GL_LINES GL_LINE_STRIP
GL_LINE_LOOP
GL_TRIANGLES
GL_QUAD_STRIP
GL_TRIANGLE_STRIP GL_TRIANGLE_FAN
nonconvex polygon
nonsimple polygon
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 6
7
Attributes
• Repeat
• Five subdivisions
/* initial triangle */
after 5 iterations
Eg :
glutBitmapCharacter(GLUT_BITMAP_8_BY_13,c)
mouse trackball
light pen
void mykey()
{
if(key == ‘Q’ | key == ‘q’)
exit(0);
}
Special and Modifier Keys
original
reshaped
The Reshape callback
glutReshapeFunc(myreshape)
void myreshape( int w, int h)
• Returns width and height of new window (in
pixels)
• A redisplay is posted automatically at end of
execution of the callback
• GLUT has a default reshape callback but you
probably want to define your own
• The reshape callback is good place to put
viewing functions because it is invoked
when the window is first opened
Viewports
• Do not have use the entire window for the
image: glViewport(x,y,w,h)
• Values in pixels (screen coordinates)
Menus
gluAddMenuEntry(“exit”, 2);
clear screen
glutAttachMenu(GLUT_RIGHT_BUTTON);
exit