Sign in to follow this  

Direct3D mesh and texture

This topic is 2847 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. I am new on Direct3D programming and I have a problem I can't seem to fix. First of all, I am using DirectX 9. I am trying to create a polygon mesh and put a texture to it but it doesn't seem to work. I have added a cube to check if the texture is loaded properly and I can see the picture on the cube but not on the mesh. The code is the following: // create the texture if(FAILED(D3DXCreateTextureFromFile( m_pDX3dDevice, // the Direct3D device _T("Picture.jpg"), // the filename of the texture &m_pTexture))) // the address of the texture storage m_pTexture = NULL; D3DXCreatePolygon(m_pDX3dDevice,5,4,&m_pRectMesh,NULL); //create the mesh D3DXCreatePolygon(d3ddev,10,4,&m_pRectMesh,NULL); ..... // set the texture d3ddev->SetTexture(0, texture); // set the FVF to allow texturing LPD3DXMESH pClone; if ( !(m_pRectMesh->GetFVF() & D3DFVF_TEX1) ) { m_pRectMesh->CloneMeshFVF (D3DXMESH_SYSTEMMEM, m_pRectMesh->GetFVF() | D3DFVF_TEX1, d3ddev, &pClone); if ( m_pRectMesh != NULL ) m_pRectMesh->Release(); m_pRectMesh = pClone; } // draw the cube d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12); m_pRectMesh->DrawSubset(0); Can you please help me and tell me if there is something i'm doing wrong? Best regards, Madalina

Share this post


Link to post
Share on other sites
As you appear to realize, the polygon isn't created with tex coords. After you create a mesh with tex coords, you'll have to set them. I'm guessing they're initialized to (0,0).

EDIT: you create the polygon twice? Also, do you have 2 devices?

Share this post


Link to post
Share on other sites
I didn't create the polygon twice and I have only one device. The problem is, probably, as you mentioned that i have to set manually the texture coordinates. I didn't think about that. Thank you. It was very helpful. I'll try it and announce the results.

Share this post


Link to post
Share on other sites

This topic is 2847 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this