greyscaling a texture

Started by
15 comments, last by Tiresias 13 years, 4 months ago
Quote:Original post by DracoLacertae
So, it just copies the Red channel into Luminance? Oh well, that's what I get for cheating and trying to get GL to do it for free. I wonder if the color matrix can be abused for anything...

It can. You just need to set the matrix so the red component of the output from the multiplication is the weighting of the input you want.
GLfloat weight[16] = {0};weight[0] = 0.3; // some typical RGB to G weightsweight[4] = 0.6;weight[8] = 0.1;glMatrixMode(GL_COLOR);glLoadMatrix(weight);


Advertisement
Be aware that the color matrix is part of the imaging subset and may not be available on all hardware, and also may be software emulated on hardware which it is available on: http://www.opengl.org/wiki/Common_Mistakes#Color_Index.2C_The_imaging_subset

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

on opengl es iPhone this code:
glTexImage2D(
GL_TEXTURE_2D, //duh
0, //no mipmaps
GL_LUMINANCE, //store as luminance
width,
height,
0, //no border
GL_RGB, //we have RGB data
GL_UNSIGNED_BYTE,
image_data);

just crash because opengl return erro (GL_CALL assert error),

if u change GL_RGB with LUMINANCE parameter there is some kind of grey, and most is black.

in other words: it just doesnt work :)
Then why don't you just preprocess the texture and actually grayscale them,
instead of changing opengles states just to visualize them as grey? Do the textures change often?
I havent dealt much with opengl es, only a bit, so i don't know about that error you get.
Yes i agree.
I decided to preprocess the pixels.
my button are small so no need to worry about perf.
i think we can close this topic. (and the related one ;..)
Sorry to bother again but i am still not sure how to achieve the pixels replacement.

for RGB i think we need to average the luminance like R+G+B / 3 (or other formula), then create the 8 bit luminance buffer.

but ... for RGBA ?? my textures contains alpha channel and i want to keep it ...
Hello
just to confirm that changing pixel color
{r, g, b, a}
with
{ r+g+b / 3, r+g+b / 3, r+g+b / 3, a}

in a RBGA texture , as proposed, work smoothly.

thanks !
topic can be closed-

This topic is closed to new replies.

Advertisement