Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
glClearColor
本身不进行任何清除——它只是设置实际清除时的颜色。要自行进行清除,您需要使用(至少)COLOR_BUFFER_BIT
调用glClear
。编辑:自从我使用 glut 以来已经有一段时间了,所以这个细节可能是错误的,但如果没记错的话,要改变屏幕颜色以响应按下键盘上的按键,你会做这样的事情:
基本上,您可以在传递给 glutDisplayFunc 的任何函数中完成所有绘图。几乎任何其他事情都只是更改状态,然后调用 PostRedisplayFunc(); 来告诉 glut 窗口需要重新绘制。警告:正如我所说,自从我使用 glut 以来已经有一段时间了,而且我还没有测试过这段代码。据我所知,它展示了过剩程序的一般结构,但不要指望它能完全按原样工作。
glClearColor
does not do any clearing itself -- it just sets what the color will be when you do actually clear. To do the clearing itself, you need to callglClear
with (at least)COLOR_BUFFER_BIT
.Edit: it's been quite a while since I used glut, so the details of this could be wrong, but if memory serves, to change the screen color in response to pressing a key on the keyboard, you'd do something like this:
Basically, you do all your drawing in whatever function you pass to
glutDisplayFunc
. Almost anything else just changes the state, then callsPostRedisplayFunc();
to tell glut that the window needs to be redrawn. Warning: as I said, it's been a while since I used glut and I haven't tested this code. It shows the general structure of a glut program to the best of my recollection, but don't expect it to work exactly as-is.我想您在调用
glClearColor
时没有 OpenGL 上下文。但是……
我以前从未使用过 glut,所以快速浏览一下 docs 表明您实际上在
glutCreateWindow
之后会有一个上下文,所以也许不是这样。正如我对您的问题的评论所说,我很好奇第二次调用
glClearColor
以及您认为如何实现它。这更有可能是问题的原因。要在按键上执行任何操作,我相信您必须使用 glutKeyboardFunc 注册回调。I would imagine you don't have an OpenGL context at that point that you call
glClearColor
.But...
...I've never used glut before so a quick look at the docs suggests that you will actually have a context after
glutCreateWindow
so perhaps that's not it.As my comment on your question says I'm curious about the second call to
glClearColor
and how you think you will reach it. That's more likely the cause of the problem. To do anything on a key press I believe you would have to register a callback usingglutKeyboardFunc
.