Ich lerne opengl auch. Ich bin gestern mit diesem Problem konfrontiert worden und habe die richtige Antwort nicht gefunden. Heute habe ich das Problem gelöst. In meinem kleinen Programm ändert das Objekt seine Größe, wenn es die Fensterbreite oder -höhe ändert. Dies ist mein Code (bitte verzeihen Sie meine Fehler):
#include <GL/freeglut.h>
void fnReshape(int ww, int hh)
{
GLdouble r;
if(hh == 0)
hh = 1.0;
if(hh > ww)
r = (double) hh/(double) ww;
else
r = (double) ww/(double) hh;
glViewport(0, 0, ww, hh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(hh > ww)
glFrustum(-1.0, 1.0, -1.0 * r, 1.0 * r, 2.0, 200.0);
else
glFrustum(-1.0 * r, 1.0 * r, -1.0, 1.0, 2.0, 200.0);
}
//////////////////////////////////////////////////////////////////
void fnDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0., 0., -5.);
glBegin(GL_QUAD_STRIP);
glColor3f(0., 0., 1.0);
glVertex3f(-1., -1., 0.);
glVertex3f(-1., 1., 0.);
glVertex3f(1., -1., 0.);
glVertex3f(1., 1., 0.);
glEnd();
glutSwapBuffers();
}
////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE);
glutInitWindowSize(500, 500);
glutCreateWindow("Sample window");
glClearColor(1.0, 0, 0, 1.0);
glutDisplayFunc(fnDisplay);
glutReshapeFunc(fnReshape);
glutMainLoop();
return 0;
}
Scissoring beeinflusst auch den neu gezeichnet Bereich, wenn Sie einmal den Clip rect gesetzt durch den Aufruf 'glScissor()'. Siehe [this] (https://www.opengl.org/discussion_boards/showthread.php/176760-glClearColor-MM-SIZE-only-part-is-cleared). – zwcloud