Texture Mapping

Started by
9 comments, last by EasyGino 20 years, 6 months ago
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.tv = -1.0f; #endif } </code> HOWEVER i''m honestly unsure &#111;n 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 </i>
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.
You are not the one beautiful and unique snowflake who, unlike the rest of us, doesn't have to go through the tedious and difficult process of science in order to establish the truth. You're as foolable as anyone else. And since you have taken no precautions to avoid fooling yourself, the self-evident fact that countless millions of humans before you have also fooled themselves leads me to the parsimonious belief that you have too.--Daniel Rutter
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.
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

Niko Suni

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?
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]

Niko Suni

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?

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

Niko Suni

you only need one set of uv coordinates per texture, generally.

each vertex just set the texture coordinates you want it to have.
Essentially would this work?


for (int i=0; i<4; i++){
g_Vertices.tu = 0.0f;
g_Vertices.tv = 0.0f;<br>g_Vertices.tu = 0.0f;<br>g_Vertices.tv = 1.0f;<br>g_Vertices.tu = 1.0f;<br>g_Vertices.tv = 1.0f;<br>}<br></code> </i>

This topic is closed to new replies.

Advertisement