Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


'Programming RPG With DirectX' engine question

This topic is 5287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 VertexFVF

struct sVertex
	float x, y, z, rhw;		// xyz Coordinates

	float tu, tv;
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 buffer

	App->mVertexBuffer.Set(0, 4, &sBackground);

	// Set the texture to the graphics class

	App->mGraphics.SetTexture(0, &App->mTexture[0]);

	// Clear the Back Buffer

	App->mGraphics.ClearDisplay(D3DCOLOR_RGBA(0, 0, 0, 255));

	// Lock the Back Buffer to do the drawing


	// Draw the Vertex Buffer

	App->mVertexBuffer.Render(0, 2, D3DPT_TRIANGLESTRIP);

	// Unlock the Back Buffer


	// Display the Back Buffer

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]

Share this post

Link to post
Share on other sites
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 Vertex
1,0 - Top Right Vertex
0,1 - Bottom Left Vertex
1,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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!