SDL2 FillRect with SDL_Window issues

SDL2 FillRect with SDL_Window issues

本文关键字:Window issues SDL FillRect with SDL2      更新时间:2023-10-16

我尝试使用SDL_FillRect与SDL 2.0

下面是我的代码:

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;

得到的错误是:

1>c:usersethandesktopc++ projectsanother test with sdlanother测试与sdlmain.cpp(16):错误C2664: 'int SDL_FillRect(SDL_Surface . int)*,const SDL_Rect *,Uint32)':无法将参数1从'SDL_Window *'转换为'SDL_Surface *'

1比;指向的类型有不相关的;转换需要reinterpret_cast、c风格强制转换或function-style铸

在SDL2中,您应该创建SDL_Renderer并使用SDL_RenderClear

如果你真的想使用SDL_FillRect,那么你可以在单独的SDL_Surface上调用它,然后在2步中将该表面渲染到你的窗口上。SDL2迁移指南谈到了这些东西:https://wiki.libsdl.org/MigrationGuide

SDL_RenderPresent是需要的,以便您的纹理呈现在您的渲染