Using an OpenGL 3.1 core profile I've been trying to get mouse picking to work.
I want to be able to render each object with a simple GLSL shader that outputs a color corresponding to the ID of the object, more precisely I wanted the red component to be an unsigned char that has the ID of the player that the object belongs to, the green to contain the type of object (character, building, map resource, etc...) and the blue component to contain the ID of the object.
I have created a FBO with a texture for the color attachment the size of the screen and GL_RGB8 for the internal format and GL_UNSIGNED_BYTE for the type...
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
I bind this FBO, render the scene with the picking shader, and then get the pixel from the texture at the mouse location.
So, my questions are...
- Will this work?
- How do I make the outFragColor in the shader the exact char values I want?
Thanks for any help.