Lucas Arrefelt
Lucas Arrefelt

Reputation: 3929

SDL DisplayFormat does rectangle

Im new to SDL and C++ overall.

However when i do DisplayFormat on an image for faster blitting it makes it an rectangle.

SDL_Surface* tempImage = NULL;

// The image that will be used (optimized)
image = NULL;

image = IMG_Load( filename.c_str() );

if ( tempImage != NULL )
{
    // Create optimization
    image = SDL_DisplayFormat( tempImage ); // Makes the circle an rectangle

    // Free the old image
    SDL_FreeSurface( tempImage );
}

Why is that? If i dont do DisplayFormat, the circle remains an circle when blitted.

Upvotes: 0

Views: 141

Answers (1)

user142162
user142162

Reputation:

This is because your display format which you're converting your image to does not support transparent pixels. You must set your video mode to have 32 bits per pixel, like below:

SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface *window = SDL_SetVideoMode(width, height, 32, flags);

// ...

You also need to change SDL_DisplayFormat to SDL_DisplayFormatAlpha.

Upvotes: 4

Related Questions