0
votes

i have several objects in OpenGL and i want to mark the selected object. My idea was to use a GLSL shader to add the selected color. How can I get the 'original' color of the pixel in the fragment shader? I could look the color up in the texture, but when there's more than one texture?

2

2 Answers

0
votes

If you intent to render your selected object with a specific shader, then you have to create a shader that has the same behavior as the regular rendering of your objects (lighting, texturing, ...). That means you have to compute that color of the pixel by yourself.

If you intent to render all your objects, and then add your selection, then it is impossible to retrieve the color of the framebuffer pixel from your fragment shader (you need to create a texture out of your framebuffer and use it, but it is out of scope, I think).

0
votes

Option A) you can add a color to the current diffuse color/texture and apply that fragment shader only to the selected one: color = ... gl_FragColor= mix(color, selectioncolor, 0.5);

Option B) you render to a framebuffer, and postproccess the object to add the color

The options depends on your capability to change the shader and identify the object.