gpt4 book ai didi

c++ - SDL 程序卡住

转载 作者:行者123 更新时间:2023-11-30 03:09:37 27 4
gpt4 key购买 nike

我正在编写一个简单的程序来测试鼠标。它编译得很好,但不起作用。当我启动它时,窗口卡住。我做错了什么?

#include <SDL/SDL.h>
#undef main

int main()
{
if (SDL_Init (SDL_INIT_EVERYTHING) != 0)
return 1;
SDL_Surface* Scr;
if ((Scr = SDL_SetVideoMode (300, 200, 32, 0)) == 0)
return 2;

SDL_Rect Mouse1 = {50, 50, 50, 100};
SDL_Rect Mouse3 = {150, 50, 50, 100};
SDL_Rect Mouse2 = {250, 50, 50, 100};
SDL_Surface Colors;
SDL_Rect Click = {0, 0, 50, 100};
SDL_Rect NoClick = {50, 0, 50, 100};

SDL_FillRect (Scr, 0, SDL_MapRGB (Scr->format, 255, 255, 255));
SDL_FillRect (&Colors, &Click, SDL_MapRGB (Colors.format, 255, 0, 0));
SDL_FillRect (&Colors, &NoClick, SDL_MapRGB (Colors.format, 0, 0, 255));

while (true)
{
if (SDL_GetMouseState (0, 0) & SDL_BUTTON(1))
SDL_BlitSurface (&Colors, &Click, Scr, &Mouse1);
else
SDL_BlitSurface (&Colors, &NoClick, Scr, &Mouse1);

if (SDL_GetMouseState (0, 0) & SDL_BUTTON(2))
SDL_BlitSurface (&Colors, &Click, Scr, &Mouse2);
else
SDL_BlitSurface (&Colors, &NoClick, Scr, &Mouse2);

if (SDL_GetMouseState (0, 0) & SDL_BUTTON(3))
SDL_BlitSurface (&Colors, &Click, Scr, &Mouse3);
else
SDL_BlitSurface (&Colors, &NoClick, Scr, &Mouse3);

if (SDL_GetKeyState (0) [SDLK_ESCAPE])
return 0;

SDL_Delay (17);
}
}

最佳答案

您没有处理任何事件。在您的情况下,调用 SDL_PumpEvents 使 SDL 处理它们并更新其所有内部状态:

while (true)
{
SDL_PumpEvents();

// The rest is the same ...
}

关于c++ - SDL 程序卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3951113/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com