If you want rendering to leave the green and blue components in the framebuffer unchanged, use glColorMask(). It’s not possible to achieve the same result using a fragment shader, as the fragment shader can’t control which components are written, and can’t read from the framebuffer directly (although you could make a copy of the framebuffer as a texture and have the fragment shader read from that).
Ok so i’ll try to be more precise.
Actually the aim of the programm I’m developping is to transmit Z buffer from Opengl to Cuda
To transmit it I comput it into my fragment shader(the calculation code is missing in the given code) and dump it into the Red color channel of my texture (The z value).
As I have many triangulations my idea was to make a differentiation between them into cuda thanks to values i set in G and B color channels with a color_buffer.
that’s why I want my fragment shader to change only red color channel, and keep the color channels G and B setted by my color_buffer.
I tried also this so get the value setted by my color_buffer
I’m sorry, I’m sure I’m missing something. I used color masking this allow only my fragment shader to update red color wich is what I want but glDrawArray can’t set Green and Blue from my color buffer when I do that.
glColorPointer(3, GL_FLOAT, 0, color_buffer_);
glVertexPointer(3,GL_FLOAT, 0, faces_);// Vertex Pointer to triangle array
glNormalPointer(GL_FLOAT, 0, normale_); // Normal pointer to normal array
glDrawArrays(GL_TRIANGLES, 0, totalconnectedtriangles_);
How can i specify color masking for olny my fragment shader attached ?
When you bind the program you want to only write red, you also turn on color masking. When you bind some other program, you turn off color masking. This is not a hard problem.
OK, at some point in your render loop, you bind the program for use (with glUseProgram). Following this call, you make some rendering calls. And during those rendering calls, you want to write only to the red color. At some later point in your render loop, you bind a different program. Then you make other rendering calls. And during those calls, you want to write to all color channels.
So you do that. When you bind the program that you only want to write to the red color channel, you set the color mask to write only red. When you bind a different program, you change the color mask back.