Game Development Reference
In-Depth Information
We begin by instantiating several global variables; one is the vertex
buffer that stores the vertices of the quad and the other is the texture
that we map to the quad:
IDirect3DVertexBuffer9* Quad = 0;
IDirect3DTexture9* Tex = 0;
The
Setup
routine is fairly straightforward; we construct a quad from
two triangles with texture coordinates defined. We then load the bitmap
file dx5_logo.bmp into an
IDirect3DTexture9
interface. Next we
enable the texture using the
SetTexture
method. Finally, we set the
minification and magnification filters to linear filtering, and we also set
the mipmap filter to
D3DTEXF_POINT
:
bool Setup()
{
Device->CreateVertexBuffer(
6 * sizeof(Vertex),
D3DUSAGE_WRITEONLY,
Vertex::FVF,
D3DPOOL_MANAGED,
&Quad,
0);
Vertex* v;
Quad->Lock(0, 0, (void**)&v, 0);
// quad built from two triangles, note texture coordinates:
v[0] = Vertex(-1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
v[1] = Vertex(-1.0f, 1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
v[2] = Vertex( 1.0f, 1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
v[3] = Vertex(-1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
v[4] = Vertex( 1.0f, 1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
v[5] = Vertex( 1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);
Quad->Unlock();
// Load texture data.
D3DXCreateTextureFromFile(
Device,
"dx5_logo.bmp",
&Tex);
// Enable the texture.
Device->SetTexture(0, Tex);
// Set texture filters.
Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
// set projection matrix
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
Search WWH ::
Custom Search