SDL DisplayFormat does rectangle

SDL DisplayFormat does rectangle

本文关键字:rectangle does DisplayFormat SDL      更新时间:2023-10-16

我对SDL和c++都是新手。

然而,当我对图像进行DisplayFormat以加快比特化时,它会使其成为矩形。

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

为什么?

这是因为您要转换图像的显示格式不支持透明像素。您必须将视频模式设置为每像素32位,如下所示:

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

您还需要将SDL_DisplayFormat更改为SDL_DisplayFormatAlpha