opengl color matrix

Started by
7 comments, last by dasan11 17 years, 6 months ago
I want to use the color matrix to copy the red channel to green channel. Before the operation,the color of the pixel is (1,0,0), after the operation,the color changes to (1,1,0). how to do this?
Advertisement
try (should copy red to green & keep the other three):

1 0 0 0
1 0 0 0
0 0 1 0
0 0 0 1

cheers
zimerman

Quote:Original post by zimerman
try (should copy red to green & keep the other three):

1 0 0 0
1 0 0 0
0 0 1 0
0 0 0 1

cheers
zimerman

GLfloat color[16]={1,0,0,0,
1,0,0,0,
0,0,1,0,
0,0,0,1};
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0, 0.0, 0.0, 0.5);
glBegin (GL_TRIANGLES);
glVertex2f(0.9, 0.9);
glVertex2f(0.3, 0.5);
glVertex2f(0.9, 0.1);
glEnd();
glMatrixMode(GL_COLOR);
glMultMatrixf(color);
glMatrixMode(GL_MODELVIEW);

glBegin (GL_TRIANGLES);
glVertex2f(0.4, 0.9);
glVertex2f(0.3, 0.5);
glVertex2f(0.4, 0.1);
glEnd();
why the two triangles are still red?
How to write?
OpenGL uses column major storage for matrices, so

GLfloat color[16]={1,0,0,0,
1,0,0,0,
0,0,1,0,
0,0,0,1};

equals

1 1 0 0
0 0 0 0
0 0 1 0
0 0 0 1

try

GLfloat color[16]={1,1,0,0,
0,0,0,0,
0,0,1,0,
0,0,0,1};

cheers
zimerman
I tried it .

GLfloat color[16]={1,1,0,0,
0,0,0,0,
0,0,1,0,
0,0,0,1};

But it's still red.

void display(void)
{
GLfloat color[16]={1,1,0,0,
0,0,0,0,
0,0,1,0,
0,0,0,1};
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0, 0.0, 0.0, 0.5);
glBegin (GL_TRIANGLES);
glVertex2f(0.9, 0.9);
glVertex2f(0.3, 0.5);
glVertex2f(0.9, 0.1);
glEnd();
glMatrixMode(GL_COLOR);
glLoadIdentity();
glMultMatrixf(color);
glMatrixMode(GL_MODELVIEW);

glBegin (GL_TRIANGLES);
glVertex2f(0.4, 0.9);
glVertex2f(0.3, 0.5);
glVertex2f(0.4, 0.1);
glEnd();

glFlush();
}

The color matrix is only used during pixel transfer operations such as glDrawPixels or glTex[Sub]Image2D.
did a quick google look-up:

http://oss.sgi.com/projects/performer/mail/info-performer/perf-03-12/0020.html

...Kalidor is right...sry for raising your hopes (never used w/ color matrices myself)...

zimerman (wearing sackcloth & ashes)


[Edited by - zimerman on October 24, 2006 11:17:33 AM]
you can make copy of the buffer after drawing everything then enable it as texture on quad that fill the whole screen and then u can use color_matrix for coping the channs this will be bit slower tho.
-EDIT :
also if ur graphic card support shader u can do this
<Vertex_Shader>:
void main(){  gl_FrontColor = vec4(gl_Color.x,gl_Color.x,0,1.0);gl_Position = ftransform();}

<Pixel_Shader>:
void main(){gl_FragColor = gl_Color;}


take care.

[Edited by - ff8 on October 24, 2006 2:02:38 PM]
Thank you .I use glReadPixels to do this transform.

GLfloat *pixels=(GLfloat *)malloc(200*200*4);
GLfloat color[16]={1,0,1,0,
0,1,0,0,
0,0,0,0,
0,0,0,1};
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1.0, 0.0, 0.0, 0.5);
glBegin (GL_TRIANGLES);
glVertex2f(0.9, 0.9);
glVertex2f(0.3, 0.5);
glVertex2f(0.9, 0.1);
glEnd();
glReadPixels(0,0,200,200,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
glMatrixMode(GL_COLOR);
glLoadIdentity();
glMultMatrixf(color);
glDrawPixels(200,200,GL_RGBA,GL_UNSIGNED_BYTE,pixels);

This topic is closed to new replies.

Advertisement