【发布时间】:2021-06-03 00:19:14
【问题描述】:
我是 OpenGL 新手,尝试渲染两个对象,但只有一个对象应该旋转。我从here 了解到,我可以使用glPushMatrix 和glPopMatrix 仅对一个对象应用旋转,但我的不起作用。
这是我的代码:
void renderObjs() {
//glPushMatrix();
drawPyramid(0, 0.7, 0, 0.289, 0, 0.167, -0.289, 0, 0.167, 0, 0, -0.33); // a function to draw triangles
//glPopMatrix();
glPushMatrix();
glRotatef(0.3f, 1.f, 1.f, 1.f);
drawPyramid(0 - 0.5, 0.7 - 0.5, 0 - 0.5, 0.289 - 0.5, 0 - 0.5, 0.167 - 0.5, -0.289 - 0.5, 0 - 0.5, 0.167 - 0.5, 0 - 0.5, 0 - 0.5, -0.33 - 0.5);
glPopMatrix();
}
int main() {
// some initialization
...codes here...
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
renderObjs();
glfwSwapBuffers(window);
glfwPollEvents();
}
// other useful functions
...codes here...
}
但是我的金字塔都没有旋转。为什么会这样?我是否以错误的方式使用了glPushMatrix 和glPopMatrix?
【问题讨论】:
标签: c++ opengl opengl-compat