Milcho
Milcho

Reputation: 339

Opengl Rgba to grayscale from 1 component

Lets say I have a 32bbp pixel array, but I am using only the blue channel/component from the pixels. I need to upload this pixel array to a texture in a grayscale/luminance format. For example if a have a color (a:0,r:0,g:0,b:x) it needs to become (0,x,x,x) in the texture.

I am using Opengl v1.5

Upvotes: 1

Views: 1022

Answers (1)

datenwolf
datenwolf

Reputation: 162164

OpenGL up to version 2 had the texture internal format GL_LUMINANCE, which does exactly what you want.

In OpenGL-3 this was replaced with the internal format GL_R (GL_RED), which is a single component texture. In a shader you can use a swizzle like

gl_FrontColor.rgb = texture().rrr;

But there's also the option to set a "static" you may call it swizzle in the texture parameters:

glTexParameteri(GL_TEXTURE_…, GL_TEXTURE_SWIZZLE_R, GL_RED);
glTexParameteri(GL_TEXTURE_…, GL_TEXTURE_SWIZZLE_G, GL_RED);
glTexParameteri(GL_TEXTURE_…, GL_TEXTURE_SWIZZLE_B, GL_RED);

Upvotes: 3

Related Questions