Home > Back-end >  Getting "too few arguments in function call" error in SDL_CreateWindow() function
Getting "too few arguments in function call" error in SDL_CreateWindow() function

Time:08-21

#include <iostream>
#include <SDL2/SDL.h>

using namespace std;

const int sWidth = 800, sHeight = 800;

int main() {
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window *window  = SDL_CreateWindow("My SDL", SDL_WINDOWPOS_UNDEFINED, sWidth, sHeight, SDL_WINDOW_ALLOW_HIGHDPI);

}

CodePudding user response:

Documentation states that SDL_CreateWindow requires six parameters, but you have only provided five. Compiler is telling you the same thing.

Try this

SDL_Window *window = SDL_CreateWindow("My SDL", 
    SDL_WINDOWPOS_UNDEFINED, 
    SDL_WINDOWPOS_UNDEFINED, 
    sWidth, sHeight, SDL_WINDOW_ALLOW_HIGHDPI);

CodePudding user response:

As stated in the documentation page, SDL_CreateWindow() has the following signature:

SDL_Window * SDL_CreateWindow(const char *title,
                              int x, int y, int w,
                              int h, Uint32 flags);

As you can see, you're missing int y window position argument.

Since you're starting learning it, I suggest you to go check some tutorials. Lazy foo has some pretty useful ones: https://lazyfoo.net/tutorials/SDL/.

  • Related