示例SDL程序给出了一个空窗口 [英] Sample SDL program gives an empty window

查看:388
本文介绍了示例SDL程序给出了一个空窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

config:archlinux with awesome desktop environment

config: archlinux with awesome desktop environment

我刚刚安装了sdl2,并尝试运行这个示例代码:
https://github.com/xyproto/hello_sdl2/blob/master/c%2B%2B /main.cpp

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

结果是一个空白窗口(我可以通过它看到我的控制台)在屏幕中间。即使当我打mod4 + Enter,它不会和其他人很好地平铺。为什么呢?

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?

(我更新了我的系统,重新安装了sdl2,我也找不到任何相关的浏览google。)

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

推荐答案

所有窗口系统都需要你通过消息队列处理消息。有关SDL的一些具体示例,请参见本章,但本质是定期调用SDL_PollEvent或一些其他SDL函数来处理任何事件。你的代码只是延迟了一段时间。你不能把你的主线程睡觉,并期望一个窗口系统,以满足。他们运行事件。当窗口被映射时,有一个事件,然后另一个告诉窗口绘制自己或键盘输入。在等待期间泵送事件队列。

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.

这篇关于示例SDL程序给出了一个空窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆