PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Drawing lines of variable widths with GapiDraw

elevenseventeen · 07 Jul 2006, 15:36 UTC
Is there an algorithm available to draw lines of variable thickness using GapiDraw. I see that GapiDraw supports only the DrawLine() function and this only draws lines of single thickness. I am looking for something similiar to the GDI functionality that creates a pen of a certain thickness then draws a line using the pen.

This is an easy thing to do when I want to draw a line of zero or no slope (i just draw parallel lines using DrawLine() of course), however when i need to draw thicker lines of variable slope, it becomes quite complex. I assume this has been done before though.

Thank you for any advice!

George
elevenseventeen · 12 Jul 2006, 15:00 UTC
I see there is an algorithm posted here: http://homepages.enterprise.net/murphy/ ... index.html

however using the Murphy.c code supplied on sourceforge it does not draw lines of perceived equal thickness in all cases. I assume the algorithm is correct and the source is not. Can anyone point me to a successful implementation of such a thick line drawing algorithm?

Thanks
elevenseventeen · 12 Jul 2006, 20:11 UTC
Should I assume that there is no way to draw variable width lines using GapiDraw other than to develop up my own algorithm and use SetPixel()?

This is not a trivial task, yet this seems like it would be a common function. Any reason why this is not included in gapi already?

Thank you
SetPixel seem to slow I presume. You should write directly in the Buffer, like in the GapiDraw Plasma sample...

Looks like that:
Code:

int offsetx = BoundingX;
int offsety = BoundingY;
int width = BoundingWidth;
int height = BoundingHeight;

// Get raw access to the CGapiSurface internal buffer
GDBUFFERDESC buffer;
backbuffer->GetBuffer(&buffer);

long xPitch = buffer.xPitch >> 1;
long yPitch = buffer.yPitch >> 1;

WORD* pBits = (WORD*)buffer.pBuffer;

WORD* dest;
LONG nDestOffsetX = offsetx*xPitch;
LONG nDestOffsetY = offsety*yPitch;

// Write here you routine ...
for(int y=offsety; y<offsety+height; y++)
{
dest = pBits + nDestOffsetY + nDestOffsetX;
for(int x=offsetx; x<offsetx+width; x++)
{
*dest = (WORD) gd565::ColorrefToNative(RGB(0, 0, 0));
dest += xPitch;
}
nDestOffsetY += yPitch;
}

// Release raw buffer access
backbuffer->ReleaseBuffer();


This code just fill a Black Rect in the (offsetx, offsety, offsetx+width, offsetx+height) Rect Bounding Box, I think you just have to implement your line algorithm in it...

I am French, I hope you understood
elevenseventeen · 16 Jul 2006, 21:53 UTC
I'm looking for the actual thick line drawing algorithm, not a framework to put it in.