Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Drawing a line

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Emagen   Members   

122
Like
Likes
Like

Posted 24 January 2000 - 04:24 PM

How do I draw a simple line given (x1, y1) and (x2, y2) coordinates using DirectX? Thanks All

#2 Anonymous Poster_Anonymous Poster_*   Guests   

Likes

Posted 24 January 2000 - 08:23 PM

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

#3 sayshell   Members   

122
Like
Likes
Like

Posted 25 January 2000 - 06:06 AM

try DrawPrimitive(...)
im using my own rootines, but i think
you can use DrawPrimitive to draw staff like lines etc...

#4 Fnjord   Members   

122
Like
Likes
Like

Posted 26 January 2000 - 12:35 PM

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.

#5 CJ   Members   

122
Like
Likes
Like

Posted 26 January 2000 - 09:27 PM


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;
}
}
}
}
[/CODE]
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





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.