And*_*uri 1 c++ opengl orthographic perspective projection-matrix
我在C++ Visual Studio 2008 Forms应用程序中使用OpenGL,当bool设置为true/false时,我希望GLcontrol在3D和2D之间切换.
3D绘图工作正常,2D绘图工作正常,从一个切换到另一个时出现问题.因此,如果我在2D中启动应用程序绘图,它可以完美地运行并且与3D相同,但是如果我在运行时更改布尔值则不会绘制任何内容.
这是我从一个变为另一个的代码.
if(opciones->draw3D){
GL::MatrixMode(MatrixMode::Modelview);
GL::LoadIdentity();
GL::Viewport(0, 0, w, h);
Matrix4 lookat = Matrix4::LookAt(100, 100, 100, 0, 0, 0, 0, 0, 1);
GL::LoadMatrix(lookat);
GL::Scale(this->zoom, this->zoom, this->zoom);
GL::Rotate(xrot, 1.0f, 0.0f, 0.0f);
GL::Rotate(yrot, 0.0f, 1.0f, 0.0f);
GL::Clear(ClearBufferMask::ColorBufferBit | ClearBufferMask::DepthBufferBit);
GL::ClearColor(Color::LightGray);
// Draw3D
}
else {
GL::MatrixMode(MatrixMode::Projection);
GL::LoadIdentity();
GL::Ortho(5, w-5, 5, h-5, -1, 1);
GL::Viewport(5, 5, w-5, h-5);
GL::Clear(ClearBufferMask::ColorBufferBit|ClearBufferMask::DepthBufferBit);
GL::ClearColor(Color::LightGray);
GL::MatrixMode(MatrixMode::Modelview);
GL::LoadIdentity();
// Draw 2D
}
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,但我想我不清楚某些矩阵或其他东西,因为正如我之前所说的那样,变量draw3D==true在开始时它完美地绘制,当变量draw3D==false在开始时它完全绘制在2D中,但运行时的更改使其无法正常工作.
| 归档时间: |
|
| 查看次数: |
2121 次 |
| 最近记录: |