[英]C++ OpenGL switching from 2D to 3D
I'm using OpenGL in C++ Visual Studio 2008 Forms application and I want a GLcontrol to switch between 3D and 2D when a bool is set to true/false. 我在C ++ Visual Studio 2008窗体应用程序中使用OpenGL,并且当布尔值设置为true / false时,我希望GLcontrol在3D和2D之间切换。
The drawing in 3D works fine, the drawing in 2D works fine, the problem comes when switching from one to another. 在3D模式下工作正常,在2D模式下工作正常,从一个切换到另一个时出现问题。 So if I start the application drawing in 2D it works perfectly and the same with 3D, but if I change the boolean while running it won't draw anything.
因此,如果我以2D模式启动应用程序绘图,则它可以完美地工作,并且与3D相同,但是如果我在运行时更改布尔值,它将不会绘制任何内容。
Here is the code where I change from one to another. 这是我从一个更改为另一个的代码。
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
}
I don't know what am doing wrong, but I guess that I don't clear some matrix or something, because like I said before when the variable is draw3D==true
at the beginning it draws perfectly and when the variable is draw3D==false
at the beginning it draws perfectly in 2D, but the change during runtime makes it not work. 我不知道自己在做什么错,但是我想我并没有清除某些矩阵或某些东西,因为就像我之前说过的,当变量在开始时为
draw3D==true
时,它绘制完美,而当变量为draw3D==false
在开始时会完美地以2D绘制,但是运行时的更改使其无法正常工作。
You need to set the projection matrix in 3D mode for one thing. 您需要在3D模式下设置投影矩阵。 I'm guessing by default your framework is setting up a perspective projection for you.
我猜默认情况下,您的框架正在为您设置透视投影。 This is getting overwritten when you do GL::Ortho() in the 2d part.
在2d部分中执行GL :: Ortho()时,这将被覆盖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.