问题
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:
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.
来源:https://stackoverflow.com/questions/29332155/sample-sdl-program-gives-an-empty-window