loading raw pixel data into an SDL_Surface?

Started by
3 comments, last by barazor 21 years, 2 months ago
i have been trying to figure out how to load my own custom image format into an SDL_Surface, with no luck. i''ve tried looking at the SDL_Image code, but i haven''t been able to get anywhere. can anyone show me the basic steps in loading raw pixel data from a file into a a surface?
Advertisement
Read the guidevideo.htm file in the SDL docs. You learn about writing directly to the surface memory, locking and unlocking the surface, with code examples.
Look up SDL_CreateRGBSurfaceFrom if you haven''t done so already.
You can load your raw image data using your own functions and then pass the pixeldate to the above function creating an SDL_Surface.
baumep
If you use SDL_CreateRGBSurfaceFrom, remember you have to free the pixel data, and remember that SDL_FreeSurface won''t do this for you:

quote:
From SDL_CreateRGBSurfaceFrom

The pixel data is not copied into the SDL_Surface structure so it should not be freed until the surface has been freed with a called to SDL_FreeSurface.



quote:
From SDL_FreeSurface

If the surface was created using SDL_CreateRGBSurfaceFrom then the pixel data is not freed.


aut viam inveniam aut faciam

MoonStar Projects
alright, i solved my own problem. turned out that i confused the amask and rmask parameters, and set the red channel mask to 0

This topic is closed to new replies.

Advertisement