Original Post
Hey all,
this is gonna be my first post ... I''ve been lurking here for a bit now and have started experimenting with some basic game/graphics programming. I''ll start off by saying that I specifically want to use GDI+ as opposed to MDX because I want to learn the concepts behind it all first before I move on to a powerhouse platform like MDX or C++ or whatever.
Now ... I''ve implemented (ok, copied ;-) ) the C function found here [http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html] in C# ... only problem is, that it''s rather slow. I''ve got a demo that draws a line between a point, and the location of the mouse. Once it gets longer than about 100 pixels, it starts to visibly lag behind the mouse as it redraws each frame.
void Line(Graphics g, int x1, int y1, int x2, int y2, Pen pen)
{
int dx = x2 - x1;
int dy = y2 - y1;
int y = y1;
int eps = 0;
Bitmap bmp = new Bitmap(1,1,g);
bmp.SetPixel(0,0,Color.Black);
for (int x=x1; x<=x2;x++)
{
g.DrawImage(bmp,x,y);
eps+=dy;
if ((eps*2) &rts= dx)
{
y++;
eps-=dx;
}
}
}
The only thing I can guess is causing it to be slow is the use of a Bitmap object to draw the pixel as there''s no way to set an individual pixel using only the Graphics object. I was wondering if anyone else here had enough C#/GDI+ experience to see if there was a way to speed this up.
Thanks in advance
Joel Martinez
http://www.codecube.net/