Ethan Webster
Ethan Webster

Reputation: 41

SDL2 FillRect with SDL_Window issues

I'm having issues trying to use SDL_FillRect with SDL 2.0

Here's my code:

bool running = true;

//Initialise SDL
SDL_Init(SDL_INIT_EVERYTHING);

SDL_Window *screen = SDL_CreateWindow("Test Game",
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    640, 480,
    SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL);

while (running){
    SDL_FillRect(screen, NULL, 0);
}

//Quit SDL
SDL_Quit();

return 0;

The error I'm getting is:

1>c:\users\ethan\desktop\c++ projects\another test with sdl\another test with sdl\main.cpp(16): error C2664: 'int SDL_FillRect(SDL_Surface *,const SDL_Rect *,Uint32)' : cannot convert argument 1 from 'SDL_Window *' to 'SDL_Surface *'

1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Upvotes: 1

Views: 1756

Answers (2)

user3809627
user3809627

Reputation: 1

SDL_RenderPresent is needed in order for your textures to be present in your render

Upvotes: 0

Nicolas Louis Guillemot
Nicolas Louis Guillemot

Reputation: 1628

In SDL2, you should create a SDL_Renderer and use SDL_RenderClear.

If you really want to use SDL_FillRect, then you could call it on a separate SDL_Surface and then render that surface onto your window in 2 steps. The SDL2 migration guide talks about this stuff: https://wiki.libsdl.org/MigrationGuide

Upvotes: 2

Related Questions