I’m testing SDL 1.3 API to evaluate porting of some projects to this API,
I’m wondering if there is an easy way to port a game where every sprite has
a back buffer to SDL 1.3 (it’s a card game it doesn’t need to redraw the
whole screen every time you click a card).
At the moment to fill the backbuffer I’m trying this approach that I think
it’s quite slow (from what I’ve read on the SDL 1.3 headers at least):
char buffer[4 * rend_.card_size_.X() * rend_.card_size_.Y()];
SDL_RenderReadPixels(&r, buffer, 4);
SDL_UpdateTexture(it->second.Dirty(), NULL, buffer, 4);
I cannot test if this approach works because on linux (ubuntu 8.04) with the
latest SVN (as of today) I get the following error in link stage:
lowres_renderer.cpp|326| undefined reference to `SDL_RenderReadPixels’
Looking at the source and grepping the binary I’ve seen that function is
only defined on headers:
gabry at nevada:~/no-backup/SDL-1.3/test$ strings …/…/lib/libSDL-1.3.so.0.0.0
| grep Pixels
SDL_QueryTexturePixels
gabry at nevada:~/no-backup/SDL-1.3/test$
Anyway I understand that, also if implemented, calling
SDL_RenderReadPixels()/SDL_UpdateTexture, very often is not a good idea, but
at this point what I could do?
I have to rework the whole game logic moving the screen update code from
being event based to be frame based and redraw the whole cardset every
frame?
Actually only if you click something or drag something a partial screen
update is triggered, otherwise the game waits in a SDL_WaitEvent call, and I
think this is a good approach, expecially for mobile devices where keeping
the CPU in idle is very important.
It would be nice to be able to copy to a texture a part of the render
surface or to render a texture to another texture (using the RTT extensions
that most gfx chipset have). From what I’ve seen from the headers the only
operation you can do with a texture is to blit it to a render target (that
can be only a window) or to modify it with direct pixel access.
Speaking about textures I’ve also found another minor problem, it seems that
SDL_CreateTextureFrom() is unable to import 32bit BMP loaded from
SDL_LoadBMP (Unknown pixel format error), I worked around it with the
following code:
if (SDL_Surface *dest = SDL_LoadBMP_RW(rw, 1)) { // rwops is closed
by loadbmp
if (SDL_Surface *temp = SDL_CreateRGBSurface( SDL_SWSURFACE,
dest->w, dest->h, 32,
0xff000000, 0xff0000, 0xff00, 0xff
)) {
SDL_BlitSurface(dest, NULL, temp, NULL);
SDL_TextureID id = SDL_CreateTextureFromSurface(0, temp);
if (id == 0)
std::cerr << "SDL Error: " << SDL_GetError() << '\n';
SDL_FreeSurface(temp);
SDL_FreeSurface(dest);
return id;
}
SDL_FreeSurface(dest);
}
return 0;--
Bye,
Gabry