Graphics Reference
In-Depth Information
12.3.5
Implementation
To work with file texture mapping, our program must:
1. define texture coordinate on all vertices;
2. select and load the file texture into graphics hardware;
3. define how texel values are used to compute pixel colors;
4. enable texture-mapping functionality.
Tutorial 12.4.
Project Name:
D3D _ SimpleTexture
Library Support:
UWB_MFC_Lib1
UWB_D3D_Lib13
Tutorial 12.4. Simple File Texture Mapping
Goal. Demonstrate how to work with graphics API file texture mapping.
Approach. Implement a simple program without the UWBGL library to
clearly illustrate the steps required for working with graphics API texture
mapping.
Figure 12.17 is a screenshot of running Tutorial 12.4. In this tutorial, we can
select a current file texture by clicking the “Select File Texture” button to select
an image file. The texture-mapping functionality can be enabled by the “Enable
Texture” checkbox. Select any image file and enable the texture mapping. Now,
try transforming the primitive. Observe that the texture map behaves as though it
is a flexible sticker pasted on the geometry: the textured image stretches, rotates,
and moves with the primitive. In addition, notice that negative scaling flips the
texture image.
The implementation of this tutorial is purposefully independent of the UWBGL
library. In this case, all texture-mapping functionality is implemented in the
Model.cpp file. With this simple tutorial, we can examine and understand the
programming of texture-mapping functionality in a continuous linear sequence.
After this understanding, in the next tutorial the texture-mapping functionality
will be abstracted into different modules of the UWBGL library.
To ensure clear and focused presentation, the Model.cpp file is divided ac-
Figure 12.17.
Tutorial
12.4.
DeviceVertexFormat . See
Step 3 in Listing 3.3 (on
p. 82); this is the mechanism
for a program to communicate
vertex size and content to the
D3D API.
cording to functional/logical modules in the following different listings. List-
ing 12.8 shows the DeviceVertexFormat defined in Model.cpp for drawing
the textured rectangle and circle. At label A, we see that besides position and
color, we must associate a uv coordinate with each vertex position. Label B de-
fines the corresponding code for programming the D3D API. Listing 12.9 shows
the
draw
functions
of
the
rectangle
( DrawUnitSquare() )
and
the
circle
Search WWH ::




Custom Search