Can't draw a line on 2D picture.

Started by
4 comments, last by Namethatnobodyelsetook 14 years, 9 months ago
I used the simple sample on Directx SDK (2009 march).

//draw a white line from 100,100 to 150,150;
DXUT_SCREEN_VERTEX vertices[2] = {
	{100,100,0.5f,1.0f,0xffffffff,0,0},
	{150,150,0.5f,1.0f,0xffffffff,0,0}
};
pd3dDevice->SetFVF( DXUT_SCREEN_VERTEX::FVF );
pd3dDevice->DrawPrimitiveUP( D3DPT_LINESTRIP, 1, vertices, sizeof( DXUT_SCREEN_VERTEX ) );


DXUT_SCREEN_VERTEX struct is struct DXUT_SCREEN_VERTEX { float x, y, z, h; D3DCOLOR color; float tu, tv; static DWORD FVF; }; It's can show on the screen. but when I want to draw it on a picture.like this

		ID3DXSprite* &sp = g_pSprite9;
		sp->Begin(D3DXSPRITE_ALPHABLEND);
		sp->Draw(bg,NULL,NULL,NULL,0xffffffff);//bg is a texture pointer
		sp->End();


		DXUT_SCREEN_VERTEX vertices[2] = {
			{100,100,0.5f,1.0f,0xffffffff,0,0},
			{150,150,0.5f,1.0f,0xffffffff,0,0}
		};
		pd3dDevice->SetFVF( DXUT_SCREEN_VERTEX::FVF );
		pd3dDevice->DrawPrimitiveUP( D3DPT_LINESTRIP, 1, vertices, sizeof( DXUT_SCREEN_VERTEX ) );


it didn't work!If I want to show the line,I can't draw the picture.How to draw upon no it.
Advertisement

.

My guess would be that the sprite is closer than the line in terms of Z. Try using a Z of 0 in the vertices.
Quote:Original post by Banhurt
This is not a direct solution to your problem, but if you're using ID3DXSprite for sprites, why don't you use ID3DXLine for lines? :) You may like it.



It's can draw lines,but it still dont fix the problem.
Quote:Original post by ET3D
My guess would be that the sprite is closer than the line in terms of Z. Try using a Z of 0 in the vertices.


yeah,it works.is that d3d device have option to disable the z order sort?
pDev->SetRenderState(D3DRS_ZENABLE, false);

If you never use the Z buffer, when creating your device, set EnableAutoDepthStencil to false. You will need to update your Clear call to not clear Z if you do this, otherwise Clear will fail, and won't even clear your backbuffer.

This topic is closed to new replies.

Advertisement