Jump to content
  • Advertisement

Archived

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

EasyGino

Texture Mapping

This topic is 5458 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

Hello all, Ok, I''ve moved on from drawing some primitive objects like a triangle to a more advanced "pyramid" and now im looking at wrapping it up in the DX9 tutorial "banana" texture. However in there example they wrap it around a cylinder where my object is a pyramid. So I have this to define my pyramid. CUSTOMVERTEX g_Vertices[] = { { -.50f, 1.0f, -0.0f, 0xff000fff, }, { -1.0f, .0f, -.5f, 0xff000fff, }, { -.50f, .0f, 0.0f, 0xff0fffff, }, { -.5f, .0f,0.0f, 0xff000fff, }, { -.50f, 1.0f, -0.0f, 0xff000fff, }, { 0.0f, .0f, -0.5f, 0xff0fffff, }, { -1.0f, .0f, -.5f, 0xff000fff, }, { .0f, .0f, -.5f, 0xff000fff, }, { -.5f, 1.0f, .0f, 0xff0fffff,}, { -1.0f, .0f, -.5f, 0xff000fff, }, { .0f, .0f, -.5f, 0xff000fff, }, { -.5f, .0f, .0f,0xff0fffff, }, }; for( int i=0; i<12; i++) { #ifndef TEXTURE g_Vertices.tu = -1.0f; g_Vertices[i].tv = -1.0f; #endif } HOWEVER i''m honestly unsure on what tu and tv is suppose to be set too. I''ve tried mimicing the x,y coordinates of my g_Vertices, but that doesn''t work either. Help please! Mike

Share this post


Link to post
Share on other sites
Advertisement
Well, first of all, the tu and tv coordinates (henceforth known as uv coords) will need to be different for each vertex. That loop you''ve got assigns identical uv coords to all the vertices, which will result in an object with a uniform color.

Look here for a brief introduction to uv mapping.

Share this post


Link to post
Share on other sites
Ok can anyone else offer me some insight on what I need to do? I can''t read a tutorial like that and understand fully, I need to be able to see the code for what they are doing. It''s a simple pyramid with the above vertices and im confused on where to start using these UV settings. argh.

Share this post


Link to post
Share on other sites
Think a texture as a 2d plane with area (0,0)-(1,1).
Now, every vertex needs to include a coordinate corresponding to one point in this plane. The hardware calculates, by these coordinates, at which points of the texture it should get the colors of the pixels of the rasterized triangles.

Sorry, i can''t explain it easier, but i hope this helps.

-Nik

Share this post


Link to post
Share on other sites
Im such a pain,

Ok for example this triangle here, just a plane triangle.

{ -.50f, 1.0f, 0.0f, 0xff000fff, }
{ -1.0f, .0f, 0.0f, 0xff000fff, }
{ -.50f, .0f, 0.0f, 0xff0fffff, }

now what would the value of my pu, pv? -1.0f, 1.0f? that would cover almost all the triangle? Or am I not looking at this in the right way?

Share this post


Link to post
Share on other sites
You cannot easily map a square texture to a single triangle.

The numbers are texture coordinates:



[edited by - Nik02 on October 9, 2003 11:59:58 AM]

Share this post


Link to post
Share on other sites
Ok so what you are saying is, for a triangle I need 3 pu, pv coords right? each corresponding to each vertex.. respectively.

so a [0,0] [0,1] [1,1] and that will draw a half triangle BUT completely distort my image, right? but it''ll draw it onto the triangle?

Share this post


Link to post
Share on other sites
It''ll draw exactly half of the texture into your triangle.
It does not distort it in any way, however.
Try different coords, i''m sure you''ll get the idea soon

-Nik

Share this post


Link to post
Share on other sites
you only need one set of uv coordinates per texture, generally.

each vertex just set the texture coordinates you want it to have.

Share this post


Link to post
Share on other sites
Essentially would this work?


for (int i=0; i<4; i++){
g_Vertices.tu = 0.0f;
g_Vertices[i].tv = 0.0f;
g_Vertices[i + 1].tu = 0.0f;
g_Vertices[i + 1].tv = 1.0f;
g_Vertices[i + 2].tu = 1.0f;
g_Vertices[i + 2].tv = 1.0f;
}

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!