Layers for grapics?

BlitzMax Forums/BlitzMax Programming/Layers for grapics?

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?

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.

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.

This works
Graphics 800,600

Local Cave:TImage = LoadImage("cave.png") 'load the cave graphic
Local Player:TImage = LoadImage("player.png") 'load the player graphic
MidHandleImage Player
Local PlayerX:Int = 400 'Player x position
Local PlayerY:Int = 300 'Player y position
SetClsColor 0,0,0 'make sure cls color is black (Defaults to that anyway)
'use other values for cls color to illuminate the cave at different levels


While Not KeyHit(KEY_ESCAPE)
	Cls 'clear the backbuffer
	
	SetBlend SOLIDBLEND 'draw solid
	DrawOval PlayerX - 64, PlayerY - 64,128,128 'draw a circle around the player
	
	SetBlend SHADEBLEND 'draw multiply
	DrawImage Cave,0,0
	
	SetBlend ALPHABLEND 'draw with alpha
	DrawImage Player,PlayerX,PlayerY

	Flip
	
	If KeyDown(KEY_LEFT) Then PlayerX :- 1
	If KeyDown(KEY_RIGHT) Then PlayerX :+ 1
	If KeyDown(KEY_UP) Then PlayerY :- 1
	If KeyDown(KEY_DOWN) Then PlayerY :+ 1
Wend


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.

yah........what he said. :) lol..

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.

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.