Game Development Reference
In-Depth Information
Assigning pixel data to the OpenGL texture engine
We now have a DWORD aligned, vertically flipped BGR buffer. The next
step is to provide this pixel data to OpenGL. Texture images are defined
with glTexImage2D .
void glTexImage2D( GLenum target , GLint level , GLint components ,
GLsizei width , GLsizei height , GLint border , GLenum format ,
GLenum type , const GLvoid *pixels );
The arguments describe the parameters of the texture image, such
as height, width, width of the border and number of colour components
provided. The last three arguments describe the way the image is
represented in memory. For our purposes, we define the format as GL_
BGR_EXT and the type as GL_UNSIGNED_BYTE, which is the
way that a Windows bitmap is stored in memory. Data are read from
pixels as a sequence of unsigned bytes. These values are grouped into
sets of three values because we have chosen GL_BGR_EXT as the
format.
Table 6.1
Level
Width
Height
0
128
64
1
64
32
2
32
16
3
16
8
4
f8
4
5
4
2
6
2
1
OpenGL can use several versions of a texture depending on the
scale of that texture on the screen. When using the function glTex-
Image2D, we define which level of detail we are supplying using the
level parameter. OpenGL uses textures that are exact powers of 2 in
width and height. If a bitmap is 128
×
64, then the potential levels of
detail are as shown in Table 6.1.
If you intend to use multiple levels of detail then you can create all these
in one go using the GLU function gluBuild2Dmipmaps.
 
Search Nedrilad ::




Custom Search