PDA

View Full Version : Displaying single color channel



lechoo
08-26-2010, 03:07 AM
Hi,
I have very simple image browser which is using opengl to display images. I create texture and display it on single polygon. I want to give user possibility to see image channels: red, green, blue and optionally alpha. How can I force opengl to draw only single channel, for example red? Or even better how can I put red channel into RGB channels to get gray scale image?
Right now for red channel I'm using following mask glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); and result not quite as I wanted (see attached files).

ZbuffeR
08-26-2010, 04:59 AM
glColorMask should be enough, be you sure you clear to black while color mask is true for all channels.

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(GL_COLOR_BUFFER_BIT);
glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
// draw image now


Currently the blue and green channels are uniformly at half intensity (127 in unsigned byte), middle gray, no idea where this comes from ?

Otherwise you have a lot of flexibility with a simple GLSL fragment shader to sampling the texture the way you want, assing r value to rgb, scaled/tweaked differently for each channel, etc.
http://www.lighthouse3d.com/opengl/glsl/index.php?texture

lechoo
09-01-2010, 04:46 AM
Hi,
thanks for your help. I've solved all of my problems with displaying channels. It turned out that my clear color was set to 0.5, that's where half intensity was coming from. I took your advice and tried fragment shader. It does exactly what I need.