# 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.

## Recommended Posts

Hello,

I am trying do something similar to do a lighting effect similar to this:

http://www.emanueleferonato.com/2007/09/26/create-a-survival-horror-game-in-flash-tutorial-part-1/

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?

##### 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 on other sites
The part where you only show the calculated area for the flash light. Sorry for not being more specific.

##### 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. :)

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633697
• Total Posts
3013407
×

## Important Information

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!