调整 GLUT 窗口大小时出现问题
我有以下代码,但无法调整窗口大小。有什么建议吗?
GLsizei width = 600;
GLsizei height = 600;
GLfloat AspectRatio;
int max = 500;
double xmax = 2.0;
double xmin = -2.0;
double ymax = 2.0;
double ymin = -2.0;
using namespace std;
void display()
{
gluOrtho2D(-2, width, -2, height);
AspectRatio=1.0*width/height;
mandelbrot();
glutSwapBuffers();
}
void reshize(GLsizei w, GLsizei h) {
GLsizei vsize;
if(w<h) vsize=w; else vsize=h;
glViewport(0,0,AspectRatio*vsize,vsize);
}
void mandelbrot()
{
...
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("mandelbrot Set");
glutDisplayFunc(display);
glutReshapeFunc(reshize);
glutMainLoop();
return 0;
}
已编辑
我更改为关注,现在可以了。
void display()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2, width, -2, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT );
mandelbrot();
glutSwapBuffers();
}
void reshize(GLsizei w, GLsizei h) {
width=w; height=h;
glViewport(0,0,width,height);
glutPostRedisplay();
}
I have the following code and I can't resize the window. Any suggestions?
GLsizei width = 600;
GLsizei height = 600;
GLfloat AspectRatio;
int max = 500;
double xmax = 2.0;
double xmin = -2.0;
double ymax = 2.0;
double ymin = -2.0;
using namespace std;
void display()
{
gluOrtho2D(-2, width, -2, height);
AspectRatio=1.0*width/height;
mandelbrot();
glutSwapBuffers();
}
void reshize(GLsizei w, GLsizei h) {
GLsizei vsize;
if(w<h) vsize=w; else vsize=h;
glViewport(0,0,AspectRatio*vsize,vsize);
}
void mandelbrot()
{
...
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(600, 600);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("mandelbrot Set");
glutDisplayFunc(display);
glutReshapeFunc(reshize);
glutMainLoop();
return 0;
}
EDITED
I changed to following and now it's OK.
void display()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-2, width, -2, height);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT );
mandelbrot();
glutSwapBuffers();
}
void reshize(GLsizei w, GLsizei h) {
width=w; height=h;
glViewport(0,0,width,height);
glutPostRedisplay();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论