Graphics Reference
In-Depth Information
Figure 9.2. A texture and the familiar teapot with this texture.
An example texture, and that texture applied to the familiar teapot, are shown
in Figure 9.2. The fragment shader code for this image follows.
In the shader code below, the linking of the uImageUnit sampler with the
actual texture object has already happened in the application, and the map-
ping from the original texture atribute to the variable vST has been done in
the vertex shader. In this example we are using the multitexture at index 0, or
glTexCoord2f in traditional OpenGL API. The 2D texture coordinates for the
individual texture have been interpolated as the . st components of the texture
variable, and the texture( ) function has returned the value from the texture
unit at those coordinates. Finally, we note that the texture has been set up to
wrap.
Below we give the GLIB file, the vertex shader, and the fragment shader for
this example. The GLIB file sets the texture object to come from the apples.bmp
file and links that to texture unit 5. It also assigns a value of 5 to a uniform
variable called uImageUnit and
tells the shader program about
it. The vertex shader sets the tex-
ture coordinate and the value of
gl_Position , and the fragment
shader reads the color of the
texture from uImageUnit and
assigns it to the pixel.
Here we use the function texture( ) in place
of the texture1D , texture2D , texture3D , and
textureCube functions used in compatibility
mode. In the newer versions of OpenGL, the
texture( ) function takes its dimension from
the dimension of the sample variable.
Search WWH ::




Custom Search