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

texture wrappingg!!!! argghh

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

im trying to create a cube...created from D3DXCreateBox()...but i just can''t seem to wrap a texture around it? anyone got a sample code i could use? thanksss if you see me running, try and catch me!!

Share this post

Link to post
Share on other sites
what do you mean by ''wrap''?...i think you need cubical mapping...
either way what you need to do is to Lock the Vertex Buffer and retrieve a pointer to the vertex buffer, modify the uv coordinates for each vertex for the ''wrap'' mapping and unlock the buffer, then draw the box with a texture selected...

I don''t think you want to do all this...if you do, you wouldn''t be drawing a box on the screen... am i guessing right here?

(btw: you can do a search in google to find ab''t generating mapping coordinates for each mapping, like cubical mapping, cylindrical etc.)

Share this post

Link to post
Share on other sites
ei thanks for the reply! what i am really trying to do is create a wall of sort, with a texture on it. Maybe you could help me find a way to place a texture around a mesh?

i found this code from Robert Dunlop site at

LPD3DXMESH CTriarts103View::Posterize() // can be placed in object for better customization

if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, _T("mukha_niya.jpg"),
&m_pBackgroundTexture ) ) )
return NULL;


if(FAILED(D3DXCreateBox(m_pd3dDevice, 5.0f, 5.0f, 0.0f, &mesh2, NULL)))
return NULL;

// create a copy of the mesh with texture coordinates,

// since the D3DX function doesn''t include them

return mesh2;

// finished with the original mesh, release it


// lock the vertex buffer

VERTEX *pVerts;

if (SUCCEEDED(texMesh->LockVertexBuffer(0,(BYTE **) &pVerts))) {

// get vertex count

int numVerts=texMesh->GetNumVertices();

D3DXVECTOR3 vMin,vMax;

// calculate center


// loop through the vertices

for (int i=0;i<=numVerts;i++) {

// calculate normalized offset from center


// calculate texture coordinates


// go to next vertex


// unlock the vertex buffer


// return pointer to caller

return texMesh;

the code only allowed me to create 7 cubes. then it would cause an error. maybe you could help find an alternative or answer for this? your help would be much appreciated. And i think i should reconsider using cubic mapping for my environment. thanks.

Share this post

Link to post
Share on other sites when i said cubical mapping, i didn''t mean ''cubical environment mapping'' which is generally used for special effect (or eyecandy). I was refering to a texture coordinate mapping method.

Anyway, for wrapping the texture around the cube (or wall) you need to understand how each vertices is stored in the mesh vertex buffer. Also you need to understand, which vertex (in the v-buffer) corresponds to a particular vertex of the cube. Then you should loop through the vertices in the vertex buffer and assign the uv for it. The actual calculation of the uv coordinates for different mapping can be found from some articles (i don''t recall any at this moment, sorry, u can do a search in google).

But if you are new to DirectX, then what i would suggest is to use the .X Files to load the cube mesh. Create the cube mesh in some modelling package and map it in the same (only 3DSMax has a .X file exporter).

I don''t know exactly what your level is, also generally nobody maps any mesh programatically (yeah, some, do but only in the initial stages and they know how to do it). Explaining the entire process is too lengthy to place it should get a firm grasp of uv-mapping, how textures are mapped etc. if you want to do it through program...(or else you can try some sample code, there are couple of them in opengl, maybe you can port )

Share this post

Link to post
Share on other sites
aanand ei thanks for the help i got my code working already. what i did wrong was that i did not release some of my previous vertex buffers and forgot to place my SetVertexShader to my Vertex thanks for your help

by any chance do u know how to pick in an orthographic projection? i was able to pick in perspective projection but am having a hard time in the orthographic part... thanks

if you see me running, try and catch me!!

Share this post

Link to post
Share on other sites