Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

yanuart

Thickness of lines..

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

Advertisement
Simple: you can''t. At least not with DirectX (I don''t knowwhether that''ll be the case with DirectX9, but it surely is so with all versions up to 8.1). OpenGL can render variable width lines AFAIK.

Of course, there is a workaround for this inconvenience in DX; it''s actually the way to render textured lines that can be also used in projects such as lightning bolts, laser beams, et al.

The trick is simple: instead of defining two certices in space and rendering them as a linelist or a linestrip, define a quad (two triangular polygons, sharing one edge - two vertices, that is), which is equivalent to four vertices (or 6 if you use triangle lists; however this is less efficient than using a triangelist or a trianglestrip - do pay attention to the (counter)clockwiseness of the vertices :D). Then you render the quad at the correct dimensions in order to resemble a line.

In essence, you create a square that is so stretched that it is no longer a square, but rather a thich line.

Try it out; should you come up with any code samples, I''d like to see them.

GL
Spyros

-----------<<>>-----------
Flareman (a.k.a Ga1adaN)
Primus ante Adain
flareman@freemail.gr
-----------<<>>------------

Share this post


Link to post
Share on other sites
Maybe there''s some way using vertex shaders...

I realy don''t know a lot of vertex shaders but if they are
the renderers they should do it...

P.S. I don''t know if there''s really a way to do that, just
trying to give help...

Share this post


Link to post
Share on other sites
quote:
Original post by Kamikaze15
Maybe there''s some way using vertex shaders...

I realy don''t know a lot of vertex shaders but if they are
the renderers they should do it...

P.S. I don''t know if there''s really a way to do that, just
trying to give help...


Vertex shaders have nothing to do with this.


Don''t listen to me. I''ve had too much coffee.

Share this post


Link to post
Share on other sites
Whatever you do , a lines width will always be equal to 1 pixel.Remember this , not matter where ur camera is.The only solution to creating thick lines is to make more than 1 and position them next to each other

Share this post


Link to post
Share on other sites
Actually, you can emulate line thickness (to an extent) using vertex shaders. I remember somewhere (I think it was the cg browser) had an example.

Share this post


Link to post
Share on other sites
Although this thread is a couple years old, it helped me get line drawing (at least in my app) working. Special thanks to "flareman".

If you are working with DirectDraw (using pixel coordinates and such), the simplest way to draw a lines is to use the "D3DXCreateLine" function to get a "ID3DXLine". Then you can do something like this (code might not be perfect)


D3DXVECTOR2 verts[] = { { startX, startY }, { endX, endY } };

LPD3DXLINE* ppLine;
D3DXCreateLine(g_youd3ddevice, ppLine);

ppLine.SetWidth(10);
ppLine.Begin();
// draw function takes array, number of verts, and color
// in this case color should be red
ppLine.Draw(verts, 2, 0xffff0000);
ppLine.End();


Simple, huh? This only works if you to make a 2d program. The line only accepts "D3DXVECTOR2" types, which contain only two members: x and y. These members are also pixel positions, not world coordinates (i.e. 0,0 is the top left of the window).

The 3d version is more complicated. You basically make two triangles using four vertices (using a triangle strip). Something like this:


HRESULT drawLine()
{
int numVerts = 4;

float startX, startY, endX, endY;
startX = 0.5;
startY = -0.5;
endX = 30.5;
endY = -0.5;

float thickness = 0.25;
DWORD color = D3DCOLOR_ARGB(255,255,0,0);
// the first three vertices (0,1,2) define the first triangle
// the next triangle is defined by using the the last two vertices from
// the first triangle, and the next vertex in the list (3), so
// the second triangle is defined by (1,2,3)
createVertex(0, startX, startY + thickness, color);
createVertex(1, startX, startY - thickness, color);
createVertex(2, endX, endY + thickness, color);
createVertex(3, endX, endY - thickness, color);

// Direct X calls follow
if( FAILED( g_pd3dDevice->CreateVertexBuffer( numVerts*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}

// Fill the vertex buffer.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, g_verts, numVerts*sizeof(CUSTOMVERTEX) );
g_pVB->Unlock();

// Render the vertex buffer contents
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

g_pVB->Release();

return S_OK;
}


"createVertex" fills up a globally defined vertex array called g_verts. Note that this line has no depth, it's just a flat line.

Hope this helps someone.



[edited by - jashugan on May 31, 2004 1:27:40 PM]

Share this post


Link to post
Share on other sites

  • 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!