Strange error

I’m working on a simple SDL with Map class containing a vector of vectors of
Field classes. Map::render calls Field::render in a loop to draw a matrix of
Fields… but resulting surface comes out empty (or doesnt blit properly).
Field::render is working.
Fragments of code: http://pastebin.com/d7c52de2d

It’s not clear what you’re doing, so I can’t help fully yet. I can
say that you seem to be creating and freeing tons of surfaces each
frame when you really shouldn’t. In fact, this may be what is causing
your problems. If you create a surface with an alpha channel, is it
totally transparent? If you blit to a transparent surface, it stays
transparent. You have to used SDL_SetAlpha to make sure the source
surface’s alpha info gets used.

As for the many surfaces thing, if you really want to use a surface to
compose (which usually isn’t necessary at all) before blitting to the
screen, then you should just keep one surface around and clear it
before you reuse it.

Jonny DOn Sat, Oct 3, 2009 at 4:15 PM, Hubert Maraszek wrote:

I’m working on a simple SDL with Map class containing a vector of vectors of
Field classes. Map::render calls Field::render in a loop to draw a matrix of
Fields… but resulting surface comes out empty (or doesnt blit properly).
Field::render is working.
Fragments of code: http://pastebin.com/d7c52de2d


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, both Field::render and result surfaces have alpha channel. What should
I do to make it work?

2009/10/3 Jonathan Dearborn > It’s not clear what you’re doing, so I can’t help fully yet. I can

say that you seem to be creating and freeing tons of surfaces each
frame when you really shouldn’t. In fact, this may be what is causing
your problems. If you create a surface with an alpha channel, is it
totally transparent? If you blit to a transparent surface, it stays
transparent. You have to used SDL_SetAlpha to make sure the source
surface’s alpha info gets used.

As for the many surfaces thing, if you really want to use a surface to
compose (which usually isn’t necessary at all) before blitting to the
screen, then you should just keep one surface around and clear it
before you reuse it.

Jonny D

On Sat, Oct 3, 2009 at 4:15 PM, Hubert Maraszek <@Hubert_Maraszek> wrote:

I’m working on a simple SDL with Map class containing a vector of vectors
of
Field classes. Map::render calls Field::render in a loop to draw a matrix
of
Fields… but resulting surface comes out empty (or doesnt blit
properly).
Field::render is working.
Fragments of code: http://pastebin.com/d7c52de2d


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Result of Field::render has alpha channel because of rendering sub-pixel
rectangles. Map::render is transparent too, because it would otherwise
override the background. Only thing that makes Fields visible is:
SDL_SetAlpha(result, SDL_SRCCOLORKEY, 255); // in Field::render
But I think it removes sub-pixel alpha. What is the optimal solution?