Question

I wrote a simple 24-bit bitmap loader in OpenGL. I open a bitmap file and read its pixels, then from that I create an array of RGB pixel data that I will then pass to glDrawPixels().

The problem: I need to make certain pixels of my image transparent, but I'm not sure how the Alpha channel works. I'm not sure what type of parameters to pass for the format and type in glDrawPixels if I want to add transparency? I tried to create a bitmap file with an alpha channel, but then after looking at the contents of the file, the 4th byte(alpha) is always zero, and the image itself doesn't appear transparent either.

This is my RGB file structure:

struct bmpRGB{
unsigned char R, G, B;
};

What do I need to add to this to include Alpha? And what type parameter should I pass to the function when using RGBA? I'm going to add the alpha channel myself as I fill the pixel array, but I need to know the data structure needed for that.

This is what I do for now:

glDrawPixels(bmp->Width, bmp->Height, GL_RGB,GL_UNSIGNED_BYTE, bmp->Data);
Was it helpful?

Solution

Tack on an alpha component and set format to GL_RGBA:

struct bmpRGB
{
    unsigned char R, G, B, A;
};

glDrawPixels(bmp->Width, bmp->Height, GL_RGBA, GL_UNSIGNED_BYTE, bmp->Data);

Make sure you enable and configure blending.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top