Filling a shape

Previous topic - Next topic

loganite

Hello,
Does anyone know of a way fill a shape? I am working on a way of using true type fonts in GLBasic that doesn't require bitmapping and I can produce outlines using the drawline command but I need someway of filling them.

PeeJay

www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

loganite

Thanks for that. Using it I came up with

FUNCTION FILL: x,y,replacementRGB

TYPE POINT
x
y
ENDTYPE

LOCAL points[] AS POINT
LOCAL point AS POINT
LOCAL Epoint AS POINT
LOCAL Wpoint AS POINT
LOCAL Npoint AS POINT
LOCAL Spoint AS POINT

point.x = x;point.y=y
DIMPUSH points[],point
targetRGB=GETPIXEL(x,y)
FOREACH p IN points[]
   SETPIXEL p.x,p.y,replacementRGB
   
   Epoint.x = p.x+1;Epoint.y = p.y
   Wpoint.x = p.x-1;Wpoint.y = p.y
   Npoint.x = p.x;Npoint.y = p.y-1
   Spoint.x = p.x;Spoint.y = p.y+1

   IF GETPIXEL(Epoint.x,Epoint.y)=targetRGB THEN DIMPUSH points[],Epoint
   IF GETPIXEL(Wpoint.x,Wpoint.y)=targetRGB THEN DIMPUSH points[],Wpoint
   IF GETPIXEL(Npoint.x,Npoint.y)=targetRGB THEN DIMPUSH points[],Npoint
   IF GETPIXEL(Spoint.x,Spoint.y)=targetRGB THEN DIMPUSH points[],Spoint


   DELETE p
NEXT


ENDFUNCTION


The problem is now its WAY toooo slooooow. I think I read in the GL documentation about the getpixel being very slow. They wern't kidding. I may just have to stick to outlines.

AndyH

In an ellipse drawing routine Gernot wrote, he used the DRAWLINE command to draw a line from the start X of the shape to the end X of the shape, working down the Y axis line by line.  This is much faster than SETPIXEL for example but does mean you need to be able to calculate the start and end each line segment, and it would get more complicated for irregular shapes such as flood filling an area or drawing a character from the TT font.

Kitty Hello

BTW: Polyvector is now working on GP2X, too.