Question

Pour une raison quelconque, lorsque je redimensionne mes fenêtres OpenGL, tout s’effondre. L'image est déformée, les coordonnées ne fonctionnent pas et tout tombe en morceaux. Je chante Glut pour le mettre en place.

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

L’application OpenGL est strictement 2D.

Voici à quoi cela ressemble au départ: http://www.picgarage.net/images /Corre_53880_651.jpeg

voici à quoi cela ressemble après le redimensionnement: http://www.picgarage.net/ images / wrong_53885_268.jpeg

Était-ce utile?

La solution

Vous ne devez pas oublier de raccrocher l'événement GLUT 'remodeler':

glutReshapeFunc(resize);

Et réinitialisez votre fenêtre d'affichage:

void resize(int w, int h)
{
    glViewport(0, 0, width, height); //NEW
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, w, h, 0);
}

Une projection en perspective devrait prendre en compte le nouveau format d'image:

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);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top