Platform SDK: DirectX |
This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.
Direct3D represents textures as two dimensional arrays of color values. Each element in the array is referred to as a texel. You can access a texel through column and row numbers, which are labeled U and V, respectively.
Your application can assign texture coordinates directly to the vertices by using the DirectX7.CreateD3DVertex method. The following code fragment, taken from the Texture application, creates a set of four vertices describing the front face of a cube:
g_dx.CreateD3DVertex -1, 1, -1, 0, 0, -1, 0, 0, vertices(0) g_dx.CreateD3DVertex 1, 1, -1, 0, 0, -1, 1, 0, vertices(1) g_dx.CreateD3DVertex -1, -1, -1, 0, 0, -1, 0, 1, vertices(2) g_dx.CreateD3DVertex 1, -1, -1, 0, 0, -1, 1, 1, vertices(3)
For each CreateD3DVertex method call, the first three arguments define a vertex, the second three arguments define the orientation of the vertex normal vector, and the next two arguments represent the texture coordinates of the vertex. In this case, you want the application to map the entire bitmap texture onto the front face of the cube, so you will use the following texture coordinates: (0, 0), (1, 0), (0, 1), and (1, 1).
For more information on texture coordinates, see Texture Coordinates.
You should employ the same procedures for the back, top, bottom, right, and left faces of the cube. See the Texture application code in the SDK for information on how to do this.
The Texture application uses the programmer-defined function CreateTextureSurface to return a DirectDrawSurface7 object. The returned texture surface object will be set to the primitive during rendering:
Set g_ddsTexture1 = CreateTextureSurface("tree1.bmp") Set g_ddsTexture2 = CreateTextureSurface("tex1.bmp") Set g_ddsTexture3 = CreateTextureSurface("earth.bmp")
In the preceding code, three texture surface objects are created from the following bitmap files: ("tree1.bmp, " "tex1.bmp," and "earth.bmp").
Note In order to run the Texture application, you need to ensure that your Visual Basic application can find your texture files ("tree1.bmp", "tex1.bmp", and "earth.bmp"). The Texture application looks for these files in the same folder that contains your Texture application's project file (.vbp).
Now, you can look at the programmer-defined subroutine CreateTextureSurface in detail, to see how texture surface objects are prepared and created. The initial step of this process is illustrated in Step 1.2: Prepare the Texture Surface.