Game Development Reference
In-Depth Information
Generating the texture object
Now we have set up all the necessary parameters, it is time to get the
pixel data from the memory store. This is done with the function
glTexImage2D. The details of this function call are
void glTexImage2D (Glenum target , Glint level , Glint internalFormat ,
Glsizei width , Glsizei height , Glint border , Glenum
format , Glenum type , const Glvoid *pixels );
Nine parameters, aargh! But fear not, it is fairly easy to use. Target is
whether we are dealing with real data or a proxy. A proxy is used to enable
the developer to try to create a texture object and then check whether this
would work. Texture memory is a limited resource and the developer could
decide to size the texture down so that it will fit into memory or clear out
other textures that they may feel have a lower priority. A texture object is not
really created using a proxy and the value for the pixel data passed to it
should be NULL. The level parameter allows a single texture object to use
more than one bitmap; the base level is 0, subsequent levels scale the
bitmap down. OpenGL can then use a smaller version of the bitmap when
the texture object is more distant. More on using multiple levels of detail
later. The internalFormat can be one of 38 different constants that define
how the pixel data are stored when the texture object is created. In the
example we use GL_RGB to store the pixels as RGB values. Width and
height are self-explanatory. A texture can have a coloured border, turned on
or off using the border parameter, 0 for no border and 1 for a border. The
format dictates the way that pixel data are stored before unpacking; in the
sample we use GL_BGR_EXT, which is the way that standard windows
bitmaps are unpacked. The data type in our example is GL_UNSIGNED_
BYTE. Finally, the last parameter is the actual pixel data.
The final code snippet to create a texture object is:
glBindTexture (GL_TEXTURE_2D, m_texID);
glPixelStorei GL_UNPACK_ALIGNMENT, 1);
Search Nedrilad ::

Custom Search