ここで私が達成したいことは、以下のコードでswitch_2D_3Dというフラグがあり、それが真であれば2Dモード、そうでなければ3Dに切り替わります。スイッチfron 2Dから3Dへ
void reshape(GLsizei width, GLsizei height)
{
if (switch_2D_3D)
{
// GLsizei for non-negative integer
// Compute aspect ratio of the new window
if (height == 0)
height = 1; // To prevent divide by 0
GLfloat aspect = (GLfloat)width/(GLfloat)height;
// Reset transformations
glLoadIdentity();
// Set the aspect ratio of the clipping area to match the viewport
glMatrixMode(GL_PROJECTION); // To operate on the Projection matrix
// Set the viewport to cover the new window
glViewport(0, 0, width, height);
if (width >= height)
{
// aspect >= 1, set the height from -1 to 1, with larger width
gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
}
else
{
// aspect < 1, set the width to -1 to 1, with larger height
gluOrtho2D(-1.0, 1.0, -1.0/aspect, 1.0/aspect);
}
winWidth = width;
winHeight = height;
} // 2D mode
else
{
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (height == 0)
height = 1;
float ratio = width * 1.0/height;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, width, height);
// Set the correct perspective.
gluPerspective(45.0f, ratio, 0.1f, 100.0f);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
winWidth = width;
winHeight = height;
}// 3D mode
}
のみ、2Dモードで描画するときにすべてが完璧に動作しますが、私は3Dモードに切り替えるためのフラグを変更すると、ここで問題
が、私は、ウィンドウのサイズを変更するたびに来て、私が描くもの
2次元モードに戻っても、2次元モードのすべてが問題なく機能しますが、問題は3Dモードです。
また、I staフラグがfalseに設定されているプログラムでは、キューブが表示され、毎回ウィンドウのサイズを変更するにつれてサイズが小さくなります。
どうしてですか?
「2D対3D」の考え方をやめてください。その区別は意味をなさない、言われるべき真実。ここで切り替えているのは投影ですが、もちろん3Dシーンに対しても正射投影を使用できます。 – datenwolf