Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem with SDL_DisplayFormat

Started by beefsteak Dec 17, 2005 at 7:53 AM 1 replies 650+ views
Original Post
beefsteak
beefsteak
I'm fairly new with SDL. What I want to do is load an image and display it. For fast blitting, I convert it to the display format using SDL_DisplayFormat. Here's how I load my image:
// initialize SDL first...

SDL_Surface *image = IMG_Load("image.png"); // load image
if (image != NULL) {
    // convert to display-native pixel format, for fast blitting
    SDL_Surface *dfImage = SDL_DisplayFormat(image);
    SDL_FreeSurface(image);
    
    if (dfImage != NULL) {
        LOG("with = " << dfImage->w << ", height = " << dfImage->h << ", pitch = " << dfImage->pitch);
        
        if (dfImage->pixels == NULL)
            LOG("pixels NULL!");
    }
}
As I have indicated, I initialize SDL before executing this code. When I call SDL_SetVideoMode with flags SW_SURFACE, then everything works fine and the output appears to be correct: with = 76, height = 67, pitch = 304 When I call it with flags SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN, then I get the following: with = 76, height = 67, pitch = 320 pixels NULL! Why is the pixels data NULL in this case? The surface seems to be unusable that way. And why is pitch 320 instead of 304? (Note: 76 width * 4 depth = 304 pitch) Is it not possible to convert pixelformat to a hardware-surface? I thought it's just the same, converting to 4 byte color depth. I'm using WindowsXP, VisualStudio, Cpp, SDL for graphics and an NVIDIA GeForce FX 5200 graphics card, if it matters. Thanks for help! [smile]
rip-off
rip-off
if you make a surface the same as the display surface, and your display is hardware( ie, graphics memory), then you cant access it via that pointer.

the calls SDL_LockSurface() and SDL_UnlockSurface() will copy the image to system memory for manipulation, and then copy it back. this is why we dont read from a harware surface :)

your code is perfectly right. but dont check the pixels pointer. you can assume that if the surface pointer is good, SDL has Done The Right Thing and that the surface is valid

good luck!

[Edited by - rip-off on December 17, 2005 8:06:22 AM]
beefsteak
beefsteak
Ah, that explains it.
Thank you very much for this helpful answer.

I rate you up. Thanks.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.