New to D3D - Textures not visible!?

Started by
15 comments, last by TheAdmiral 17 years, 6 months ago
Hi there! I started with D3D a few days ago following a simple tutorial. So far I managed to render a spinning cube... ;-D Now I tried to add a texture to the cube. Therefore I 1) Created a 256x256 24-Bit .bmp texture 2) Changed the vertex structure so that it contains tex-coords 3) Adjusted the cube's vertex buffer (added texcoords) 4) Loaded and set the texture (using D3DX functions, which returned no errors) But the cube is just plain white, no texture anywhere near it ;-) Is there a step I have forgotten? What could be the reason for the texture not showing up? Thanks a lot!
Advertisement
Did you call
pDevice->SetTexture(0, pTexture);
?
And don't forget to disable lighting, or if you have lighting, to make light objects.
Nope, there's no lighting. And yes, I used "pDevice->SetTexture(0, pTexture);".
So the problem's got to lie somewhere else...
How about some code?
Specifically your tex loading, drawing, and vector defs. Heck, if its not too large all of it :)
OK, here's some code :-)

The vertex structure
#define D3DFVF_CUSTOMVERTEX	(D3DFVF_XYZ | D3DFVF_TEX1)struct D3DVERTEX{	float	x, y, z;	float	u, v;};


Texture loading
if( FAILED( D3DXCreateTextureFromFileA( globalCorePtr->mVideo->getDevice(), filename, &target ) ) )	{		// Crazy error message!!!		return false;	}//end if


Texture binding
if( FAILED( globalCorePtr->mVideo->getDevice()->SetTexture( 0, tex ) ))		// Cry!


Any ideas?
Try setting the texture stage states to SelectArg1 and setting Arg1 to Texture.

Here's some psuedo-code:

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

Note that this disables vertex colors and lighting (which you don't seem to be using, so it doesn't matter). If at some point you want to enable these, you'll need to change the color op to modulate, and set Arg2 to Diffuse.

[EDIT] You're not using shaders, right?

Hope this helps.
Sirob Yes.» - status: Work-O-Rama.
No, I'm not using any shaders.
Sadly

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

didn't help. Everything's still plain white :-(
But nevertheless: thanks for your help so far!



Maybe some more code can help:

Object initialization
	LPDIRECT3DVERTEXBUFFER9 pQuadVB = NULL;	VOID* pData;	D3DXMATRIX matRotationX,matRotationY,matTranslation;	float fRotation = 0.0f;	D3DVERTEX aQuad[ ] = {	{-1.0f,-1.0f,-1.0f,0.0f,0.0f},							{1.0f,-1.0f,-1.0f,1.0f,0.0f},							{-1.0f,-1.0f,1.0f,0.0f,1.0f},							{1.0f,-1.0f,1.0f,1.0f,1.0f}		};	mc.mVideo->getDevice()->CreateVertexBuffer(sizeof(aQuad),D3DUSAGE_WRITEONLY,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&pQuadVB,NULL);	pQuadVB->Lock(0,sizeof(pData),(void**)&pData,0);	memcpy(pData,aQuad,sizeof(aQuad));	pQuadVB->Unlock();



Object rendering
D3DXMatrixRotationX(&matRotationX,fRotation);		D3DXMatrixRotationY(&matRotationY,fRotation * 0.75f);		D3DXMatrixTranslation(&matTranslation,0.0f,0.0f,10.0f);		mc.mVideo->getDevice()->SetTransform(D3DTS_WORLD,&(matRotationX * matRotationY * matTranslation));		mc.mVideo->getDevice()->SetStreamSource(0,pQuadVB,0,sizeof(D3DVERTEX));		mc.mVideo->getDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);		fRotation += 0.01f;


More ideas?
Can't see any SetFVF calls?

pDevice->SetFVF( D3DFVF_XYZ | D3DFVF_TEX0 )
might help?
Quote:Original post by Wixner
pDevice->SetFVF( D3DFVF_XYZ | D3DFVF_TEX0 ) might help?
Using D3DFVF_TEX1 might help even more. ;)

This topic is closed to new replies.

Advertisement