Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Inverting a 2D polygon drawing area

  1. #1
    Newbie Newbie
    Join Date
    Jun 2013

    Question Inverting a 2D polygon drawing area

    Hi there,
    I'm working on a simple 2D lighting system. I'm attempting to make a cone 'light' area, wherein the objects within are drawn normally. Outside of this cone of light, a black overlay with 0.5f alpha will be drawn, causing all drawn objects outside the cone to appear darker. Imagine a torch in 2D. See the below diagram:

    So the way I was thinking of going about this was to somehow specify an inverse cone of light, and draw it with an alpha level of 0.5f and a black color after drawing my objects, like a dark semi-transparent overlay. That should work in theory, but I have no idea how to specify this inverted cone of light!

    Any help would be much appreciated.

    An alternative would be just as good, as I'm not sure I'm going down the right path here. I have experimented with different blending modes, with no luck.

    Thanks in advance!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Aren't you able to do proper lighting in shaders and just assign all unlit objects a default medium gray ambient intensity?

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Alternatively, write to the stencil buffer (but not the color/depth buffers) when drawing the light cone. Then draw the full screen overlay and only write to the color buffer where the stencil buffer is zero.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts