Search code examples
openglglslopengl-3

Rendering integers to a separate texture in GLSL


I want to render a set of textured quads in OpenGL, but I was wondering if there was any way to pass in a unique integer id with each quad to the shader pipeline?

The id needs to be available to the fragment shader so that it can be rendered to a texture, separately from the rest of the image, because I want to reference the texture later to find out what id is at what location on the screen.


Solution

  • Tack on another vertex attribute for the ID and pass that through to your fragment shader.

    You can set up Multiple Render Targets (MRT) to render your IDs out to another framebuffer attachment.