   'Programming RPG With DirectX' engine question
  I have the book 'Programming Role Playing Games With DirectX' to learn DirectX 8 and right now I'm just fooling around with the provided graphics engine. My question is how do I draw texture mapped polygons with the graphics engine...he doesn't explain how to use it in the book, at least not that I've seen. I can create the texture fine, and if I just use the provided Blit() function provided with the cTexture class that works, but I want to map it to a polygon. I've gotten my polygon made, and it displays fine, and I have the VERTEXFVF set to include Textures. Here is my Vertex structure definition: // Define Vertex Structure and associated VertexFVFstruct sVertex{float x, y, z, rhw;// xyz Coordinatesfloat tu, tv;};#define VERTEXFVF (D3DFVF_XYZRHW | D3DFVF_TEX1)and later in the game loop I have this code to create the vertices and put them into the vertex buffer, set the graphics engine to use the texture, clear the backbuffer and display the polygon.   sVertex sBackground[4] ={{0, 0, 0, 1, 1, 1},{640, 0, 0, 1, 1, 1},{0, 480, 0, 1, 1, 1},{640, 480, 0, 1, 1, 1}};// Put the vertices into the vertex bufferApp->mVertexBuffer.Set(0, 4, &sBackground);// Set the texture to the graphics classApp->mGraphics.SetTexture(0, &App->mTexture[0]);// Clear the Back BufferApp->mGraphics.ClearDisplay(D3DCOLOR_RGBA(0, 0, 0, 255));// Lock the Back Buffer to do the drawingApp->mGraphics.BeginScene();// Draw the Vertex BufferApp->mVertexBuffer.Render(0, 2, D3DPT_TRIANGLESTRIP);// Unlock the Back BufferApp->mGraphics.EndScene();// Display the Back BufferApp->mGraphics.Display();where mTexture[0] is an instance of the cTexture class which I've loaded a .bmp into. I assume this is how it is supposed to work. Create Texture->Create Vertices->Put Vertices in Vertex Buffer->Set Texture to the graphics engine->Draw Vertex Buffer. Instead of the picture it just draws a greenish block, and if I change the tu, tv numbers of the vertices then it sort of smears some colors of the .bmp across the green block. Anybody else with this book know how this is supposed to be done? or can anybody point out what I'm doing wrong. Thnx.   - God is my favorite fictional character[edited by - deadlydog on May 29, 2004 1:09:08 AM]
  Texture co-ordinates specify exactly that, texture co-ordinates.Right now you''re setting all of your values to 1,1.  That means every texel (I believe) is the bottom right of the texture.To map an entire texture to a single polygon, you have to map it properly:0,0 - Top Left Vertex1,0 - Top Right Vertex0,1 - Bottom Left Vertex1,1 - Bottom Right Vertex.Basically, the top-left vertex is going to be 0,0 in the image.  Then it''ll move texel by texel to 0,1 where it''ll use 0, X (where X is the width of the image).And so forth, and so forth.Hope you follow. 