I would like some insight about how to place an image with an alpha, and a certain amount of opacity, on the top of everything that is rendered. What's the cheapest way to do that?

I use C++ with a programmable OpenGL pipeline.

  • \$\begingroup\$ Usage of c++ language doesn't matter here. The main is principle in words and if you are programmer you must be able to "convert" it into c++ :) \$\endgroup\$
    – kravemir
    Aug 23 '12 at 8:54

After you've rendered your normal bits and pieces:

  • Disable depth testing.
  • Prepare an orthographic matrix to get a screen-aligned coordinate system you can reason about, taking care to honor your aspect ratio.
  • Enable blending with blend modes of your choice.
  • Generate a quad and draw it with a simple fragment shader sampling from your texture.

One way is with overlays. It should be fast/cheap enough.

UPDATE: As Lars Viklund's comment explanations go, these overlays do not refer to the older concept that predates the programmable pipeline. The older way to add overlays (or underlays for that matter of fact) had to do with creating special render context planes like described here.

  • 1
    \$\begingroup\$ You might want to clarify that it's a term invented on that wiki page and not actually the old antiquated overlay planes. Your answer will likely confuse anyone with historical experience. \$\endgroup\$ Aug 22 '12 at 14:09
  • \$\begingroup\$ I'm not aware of the historical semantic of this term, but it might be conceptually similar (the difference being in the fixed pipe-line process, or am I seriously off with this guess). I used it only with this meaning several times.. \$\endgroup\$
    – teodron
    Aug 22 '12 at 14:22
  • \$\begingroup\$ In the dark ages, graphics cards could have one or more overlay and underlay planes, which were composited on top or below of the main display plane. This let you do popups without disturbing the contents of existing windows. OpenGL implementations tend to expose it through some kind of layer context. \$\endgroup\$ Aug 22 '12 at 16:03
  • \$\begingroup\$ @LarsViklund thanks for that piece of info :).. since in the dark ages I was a kindergarten GLUT fan and seeing that there were no such direct mechanisms to enable it.. I haven't used the over/underlays. I'll update the answer to reflect the piece of knowledge you shared. \$\endgroup\$
    – teodron
    Aug 22 '12 at 16:15

Depending on what your current pipeline is, it could be really easy to add it in a post process step.

Assuming you already have a post-process chain where you can render to a certain target to apply some extra processing to your scene, adding the watermark could be a post-process where you just render your final scene texture and then add your watermark texture. Obviously you can "factorize" this step into other if you don't want to add a new step and even come up with fancy effects for your watermark. Also with this method it could be extremely simple to remove your watermark step later.

  • \$\begingroup\$ can you offer an example in C or C++ ? \$\endgroup\$
    – user827992
    Aug 22 '12 at 13:46
  • \$\begingroup\$ Sadly, i don't have a C/C++ example that i can share. Although i remember reading a good sample from an XNA book. IIRC it was in XNA 2.0 recipes, which is kind of outdated but the idea was there. Basically you create a system where you render everything normally, but instead of writing directly the framebuffer, you set a texture as your target. Then you can use that texture to draw a "full-screen sprite" into the real final buffer. The trick is to use a pixel shader to draw that texture, so you can apply all sorts of fancy effects such as blur, noise, color modification, etc. I hope this helps \$\endgroup\$
    – Carlos
    Aug 22 '12 at 14:01

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.