簡體   English   中英

SDL_CreateRGBSurfaceFrom() 不能編譯?

[英]SDL_CreateRGBSurfaceFrom() doesn't compile?

我試圖用 SDL_CreateRGBSurfaceFrom 從另一個表面創建一個 RGB 表面,因為它是一個 TTF 表面,我想改變深度來訪問表面像素,這個函數應該返回一個 SDL_Surface* 指針,但編譯器說它返回一個 int並且我無法將返回值分配給我的 SDL_Surface* 指針,這很奇怪,因為 SDL_CreateRGBSurface 完全按照預期的方式工作。

這是代碼和編譯器消息:

SDL_Surface     *tmp = SDL_CreateRGBSurfaceFrom(mySurface->pixels, mySurface->w, mySurface->h, 32, 32 * mySurface->w, RMASK, GMASK, BMASK, AMASK);

Compiling src/main.c: error: incompatible integer to pointer conversion assigning to 'SDL_Surface *' (aka 'struct SDL_Surface *') from 'int' [-,-Wint-conversion]
  ...= SDL_CreateRGBSurfaceFrom(mySurface->pixels, mySurface->w, mySurface->h, 32, 32 * mySurface->w, RMASK, GMASK, BMASK, AMASK)
     ^ 

最小可復制程序:

# include <SDL.h>
# include <SDL_ttf.h>
# if SDL_BYTEORDER == SDL_BIG_ENDIAN
#  define RMASK 0xff000000
#  define GMASK 0x00ff0000
#  define BMASK 0x0000ff00
#  define AMASK 0x000000ff
# else
#  define RMASK 0x000000ff
#  define GMASK 0x0000ff00
#  define BMASK 0x00ff0000
#  define AMASK 0xff000000
# endif

int             main(void)
{
    SDL_Surface     *textSurface;
    SDL_Surface     *newSurface;
    TTF_Font        *font;
    SDL_Color       white = {255, 255, 255, 255};

    font = TTF_OpenFont()
    if (SDL_Init() || TTF_Init()
    || !(font = TTF_OpenFont("assets/fonts/SweetCreamy.ttf", 30))
    || !(textSurface = TTF_RenderText_Solid(font, "Test", white))
    || !(newSurface = SDL_CreateRGBSurfaceFrom(textSurface->pixels, textSurface->w, textSurface->h, 32, 32 * textSurface->w, RMASK, GMASK, BMASK, AMASK)))
        return (-1);
    SDL_FreeSurface(textSurface);
    SDL_FreeSurface(newSurface);
    TTF_Quit();
    SDL_Quit();
    return (0);
}

似乎 SDL_CreateRGBSurfaceFrom 被隱式定義,因此返回一個 int 作為默認值。 確保您包含 SDL.h。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM