Game Development Reference
In-Depth Information
Listing 3-10 shows CreateEmptyTextureRGB565 , which creates an empty texture for drawing
and has the following arguments:
w,h : This is the size of the video image.
x_offset, y_offset : These are the XY offset coordinates at which the
image will be rendered into the texture. Read on to see why you may
need this.
To create a texture in OpenGL, you simply call
glGenTextures(1, &mTextureID);
glBindTexture(GL_TEXTURE_2D, mTextureID);
where mTextureID is an integer that has stored the ID of your texture. Next, it sets the
following texture parameters:
GL_TEXTURE_MIN_FILTER : This texture-minifying function is used
whenever the pixel being textured maps to an area greater than one
texture element. The minifying function you use is GL_NEAREST , which
returns the value of the texture element that is nearest (in Manhattan
distance) to the center of the pixel being textured.
GL_TEXTURE_MAG_FILTER : This texture-magnification function is used
when the pixel being textured maps to an area less than or equal to
one texture element. The magnification function you use is GL_LINEAR ,
which returns the weighted average of the four texture elements that are
closest to the center of the pixel being textured.
GL_TEXTURE_WRAP_S : This sets the wrap parameter for each texture
coordinate S to GL_CLAMP , which causes the coordinates to be clamped
to the range [0,1] and is useful for preventing wrapping artifacts when
mapping a single image onto an object.
GL_TEXTURE_WRAP_T : This sets the wrap parameter for each texture
coordinate T to GL_CLAMP .
Finally, you specify a two-dimensional texture image with glTexImage2D with the following
parameters:
GL_TEXTURE_2D : Specifies the target texture.
Level : Specifies the level-of-detail number. Level 0 is the base
image level.
Internal format : Specifies the color components in the texture, in this
case RGB.
Width and height : Size of the texture. It must be a power of two.
Format : It specifies the format of the pixel data and must be the same
as the internal format.
Search WWH ::




Custom Search