I'm trying to draw a mini map. Succeeded to put current screen to smaller screen (mini map) via FBO.

But I do not know how to make the mini screen brighter when hover. You can imagine that, the real screen is very large, and you have a mini screen in the left bottom (like StarCraft), and when you hover on it, it's brighter than others.

I'm trying to use multiple attachment in FBO but it doesn't work. In fact that I don't know how does multiple attachment work, how is it used for?.

My way, draw map with attachment_0 first, draw a hovering rectangle with attachment_1. Bind then draw all of the attachment textures in legal sequence (NOT WORKED).

I mean, the first draws a mini "large screen".

The second draws a brighter rectangle when hover.

Can anyone lead me how to do this or give me any suggestion?

Thank you very much!


Multiple colour attachments are used for writing to more than one colour target from the same invocation of the fragment shader. That is, they are for fragment shader outputs.

A common use of multiple attachments is when you do deferred shading, where you may have one attachment for output position, one for output normal, one for output diffuse colour.

If you want to use multiple textures as inputs when drawing, you bind your textures to separate texture units and store the index of the units in your sampler uniforms. This is the same thing you do with a single texture, but as you use other texture units than 0, you may not have explicitly done so.

OpenGL has a set of texture units, named from GL_TEXTURE0 up to some maximum. In the old days, each texture unit was sampled and the results combined in some manner by the fixed function pipeline. You select the active texture unit that glBindTexture shall affect with a call to glActiveTexture(GL_TEXTURE0 + unitNumber).

Once you've got your texture ids bound to texture units, you can relate your sampler uniform variables in your shader with the texture units. If you have uniform sampler2D mapTexture in your shader, you would glGetUniformLocation(prog, "mapTexture") in your code to find the uniform, and glUniform1i(that, N) to indicate it should read from texture unit N.

For more details, consider reading a proper article like the arcsynthesis section on texturing.

The task you present, drawing a base image and something on top of it can be done in two ways:

  • draw a quad textured with your base image, enable alpha blending, and draw a quad with your modification on top;
  • draw a quad with a shader that combines the source texture with some modification, either from texture or programmatically.
  • \$\begingroup\$ Can you make me more clear about "store the index of the units in your sampler uniforms" \$\endgroup\$ – LongLT Feb 23 '15 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.