#### Archived

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

# 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 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 on other sites
Look up SDL_CreateRGBSurfaceFrom if you haven''t done this already.

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982057

• 12
• 9
• 9
• 13
• 11