Drawing a line
How do I draw a simple line given (x1, y1) and (x2, y2)
coordinates using DirectX?
Thanks All
You will have to write you own function. There are a few algorithms out there that deal with this kind stuff, for example like the Bresenham''s algorithnm. The easiest way to do it get a graphic libary that does the job for you. CDX for DX comes to mind(For dos programming Allegro is a good one). Check them out at:
http://www.cdx.sk
http://www.cdx.sk
try DrawPrimitive(...)
im using my own rootines, but i think
you can use DrawPrimitive to draw staff like lines etc...
im using my own rootines, but i think
you can use DrawPrimitive to draw staff like lines etc...
if you want a really slow method you could get a DC and make GDI calls(moveto(hdc,x,y);LineTo(hdc,x,y), but somehow I think making your own function to find yer slope and blit pixels would work a little faster.
void BresenhamLine(int x0, int y0, int x1, int y1){ int XUnit, YUnit, Offset = y0 * Pitch + (x0*3); int dy = y1 - y0; if(dy < 0) { dy = -dy; YUnit = -Pitch; } else YUnit = Pitch; int dx = x1 - x0; if(dx < 0) { dx = -dx; XUnit = -3; } else XUnit = 3; int ErrorTerm = 0; if(dx > dy) { for(int i = 0; i <= dx; i++) { Dest[Offset] = 255; Dest[Offset+1] = 0; Dest[Offset+2] = 0; Offset += XUnit; ErrorTerm += dy; while(ErrorTerm > dx) { ErrorTerm -= dx; Offset += YUnit; } } } else { for(int i = 0; i <= dy; i++) { Dest[Offset] = 255; Dest[Offset+1] = 0; Dest[Offset+2] = 0; Offset += YUnit; ErrorTerm += dx; while(ErrorTerm > 0) { ErrorTerm -= dy; Offset += XUnit; } } }}
This bit of source can show a line on the screen using a 24 bits surface.....
Dest is the surface pointer
Dance with me......
http://members.xoom.com/CJdeVos/index.htm
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement