Jump to content
  • Advertisement
Sign in to follow this  
BigBeginner

D3D doesn't draw my texture :(

This topic is 4855 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... I want to draw an simple 2D texture that is stretched on an vertex (Direct3D8). The D3Dinit: D3DXCreateTextureFromFile (Device, 'back.bmp', Tex); Device.CreateVertexBuffer(4*sizeof(TVertex2), 0, MYFORMAT2, D3DPOOL_MANAGED, NegyszogTEX); NegyszogTEX.Lock (0, 0, PO, 0); p2[0].x:= -0.5; p2[0].y:= -0.5; p2[0].z:= 0; p2[0].tu:= 0; p2[0].tv:= 0; p2[1].x:= -0.5; p2[1].y:= 0.5; p2[1].z:= 0; p2[1].tu:= 1; p2[1].tv:= 0; p2[2].x:= 0.5; p2[2].y:= -0.5; p2[2].z:= 0; p2[2].tu:= 0; p2[2].tv:= 1; p2[3].x:= 0.5; p2[3].y:= 0.5; p2[3].z:= 0; p2[3].tu:= 1; p2[3].tv:= 1; Move (p, PO^, SizeOf(Tvertex)*4); NegyszogTEX.Unlock; The renderering: ---------------- Device.Clear(0, NIL, D3DCLEAR_TARGET, RGB(0,0,0), 1.0, 0); Device.BeginScene; Device.SetTexture (0, TEX); Device.SetVertexShader (MYFORMAT2); Device.SetStreamSource (0, NegyszogTEX, sizeof(TVertex2)); Device.DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2); Device.SetTexture (0, nil); Device.EndScene; Device.Present (NIL,NIL,0,NIL); The vertex format: ------------------ TVertex2 = packed record x,y,z : single; diffuse: cardinal; end; MYFORMAT2 = D3DFVF_XYZ or D3DFVF_TEX1; This sh*t draws nothing :( every function results D3D_OK. What

Share this post


Link to post
Share on other sites
Advertisement
A few items:

You modify p2, but copy p into PO. Without seeing what p and p2 are, is this a bug?

TVertex2 has position and diffuse, not the expected position and UV. This will throw off the size of the allocated buffer, and the stride in SetStreamSource.

replace
diffuse : cardinal
with
u,v : single

Also, if you haven't already disabled lighting (it's on by default), you should turn it off so that you'll actually see something.
Device.SetRenderState(D3DRS_LIGHTING, false);

If you created a depth/stencil buffer when you created your device (autodepthstencil=true, autodepthstencilformat = ?) you should probably clear it along the render target. If you aren't using depth buffers yet, then don't worry about it for now.

Share this post


Link to post
Share on other sites
AAAAAAA you are cool!!

Just one thing: the texture not excatly square, and its mirroring... maybe the TU, TV parameters are incorrect?

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!