Game Development Reference
In-Depth Information
Figure 4-1. Rendering using glDrawArrays
Simple enough, but things get tricky when you need to apply image data to your geometry
(also known as texturing). Let's see how this is done on the PC. The following fragment
renders a textured quad with traditional OpenGL:
glBindTexture (GL_TEXTURE_2D, 13);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (10.0, 0.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (10.0, 10.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, 10.0, 0.0);
glEnd ();
Note that this fragment assumes that texturing has been enabled and that a texture has
been uploaded with the ID of 13—perhaps with a call such as
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
imageData)
where imageData is an array of unsigned bytes representing RGB values for the texture with
ID 13. Listing 4-1 shows the previous fragment re-written using arrays for GL ES.
 
Search WWH ::




Custom Search