#### Archived

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

# D3D texture mapping

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

## Recommended Posts

sorry, but ive got a bunch of questions.. Ok, I''m using the flexible vertex format, so I have to add D3DFVF_TEX1 right? Then in my struct I have float tu1 and tv1. So what exactly do these values have to correspond to? Also, how do I load a texture in? And..how do I set the texture before I plot the triangle? thx

##### Share on other sites
The whole concept of U/V coordinates can best be described with a rubics cube and a piece of paper. The cube represents your 3d model and the paper represents your 2d bitmap texture.

UV coords describe how that 2d picture gets placed on that 3D cube.

  Fig 1. Here is your cube: Fig 2. And your texture: /------// 0------------1 U / / / / O O //------/ / / l // / / / // / / / \---/ /--------/ V 1--------------Fig 3. 0,0---------0.5,0 / / / / / / 0,0.5-------0.5,0.5

Take the paper and draw a 0 in the upper left corner and draw 1 in the upper right and lower left corner.

Now plop your cube on the piece of paper. Your cube is probably smaller than the piece of paper so you can position wherever on the paper. The part of the paper that is covered will be mapped to that face of the cube. The U coord is really just the horizontal precentage (from 0 - 1) of the texture and the V is the vertical percentage of the texture. This makes the texture coordinates resolution independant.

Every vertex will get its own U&V coordinate. So lets say the cube covers the upper left quarter of the paper. The UV Coords would be: (see Fig.3)

So when the cube is rendered only the upper left quarter will be 'mapped' to that face.

If you want the whole texture on the single face then change the 0.5's to 1's. If you want the texture to repeat five times across the one face change the 0.5's to 5's

or you can flip the texture by swaping U and V coords.

Hope this helped.

As far as your vertex format...just stick to the basic:
'D3DFVF_VERTEX' which is defined by:
D3DFVF_XYZ / D3DFVF_NORMAL / D3DFVF_TEX1

^Transform ^Lighting ^Texture Map (UV)

This will tell Direct3D to transform,light and texture map your data.

For info on how to load a texture, do a search in the DirectX SDK directory for 'D3DTextr_CreateTextureFromFile'

//Init Direct3D for texturing
m_lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
m_lpD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
m_lpD3DDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
m_lpD3DDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );

To set the active texture:
IDirect3DDevice7::SetTexture

Good Luck. I hope I helped.

"You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!""

Edited by - emfb on June 15, 2000 2:31:26 AM

thanks

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002235
×