Jump to content
  • Advertisement
Sign in to follow this  

problem with SDL_DisplayFormat

This topic is 4685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
    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]

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!