0

is it possible to use fragment shader to set one color channel of a rendering and

glColorPointer(...);
glDrawArray();

to set the 2 others colors channels. If yes how can I do that ?

1 Answer 1

3

If you are stepping to the programmable pipeline then I also suggest stepping away from glColorPointer glVertexPointer and the matrix stack and instead use glVertexAttribPointer and pass the transformation matrices as uniforms.

In the fragment shader you would do

gl_FragColor = vec4(channel1, channels2_3.xy, 1);

Where channel1 and channel2_3 can come from either a uniform or a attribute passed from the vertex shader.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm new to openGl your explanation is little bit tricky for me, does it mean i should write a vertexshader ? should I still use glDrawArrays? glDrawArrays() will still work fine if I use glVertexAttributePointer(...) instead of glVertexPointer(..)?
You'd have to create the vertex shader anyway. glDrawArrays will still work fine.
Don't you need to declare the output variable explicitely? I think gl_FragColor is a reserved name that can't be used.
@BartekBanachewicz that depends on the version openGL 3.3 would use gl_FracColor while 4.x needs explicit declaration (IIRC)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.