Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with Textures in DX7


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 nPawn   Members   -  Reputation: 110

Like
Likes
Like

Posted 29 October 1999 - 09:12 AM

I'm trying to do the simple task of adding a texture to a triangle in DX7. I've loaded up the image just fine, into a LPDIRECTDRAWSURFACE7 as a texture, I then use the SetTexture command right before i call drawprimitive yes the triangle doesn't get textured, it just remains the color of the material that i set. Here's a snippet of code:

hResult = g3d.m_pDevice->SetTexture( 0, lpSurface); //set the texture here, works just fine
if (hResult != D3D_OK)
{
ErrorSys.Log("SetTexture failed",hResult,false,true);
}
hResult = g3d.m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX, objTriangle.m_pVertex_List, objTriangle.m_dwVertex_Count, NULL ); //drawprimitive works just fine

the only difference i see is that in my code i use D3DPT_TRIANGLELIST instead of D3DPT_TRIANGLESTRIP like the tutorials, but even if i use trianglestrip it makes no difference i still get the bland triangle. The only thing i can think of is that because my texture isn't the same size of my triangle it doesn't "fit" on maybe, i'm just trying to apply one of the example textures from the tutorias. Any suggestions of where to look, everything seems to be working, no error codes at all, just no texture, so i must be missing something simple along the way.


Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 29 October 1999 - 08:41 AM

you have to set the texel coordinates on the triangle. Did you do this? Each vertex has an additional 2 fields for texels. The coordinates range from 0 --> 1. The lower left corner of your image is 0,0 and the upper right corner is 1,1. If you wanted to map this image to a triangle you would set the texels like this(crappy triangle though):
(0.5,1)
/\
/ \
/____\
(0,0) (1,0)

sorry kinda crappy explanation. If you don't do that, Direct3D doesn't know how to map the texture onto the geometry so you don't see it.

Killer


#3 nPawn   Members   -  Reputation: 110

Like
Likes
Like

Posted 29 October 1999 - 08:52 AM

Ahh thanks, i saw no mention of this in the docs i'll have to look a bit harder. I'll go give it a try right now.

#4 nPawn   Members   -  Reputation: 110

Like
Likes
Like

Posted 29 October 1999 - 08:56 AM

Yep, you were right, now i just wonder how i'm going to apply a single texture to several triangles, that looks like it might get ugly doing it this way...?

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 29 October 1999 - 09:12 AM

all you need is to write a function that figures out the dimensions of your object and automatically sets up the texels for you. One way to do it for linear texture projections(ie. say we're putting a texture on the wall of a building that is made up of 10x10 vertices, each of which needs texel coords). When you load your object, go through all the vertices and figure out the max/min displacements for the wall on the two axes perpendicular to the surface normal. Since you know that you want (0,0) on the lower right hand part of the wall and (1,1) on the upper left part, you need to visit each vertex again and give it a value from 0-->1 based on it's percentage of the way from max-->min. ie. if it is 95% of the way from min to max on the X axis, you would give it 0.95 as a texel coordinate for X, if the same vertex was only 20% of the way from min to max on the Y axis, you would give it 0.20 as a texel coord for the Y axis. You can come up with some simple formulas to go through all your vertices and do this.

Killer





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS