Sign in to follow this  
VanKurt

New to D3D - Textures not visible!?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Nope, there's no lighting. And yes, I used "pDevice->SetTexture(0, pTexture);".
So the problem's got to lie somewhere else...

Share this post


Link to post
Share on other sites
How about some code?
Specifically your tex loading, drawing, and vector defs. Heck, if its not too large all of it :)

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
Quote:
Original post by Wixner
pDevice->SetFVF( D3DFVF_XYZ | D3DFVF_TEX0 ) might help?
Using D3DFVF_TEX1 might help even more. ;)


O RLY? :p

pDevice->SetFVF( D3DFVF_XYZ | D3DFVF_TEX1);
might do the trick, unless you're using [i]IDirect3DVertexDeclaration9[i]'s

Edit:
I typo'd again :)

Share this post


Link to post
Share on other sites
Actually I call SetFVF! (Using the structure seen in my first code segment).
So this can't be the problem either...

Share this post


Link to post
Share on other sites
Does the Direct3D Debug Runtime spew some debug information? Assuming you're using Visual Studio, you can take a look here http://nexe.gamedev.net/directKnowledge/default.asp?p=Debugging about Direct3D Debugging

Share this post


Link to post
Share on other sites
Have you set D3DRS_WRAP0 to anything other than 0? It's an odd form of wrapping, not what you usually associate with texture wrapping. Enabling it could cause you to only get a single texel of your texture.

Is D3DTSS_TEXCOORDINDEX on stage 0 set to 0? It should be.

edit: Is fogging turned off (D3DRS_FOGENABLE, false)?

[Edited by - Namethatnobodyelsetook on October 24, 2006 9:04:20 AM]

Share this post


Link to post
Share on other sites
Are you absolutely sure the image file loaded to the texture (assuming this is what you do) is in the right directory. Execution directories can be pretty unintuitive, especially in VS2005. To make sure, put your executable file in the same directory as you image file and run from explorer. This error usually gives white textures, but your error handling should have caught it.

//Emil

Share this post


Link to post
Share on other sites
Yep, like the last poster I think you should verify the image loading process somehow... are you sure your BMP file is standard and is in memory? Maybe try another file format, etc. just for kicks; I've seen stranger things...

Share this post


Link to post
Share on other sites
So it appears all the steps are present. The next goal is to ensure they are all correct. Check the return value of every relevant function. One of them will probably return a failure. My money, like the previous posters', is on the D3DXCreateTextureFromFileExA, if that's what you're using.

Regards
Admiral

Share this post


Link to post
Share on other sites

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