Sample SDL program gives an empty window

2019-04-11 21:29发布

config: archlinux with awesome desktop environment

I just installed sdl2, and tried to run this sample code: https://github.com/xyproto/hello_sdl2/blob/master/c%2B%2B/main.cpp

The result is an empty window (I can see my console through it) in the middle of the screen. Even when I hit mod4+Enter, it doesn't tile up nicely with the others. Why is that?

(I updated my system, reinstalled sdl2. I also couldn't find any relevant hit browsing google.)

1条回答
贪生不怕死
2楼-- · 2019-04-11 21:57

All windowing systems require you to handle messages by pumping a message queue. See this chapter for some SDL specific examples but the essence is call SDL_PollEvent or some other SDL function regularly to process any events. Your code just delays for some time. You can't put your main thread to sleep and expect a window system to be happy with that. They run on events. When the window gets mapped, there is an event, then another to tell the window to paint itself or for keyboard input. Pump the event queue while waiting.

查看更多
登录 后发表回答