Game Development Reference
In-Depth Information
from 0.87 to 1.0. The simplest solution to this is to test polygons for a high
range and to add one to the low value if a high range is found. The right
image in the diagram shows the result of this simple fix.
UV mapping
The final option for texture mapping is to allow the artist total control over
how to map the vertices. Many CGI packages provide a way to achieve
this end and it is the user interface that is the complex issue. As you have
learned, any form of mapping generates ( u , v ) coordinates. You may wish
to create your own interface to allow the generation of mapping data. One
technique is to start with a basic mapping and then to draw the mesh flat
over the texture and allow the artist to move vertices with point
manipulation tools. If you had a split screen then you could show the
results of the mapping as the artist edits the vertices.
Displaying the result
Then we can either blend the texture with the current colour or apply it
directly. If we are blending with the current colour then it is usually best to
set the colour to plain white. When painting a polygon we must inform
OpenGL of the current vertex location, the normal and the texture
coordinates for this vertex. Remember that a vertex can be shared in
several polygons. One of the polygons that shares the vertex may have a
different texture. For this reason it is the polygon that is used as the
storage medium for texture coordinates, not the vertex.
A short code snippet that will paint a textured polygon stored in the
previously created texture object defined by the number 'texID' is as
follows:
texID = ply->tex;
glBindTexture(GL_TEXTURE_2D, texID);
glRGB(255,255,255);
glMaterialfv(GL_FRONT, GL_SPECULAR, ply->srf.spec);
glBegin(GL_TRIANGLES);
while(ply->tex == texID){
pt=&pts[ply->p[0]];
glNormal3d(pt->mx, pt->my, pt->mz);
glTexCoord2f(ply->tc[0].u, ply->tc[0].v);
glVertex3d(pt->wx, pt->wy, pt->wz);
Search Nedrilad ::




Custom Search