I’m guessing that this is something that has been done before but
I’m trying to think of the best way to do a ‘fog-of-war’ effect…
I’ve got a screen display at 640x480x16bpp, which is a window onto a
much larger area (3.4k by 2.5k) and I want the “fog” to only reveal what
the character has seen at any time before that. Ideally what I want is a
2-stage fog, such that:
0 -> black pixels 1 -> greyed pixels - not as intense, but we've been here before 2 -> currently visible pixels.
It seems to me that this maps basically to a transparency effect, with
state ‘1’ = alpha 0.5. I already have the screen surface, so if I make
another surface just for the fog, I can use alpha blitting onto the
screen to black out the bits I don’t want. All I have to do to reveal
more area is blit a pre-prepared “visibility” image centred on the new
character position into the fog, and the next screen update will reveal
The thing is that I’m not sure how to set up an SDL software surface
with 1 colour (black) and 2 alpha bits, and doing it at 8-bits will
significantly increase my RAM use because the actual map is so large. Is
it in fact possible ?
Assuming it’s not… I can presumably call
int fogW = 27 * 128;
int fogH = 20 * 128;
surface *fog = SDL_CreateRGBSurface(SDL_SWSURFACE,
fogW, fogH, 16,
0xFF00, 0x00, 0x00, 0x00FF); // 16 Mb!
int rgb = SDL_MapRGB(fog->format, 255,0,0);
SDL_SetColorKey(fog, SDL_SRCCOLORKEY|SDL_RLEACCEL, rgb);
… to get myself a 16-bit (red! but I don’t care because it’s
transparent) including 8-bit alpha surface. Then I just use 0,128,255 as
alpha values for the non-visited,seen-before,and visible areas, and draw
in the colour (255,0,0) to let the underlying graphic surface shine through.
Is is possible to have just an alpha surface - no rgb ? I guess I could
just have 0,128,255 as alpha values if it were possible
Am I barking up the right tree, or is there a better/more efficient way
to do it ? I’ve noticed that at 640x480x16, with all the tiles, and some
large alpha-blitted objects, I only make ~40 fps. That’s sufficient, but
slightly lower than I’d hoped, even after converting surfaces to the
screen format and setting RLEACCEL on the alpha-blits … OTOH, it’s
only a matrox G400 card on an Athlon 1800+ (1.5GHz) which is pretty
low-end by today’s standards, and it is running in Java
Thanks in advance for any help - much appreciated.