Archived

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

Multiple Textures help!

This topic is 5093 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 everyone. I am having a problem. I am currently working on a graphics engine and right now I am trying to tackle the 2D interface. I have a list of all the textures and it goes through and maps all the textures to the polygons that are defined as using each texture. The issue is that as I render each quad the texture i have defined using SetTexture() to be used for that quad is not the only texture being applied, each previously used texture is being applied behind the newly set texture. How come that happens and how do i make it stop? Here is a screenshot:

As you can see, the upper left image is the first one to be rendered and it is a piece of an ascii chart. the second one is bottom right and it was set to a smiley face but it has the full ascii chart in the background. the third and last one on the bottom left was set to a modified screenshot (to have transparency) and it has both the smiley face and the chart in the background.
Here is my render code:
	//copies raw vertex data into vertex buffer

	VOID* pVertices;
	m_pVB->Lock( 0, sizeof(m_cvVertices), (BYTE**)&pVertices, 0 );
	memcpy( pVertices, m_cvVertices, sizeof(m_cvVertices) );
	m_pVB->Unlock();

	if(WIREFRAME == TRUE)
	{
		m_pD3D8Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
	}

	// Clear the back buffer to a blue color

	m_pD3D8Device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
	// Begin the scene.

	m_pD3D8Device->BeginScene();

	m_pD3D8Device->SetStreamSource( 0, m_pVB, sizeof(CUSTOMVERTEX) );
	m_pD3D8Device->SetVertexShader( D3DFVF_CUSTOMVERTEX );
	for(unsigned int i = 0; i < m_uiNTextures; i++)
	{
		if( !(m_tmTextures[i].ridTex == SK3_NO_TEXTURE) )
		{
			m_pD3D8Device->SetTexture( 0, 
				(LPDIRECT3DTEXTURE8)SK3ResMan::GetSing().GetResource(m_tmTextures[i].ridTex));
		}
		else
		{
			m_pD3D8Device->SetTexture( 0, NULL );

		}
		m_pD3D8Device->DrawPrimitive( D3DPT_TRIANGLELIST, m_tmTextures[i].uiBegin, 
									  m_tmTextures[i].uiEnd );
	}
	// End the scene.

	m_pD3D8Device->EndScene();
	m_pD3D8Device->Present( NULL, NULL, NULL, NULL );

	m_uiNTextures = 0;
	m_uiNVertices = 0;
I'm sorry for providing so much info without being extremely specific, but if you need clarification or need more info please respond and say so. Any help is greatly appreciated. Thanks! David http://mywebpages.comcast.net/drake22/ [edited by - drake22 on February 7, 2004 5:18:20 AM]

Share this post


Link to post
Share on other sites
Are your begin and end indices correctly set?
Esp. the end seems to be set to the total end for all your quads.

[edited by - Endurion on February 7, 2004 7:03:54 AM]

Share this post


Link to post
Share on other sites
I'm not quite sure what you mean.....if you mean m_tmTextures.uiBegin and m_tmTextures[i].uiEnd then yes they are set correctly. Those are set to the beginning and ending vertices in the list that use each texture that is defined by m_tmTextures[i].ridTex. There is an entry in m_tmTextures for each time that a texture is used.

David
http://mywebpages.comcast.net/drake22/

[edited by - drake22 on February 7, 2004 1:02:02 PM]

Share this post


Link to post
Share on other sites
Change your for loop for testing purposes to

for(unsigned int i = 0; i < 1; i++)

If you see three quads with letters on them your m_tmTextures[ i ].uiEnd is wrong.


If that ain't it show the code where you set uiBegin and uiEnd for this example.

[edited by - Endurion on February 8, 2004 2:06:33 AM]

Share this post


Link to post
Share on other sites
Thanks! While my uiEnd wasnt technically wrong, it was wrong logically. I (stupidly as I know DrawPrimitive better than to do this) supplied the beginning and ending vertices to draw and not the required beginning vertex and number of primitives. Now I have to modify the texture structure and code that fills it to indicate the change in logic. Once again thank you for your help.

David
"One of the keys to happiness is a bad memory." - Rita Mae Brown

Share this post


Link to post
Share on other sites