Drawing fat lines in DirectDraw

Started by
4 comments, last by Michalson 22 years, 2 months ago
I''m looking to draw thick rounded lines (Go into mspaint, select the line tool and choose the thickest line to see what i mean). The parameters are start and end coordinates, color and thickness (expressed as the radius of the line). At the moment I have engine class that draws them using circle sprites (Just blitting the same sprite from start to end coordinates). The sprites are the color and radius (thickness) of the line and are stored in a cache. At the moment it is quite fast (running on an Athlon 1200, 32mb All-In-Wonder AGP Pro 128) but I''m wondering if there is a faster method without using Direct3D.
Advertisement
Draw one filled rectangle and just draw two circles, one to cap each end.
The lines need to be from any point P1 to any other point P2, they are normally not going to be perfectly vertical or horizontal.
if the circles'' radii == width of the polygon "line" mentioned above, they will match the corners perfectly (assuming the circle''s center is at the middle of the short edges)...
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Get a handle to the DC, lock the surface, and the use the GDI line drawing functions. I''m not sure, but I think you''d use a combination of CreatePen, SelectObject, MoveToEx, LineTo, and DeleteObject.
I wrote and tested this function based on what TerranFury wrote,
with the exception that you don't lock the surface.

    BOOL DrawLine(int x1,int y1,int x2,int y2,int thickness,DWORD colour,LPDIRECTDRAWSURFACE7 lpdds){	HDC	hDC;	HPEN	Pen;	HGDIOBJ Obj;	HRESULT hr;		if (FAILED(hr = lpdds->GetDC(&hDC)))		return FALSE;	Pen = CreatePen(PS_SOLID,thickness,colour);	Obj = SelectObject(hDC,Pen);	MoveToEx(hDC,x1,y1,NULL);	LineTo(hDC,x2,y2);	DeleteObject(Obj);	lpdds->ReleaseDC(hDC);	return TRUE;}    


Edited by - SpazBoy the Mitey on February 19, 2002 8:57:29 PM
I''m not interested, really.

This topic is closed to new replies.

Advertisement