【发布时间】:2019-08-17 23:11:32
【问题描述】:
即使我已经调用了 glOrtho(),这个函数也不会改变任何东西。代码有什么问题?我错过了什么吗?
void glKeyCallback(unsigned char key, int x, int y){
if (key == 'z'){
width -= 10; height -= 10;
cout << "Z" << endl;
cout << width << " " << height << endl;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
}else if (key == 'x'){
width += 10; height += 10;
cout << "X" << endl;
cout << width << " " << height << endl;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 100, 100, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
}
}
当我按下 z 或 x 时,我预计场景会放大/缩小。但这并没有改变任何东西。作为记录,我已经在glutKeyboardFunc注册了这个
【问题讨论】:
-
在回调中调用 GL 函数是不确定的,因为回调可能在错误的线程中运行。最好只在您进行实际渲染的地方调用它们。
-
在minimal reproducible example 中编辑。据我们所知,您不会定期重绘;你的
glutKeyboardFunc()肯定不会打电话给glutPostRedisplay()。
标签: c++ opengl freeglut opengl-compat