Post on 18-Jan-2016
description
UBI 516 Advanced Computer Graphics
Introduction to Introduction to OpenGLOpenGLIntroduction to Introduction to OpenGLOpenGLOpenGL Programming Guide
Intro to OpenGL
OpenGL operates as an infinite loopOpenGL operates as an infinite loop
• Put things in the scene (points, colored lines, textured polys)Put things in the scene (points, colored lines, textured polys)
• Describe the camera (location, orientation, field of view)Describe the camera (location, orientation, field of view)
• Listen for keyboardListen for keyboard/mouse/mouse events events
• Render – draw the sceneRender – draw the scene
OpenGL operates as an infinite loopOpenGL operates as an infinite loop
• Put things in the scene (points, colored lines, textured polys)Put things in the scene (points, colored lines, textured polys)
• Describe the camera (location, orientation, field of view)Describe the camera (location, orientation, field of view)
• Listen for keyboardListen for keyboard/mouse/mouse events events
• Render – draw the sceneRender – draw the scene
Intro to OpenGL
OpenGL has a “state”OpenGL has a “state”
• There are a lot of ways your OpenGL program can be There are a lot of ways your OpenGL program can be configuredconfigured
• The current configuration is stored in OpenGL’s stateThe current configuration is stored in OpenGL’s state
• Be aware that OpenGL commands affect the program’s state Be aware that OpenGL commands affect the program’s state rather than redirect its logical executionrather than redirect its logical execution
OpenGL has a “state”OpenGL has a “state”
• There are a lot of ways your OpenGL program can be There are a lot of ways your OpenGL program can be configuredconfigured
• The current configuration is stored in OpenGL’s stateThe current configuration is stored in OpenGL’s state
• Be aware that OpenGL commands affect the program’s state Be aware that OpenGL commands affect the program’s state rather than redirect its logical executionrather than redirect its logical execution
The Graphics Pipeline and State MachinesGraphic system as a state machine, a black box that contains a finite-Graphic system as a state machine, a black box that contains a finite-
state machine.state machine.• Machine may change the state,Machine may change the state,
• Or cause to produce a visible output.Or cause to produce a visible output.
An example state :An example state :• We set a color,We set a color,
• That remains the That remains the present colorpresent color until it is changed.until it is changed.
Graphic system as a state machine, a black box that contains a finite-Graphic system as a state machine, a black box that contains a finite-state machine.state machine.• Machine may change the state,Machine may change the state,
• Or cause to produce a visible output.Or cause to produce a visible output.
An example state :An example state :• We set a color,We set a color,
• That remains the That remains the present colorpresent color until it is changed.until it is changed.
The OpenGL Interface
GLUT : Graphics utility toolkit (glut~)- interface with the window system- #include <GL/glut.h>
GLU : Graphics utility library (glu~)- Contain code for common objects such as spheres, teapot, etc.- #include <GL/glu.h>
GL : OpenGL functions (gl~)- #include <GL/gl.h>
GLX
MS windows extension
X window system
MS windows system
Frame buffer(video card)
OpenGLapplication
program
Software
Hide the detailsHide the details• User should not need to worry about how graphics are User should not need to worry about how graphics are
displayed on monitordisplayed on monitor
• User doesn’t need to know about how a line is converted into User doesn’t need to know about how a line is converted into pixels and drawn on screen (hardware dependent)pixels and drawn on screen (hardware dependent)
• User doesn’t need to rebuild the basic tools of a 3D sceneUser doesn’t need to rebuild the basic tools of a 3D scene
– Virtual camera, light sources, polygon drawingVirtual camera, light sources, polygon drawing
OpenGL does this for you…OpenGL does this for you…
Hide the detailsHide the details• User should not need to worry about how graphics are User should not need to worry about how graphics are
displayed on monitordisplayed on monitor
• User doesn’t need to know about how a line is converted into User doesn’t need to know about how a line is converted into pixels and drawn on screen (hardware dependent)pixels and drawn on screen (hardware dependent)
• User doesn’t need to rebuild the basic tools of a 3D sceneUser doesn’t need to rebuild the basic tools of a 3D scene
– Virtual camera, light sources, polygon drawingVirtual camera, light sources, polygon drawing
OpenGL does this for you…OpenGL does this for you…
Software
Hide the detailsHide the details
• User doesn’t need to know how to read the data coming from User doesn’t need to know how to read the data coming from the mousethe mouse
• User doesn’t need to know how to read the keystrokesUser doesn’t need to know how to read the keystrokes
OpenGL Utility Toolkit (GLUT) does this for you…OpenGL Utility Toolkit (GLUT) does this for you…
Hide the detailsHide the details
• User doesn’t need to know how to read the data coming from User doesn’t need to know how to read the data coming from the mousethe mouse
• User doesn’t need to know how to read the keystrokesUser doesn’t need to know how to read the keystrokes
OpenGL Utility Toolkit (GLUT) does this for you…OpenGL Utility Toolkit (GLUT) does this for you…
OpenGL Design Goals
SGI’s design goals for OpenGL:SGI’s design goals for OpenGL:
• High-performance (hardware-accelerated) graphics APIHigh-performance (hardware-accelerated) graphics API
• Some hardware independence Some hardware independence
• Natural, terse API with some built-in extensibilityNatural, terse API with some built-in extensibility
OpenGL has become a standard (competing with DirectX) because:OpenGL has become a standard (competing with DirectX) because:
• It doesn’t try to do too muchIt doesn’t try to do too much
– Only renders the image, doesn’t manage windows, etc.Only renders the image, doesn’t manage windows, etc.
– No high-level animation, modeling, sound (!), etc.No high-level animation, modeling, sound (!), etc.
• It does enoughIt does enough
– Useful rendering effects + high performanceUseful rendering effects + high performance
• Open source and promoted by SGI (& Microsoft, half-heartedly)Open source and promoted by SGI (& Microsoft, half-heartedly)
SGI’s design goals for OpenGL:SGI’s design goals for OpenGL:
• High-performance (hardware-accelerated) graphics APIHigh-performance (hardware-accelerated) graphics API
• Some hardware independence Some hardware independence
• Natural, terse API with some built-in extensibilityNatural, terse API with some built-in extensibility
OpenGL has become a standard (competing with DirectX) because:OpenGL has become a standard (competing with DirectX) because:
• It doesn’t try to do too muchIt doesn’t try to do too much
– Only renders the image, doesn’t manage windows, etc.Only renders the image, doesn’t manage windows, etc.
– No high-level animation, modeling, sound (!), etc.No high-level animation, modeling, sound (!), etc.
• It does enoughIt does enough
– Useful rendering effects + high performanceUseful rendering effects + high performance
• Open source and promoted by SGI (& Microsoft, half-heartedly)Open source and promoted by SGI (& Microsoft, half-heartedly)
The Big Picture
Who gets control of the main control loop?Who gets control of the main control loop?• GLUTGLUT – the code that controls the window and refresh – the code that controls the window and refresh
– Must be responsive to windowing system and OSMust be responsive to windowing system and OS
• OpenGLOpenGL – the code that controls what is drawn – the code that controls what is drawn
– Must be responsive to the program that specifies where Must be responsive to the program that specifies where objects are located. If something moves, I want to see it.objects are located. If something moves, I want to see it.
Who gets control of the main control loop?Who gets control of the main control loop?• GLUTGLUT – the code that controls the window and refresh – the code that controls the window and refresh
– Must be responsive to windowing system and OSMust be responsive to windowing system and OS
• OpenGLOpenGL – the code that controls what is drawn – the code that controls what is drawn
– Must be responsive to the program that specifies where Must be responsive to the program that specifies where objects are located. If something moves, I want to see it.objects are located. If something moves, I want to see it.
Intro to OpenGL
OpenGL uses matricesOpenGL uses matrices
• Matrix describes camera typeMatrix describes camera type
• Matrix describes current configuration of the 3D spaceMatrix describes current configuration of the 3D space
– Explanation…Explanation…
OpenGL uses matricesOpenGL uses matrices
• Matrix describes camera typeMatrix describes camera type
• Matrix describes current configuration of the 3D spaceMatrix describes current configuration of the 3D space
– Explanation…Explanation…
Intro to OpenGL
OpenGL coordinate systemOpenGL coordinate system
• right-handedright-handed
– Hold out your right hand and hold your thumb, index, and Hold out your right hand and hold your thumb, index, and middle fingers middle fingers orthogonalorthogonal to one another to one another
– Call your thumb the x-axis, index = y-axis, and middle = Call your thumb the x-axis, index = y-axis, and middle = axisaxis
– This is the OpenGL coordinate systemThis is the OpenGL coordinate system
• The camera defaults to look down negative z-axisThe camera defaults to look down negative z-axis
OpenGL coordinate systemOpenGL coordinate system
• right-handedright-handed
– Hold out your right hand and hold your thumb, index, and Hold out your right hand and hold your thumb, index, and middle fingers middle fingers orthogonalorthogonal to one another to one another
– Call your thumb the x-axis, index = y-axis, and middle = Call your thumb the x-axis, index = y-axis, and middle = axisaxis
– This is the OpenGL coordinate systemThis is the OpenGL coordinate system
• The camera defaults to look down negative z-axisThe camera defaults to look down negative z-axis
Intro to OpenGL
So…So…
• X-axis = thumb = 1, 0, 0X-axis = thumb = 1, 0, 0
• Y-axis = index = 0, 1, 0Y-axis = index = 0, 1, 0
• Z-axis = middle = 0, 0, 1Z-axis = middle = 0, 0, 1
• Camera defaults to look down negative z-axisCamera defaults to look down negative z-axis
• Let’s say we want it to look down x-axisLet’s say we want it to look down x-axis
So…So…
• X-axis = thumb = 1, 0, 0X-axis = thumb = 1, 0, 0
• Y-axis = index = 0, 1, 0Y-axis = index = 0, 1, 0
• Z-axis = middle = 0, 0, 1Z-axis = middle = 0, 0, 1
• Camera defaults to look down negative z-axisCamera defaults to look down negative z-axis
• Let’s say we want it to look down x-axisLet’s say we want it to look down x-axis
100
010
001
Intro to OpenGL
Coordinate system transformation so camera Coordinate system transformation so camera looks down x-axislooks down x-axis
• If x-axis If x-axis negative z-axis negative z-axis
– x x -z -z
– y y y y
– z z x x
Coordinate system transformation so camera Coordinate system transformation so camera looks down x-axislooks down x-axis
• If x-axis If x-axis negative z-axis negative z-axis
– x x -z -z
– y y y y
– z z x x
001
010
100
Intro to OpenGL
The aThe a i matrix defines the transformation i matrix defines the transformation
Why store the transformation matrix and not the final Why store the transformation matrix and not the final desired matrix?desired matrix?
The aThe a i matrix defines the transformation i matrix defines the transformation
Why store the transformation matrix and not the final Why store the transformation matrix and not the final desired matrix?desired matrix?
ihg
fed
cba
100
010
001
001
010
100
=
Intro to OpenGL
The transformation will be applied to many pointsThe transformation will be applied to many points
• If the following transformation moves the axesIf the following transformation moves the axes
• The same transformation moves vertices The same transformation moves vertices
– Example: (1, 1, -1) Example: (1, 1, -1) (-1, 1, -1) (-1, 1, -1)
The transformation will be applied to many pointsThe transformation will be applied to many points
• If the following transformation moves the axesIf the following transformation moves the axes
• The same transformation moves vertices The same transformation moves vertices
– Example: (1, 1, -1) Example: (1, 1, -1) (-1, 1, -1) (-1, 1, -1)
ihg
fed
cba
100
010
001
001
010
100
=
'
'
'
001
010
100
k
j
i
k
j
i
Intro to OpenGL
This important matrix is stored as the This important matrix is stored as the MODELVIEWMODELVIEW matrix matrix
• The MODELVIEW matrix is so important OpenGL maintains a stack of The MODELVIEW matrix is so important OpenGL maintains a stack of these matricesthese matrices
• You have control of this stack with the glPushMatrix and glPopMatrix You have control of this stack with the glPushMatrix and glPopMatrix commandscommands
• (The matrix is actually 4x4, but we will study the details to understand (The matrix is actually 4x4, but we will study the details to understand why in the future)why in the future)
Note OpenGL preserves a similar matrix to describe the Note OpenGL preserves a similar matrix to describe the camera type and this is called the camera type and this is called the PROJECTION_MATRIXPROJECTION_MATRIX
This important matrix is stored as the This important matrix is stored as the MODELVIEWMODELVIEW matrix matrix
• The MODELVIEW matrix is so important OpenGL maintains a stack of The MODELVIEW matrix is so important OpenGL maintains a stack of these matricesthese matrices
• You have control of this stack with the glPushMatrix and glPopMatrix You have control of this stack with the glPushMatrix and glPopMatrix commandscommands
• (The matrix is actually 4x4, but we will study the details to understand (The matrix is actually 4x4, but we will study the details to understand why in the future)why in the future)
Note OpenGL preserves a similar matrix to describe the Note OpenGL preserves a similar matrix to describe the camera type and this is called the camera type and this is called the PROJECTION_MATRIXPROJECTION_MATRIX
Introduction to OpenGL
What’s hard about this assignment?What’s hard about this assignment?• Managing the MODELVIEW stackManaging the MODELVIEW stack
• We’ll use:We’ll use:
– glLoadIdentity();glLoadIdentity();
– glTranslatef(GLfloat x, y, z);glTranslatef(GLfloat x, y, z);
– glRotatef(GLfloat degrees, x, y, z);glRotatef(GLfloat degrees, x, y, z);
– glScalef (GLfloat x, y, z);glScalef (GLfloat x, y, z);
– glPushMatrix(), glPopMatrix();glPushMatrix(), glPopMatrix();
What’s hard about this assignment?What’s hard about this assignment?• Managing the MODELVIEW stackManaging the MODELVIEW stack
• We’ll use:We’ll use:
– glLoadIdentity();glLoadIdentity();
– glTranslatef(GLfloat x, y, z);glTranslatef(GLfloat x, y, z);
– glRotatef(GLfloat degrees, x, y, z);glRotatef(GLfloat degrees, x, y, z);
– glScalef (GLfloat x, y, z);glScalef (GLfloat x, y, z);
– glPushMatrix(), glPopMatrix();glPushMatrix(), glPopMatrix();
Modeling Transformations
glTranslate (x, y, z)glTranslate (x, y, z)• Post-multiplies the current matrix by a matrix that moves Post-multiplies the current matrix by a matrix that moves
the object by the given x-, y-, and z-valuesthe object by the given x-, y-, and z-values
glRotate (theta, x, y, z)glRotate (theta, x, y, z)• Post-multiplies the current matrix by a matrix that rotates Post-multiplies the current matrix by a matrix that rotates
the object in a counterclockwise direction about the ray the object in a counterclockwise direction about the ray from the origin through the point (x, y, z)from the origin through the point (x, y, z)
glTranslate (x, y, z)glTranslate (x, y, z)• Post-multiplies the current matrix by a matrix that moves Post-multiplies the current matrix by a matrix that moves
the object by the given x-, y-, and z-valuesthe object by the given x-, y-, and z-values
glRotate (theta, x, y, z)glRotate (theta, x, y, z)• Post-multiplies the current matrix by a matrix that rotates Post-multiplies the current matrix by a matrix that rotates
the object in a counterclockwise direction about the ray the object in a counterclockwise direction about the ray from the origin through the point (x, y, z)from the origin through the point (x, y, z)
Modeling Transformations
glScale (x, y, z)glScale (x, y, z)
• Post-multiplies the current matrix by a matrix that stretches, Post-multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axesshrinks, or reflects an object along the axes
glScale (x, y, z)glScale (x, y, z)
• Post-multiplies the current matrix by a matrix that stretches, Post-multiplies the current matrix by a matrix that stretches, shrinks, or reflects an object along the axesshrinks, or reflects an object along the axes
Modeling Transformations
It is important that you understand the order in which It is important that you understand the order in which OpenGL concatenates matricesOpenGL concatenates matrices
It is important that you understand the order in which It is important that you understand the order in which OpenGL concatenates matricesOpenGL concatenates matrices
glMatrixMode (MODELVIEW);glMatrixMode (MODELVIEW);
glLoadIdentity();glLoadIdentity();
glMultMatrix(N);glMultMatrix(N);
glMultMatrix(M);glMultMatrix(M);
glMultMatrix(L);glMultMatrix(L);
glBegin(POINTS);glBegin(POINTS);
glVertex3f(v);glVertex3f(v);
glEnd();glEnd();
glMatrixMode (MODELVIEW);glMatrixMode (MODELVIEW);
glLoadIdentity();glLoadIdentity();
glMultMatrix(N);glMultMatrix(N);
glMultMatrix(M);glMultMatrix(M);
glMultMatrix(L);glMultMatrix(L);
glBegin(POINTS);glBegin(POINTS);
glVertex3f(v);glVertex3f(v);
glEnd();glEnd();
Modelview matrix successively contains:I(dentity), N, NM, NML
The transformed vertex is:NMLv = N(M(Lv))
Manipulating Matrix Stacks
Observation: Certain model transformations are shared Observation: Certain model transformations are shared among many modelsamong many models
We want to avoid continuously reloading the same We want to avoid continuously reloading the same sequence of transformationssequence of transformations
glPushMatrix ( )glPushMatrix ( ) • push all matrices in current stack down one level and copy topmost push all matrices in current stack down one level and copy topmost
matrix of stackmatrix of stack
glPopMatrix ( )glPopMatrix ( )• pop the top matrix off the stackpop the top matrix off the stack
Observation: Certain model transformations are shared Observation: Certain model transformations are shared among many modelsamong many models
We want to avoid continuously reloading the same We want to avoid continuously reloading the same sequence of transformationssequence of transformations
glPushMatrix ( )glPushMatrix ( ) • push all matrices in current stack down one level and copy topmost push all matrices in current stack down one level and copy topmost
matrix of stackmatrix of stack
glPopMatrix ( )glPopMatrix ( )• pop the top matrix off the stackpop the top matrix off the stack
Matrix Manipulation - Example
Drawing a car with wheels and lugnutsDrawing a car with wheels and lugnutsDrawing a car with wheels and lugnutsDrawing a car with wheels and lugnuts
draw_wheel( );for (j=0; j<5; j++) {
glPushMatrix ();glRotatef(72.0*j, 0.0, 0.0, 1.0);glTranslatef (3.0, 0.0, 0.0);draw_bolt ( );
glPopMatrix ( );}
Matrix Manipulation – ExampleMatrix Manipulation – ExampleGrand, fixed coordinate systemGrand, fixed coordinate system
draw_wheel( );for (j=0; j<5; j++) {
glPushMatrix ();glRotatef(72.0*j, 0.0, 0.0, 1.0);glTranslatef (3.0, 0.0, 0.0);draw_bolt ( );
glPopMatrix ( );
Global – Bottom Up
Start RotTrans
RRT
RTv
Matrix Manipulation – ExampleMatrix Manipulation – ExampleLocal coordinate systemLocal coordinate system
draw_wheel( );for (j=0; j<5; j++) {
glPushMatrix ();glRotatef(72.0*j, 0.0, 0.0, 1.0);glTranslatef (3.0, 0.0, 0.0);draw_bolt ( );
glPopMatrix ( );
Local – Top Down
Start Rot Trans
RRT
RTv
OpenGL: Conventions
Functions in OpenGL start with Functions in OpenGL start with glgl
• Most functions just Most functions just gl gl (e.g., (e.g., glColor()glColor()) )
• Functions starting with Functions starting with gluglu are utility functions (e.g., are utility functions (e.g., gluLookAt()gluLookAt()))
• Functions starting with Functions starting with glxglx are for interfacing with the X are for interfacing with the X Windows system (e.g., in gfx.c)Windows system (e.g., in gfx.c)
Functions in OpenGL start with Functions in OpenGL start with glgl
• Most functions just Most functions just gl gl (e.g., (e.g., glColor()glColor()) )
• Functions starting with Functions starting with gluglu are utility functions (e.g., are utility functions (e.g., gluLookAt()gluLookAt()))
• Functions starting with Functions starting with glxglx are for interfacing with the X are for interfacing with the X Windows system (e.g., in gfx.c)Windows system (e.g., in gfx.c)
OpenGL: Conventions
Function names indicate argument type and numberFunction names indicate argument type and number
• Functions ending with Functions ending with ff take floats take floats
• Functions ending with Functions ending with ii take ints take ints
• Functions ending with Functions ending with bb take bytes take bytes
• Functions ending with Functions ending with ubub take unsigned bytes take unsigned bytes
• Functions that end with Functions that end with vv take an array. take an array.
ExamplesExamples• glColor3f()glColor3f() takes 3 floats takes 3 floats
• glColor4fv() glColor4fv() takes an array of 4 floatstakes an array of 4 floats
Function names indicate argument type and numberFunction names indicate argument type and number
• Functions ending with Functions ending with ff take floats take floats
• Functions ending with Functions ending with ii take ints take ints
• Functions ending with Functions ending with bb take bytes take bytes
• Functions ending with Functions ending with ubub take unsigned bytes take unsigned bytes
• Functions that end with Functions that end with vv take an array. take an array.
ExamplesExamples• glColor3f()glColor3f() takes 3 floats takes 3 floats
• glColor4fv() glColor4fv() takes an array of 4 floatstakes an array of 4 floats
OpenGL: Conventions
Variables written in CAPITAL lettersVariables written in CAPITAL letters
• Example: GLUT_SINGLE, GLUT_RGBExample: GLUT_SINGLE, GLUT_RGB
• usually constantsusually constants
• use the bitwise or command (x | y) to combine constantsuse the bitwise or command (x | y) to combine constants
Variables written in CAPITAL lettersVariables written in CAPITAL letters
• Example: GLUT_SINGLE, GLUT_RGBExample: GLUT_SINGLE, GLUT_RGB
• usually constantsusually constants
• use the bitwise or command (x | y) to combine constantsuse the bitwise or command (x | y) to combine constants
OpenGL: Simple Use
Open a window and attach OpenGL to itOpen a window and attach OpenGL to it
Set projection parameters (e.g., field of view)Set projection parameters (e.g., field of view)
Setup lighting, if anySetup lighting, if any
Main rendering loopMain rendering loop
• Set camera pose with Set camera pose with gluLookAt() gluLookAt()
– Camera position specified in world coordinatesCamera position specified in world coordinates
• Render polygons of modelRender polygons of model
– Simplest case: vertices of polygons in world coordinatesSimplest case: vertices of polygons in world coordinates
Open a window and attach OpenGL to itOpen a window and attach OpenGL to it
Set projection parameters (e.g., field of view)Set projection parameters (e.g., field of view)
Setup lighting, if anySetup lighting, if any
Main rendering loopMain rendering loop
• Set camera pose with Set camera pose with gluLookAt() gluLookAt()
– Camera position specified in world coordinatesCamera position specified in world coordinates
• Render polygons of modelRender polygons of model
– Simplest case: vertices of polygons in world coordinatesSimplest case: vertices of polygons in world coordinates
OpenGL: Simple Use
Open a window and attach OpenGL to itOpen a window and attach OpenGL to it
• glutCreateWindow()glutCreateWindow()
Open a window and attach OpenGL to itOpen a window and attach OpenGL to it
• glutCreateWindow()glutCreateWindow()
OpenGL: Perspective Projection
Set projection parameters (e.g., field of view)Set projection parameters (e.g., field of view)
Typically, we use a Typically, we use a perspective projectionperspective projection
• Distant objects appear smaller than near objects Distant objects appear smaller than near objects
• Vanishing point at center of screenVanishing point at center of screen
• Defined by a Defined by a view frustumview frustum (draw it) (draw it)
Other projections: Other projections: orthographicorthographic, , isometricisometric
Set projection parameters (e.g., field of view)Set projection parameters (e.g., field of view)
Typically, we use a Typically, we use a perspective projectionperspective projection
• Distant objects appear smaller than near objects Distant objects appear smaller than near objects
• Vanishing point at center of screenVanishing point at center of screen
• Defined by a Defined by a view frustumview frustum (draw it) (draw it)
Other projections: Other projections: orthographicorthographic, , isometricisometric
Setting up CameraglMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW);
glLoadIdentity();glLoadIdentity();
gluLookAt(gluLookAt( eyeX, eyeY, eyeZ, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, lookX, lookY, lookZ, upX, upY, upZ);upX, upY, upZ);
• eye[XYZ]: camera position in world coordinateseye[XYZ]: camera position in world coordinates
• look[XYZ]: a point centered in camera’s viewlook[XYZ]: a point centered in camera’s view
• up[XYZ]: a up[XYZ]: a vectorvector defining the camera’s vertical defining the camera’s vertical
Creates a matrix that transforms points in world coordinates to Creates a matrix that transforms points in world coordinates to camera coordinatescamera coordinates
• Camera at originCamera at origin
• Looking down -Z axisLooking down -Z axis
• Up vector aligned with Y axisUp vector aligned with Y axis
glMatrixMode(GL_MODELVIEW);glMatrixMode(GL_MODELVIEW);
glLoadIdentity();glLoadIdentity();
gluLookAt(gluLookAt( eyeX, eyeY, eyeZ, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, lookX, lookY, lookZ, upX, upY, upZ);upX, upY, upZ);
• eye[XYZ]: camera position in world coordinateseye[XYZ]: camera position in world coordinates
• look[XYZ]: a point centered in camera’s viewlook[XYZ]: a point centered in camera’s view
• up[XYZ]: a up[XYZ]: a vectorvector defining the camera’s vertical defining the camera’s vertical
Creates a matrix that transforms points in world coordinates to Creates a matrix that transforms points in world coordinates to camera coordinatescamera coordinates
• Camera at originCamera at origin
• Looking down -Z axisLooking down -Z axis
• Up vector aligned with Y axisUp vector aligned with Y axis
OpenGL: Perspective Projection
In OpenGL: In OpenGL: • Projections implemented by Projections implemented by projection matrixprojection matrix
• gluPerspective()gluPerspective() creates a perspective creates a perspective projection matrix:projection matrix:
glSetMatrix(GL_PROJECTION);glSetMatrix(GL_PROJECTION);
glLoadIdentity(); //glLoadIdentity(); //load an identity matrixload an identity matrix
gluPerspective(vfov, aspect, near, far);gluPerspective(vfov, aspect, near, far);
Parameters to Parameters to gluPerspective()gluPerspective()::• vfovvfov: vertical field of view: vertical field of view
• aspectaspect: window width/height: window width/height
• nearnear, , farfar: distance to near & far clipping planes: distance to near & far clipping planes
In OpenGL: In OpenGL: • Projections implemented by Projections implemented by projection matrixprojection matrix
• gluPerspective()gluPerspective() creates a perspective creates a perspective projection matrix:projection matrix:
glSetMatrix(GL_PROJECTION);glSetMatrix(GL_PROJECTION);
glLoadIdentity(); //glLoadIdentity(); //load an identity matrixload an identity matrix
gluPerspective(vfov, aspect, near, far);gluPerspective(vfov, aspect, near, far);
Parameters to Parameters to gluPerspective()gluPerspective()::• vfovvfov: vertical field of view: vertical field of view
• aspectaspect: window width/height: window width/height
• nearnear, , farfar: distance to near & far clipping planes: distance to near & far clipping planes
OpenGL: Lighting
Setup lighting, if anySetup lighting, if any
Simplest option: change the Simplest option: change the current colorcurrent color between between polygons or verticespolygons or vertices• glColor() sets the current colorglColor() sets the current color
Or OpenGL provides a simple lighting model:Or OpenGL provides a simple lighting model:• Set parameters for light(s)Set parameters for light(s)
– Intensity, position, direction & falloff (if applicable) Intensity, position, direction & falloff (if applicable)
• Set Set materialmaterial parameters to describe how light reflects from the parameters to describe how light reflects from the surfacesurface
Won’t go into details now; check the red book if Won’t go into details now; check the red book if interestedinterested
Setup lighting, if anySetup lighting, if any
Simplest option: change the Simplest option: change the current colorcurrent color between between polygons or verticespolygons or vertices• glColor() sets the current colorglColor() sets the current color
Or OpenGL provides a simple lighting model:Or OpenGL provides a simple lighting model:• Set parameters for light(s)Set parameters for light(s)
– Intensity, position, direction & falloff (if applicable) Intensity, position, direction & falloff (if applicable)
• Set Set materialmaterial parameters to describe how light reflects from the parameters to describe how light reflects from the surfacesurface
Won’t go into details now; check the red book if Won’t go into details now; check the red book if interestedinterested
OpenGL: Specifying Geometry
Geometry in OpenGL consists of a list of vertices in Geometry in OpenGL consists of a list of vertices in between calls to between calls to glBegin()glBegin() and and glEnd()glEnd()• A simple example: telling GL to render a triangleA simple example: telling GL to render a triangle
glBegin(GL_POLYGON);glBegin(GL_POLYGON);
glVertex3f(x1, y1, z1);glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);glVertex3f(x2, y2, z2);
glVertex3f(x3, y3, z3);glVertex3f(x3, y3, z3);
glEnd();glEnd();
• Usage: Usage: glBegin(glBegin(geomtypegeomtype)) where geomtype is: where geomtype is:
– Points, lines, polygons, triangles, quadrilaterals, etc...Points, lines, polygons, triangles, quadrilaterals, etc...
Geometry in OpenGL consists of a list of vertices in Geometry in OpenGL consists of a list of vertices in between calls to between calls to glBegin()glBegin() and and glEnd()glEnd()• A simple example: telling GL to render a triangleA simple example: telling GL to render a triangle
glBegin(GL_POLYGON);glBegin(GL_POLYGON);
glVertex3f(x1, y1, z1);glVertex3f(x1, y1, z1);
glVertex3f(x2, y2, z2);glVertex3f(x2, y2, z2);
glVertex3f(x3, y3, z3);glVertex3f(x3, y3, z3);
glEnd();glEnd();
• Usage: Usage: glBegin(glBegin(geomtypegeomtype)) where geomtype is: where geomtype is:
– Points, lines, polygons, triangles, quadrilaterals, etc...Points, lines, polygons, triangles, quadrilaterals, etc...
Primitive Types
GL_POINTSGL_POINTS
GL_LINEGL_LINE
• {S | _STRIP | _LOOP}{S | _STRIP | _LOOP}
GL_TRIANGLEGL_TRIANGLE
• {S | _STRIP | _FAN}{S | _STRIP | _FAN}
GL_QUADGL_QUAD
• {S | _STRIP}{S | _STRIP}
GL_POLYGONGL_POLYGON
GL_POINTSGL_POINTS
GL_LINEGL_LINE
• {S | _STRIP | _LOOP}{S | _STRIP | _LOOP}
GL_TRIANGLEGL_TRIANGLE
• {S | _STRIP | _FAN}{S | _STRIP | _FAN}
GL_QUADGL_QUAD
• {S | _STRIP}{S | _STRIP}
GL_POLYGONGL_POLYGON
Points in OpenGL
glBegin(GL_POINTS);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_POINTS);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3
p4
p5
p6
p7
Lines in OpenGL (1/3)
Line SegmentsLine SegmentsLine SegmentsLine SegmentsglBegin(GL_LINES);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_LINES);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3
p4
p5
p6
p7
Lines in OpenGL (2/3)
Polylines – Line Strip Polylines – Line Strip Polylines – Line Strip Polylines – Line Strip glBegin(GL_LINE_STRIP);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_LINE_STRIP);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Lines in OpenGL (3/3)
Polylines – Line LoopPolylines – Line LoopPolylines – Line LoopPolylines – Line LoopglBegin(GL_LINE_LOOP);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_LINE_LOOP);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygon Basics (1/2)
DefinitionDefinition
• Object that is closed as a line loop, but that has an interiorObject that is closed as a line loop, but that has an interior
Simple PolygonSimple Polygon
• No pair of edges of a polygon cross each otherNo pair of edges of a polygon cross each other
DefinitionDefinition
• Object that is closed as a line loop, but that has an interiorObject that is closed as a line loop, but that has an interior
Simple PolygonSimple Polygon
• No pair of edges of a polygon cross each otherNo pair of edges of a polygon cross each other
Simple Nonsimple
Polygon Basics (2/2)
ConvexityConvexity
• If all points on the line segment between any two If all points on the line segment between any two points inside the object, or on its boundary, are inside points inside the object, or on its boundary, are inside the objectthe object
ConvexityConvexity
• If all points on the line segment between any two If all points on the line segment between any two points inside the object, or on its boundary, are inside points inside the object, or on its boundary, are inside the objectthe object
Convex Objects
p1p2
concave
convex
Polygon Rendering Options
Rendered as points, lines, or filledRendered as points, lines, or filled
Front and back faces can be rendered separately using Front and back faces can be rendered separately using glPolygonMode(face, mode)glPolygonMode(face, mode)
face face : : GL_FRONTGL_FRONT, , GL_BACKGL_BACK or or GL_FRONT_AND_BACKGL_FRONT_AND_BACK
modemode : : GL_POINTGL_POINT, , GL_LINEGL_LINE or or GL_FILLGL_FILL..glPolygonStipple( )glPolygonStipple( ) overlays a MacPaint-style overlay overlays a MacPaint-style overlay onon
the polygonthe polygon
glEdgeFlagglEdgeFlag(bool)(bool) specifies polygon edges that can be drawn specifies polygon edges that can be drawn in line modein line mode
boolbool : : GL_FGL_FALSE ALSE oror GL_GL_TRUETRUE
Normal vectors: normalized is better, but Normal vectors: normalized is better, but glEnable(GL_NORMALIZE)glEnable(GL_NORMALIZE) will guarantee it will guarantee it
Rendered as points, lines, or filledRendered as points, lines, or filled
Front and back faces can be rendered separately using Front and back faces can be rendered separately using glPolygonMode(face, mode)glPolygonMode(face, mode)
face face : : GL_FRONTGL_FRONT, , GL_BACKGL_BACK or or GL_FRONT_AND_BACKGL_FRONT_AND_BACK
modemode : : GL_POINTGL_POINT, , GL_LINEGL_LINE or or GL_FILLGL_FILL..glPolygonStipple( )glPolygonStipple( ) overlays a MacPaint-style overlay overlays a MacPaint-style overlay onon
the polygonthe polygon
glEdgeFlagglEdgeFlag(bool)(bool) specifies polygon edges that can be drawn specifies polygon edges that can be drawn in line modein line mode
boolbool : : GL_FGL_FALSE ALSE oror GL_GL_TRUETRUE
Normal vectors: normalized is better, but Normal vectors: normalized is better, but glEnable(GL_NORMALIZE)glEnable(GL_NORMALIZE) will guarantee it will guarantee it
OpenGL: Specifying Normals
Calling Calling glNormal()glNormal() sets the sets the normal vectornormal vector for the following vertices, till next for the following vertices, till next glNormal()glNormal() • So So flat-shadedflat-shaded lighting requires: lighting requires: glShadeModel(GL_FLAT);glShadeModel(GL_FLAT);glNormal3f(Nx, Ny, Nz);glNormal3f(Nx, Ny, Nz);glVertex3fv(v0);glVertex3fv(v0);glVertex3fv(v1);glVertex3fv(v1);glVertex3fv(v2);glVertex3fv(v2);
• While While smoosmootthh-shaded-shaded requires: requires:
• (Of course, lighting requires additional setup…)(Of course, lighting requires additional setup…)
Calling Calling glNormal()glNormal() sets the sets the normal vectornormal vector for the following vertices, till next for the following vertices, till next glNormal()glNormal() • So So flat-shadedflat-shaded lighting requires: lighting requires: glShadeModel(GL_FLAT);glShadeModel(GL_FLAT);glNormal3f(Nx, Ny, Nz);glNormal3f(Nx, Ny, Nz);glVertex3fv(v0);glVertex3fv(v0);glVertex3fv(v1);glVertex3fv(v1);glVertex3fv(v2);glVertex3fv(v2);
• While While smoosmootthh-shaded-shaded requires: requires:
• (Of course, lighting requires additional setup…)(Of course, lighting requires additional setup…)
glShadeModel(GL_SMOOTH);glNormal3f(N0x, N0y, N0z); glVertex3fv(v0);glNormal3f(N1x, N1y, N1z); glVertex3fv(v1);glNormal3f(N2x, N2y, N2z); glVertex3fv(v2);
Polygonalization HintsKeep orientations (windings) consistentKeep orientations (windings) consistent
Best to use triangles (guaranteed planar)Best to use triangles (guaranteed planar)
Keep polygon number to minimumKeep polygon number to minimum
Put more polygons on silhouettesPut more polygons on silhouettes
Avoid T-intersections to avoid cracksAvoid T-intersections to avoid cracks
Use exact coordinates for closing loopsUse exact coordinates for closing loops
Keep orientations (windings) consistentKeep orientations (windings) consistent
Best to use triangles (guaranteed planar)Best to use triangles (guaranteed planar)
Keep polygon number to minimumKeep polygon number to minimum
Put more polygons on silhouettesPut more polygons on silhouettes
Avoid T-intersections to avoid cracksAvoid T-intersections to avoid cracks
Use exact coordinates for closing loopsUse exact coordinates for closing loops
AA B B
CC
BAD OKE
D
Polygons in OpenGL (1/6)
PolygonPolygonPolygonPolygonglBegin(GL_POLYGON);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_POLYGON);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygons in OpenGL (2/6)
QuadrilateralsQuadrilateralsQuadrilateralsQuadrilateralsglBegin(GL_QUADS);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_QUADS);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygons in OpenGL (3/6)
QuadstripQuadstripQuadstripQuadstripglBegin(GL_QUAD_STRIP);
glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p0);glVertex2fv(p4);glVertex2fv(p7);glVertex2fv(p5);glVertex2fv(p6);
glEnd();
glBegin(GL_QUAD_STRIP);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p0);glVertex2fv(p4);glVertex2fv(p7);glVertex2fv(p5);glVertex2fv(p6);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygons in OpenGL (4/6)
TrianglesTrianglesTrianglesTrianglesglBegin(GL_TRIANGLES);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_TRIANGLES);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygons in OpenGL (5/6)
Triangle StripTriangle StripTriangle StripTriangle StripglBegin(GL_TRIANGLE_STRIP);
glVertex2fv(p0);glVertex2fv(p7);glVertex2fv(p1);glVertex2fv(p6);glVertex2fv(p2);glVertex2fv(p5);glVertex2fv(p3);glVertex2fv(p4);
glEnd();
glBegin(GL_TRIANGLE_STRIP);glVertex2fv(p0);glVertex2fv(p7);glVertex2fv(p1);glVertex2fv(p6);glVertex2fv(p2);glVertex2fv(p5);glVertex2fv(p3);glVertex2fv(p4);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Polygons in OpenGL (6/6)
Triangle FanTriangle FanTriangle FanTriangle FanglBegin(GL_TRIANGLE_FAN);
glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
glBegin(GL_TRIANGLE_FAN);glVertex2fv(p0);glVertex2fv(p1);glVertex2fv(p2);glVertex2fv(p3);glVertex2fv(p4);glVertex2fv(p5);glVertex2fv(p6);glVertex2fv(p7);
glEnd();
p0p1
p2
p3p4
p5
p6
p7
Double Buffering
Avoids displaying partially rendered frame bufferAvoids displaying partially rendered frame buffer
OpenGL generates one raster image while another OpenGL generates one raster image while another raster image is displayed on monitorraster image is displayed on monitor
glutSwapBuffers (void)glutSwapBuffers (void)
Avoids displaying partially rendered frame bufferAvoids displaying partially rendered frame buffer
OpenGL generates one raster image while another OpenGL generates one raster image while another raster image is displayed on monitorraster image is displayed on monitor
glutSwapBuffers (void)glutSwapBuffers (void)
Learn OpenGL by example
robot.c from the OpenGL Programming Guiderobot.c from the OpenGL Programming Guiderobot.c from the OpenGL Programming Guiderobot.c from the OpenGL Programming Guide
Learn OpenGL by example
Two bodiesTwo bodies
• Upper armUpper arm
• Lower armLower arm
Major tasksMajor tasks
• PositionPosition
• OrientationOrientation
Both bodies originally at originBoth bodies originally at origin
Two bodiesTwo bodies
• Upper armUpper arm
• Lower armLower arm
Major tasksMajor tasks
• PositionPosition
• OrientationOrientation
Both bodies originally at originBoth bodies originally at origin
Learn OpenGL by example
HeadersHeaders#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include <GL/glut.h> #include <GL/glut.h>
HeadersHeaders#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include <GL/glut.h> #include <GL/glut.h>
Learn OpenGL by exampleint main(int argc, char** argv) { int main(int argc, char** argv) {
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100); glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]); glutCreateWindow (argv[0]);
init (); init ();
glutDisplayFunc(display); glutDisplayFunc(display);
glutReshapeFunc(reshape);glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard); glutKeyboardFunc(keyboard);
glutMainLoop(); glutMainLoop();
return 0;return 0; } }
int main(int argc, char** argv) { int main(int argc, char** argv) {
glutInit(&argc, argv); glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100); glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]); glutCreateWindow (argv[0]);
init (); init ();
glutDisplayFunc(display); glutDisplayFunc(display);
glutReshapeFunc(reshape);glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard); glutKeyboardFunc(keyboard);
glutMainLoop(); glutMainLoop();
return 0;return 0; } }
Learn OpenGL by examplevoid init(void) { void init(void) {
glClearColor (0.0, 0.0, 0.0, 0.0); glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT); glShadeModel (GL_FLAT);
}}
void init(void) { void init(void) {
glClearColor (0.0, 0.0, 0.0, 0.0); glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT); glShadeModel (GL_FLAT);
}}
Learn OpenGL by examplevoid display(void){ void display(void){
glClear (GL_COLOR_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix(); glPushMatrix();
glTranslatef (-1.0, 0.0, 0.0); glTranslatef (-1.0, 0.0, 0.0);
glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glPushMatrix(); glPushMatrix();
glScalef (2.0, 0.4, 1.0); glScalef (2.0, 0.4, 1.0);
glutWireCube (1.0); glutWireCube (1.0);
glPopMatrix(); glPopMatrix();
Continued…Continued…
void display(void){ void display(void){
glClear (GL_COLOR_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix(); glPushMatrix();
glTranslatef (-1.0, 0.0, 0.0); glTranslatef (-1.0, 0.0, 0.0);
glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0); glRotatef ((GLfloat) shoulder, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glPushMatrix(); glPushMatrix();
glScalef (2.0, 0.4, 1.0); glScalef (2.0, 0.4, 1.0);
glutWireCube (1.0); glutWireCube (1.0);
glPopMatrix(); glPopMatrix();
Continued…Continued…
Learn OpenGL by exampleglTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glPushMatrix(); glPushMatrix();
glScalef (2.0, 0.4, 1.0); glScalef (2.0, 0.4, 1.0);
glutWireCube (1.0); glutWireCube (1.0);
glPopMatrix(); glPopMatrix();
glPopMatrix(); glPopMatrix();
glutSwapBuffers();glutSwapBuffers();
} }
glTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0); glRotatef ((GLfloat) elbow, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0); glTranslatef (1.0, 0.0, 0.0);
glPushMatrix(); glPushMatrix();
glScalef (2.0, 0.4, 1.0); glScalef (2.0, 0.4, 1.0);
glutWireCube (1.0); glutWireCube (1.0);
glPopMatrix(); glPopMatrix();
glPopMatrix(); glPopMatrix();
glutSwapBuffers();glutSwapBuffers();
} }