SDL_CreateRGBSurfaceFrom() doesn't compile?

2

I'm trying to create a RGB Surface from another surface with SDL_CreateRGBSurfaceFrom because it's a TTF surface and I want to change the depth to access the surface pixels, this function is supposed to return a SDL_Surface* pointer but the compilers says it returns an int and I cant assign the return to my SDL_Surface* pointer, which is weird because SDL_CreateRGBSurface works perfectly the way it's supposed to.

Here's the code and the compiler message:

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)
     ^ 

Minimal Reproductible program:

# 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);
}
c
sdl-2
asked on Stack Overflow Sep 28, 2020 by Fayeure • edited Sep 28, 2020 by Fayeure

1 Answer

0

It would appear that SDL_CreateRGBSurfaceFrom is being implicitly defined and as such is returning an int as is the default. Ensure you are including SDL.h.

answered on Stack Overflow Sep 28, 2020 by TTG

User contributions licensed under CC BY-SA 3.0