-1

即使我已经调用了 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

4

1 回答 1

1

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

于 2019-03-27T13:44:15.393 回答