🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help!! - Simple Texture in D3D 7.0

Started by
2 comments, last by Sieggy 24 years, 7 months ago
I had that same problem and ended up having to include:

m_pD3DDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);

See if that does it for ya. Otherwise I'd check to make sure your D3DTextr_GetSurface is returning something.

Advertisement
You might also want to move the BegineScene() function to just above the DrawPrim function.
I recently have started learning IM in DirectX 7.0 and moved on playing with the texturing capabilities. However I'm having a heck of a time trying to get it to work. Its probably a state I foolishly forgot so my apologies for any stupid questions :-).

I rewrote the Trivial Win example from MS using a skeleton MFC framework and the new D3DX texturing utils and got the plain triangle working. All attempts to texture the triangle are failing (the triangle remains a plain black). The vertices are pretty simple:

D3DVECTOR p1 = MakeVector (0.0f, 3.0f, 2.0f);
D3DVECTOR p2 = MakeVector (3.0f,-3.0f, 2.0f);
D3DVECTOR p3 = MakeVector (-3.0f,-3.0f,2.0f);
D3DVECTOR normal = MakeVector (0.0f, 0.0f, 1.0f);

//set the vertices
m_vindex [0] = MakeVertex (p1, normal, 0,0);
m_vindex [1] = MakeVertex (p2, normal, 1,0);
m_vindex [2] = MakeVertex (p3, normal, 0,1);

I set up the texture params with the following:

//load the desired texture
hr = D3DTextr_CreateTextureFromFile ("grass.bmp");

//init the texture engine states
hr = D3DTextr_RestoreAllTextures( m_pd3dev );
//bilinear texturing mode
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
hr = m_pd3dev->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

Finally the triangle is rendered with the following piece of code:

r = m_pd3dev->BeginScene();

if (SUCCEEDED (r)) {
//progress with the frame
//clear the target
m_pd3dx->Clear (D3DCLEAR_TARGET |D3DCLEAR_ZBUFFER);

//init the texture
m_pd3dev->SetTexture( 0, D3DTextr_GetSurface("grass.bmp") );
m_pd3dev->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE );

//draw the primitive
m_pd3dev->DrawPrimitive (D3DPT_TRIANGLELIST, D3DFVF_VERTEX, m_vindex, 3, NULL);

//close it up
m_pd3dev->EndScene();
}

Any thoughts on what I might be missing would be greatly appreciated and thanks in advance for any help.

Sieggy

It was actually turning off the lighting that seemed to do the trick (as well as another rather stupid error that I'll omit). Works like a charm now. Thanks for all the input folks. There is a lot of great people on this board :-).

This topic is closed to new replies.

Advertisement