GP2X Load Bitmap Data Into An Sdl_surface?


Gadget

Member
Joined
May 16, 2006
Messages
247
I have my own image format that I read into memory and decompress. I then want to blit to a pre-created (correct pixel depth and W, H etc) SDL_Surface. How can I do this? SDL_Surface width, height and pixel depth are read only apparently =/

EDIT: Also, what's wrong with this:-

void ScreenDump(SDL_Surface *Screen)
{
SDL_SaveBMP(Screen,"data/screen.bmp");
}


ScreenDump(screen);

It seems to slow the device down for a good second or two and then the main loop continues. I have no idea why it won't work. Is it because I am using the primary surface?
 
I have my own image format that I read into memory and decompress. I then want to blit to a pre-created (correct pixel depth and W, H etc) SDL_Surface. How can I do this? SDL_Surface width, height and pixel depth are read only apparently =/
Have a look at SDL_CreateRGBSurfaceFrom(). It creates a new SDL_Surface structure and you can specify all the parameters (pixels, w, h, pitch ...). This is probably exactly what you need.

Another way is to directly decompress your image to the location pointed to by the SDL_Surface's pixels member. This way the surface must have been pre-created (e.g. with SDL_CreateRGBSurface()) with the correct parameters for width, height, format etc.

void ScreenDump(SDL_Surface *Screen)
{
SDL_SaveBMP(Screen,"data/screen.bmp");
}

ScreenDump(screen);

It seems to slow the device down for a good second or two and then the main loop continues. I have no idea why it won't work. Is it because I am using the primary surface?
This should actually work. Even more so, when it takes time to execute. Maybe you should check the return value of the function and also try with a SDL_SWSURFACE (assuming your screen surface is a hardware surface).
But taking a screendump this way by saving it as a bmp file will always be SLOW since your screen surface is probably 16bit and the BMP format does not support 16bits per pixel. Saving is slowed down because SDL must convert the surface to the correct format internally.
 
Last edited by a moderator:
Thanks,

I tried changing from SW to HW and it worked, BUT the screen flickers like mad in HW mode?. I wonder if this is a problem with the HW Accel SDL? Anyway, for the purpose of an initial screen shot of my new game:-

I have the menu system, highscore table, options, map format, power-ups etc all done. Working on some awesome content now =D

screen.jpg


EDIT: FPS is limited to 50 at the moment for testing.
 
If you set the video mode with SDL_SetVideoMode() with SDL_HWSURFACE include SDL_DOUBLEBUF in the flags parameter. This way you get double buffering (assuming you use the paeryn's hw accelerated SDL).
Draw everything you want to show and then call SDL_Flip(screen) to actually display it on the screen.
 
If you set the video mode with SDL_SetVideoMode() with SDL_HWSURFACE include SDL_DOUBLEBUF in the flags parameter. This way you get double buffering (assuming you use the paeryn's hw accelerated SDL).
Draw everything you want to show and then call SDL_Flip(screen) to actually display it on the screen.

I am doing that already?? :huh:
 
Last edited by a moderator:
Back
Top