Archived

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

DirectX Texture Mapping Problem

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

I have a problem with a simple game I am writing. I have a simple rectangular room - with 4 walls, floor and ceiling. I have mapped a texture to the walls and another to the floor+ceiling. When I move the camera position left/right, the left/right walls appear to jump, as the camera moves. I know that the model is ok, as this only happens when texture mapping is used. Any suggestions would be much appreciated.

Share this post


Link to post
Share on other sites
Stupid question, but your using the correct FVF to match against the vertex structure you have defined?

D3DFVF_XYZ|D3DFVF_TEX1

for x,y,z and tx,ty texture coordinates.

If you are then it sounds a little like a memory leak in the stream, Its happened to me a few times when allocating not enough vertex memory for the vertex buffer or trying to draw 1 to many triangles or something

Can you print your main rendering code here, and allocation of your Vertex buffer. BTW. is it D3DXMESH ?

Share this post


Link to post
Share on other sites
Here is the code which initialises the room objects:
D3DXCreateTextureFromFile( m_pd3dDevice, "data\\water1.bmp",
&m_pTextureWalls );
D3DXCreateTextureFromFile( m_pd3dDevice, "data\\rock2.bmp",
&m_pTextureWalls2 );

if( FAILED( m_pd3dDevice->CreateVertexBuffer( WALL_VERT_NUM * sizeof(WALLVERTEX),
0, D3DFVF_WALLVERTEX, D3DPOOL_MANAGED, &m_pVBWalls, NULL ) ) )
{
return E_FAIL;
}

WALLVERTEX* pVertices;
m_pVBWalls->Lock( 0, 0, (void**)&pVertices, 0 );

FILL_WALLVERTEX( pVertices[ 0], -5.0f,-5.0f, 5.0f, 0.00f, 1.0f );
FILL_WALLVERTEX( pVertices[ 1], -5.0f, 5.0f, 5.0f, 0.00f, 0.0f );
FILL_WALLVERTEX( pVertices[ 2], 5.0f,-5.0f, 5.0f, 1.00f, 1.0f );
FILL_WALLVERTEX( pVertices[ 3], 5.0f, 5.0f, 5.0f, 1.00f, 0.0f );
FILL_WALLVERTEX( pVertices[ 4], 5.0f,-5.0f,-5.0f, 0.00f, 1.0f );
FILL_WALLVERTEX( pVertices[ 5], 5.0f, 5.0f,-5.0f, 0.00f, 0.0f );
FILL_WALLVERTEX( pVertices[ 6], -5.0f,-5.0f,-5.0f, 1.00f, 1.0f );
FILL_WALLVERTEX( pVertices[ 7], -5.0f, 5.0f,-5.0f, 1.00f, 0.0f );
FILL_WALLVERTEX( pVertices[ 8], -5.0f,-5.0f, 5.0f, 0.00f, 1.0f );
FILL_WALLVERTEX( pVertices[ 9], -5.0f, 5.0f, 5.0f, 0.00f, 0.0f );

m_pVBWalls->Unlock();

// Create the floor/ceiling vertex buffer
if( FAILED( m_pd3dDevice->CreateVertexBuffer( FLOORCEILING_VERT_NUM * sizeof(FLOORCEILINGVERTEX),
0, D3DFVF_FLOORCEILINGVERTEX, D3DPOOL_MANAGED, &m_pVBFloorCeiling, NULL ) ) )
{
return E_FAIL;
}

FLOORCEILINGVERTEX* pFloorVertices;
m_pVBFloorCeiling->Lock( 0, 0, (void**)&pFloorVertices, 0 );
FILL_FLOORCEILINGVERTEX( pFloorVertices[0], -5,-5, 5, 0, 1, 0, 0.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[1], 5,-5, 5, 0, 1, 0, 0.0f, 1.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[2], 5,-5,-5, 0, 1, 0, 1.0f, 1.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[3], 5,-5,-5, 0, 1, 0, 1.0f, 1.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[4], -5,-5,-5, 0, 1, 0, 1.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[5], -5,-5, 5, 0, 1, 0, 0.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[6], 5, 5,-5, 0,-1, 0, 1.0f, 1.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[7], 5, 5, 5, 0,-1, 0, 0.0f, 1.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[8], -5, 5, 5, 0,-1, 0, 0.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[9], -5, 5, 5, 0,-1, 0, 0.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[10], -5, 5,-5, 0,-1, 0, 1.0f, 0.0f );
FILL_FLOORCEILINGVERTEX( pFloorVertices[11], 5, 5,-5, 0,-1, 0, 1.0f, 1.0f );
m_pVBFloorCeiling->Unlock();

Share this post


Link to post
Share on other sites
And this is the rendering code:

void Walls::setTransfPipe()
{
D3DXMATRIXA16 matWorld, matScale;

D3DXMatrixTranslation( &matWorld, 0.0f, 0.0f, 250.0f);
D3DXMatrixScaling(&matScale, 10.0f, 4.0f, 50.0f);

D3DXMatrixMultiply(&matWorld, &matScale, &matWorld);
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

}
void Walls::setMaterials()
{
// Set / update surface material properties. P
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
mtrl.Diffuse.r = mtrl.Ambient.r = 0.8f;
mtrl.Diffuse.g = mtrl.Ambient.g = 0.8f;
mtrl.Diffuse.b = mtrl.Ambient.b = 0.8f;

m_pd3dDevice->SetMaterial( &mtrl ); // Only one material can be used at a time.
}
void Walls::Render()
{
setTransfPipe();

setMaterials();

// Render Floor & Ceiling

m_pd3dDevice->SetTexture( 0, m_pTextureWalls );

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );

m_pd3dDevice->SetFVF( D3DFVF_FLOORCEILINGVERTEX );
m_pd3dDevice->SetStreamSource( 0, m_pVBFloorCeiling, 0, sizeof(FLOORCEILINGVERTEX) );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 4 );

// Render the multi-textured object
m_pd3dDevice->SetTexture( 0, m_pTextureWalls2 );

m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );

m_pd3dDevice->SetFVF( D3DFVF_WALLVERTEX );
m_pd3dDevice->SetStreamSource( 0, m_pVBWalls, 0, sizeof(WALLVERTEX) );
m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 8);
m_pd3dDevice->SetTexture( 0, NULL );
}

Share this post


Link to post
Share on other sites
I cant immediately see what is wrong with the code there

I would suggest you change the walls into Triangle lists and see if you still get the problem so that at least you can remove that part of it from a list of possible problems.

Sorry I cant me more help.. I havn''t used triangle strips before

Share this post


Link to post
Share on other sites
Thanks for your help anyway. As this is just for a uni assignment, i''ll not worry too much right now. Although I would like to know the reason for the problem, to help in future developments... I''m thinking that it may be a scaling issue.

As my room starts as a square, and is being scaled into a rectanglar shape. Would this have an effect on the texturing? I understand the basic theory behind texture mapping, but i''m not so certain as to how it is implemented.

Share this post


Link to post
Share on other sites