简体   繁体   English

SDL2 FillRect与SDL_Window问题

[英]SDL2 FillRect with SDL_Window issues

I'm having issues trying to use SDL_FillRect with SDL 2.0 我在尝试将SDL_FillRect与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> c:\\ users \\ ethan \\ desktop \\ c ++ projects \\ sdl的另一个测试\\ sdl \\ main.cpp的另一个测试(16):错误C2664:'int SDL_FillRect(SDL_Surface *,const SDL_Rect *,Uint32)':无法将参数1从'SDL_Window *'转换为'SDL_Surface *'

1> Types pointed to are unrelated; 1>指向的类型无关; conversion requires reinterpret_cast, C-style cast or function-style cast 转换需要reinterpret_cast,C样式强制转换或函数样式强制转换

In SDL2, you should create a SDL_Renderer and use SDL_RenderClear . 在SDL2中,您应该创建一个SDL_Renderer并使用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. 如果您确实要使用SDL_FillRect ,则可以在单独的SDL_Surface上调用它,然后SDL_FillRect将该表面渲染到窗口上。 The SDL2 migration guide talks about this stuff: https://wiki.libsdl.org/MigrationGuide SDL2迁移指南讨论了这些内容: https : //wiki.libsdl.org/MigrationGuide

需要SDL_RenderPresent才能使纹理出现在渲染中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM