10. Depth Buffer Example
• Write the following in the DrawGLScene method:
– glDisable(GL_DEPTH_TEST);
• Now look at what happened. Without Depth Test, OpenGL will draw the objects
according to their ordering in the code.
With Depth Test Without Depth Test
20. Using 3D Models
You can use any 3D Model Loader
http://nehe.gamedev.net/tutorial/model_loading/16004/
21. Using Model_3DS
• You can import and export .3ds files from 3d Design Programs:
– 3DS Max
– Maya
– Blender
– Google Sketch
– etc
• You can load and draw .3ds files by using Model_3DS class (or any other):
– Model_3DS.h
– Model_3DS.cpp
• You can garment (texture) 3ds models by using:
– 3Dtexture.h
– 3Dtexture.cpp
22. Using Model_3DS
• Add the following to the project directory:
– Model_3DS.h
– Model_3DS.cpp
– 3Dtexture.h
– 3Dtexture.cpp
• In Main.cpp / your class
– #include “Model_3DS.h”
23. Init Code
// Draw a triangle
// Draw a square
// a polygon
// another triangle
// ..etc
GLvoid DrawGLScene()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( 0.0, 0.0, 5.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0 );
GLvoid init()
Global scope:
32. Draw Functions Parameters
• qobj
• The quadric object (created with gluNewQuadric).
• radius
• The radius of the sphere.
• slices
• The number of subdivisions around the z-axis (similar to lines of longitude).
• stacks
• The number of subdivisions along the z-axis (similar to lines of latitude).
38. Fog
glFog(property, value)
• Depth Cueing
– Specify a range for a linear fog ramp
• GL_FOG_LINEAR
• Environmental effects
– Simulate more realistic fog
• GL_FOG_EXP
• GL_FOG_EXP2
58. Picking
• The picking region is usually specified in a piece of code like this:
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPickMatrix(x, y, width, height, viewport);
• The picking matrix is the rare situation where the standard projection matrix
(perspective or ortho) is multiplied onto a non-identity matrix.
• Each hit record contains:
• number of names per hit
• smallest and largest depth values
• all the names
59. Picking
• Programming steps
– Restrict “drawing” to small region near pointer
Use glupickmatrix() on projection matrix
– Enter selection mode; re-render scene
– Primitives drawn near cursor cause hits
– Exit selection; analyze hit records
60. Picking with Ray Casting
http://antongerdelan.net/opengl/raycasting.html