Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Creating hole in a texture using another texture

This topic is 1123 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to make very simple effects in my 2D game of textures (PyOpenGL) and trying to figure out what blend modes to use. I have searched around and seen people talk in depth about this but couldn't find any real solution in the end. Many talk about shaders which I don't use for this.


Right now I have a world layer, an overlay layer, and then a 'light' layer. Each filled with various textures.

The world layer contains all the textures of my world, the tiles, the objects, etc.

The overlay layer is simply an opaque color that covers the screen.

The 'light' is just a very simple white circle (eventually different shapes) with a transparent background.


What I am trying to accomplish is to create a light effect by taking the light/object texture, removing it from the overlay to create a hole in the shape of the texture (with alpha), and then blend in that result to the world so that some appears dark while certain areas remain normal giving the illusion of lights. From there I can actually add a light texture in its place to control how bright it will appear along with coloring it.


Can this be accomplished with a blend mode with OpenGL? I've tried using glBlendFunc(GL_DST_COLOR, GL_ZERO) with both but it just makes the lit portion extremely bright.This works as a temporary solution but problems arise where if you get multiple 'lights' too close together, they of course get added and get way too bright washing out all the color. Also makes it hard to adjust the intensity of it.


Can someone give me some direction how I should be doing this? Is this not possible with blending? Thanks.

Share this post

Link to post
Share on other sites

I don't know offhand the one you want, but you can play with blend modes in your browser, for quicker testing.


Does this satisfy your needs?


Basically, you have a texture the same size as the screen, and you render into that texture instead of rendering into the screen.

First, you fill it completely with shadows (could be pure black, or could be animated fog or whatever)

Then, you draw your lights over the texture using the equation above (assuming I got the equation right - which is a big "if" tongue.png)

Then you go back to your typical alpha-blend equation [ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ]

And, after setting your window as the render-target, you draw your shadow/fog/whatever texture (which now has holes punched into it) over the entire screen.

Share this post

Link to post
Share on other sites

it seems you are saying that you set alpha values by the distance function (for light texture)

sth like this:



where black is fully transparent and white is full opaque.



the idea is to render all lights to texture

but then i thnk you will have to parse the texture and convert pixel brightness to alpha (so you can reduce valuse by 0.5.

anyway its overcomplication of things without shaders. i think you are trying to render world with full brightness and the add light to it, i cant imagine what are you doing maybe a screenshot of present effect?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!