由于某些原因,当我调整我的OpenGL窗口大小时,所有的东西都散开了。图像被扭曲了,坐标不起作用,一切都变得支离破碎。我正在唱Glut来设置它。
//Code to setup glut
glutInitWindowSize(appWidth, appHeight);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("Test Window");
//In drawing function
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
//Resize function
void resize(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
}
OpenGL应用程序完全是2D的。
它最初看起来是这样的:http://www.picgarage.net/images/Corre_53880_651.jpeg
这是调整大小后的样子:http://www.picgarage.net/images/wrong_53885_268.jpeg
发布于 2009-03-15 13:56:49
你不应该忘记挂接GLUT‘重塑’事件:
glutReshapeFunc(resize);
并重置视口:
void resize(int w, int h)
{
glViewport(0, 0, width, height); //NEW
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
}
透视投影必须考虑新的纵横比:
void resizeWindow(int width, int height)
{
double asratio;
if (height == 0) height = 1; //to avoid divide-by-zero
asratio = width / (double) height;
glViewport(0, 0, width, height); //adjust GL viewport
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(FOV, asratio, ZMIN, ZMAX); //adjust perspective
glMatrixMode(GL_MODELVIEW);
}
https://stackoverflow.com/questions/648619
复制相似问题