调整GLUT窗口大小的问题

时间:2011-04-17 13:33:52

标签: c opengl window 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;
    }

EDITED

我改为跟随,现在没关系。

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();
}

0 个答案:

没有答案