mpen
mpen

Reputation: 283345

glDrawPixels in grayscale?

I have an image that I'm rendering like this:

glDrawPixels(image->width, image->height, GL_BGR, GL_UNSIGNED_BYTE, image->imageData);

Is there anyway I can draw it in grayscale instead (without loading it into a texture first)? I don't care if only, say, the blue component is used for the gray value rather than the L2 norm or something, I just need a quick and dirty output.

GL_LUMINANCE would be great, except that it won't work on a 3-channel image.


@timday:

Upvotes: 3

Views: 1534

Answers (1)

timday
timday

Reputation: 24892

A perverse idea for you to try, and I've no idea if it'll work:

glPixelZoom(1.0f/3.0f,1.0f);
glDrawPixels(3*width,height,GL_LUMINANCE,GL_UNSIGNED_BYTE,data);

ie treat your 3-channel image as being a 1-channel (grayscale) image 3 times as wide, and compensate for this by squishing the width using the x zoom factor. I believe GL always does nearest-neighbour sampling for zoomed glDrawPixels, so it ought to consistently pick out the same component from each triple of samples, as you require.

Upvotes: 5

Related Questions