Jump to content
  • Advertisement
Sign in to follow this  

showing a part of a texture?

This topic is 3028 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 do something similar to do a lighting effect similar to this:


Unfortunately, that is in flash and I would like to do it using either SDL or openGL. I am running into a bit of a snag of how something like that would be accomplished.

I was thinking that I would have my bottom texture for the board, then a full black shape covering it, then put a polygon with an alpha on 0 on top of that for the 'lighting'. However, after searching for quite some time, I have come up with nothing.

Would anyone be able to help point me in the right direction?

Thank you in advance!

Share this post

Link to post
Share on other sites
I see several things in that link, exactly which of those are you struggling with?
1. Combining a tiling ground texture with a texture that defines where corridors are?
2. Calculating the exact area where your flashlight shines?
3. Combining the flashlight area polygons with the ground?

Share this post

Link to post
Share on other sites
The part where you only show the calculated area for the flash light. Sorry for not being more specific.

Share this post

Link to post
Share on other sites
There are a lot of ways to do this, depending on how complex your scene is and how many lights you have. If you have only one light like this, then this is one solution that would work:

Solution A:
-First render the entire scene as if everything is lit.
-Then calculate the light's area.
-Now create polygons that cover the entire screen, except the light area. So you create polygons for all parts of the screen that are in shadow.
-Now render these polygons in black over the screen. Only the light areas remain.

However, this requires calculating the lighting polygons, which might be a complex step if you are not good with this kind of math.

The following is an alternative that is simpler on the algorithms, but more complex on the OpenGL side. This one also supports having several lights on screen:

Solution B:
-Clear the screen to all black.
-Clear the stencil buffer to all black.
-Calculate the polygons for the light area.
-Render the polygons of the light area in white to the stencil buffer.
-Render everything else (background, monsters, weapons) normally, but with stencil testing turned on, so that things are only rendered where the stencil buffer is white.

There is also a solution C with rendertextures, but I think that one is slightly more complex than B and achieves the same thing. The benefit of using rendertextures is that you can also easily create lights that smoothly fade out. :)

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!