Sign in to follow this  
chippiejnr

coloring an area made with glDrawPixel

Recommended Posts

chippiejnr    122
Hey guys, I've got a PPM data file which i need in - its an image (or an outline image) and I'm wondering how i can fill this? When the PPM is read the canvas draws the weird looking shape - which is correct. I'm just wondering how i can fill it. Cheers. the PPM reader function:
void loadImg(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glRasterPos2f(80.0, 30.0);
    glPixelZoom(1.0, -1.0);
    glDrawPixels(700, 800, GL_RGB, GL_UNSIGNED_BYTE, pixelMap);

    glFlush();
    return;

Share this post


Link to post
Share on other sites
BionicBytes    154
OpenGl does not offer higher level API such as Fill() etc.. but there are some things you can do here which might work quite well.

Essentially use this as mask on a solid texture - of what ever color you want

Assume the PPM data is an 8-bit (or one channel) mask of size NxN pixels.
Create 4 channel channel texture image using the PPM mask data as the alpha channel. In the RGB channel just write 255 in to each channel. It will be a solid white square (but with a mask)

Enable alpha test
Set alpha func and threshold values
Enable texture 2d

Use gl immediate mode to draw a quad of NxN pixels - with the user specified color

Now due to the alpha test - you should only see the area within the texture (i.e. the filled in area).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this