Game Development Reference
In-Depth Information
int gluBuild2DMipmaps( GLenum target , GLint components ,
GLint width , GLint height , GLenum format , GLenum type ,
const void * data );
The parameters have the same effect as glTexImage2D.
When creating a texture we first get a texture ID number using
glGenTextures, so that we can restore this texture as the current
texture in OpenGL. glGenTextures simply creates an ID number, no
pixel data are created. We also use this ID to destroy the texture when
we have finished using it. Having created a texture ID we then make
this the current texture using glBindTexture. The next step is to set up
the pixel storage alignment and what we want to do if the texture does
not fit the area it is mapped to. Should we repeat the image up and
down and across, or should the edge of the image be used as a
colour? We also specify how OpenGL will scale the image. Since we
are writing a real-time application we want the fastest method of
scaling, which is to use the nearest pixel to the one we want. Another
method would be to blend pixels, but this takes longer and is not really
suited to real-time applications. The final option in the sample code
fragment is how to use the texture with the current lighting model.
I prefer to blend the texture with the existing surface colour. If you make
the colour for any textured surface white, then this gives you the lit
texture.
Having set up all the parameters, we can now exchange our pixel
buffer with OpenGL using either glTexImage2D or gluBuild2Dmipmaps
depending on your choice of levels of detail.
//Create a texture id and make it current
glGenTextures(1, &texID);
glBindTexture (GL_TEXTURE_2D, texID);
//Set DWORD alignment
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
//Set width repeat option
if (widthRepeat){
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
}else{
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
}
Search Nedrilad ::




Custom Search