Archived

This topic is now archived and is closed to further replies.

Lode

Images in SDL

Recommended Posts

How can you create surfaces for images in SDL without using SDL_LoadBMP or something similar? When using LoadBMP it works perfectly so I have an image on screen, but I don''t want to load files from HD, I hardcode the images into the exe (because DevC++ does annoying when the program has to load files). But whenever I try to write pixel data to the SDL_Surface for the image, the program crashes. What do I have to do to this surface before it wants to let me write pixels to it? So in fact I need to generate a whole set of surfaces to be used in the rest of the program as images to blit on the screen. MANY MANY ERRORS BEFORE THIS POST FINALLY POSTED

Share this post


Link to post
Share on other sites
Read the SDL documentation, especially that sample program that fills the screen with pixels.

You need to lock the surface before writing pixel data directly to the frame buffer. And then unlock it after you have finished.

Here is bit a sample code taken directly from the SDL docs.


/* Lock the screen for direct access to the pixels */
if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 ) {
fprintf(stderr, "Can''t lock screen: %s\n",SDL_GetError());
return;
}
}

Share this post


Link to post
Share on other sites