OpenGL color matrix

How to get working OpenGL color matrix transformations?

I changed the sample program that just draws a triangle, and added the color matrix code to see if I can change the colors of the triangle, but it does not work.

static float theta = 0.0f; glClearColor( 1.0f, 1.0f, 1.0f, 1.0f ); glClearDepth(1.0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef( theta, 0.0f, 0.0f, 1.0f ); glMatrixMode(GL_COLOR); GLfloat rgbconversion[16] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; glLoadMatrixf(rgbconversion); glMatrixMode(GL_MODELVIEW); glBegin( GL_TRIANGLES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, 1.0f , 0.5f); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex3f( 0.87f, -0.5f, 0.5f ); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex3f( -0.87f, -0.5f, 0.5f ); glEnd(); glPopMatrix(); 

As far as I can tell, the color matrix I am loading should change the triangle to black, but it doesn't seem to work. Is something missing?

+1
source share
4 answers

The color matrix applies only to pixel transfer operations, such as glDrawPixels, which are not hardware accelerated on current hardware. However, implementing a color matrix using a fragmented shader is very simple. You can simply pass your matrix as a homogeneous mat4 and then mulitply it with gl_FragColor

+6
source

It looks like you are doing it right, but your current color matrix also sets the value of the triangular alpha value to 0, so while it is being drawn, it does not appear on the screen.

+1
source

"In addition, if the extension ARB_imaging is supported, GL_COLOR is also accepted."

See the glMatrixMode documentation. Is the extension supported on your computer?

+1
source

I found a possible problem. The color matrix is โ€‹โ€‹supported by a subset of image processing. In most HWs, it was supported by the driver (software implementation)

Solution: Add this line after glEnd() :

 glCopyPixels(0,0, getWidth(), getHeight(),GL_COLOR); 

It is very slow ....

0
source

Source: https://habr.com/ru/post/910491/


All Articles