Simple Lines using DirectX .. ?

It was so easy in opengl.

I want to draw a couple of line on the screen in screen space as well as text in DirectX using D3DXLine Interface,after experimenting a while i still dont see any lines though, any one know about this or have post about line drawing...

[277 byte] By [DaxThomas] at [2007-12-23]
# 1

Look at this:

VOID Render()
{
if( NULL == g_pd3dDevice )
return;

// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
LPD3DXLINE line;
D3DXCreateLine(g_pd3dDevice, &line);
D3DXVECTOR2 lines[] = {D3DXVECTOR2(0.0f, 50.0f), D3DXVECTOR2(400.0f, 50.0f)};
line->Begin();
line->Draw(lines, 2, 0xFFFFFFFF);
line->End();
line->Release();

// End the scene
g_pd3dDevice->EndScene();
}

// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

Hey, take care for line color!!! If you use 0xFFFFFF (i.e. white with alpha channel = 0), you see nothing!!! Instead set alpha to 0xFF (i.e. 0xFFFFFFFF). A common mistake with D3DXLine :D

A better way to specify a color in DirectX is through the macro D3DCOLOR_ARGB:

line->Draw(lines, 2, D3DCOLOR_ARGB(255, 255, 255, 255));

Good rule: always specify an alpha channel equal to 255 when you draw whatsoever opaque.

Hope this help,

Cheers.

AGPX at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...
# 2

If you can set up a Vertex Buffer you can also draw Line from a Vertex Buffer...

You set up a Mesh object, you lock on the VB and you set all the points of your lines

Their is two way you can have a pair of vertex and use D3DPT_LINELIST

or one point to goto next each line and use D3DPT_LINESTRIP

Device.DrawPrimitiveUP D3DPT_LINESTRIP, Ubound(Lines()), Lines(0),16

I think you can set up this without Mesh too, just a VB, setFVF and Set the Stream, and drawprimitive

You should consider what the previous poster tell you about opacity and color...

and probably you should put the light OFF so no useless calculation or shading is done...

Line are very intensive because most of the time you have Grid or long string of line segment

But by using a Mesh or a Vertex Buffer the speed is very nice

specially if you dont do anything like texture, light or alpha on them

Line with texture is slow...

Etienne2005 at 2007-8-30 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,Game Technologies: DirectX 101...