100% found this document useful (2 votes)
1K views26 pages

Computer Science Is No More About Computers Than Astronomy Is About Telescopes

The document provides information on the required files and libraries for OpenGL programs on Windows systems. It lists the necessary .dll, .lib, and header files that must be included for OpenGL, GLU, GLUT, and GLX functionality. It also gives a brief overview of the basic event loop structure for OpenGL programs.

Uploaded by

hemsr
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
100% found this document useful (2 votes)
1K views26 pages

Computer Science Is No More About Computers Than Astronomy Is About Telescopes

The document provides information on the required files and libraries for OpenGL programs on Windows systems. It lists the necessary .dll, .lib, and header files that must be included for OpenGL, GLU, GLUT, and GLX functionality. It also gives a brief overview of the basic event loop structure for OpenGL programs.

Uploaded by

hemsr
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/ 26

“Computer Science is no

more about computers


than astronomy is about
telescopes.”
Professor Edsger Dijkstra
OpenGL
Notes
&
Guides
Required files for Windows

• In the System Directory


– glu32.dll
– opengl32.dll
– glut32.dll
• In the C++ Include Directory
– gl\gl.h
– l\glu.h
– gl\glaux.h (probably won't need it)
– gl\glut.h (includes both gl.h and glu.h)
• In the C++ Library Directory
– gl\glu32.lib
– l\opengl32.lib
– gl\glaux.lib (probably won't need it)
– gl\glut32.lib
OpenGL Libraries

OpenGL
Application

GLU GL GLUT GLX

Frame Buffer

Display
Event Loop
• OpenGL programs often run in an event loop:
– Start the program
– Run some initialization code
– Run an infinite loop and wait for events such as
• Key press
• Mouse move, click
• Reshape window
• Expose event
OpenGL Command Syntax (1)
• OpenGL commands start with “gl”
• OpenGL constants start with “GL_”
• Some commands end in a number and one, two or three letters
at the end (indicating number and type of arguments)
• A Number indicates number of arguments
• Characters indicate type of argument
OpenGL Command Syntax (2)
– `f' float
– `d' double float
– `s' signed short integer
– `i' signed integer
– `b' character
– `ub' unsigned character
– `us' unsigned short integer
– `ui' unsigned integer
OpenGL Command Syntax (3)
• “v” at the end of the name indicates a vector format.
Examples: glColor*()
• glColor3b, glColor3d, glColor3f, glColor3i, glColor3s,
glColor3ub, glColor3ui, glColor3us, glColor4b, glColor4d,
glColor4f, glColor4i, glColor4s, glColor4ub, glColor4ui,
glColor4us, glColor3bv, glColor3dv, glColor3fv,
glColor3iv, glColor3sv, glColor3ubv, glColor3uiv,
glColor3usv, glColor4bv, glColor4dv, glColor4fv,
glColor4iv, glColor4sv, glColor4ubv, glColor4uiv,
glColor4usv
OpenGL Primitives
• GL_POINTS
• GL_LINES
• GL_LINE_STRIP
• GL_LINE_LOOP
• GL_TRIANGLES
• GL_TRIANGLE_STRIP
• GL_TRIANGLE_FAN
• GL_QUADS
• GL_QUAD_STRIP
• GL_POLYGON
Scene Graph

Ground
T1

Body

T2 T3 T4

Head Left Arm Right Arm


OpenGL Program Organization
• main:
– find GL visual and create window
– initialize GL states (e.g. viewing, color, lighting)
– initialize display lists
– loop
• check for events (and process them)
• if window event (window moved, exposed, etc.)
• modify viewport, if needed
• redraw
• else if mouse or keyboard
• do something, e.g., change states and redraw
• redraw:
– clear screen (to background color)
– change state(s), if needed
– render some graphics
– change more states
– render some more graphics
– .
– .
– .
– swap buffers
glMatrixMode
• glMatrixMode
– - specify which matrix is the current matrix
• C Specification
– void glMatrixMode( GLenum mode )
• Parameters
– mode Specifies which matrix stack is the target for subsequent matrix operations. Three values are
accepted: GL_MODELVIEW, GL_PROJECTION, and GL_TEXTURE. The default value is
GL_MODELVIEW.
• Description
– glMatrixMode sets the current matrix mode. mode can assume one of three values:
GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix stack.
GL_PROJECTION Applies subsequent matrix operations to the projection matrix stack.
Viewing Pipeline
General 3D Viewing Pipeline

• Modeling coordinates (MC)


• World coordinates (WC)
• Viewing coordinates (VC)
• Projection coordinates (PC)
• Normalized coordinates (NC)
• Device coordinates (DC)
Virtual Camera Model
• Viewing Transformation
– The camera position and orientation is determined
• Projection Transformation
– The selected view of a 3D scene is projected onto a view plane
Viewing-Coordinate Parameters
• Look-at point Pref

N = P0 − Pref

• View-up vector V
– N and V are specified in the world coordinates
Viewing-Coordinate Reference Frame
• The camera orientation is determined by the uvn reference
frame

N
n= = (nx , n y , nz )
N
V ×n
u= = (u x , u y , u z )
V u
v
n
v = n × u = (v x , v y , v z )
World-to-Viewing Transformation

u x uy uz 0 1 0 0 − x0 
v vy vz 0 0 1 0 − y0 
R= x T=
nx ny nz 0 0 0 1 − z0 
   
0 0 0 1 0 0 0 1 

u x uy uz − u ⋅ P0 
v vy vz − v ⋅ P0 
M wc ,vc = R ⋅T =  x
n x ny nz − n ⋅ P0 
 
0 0 0 1 
Perspective-Projection View Volume
• Viewing frustum
– Why do we need near and far clipping plane ?
Normalizing Transformation
• Transform an arbitrary perspective-projection view volume
into the canonical view volume

• Step 1: from frustum to parallelepiped


Normalizing Transformation
• Transform an arbitrary perspective-projection view volume
into the canonical view volume

• Step 2: from parallelepiped to normalized


Orthographic Transformation
• Preserves relative dimension
• The center of projection at infinity
• The direction of projection is parallel to a principle axis
• Architectural and engineering drawings
OpenGL 3D Viewing Functions
• Viewing-transformation function
– glMatrixMode(GL_MODELVIEW);
– gluLookAt(x0,y0,z0,xref,yref,zref,vx,vy,vz);
– Default: gluLookAt(0,0,0, 0,0,-1, 0,1,0);

• OpenGL orthogonal-projection function


– glMatrixMode(GL_PROJECTION);
– gluOrtho(xwmin,xwmax, ywmin,ywmax, dnear,dfar);
– Default: gluOrtho(-1,1, -1,1, -1,1);
– Note that
• dnear and dfar must be assigned positive values
• znear=-dnear and zfar=-dfar
• The near clipping plane is the view plane
glViewport
• C Specification
– void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
• Parameters
– x, y: Specify the lower left corner of the viewport rectangle, in pixels. The
initial value is (0, 0).
– width, height: Specify the width and height of the viewport. When a GL
context is first attached to a surface (e.g. window), width and height are set
to the dimensions of that surface.
• glViewport specifies the affine transformation of x and y from
normalized device coordinates to window coordinates. Let (xnd, ynd) be
normalized device coordinates. Then the window coordinates (xw, yw)
are computed as follows:
width
xw = ( xnd + 1) * +x
2
height
y w = ( ynd + 1) * +y
2
OpenGL 3D Viewing Functions
• OpenGL perspective-projection function
– The projection reference point is the viewing-coordinate origin
– The near clipping plane is the view plane
– Symmetric: gluPerspective(theta,aspect,dnear,dfar)
– General: glFrustum(xwmin,xwmax,ywmin,ywmax,dnear,dfar)
glFrustum
• glFrustum
– glFrustum - multiply the current matrix by a perspective matrix C
Specification
– void glFrustum( GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble near, GLdouble far )

 2 * near right + left 


 right − left 0 0 
right − left
 
 2 * near top + bottom 
0 0
 right − left top − bottom 
 far + near 2 * far * near 
 0 0 
 far − near far − near 
 0 0 −1 0 

You might also like