You are on page 1of 27

|  

TA: Xiaolin Yang


CISC 440/640
xiaolin@cis.udel.edu
2 | 
Ä  og amme sees the g aphics system
th ough a softwa e inte face: the
Application  og amme Inte face (AI)
a 
 
Ä GL (G aphics Lib a y): Lib a y of 2-D, 3-D
d awing p imitives and ope ations
‡ AI fo 3-D ha dwa e accele ation
Ä GLU (GL Utilities): Miscellaneous functions
dealing with came a set-up and highe -level
shape desc iptions
Ä GLUT (GL Utility Toolkit): Window-system
independent toolkit with nume ous utility
functions, mostly dealing with use inte face
O a  

application program

OpenGL Motif
widget or similar GLUT
GLX, AGL
or WGL GLU

X, Win32, Mac O/S GL

software and/or hardware


a    

 

 


glVertex3f(x,y,z)

r    
u  
u

glVertex3fv(p)

p
 
  
   
 lude <GL/glut.h>
vo d myd play(){
glClear(GL_COLOR_BUFFER_BIT);
glBeg (GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEd();
glFluh();
}
t ma ( t arg, har** argv){
glutCreateW dow(" mple");
glutD playFu(myd play);
glutMa Loop();
}
Ë 
Ä ùote that the p og am defines a m 
 function named myd play
‡ Eve y glut p og am must have a display
callback
‡ The display callback is executed wheneve
OpenGL decides the display must be
ef eshed, fo example when the window is
opened
‡ The ma  function ends with the p og am
ente ing an event loop
Ñ  
Ä  mple. is too simple
Ä Makes heavy use of state va iable
default values fo
‡ Viewing
‡ Colo s
‡ Window pa amete s
2   a 
Ä Modeling t ansfo mation
‡ Refe to the t ansfo mation of models (i.e., the
scenes, o objects)
Ä Viewing t ansfo mation
‡ Refe to the t ansfo mation on the came a
Ä  ojection t ansfo mation
‡ Refe to the t ansfo mation f om scene to
image
[  2  
Ä Model-view t ansfo mations a e usually
visualized as a single entity
‡ Befo e applying modeling o viewing
t ansfo mations, need to set
glMat ixMode(GL_MODELVIEW)
‡ Modeling t ansfo ms the object
‡ T anslation: glT anslate(x,y,z)
‡ Scale: glScale(sx,sy,sz)
‡ Rotation: glRotate(theta, x,y,z)
  2  
Ä T ansfo mation of the 3D scene into the
2D ende ed image plane
‡ Befo e applying p ojection t ansfo mations,
need to set glMat ixMode(GL_ROJECTIOù)
‡ O thog aphic p ojection
‡ glO tho(left, ight, bottom, top, nea , fa )
‡ e spective p ojection
‡ glF ustum (left, ight, bottom, top, nea , fa )
 O  
Ä Most OpenGL p og ams have the following
st uctu e
- ma ():
‡ defines the callback functions
‡ opens one o mo e windows with the equi ed p ope ties
‡ ente s event loop (last executable statement)
-  t(): sets the state va iables
‡ Viewing
‡ Att ibutes
‡ callbacks
‡ Display function
‡ Input and window functions
     
 lude <GL/glut.h>
 

t ma ( t arg, har** argv)
{
glutI t(&arg,argv);
glutI tD playMode(GLUT_SINGLE|GLUT_RGB);
glutI tW dowS ze(500,500);
glutI tW dowPo t o(0,0);
glutCreateW dow(" mple");  
 
  

glutD playFu(myd play);

 t(); 
  u 
glutMa Loop();     
}
   
2  
Ä glutI t allows application to get command line
a guments and initializes system
Ä gluI tD playMode equests p ope ties fo the
window (the ? m ? 
 )
‡ RGB colo
‡ Single buffe ing
Ä glutW dowS ze in pixels
Ä glutW dowPo t o f om top-left co ne of display
Ä glutCreateW dow c eate window with title ³simple´
Ä glutD playFu display callback
Ä glutMa Loop ente infinite event loop
‰  |    
u  
vo d  t()
{   

glClearColor (0.0, 0.0, 0.0, 1.0);
glColor3f(1.0, 1.0, 1.0); 
 


glMatr xMode (GL_PROJECTION);
glLoadIdet ty ();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}




Ñ  
  
vo d myd play()
{
glClear(GL_COLOR_BUFFER_BIT);

glBeg (GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEd();

glFluh();
}
!

Ä  og amming inte face fo event-d iven
input
Ä Define a   
 fo each type
of event the g aphics system ecognizes
Ä This use -supplied function is executed
when the event occu s
  u 

‡ GLUT example: glutMoueFu(mymoue)
2 
Ä Last line in ma . fo a p og am using GLUT is the
infinite event loop
glutMa Loop();
Ä In each pass th ough the event loop, GLUT
‡ looks at the events in the queue
‡ fo each event in the queue, GLUT executes the app op iate
callback function if one is defined
‡ if no callback is defined fo the event, the event is igno ed
Ä In ma .
- glutD playFu(myd play) identifies the function to
be executed
‡ Eve y GLUT p og am must have a display callback
   
Ä Many events may invoke the display callback
function
‡ Can lead to multiple executions of the display callback on a
single pass th ough the event loop
Ä We can avoid this p oblem by instead using
glutPotRed play();
which sets a flag.
Ä GLUT checks to see if the flag is set at the end of the
event loop
‡ If set then the display callback function is executed
   

Ä The idle callback is executed wheneve the e a e no events in the event queue
- glutIdleFu(my dle)
‡ Useful fo animations
vo d my dle() {
/* hage ometh g */
t += dt
glutPotRed play();
}

Vo d myd play() {
glClear();
/* draw ometh g that deped o t */
glutSwapBuffer();
}
 

Ä The fo m of all GLUT callbacks is fixed
‡ void myd play()
‡ void mymoue(GL t butto, GL t tate, GL t
x, GL t y)
Ä Must use globals to pass info mation to callbacks

float t; /*global */

vo d myd play()
{
/* draw ometh g that deped o t
}
`   
Ä åow to submit
Ä What to submit
Ä On late submission
å  
 
Ä Submit as a ta /zip file
‡ Unix:
> ta -cf use name_p ojectùum_(440|640).ta
p ojectDi
> gzip use name_p ojectùum_(440|640).ta
‡ Windows:
‡ Use a zip utility
Ä ùaming convention
‡ use name_p ojectùum_(440|640).(ta .gz|zip)
Ä Submit the ta /zip file to xiaolin@cis.udel.edu
‰  
 
Ä Must contain
‡ Readme
‡ Sou ce codes
‡ Output figu es (if any)
Ä Must ùOT contain
‡ obj inte mediate files
‡ obj data files
‰  
 
ü My name
ü My email: myemail@udel.edu
ü  oject ùum

ü a t 1: desc iption of this p oject


This p oject is to apply xxx algo ithm to plot xxx, «

ü a t 2: what I did and what I didn't do


I completed all/most/some functionalities equi ed in this p oject.
The system is obust and the ende ing is fai ly efficient, «

I didn't do «. The eason is «.

ü a t 3: What files contained, what¶s the function of each file.

ü a t 4: åow to compile and how to un


The p oject is developed in windows system and tested in stimpy (st auss) unix
system
a O  ‰  
Ä Go to the GLUT webpage
‡ www.xmission.com/~nate/glut.html
Ä Follow the inst uctions in
‡ http://www.lighthouse3d.com/opengl/glut/
Ä When c eating the Visual C/C++ p oject,
use the console based setup
a å 
Ä Tuesday 7:00 ± 9:00 pm
Ä McKinly 051
Ä Email ± xiaolin@cis.udel.edu