Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Drawing a line


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   -  Reputation: 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

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

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   -  Reputation: 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   -  Reputation: 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   -  Reputation: 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.



PARTNERS