【问题标题】:Why is glOrtho not changing anything?为什么 glOrtho 没有改变任何东西?
【发布时间】: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


【解决方案1】:

OpenGL 不是一个场景图,它是一个绘图 API。仅更改投影矩阵将无济于事。您还必须重新绘制东西。

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2020-10-24
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多