cs3241 lab 8

Click here to load reader

Upload: edison-tsui

Post on 13-Jan-2015

598 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

  • 1. Display List
    Texture Mapping
    CS3241 Lab 8

2. Objective
Display List
Understanding the benefit & limitation
Setup Display List
Texturing
Understanding basic texture mapping
Specify a texture image
Generated by program, e.g. checkerboard
Loaded from file
Using texture object
Supply texture co-ordinate
3. Display List vs Immediate Mode
Faster
As geometries are cached
See the difference (sample program loading dino)
Once setup, cannot be changed
4. Display List
Generating empty display list (init)
baseId = glGenLists(range);
Setup the list (init)
glNewList(id, GL_COMPILE);
// your draw code
glEndList();
Using the list (display)
glCallList(id);
5. Task 1
Task 1.1
Use display list to draw a teapot
Task 1.2
Use display list to draw 4 wheels attaching the teapot
So we have the body and wheels. Whats next?
Animation
Loading Mesh
Texturing
Material..
6. Texture
Enabling /Disabling Texture Mapping
glEnable/glDisable(GL_TEXTURE_1D);
glEnable/glDisable(GL_TEXTURE_2D);
7. Texture Object
Better texture management
Generate texture name (init)
GLuinttexObj; // global
glGenTextures(1, &texObj);// init()
Bind texture Object to texture data (init)
glBindTexture(GL_TEXTURE_2D, texObj);
glTexParameter*(); // setup parameter
glTexImage2D(..);// alloc space & copy texture map
Using texture Object (display)
glBindTexture(GL_TEXTURE_2D, texObj);
glutSolidTeapot(1);
TextureName (Gluint)
Parameter
Texture Data
Texture Object
8. Texture Parameters
Repeating / Clamping
Direction s/t
Repeating
Clamping
9. Texture Parameters
Filtering
10. Texture Coordinate
To supply texture coordinate to a vertex
Add glTexCoord2f(s, t); before specifying the vertex
E.g.
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
..
glEnd();
5,5
5,0
0,0
0,5
11. Task 2
Task 2.1
Load a texture from program generated source / file
Apply to Teapot
Task 2.2
Supply texture co-ordinate to a plane
Apply the texture in 2.1 to the plane
12. Example
Modeling a car
Separating different part of the mesh
For animating
the front wheel can move according to key in:P
All the wheels will rotate according to its speed
For having different texture/material
Try to extend it by putting better mesh :P