Jump to content
  • Advertisement
Sign in to follow this  
VanKurt

New to D3D - Textures not visible!?

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!