Layers for grapics?

BlitzMax Forums/BlitzMax Programming/Layers for grapics?

Drakim(Posted 2008) [#1]
I'm in some situations where I could make everything a lot better if I could somehow work with layers in my graphics.

I could give you an example. Let's say I want the player to only be able to see a few inches around his character (he is in a cave), and that the rest of the screen should be dark, with the exception of torches and other lighting stuff.

A super easy way to do this with more than one layer would be to draw the character and cave floor on layer 1, and then fill layer 2 completely black, and then "cut out" the areas of layer 2 that shouldn't be black, before you render layer 2 on top of layer 1.

(by the way, I'm not making a character in a cave-game, so don't provide better solution for that example. It's just that, an example)

Is it a viable option to have a screen sized pixmap? I'm guessing not, since pixmaps aren't very fast at drawing? Drawing the pixmap or converting it to a TImage every single frame sounds unrealistic, but I might I be wrong?

Or am I going about this completely wrong?


MGE(Posted 2008) [#2]
For the light effect, you could make all of your graphics slightly darker and then render a circle at the location of the player using Blend = LIGHTBLEND which would cause all of the pixels in the circle to be lighter.


Drakim(Posted 2008) [#3]
But, will you really be able to recreate the exact same color values?

I mean, that would perhaps work if you have a constant 50% darker effect to all the non-lighted areas. But if you want fade effects, or pitch black, then the lighting using LIGHTBLEND won't work, or will work very poorly.


TomToad(Posted 2008) [#4]
This works


using shade blend will multiply the colors of the image with what is already on the backbuffer. So you draw a white circle wherever you want the cave to be lit up using SolidBlend, then draw the cave on top using ShadeBlend. You could also use AlphaBlend on the oval and use a TImage with fading alpha to simulate light dropoff.


MGE(Posted 2008) [#5]
yah........what he said. :) lol..


Drakim(Posted 2008) [#6]
Oh, brilliant! I hadn't thought about using SHADEBLEND that way. This will work nicely.


But, anyways, it still bothers me that there isn't some kind of layers. It seems like something generally nice and nifty thing to have.


sswift(Posted 2008) [#7]
What you're asking for isn't called layers, it's called stencils.

BlitzMax, as far as I know, doesn't directly support stencils though the built in command set, but you could enable them with the appropriate DirectX and OpenGL calls.

Search the forum for "stencils" and you may find some code to enable them.

But the shadeblend method suggested above would probably be your best choice. It would be a lot easier to implement for you.


Dwapook(Posted 2014) [#8]
Nice.. This is exactly what I've been looking to do also.. I've come across a problem with this method though..

When I want to have multiple images hidden in darkness, the shadeblend causes the second image to appear transparent.. Anyone happen to know any solutions to this?



*edits* Totally didn't notice this topic is 5 years old.. O.o; oops..