0
101 Dec 30, 2005 at 12:17

hi all
i’m fresh..using openGL
i want to use the boundaryFill algorithm..but i don’t know wht to put in setPixel & getPixel functions..i searched for it but i got lost :blush:
any help plzzzzzzzzzzzzzzzzzz

#### 6 Replies

0
101 Dec 30, 2005 at 14:42

But keep in mind that will be terribly slow. You could optimize it a bit by reading all the pixels in one go in a single buffer, and use that buffer for your getpixel and setpixel functions. Then, when you’re done, upload (the changed part of) the buffer again.

0
101 Dec 30, 2005 at 14:53

yes, keep everything in a system memory buffer and just update the OpenGL texture when you need to render it.

0
101 Dec 30, 2005 at 15:15

If by any chance you are using SDL, you can obtain the pixel values as well as set the pixel values by using the “void * pixels” field of the SDL_Surface, returned by SDL_SetVideoMode.

0
101 Dec 30, 2005 at 16:29

I don’t have any experience with SDL, but I doubt that would work when you’re using OpenGL.

0
101 Dec 31, 2005 at 19:17

ok i’m not fresh..i’m too fresh :blush:
i’m trying to discover things from here & there..but i couldn’t figure it out..this is wht i came out with but it didn’t work –>

// creating array of colors
int color [3][3] = { 0,1,0,0,0,0,1,1,1 };

void setPixel ( int x , int y  )
{
glDrawPixels( 3 , 3 , GL_RGB , GL_INT , color );
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}

void getPixel ( int x , int y , int inter )
{
glReadPixels ( x , y , 3 , 3 , GL_RGB , GL_INT , color );
}

void boundaryFill4 ( int x, int y , int fillColor , int borderColor)
{
int interiorColor   ;
getPixel ( x,y, interiorColor );
if ( ( interiorColor != borderColor ) && ( interiorColor != fillColor ))
{
setPixel ( x,y);
boundaryFill4 ( x+1 , y , fillColor , borderColor);
boundaryFill4 ( x-1 , y , fillColor , borderColor);
boundaryFill4 ( x , y+1 , fillColor , borderColor);
boundaryFill4 ( x , y-1 , fillColor , borderColor);
}
}


and i called the function:
boundaryFill4 ( xg, yg , 0 , 0 );

i feel like i’m putting things all togather ( actually this is wht i did ) .. it’s not working bcoz i don’t really understand it all .. so i have some questions:
1. is there anything wrong with the array as a beginning ??
2. wht about the getPixel function?? i didn’t understand exactly wht i’m supposed to put in it
3. wht am i supposed to initialize “interiorColor” variable ?? bcoz it gave me a warning about not initailizing it..then i gave it 0 then 1 then 2 ( the color indecies in the array ) i got no output window!!

–> breifly, i don’t know wht’s wrong..any help plzzzzzzzzzzzzzzzzzz

P.S : if i’m not clear enough i can give more details

Next time put your code in [ code ] [ / code ] blocks.
[/edit]

0
167 Dec 31, 2005 at 21:02

The glDrawPixels takes the color(s) to set the pixel(s) to as its last parameter. You probably want to set the first two parameters to 1, since you are just drawing a single pixel. You also probably want to use unsigned char (GL_BYTE) for the color array and not ints. And instead of writing a 1 in the color array, you need to use 255 for full brightness. (You would write 1 for full brightness if you were using floats.)

You probably want to modify your setPixel function to take as parameters the red, green, and blue values to set to (as unsigned chars). Then construct the color array inside the setPixel function based on these parameters.

Similiarly, glReadPixels copies the pixel values into the array you pass it as a parameter. So declare a color array inside getPixel, call glReadPixels (again, set the width and height to 1,1) and then return its r, g, b values using reference parameters or some such.

And be warned that this is going to be incredibly slow. Graphics cards are really not designed to do get/set on individual pixels this way. It would be much faster to keep the image in a system memory buffer that you allocate yourself, and then do one big glDrawPixels at the end to transfer it all to the graphics card at once. But first things first. Get this working and then we’ll show you how to make it faster. ;)