当我从格洛多的欢迎屏幕转到另一个glupperspective的屏幕时,问题就出现了。
只有当我在欢迎屏幕上单击播放后调整窗口大小,否则我将收到黑屏。
我想我需要修正glVertex3f的值,以便它正确地呈现,就像当我直接移动到函数而不进入欢迎屏幕时,多边形正确地呈现一样
请检查下面的gif:
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (key1 == 3){
glOrtho(0.0, 100.0, 0.0, 100.0, -5.0 , 10.0);
glMatrixMode(GL_MODELVIEW);
}
if (key1 == 1 || key1 == 2){
gluPerspective(45.0, (float)w/(float)h, 0.1f, 200.0);
gluLookAt(0.0, 0.0, 5.0,0.0, 0.0, 0.0,0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
}
}
void par(float x1, float x2, float y1, float y2, float z1, float z2){
glColor3f(0.3,0.56,0.84);
glBegin(GL_POLYGON);
glVertex3f(x1, y1, z1);
glVertex3f(x2, y1, z1);
glVertex3f(x2, y2, z1);
glVertex3f(x1, y2, z1);
glEnd();
}
void Drawkey1/2(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();
glTranslatef(0.0, 0.0, -22.0);
int i;
par(-8.7, 9.2, 9.0, 9.2, 0.0, 0.0);
par(-8.7, 9.2, -8.5, -8.7, 0.0, 0.0);
par(-8.5, -8.7, -8.7, 9.2, 0.0, 0.0);
par( 9.2, 9.0, -8.7, 9.2, 0.0, 0.0);
while(p != NULL){
par((p -> x)/2.0,(p -> x)/2.0 + 0.4,(p -> y)/2.0,(p -> y)/2.0 + 0.4, 0.0, 0.0);
p = p -> nexploration_ratet;
}
par(food_x/2.0, food_x/2.0 + 0.4 , food_y/2.0 , food_y/2.0 + 0.4, 0.0 , 0.0);
}
void Drawkey3(){
glColor3f(0.3,0.56,0.84);
glBegin(GL_POLYGON);
glVertex3f(0.0,0.0,0.0);
glColor3f(0.137,0.137,0.556);
glVertex3f(100.0,0.0,0.0);
glColor3f(0.196,0.196,0.8);
glVertex3f(100.0,100.0,0.0);
glVertex3f(0.0,100.0,0.0);
glEnd();
glColor3f(0.196,0.196,0.8);
glRectf(39.5,39.5,60.5,45.5);
glColor3f(0.8,0.8,0.8);
glRectf(40,40,60,45);
glColor3f(0.137,0.137,0.556);
drawString(47,42,0,GLUT_BITMAP_HELVETICA_18,"USER");
glColor3f(0.196,0.196,0.8);
glRectf(39.5,29.5,60.5,35.5);
glColor3f(0.8,0.8,0.8);
glRectf(40,30,60,35);
glColor3f(0.137,0.137,0.556);
drawString(41,31,0,GLUT_BITMAP_HELVETICA_18,"NETWORK_PLAY");
glColor3f(0.196,0.196,0.8);
glRectf(39.5,19.5,60.5,25.5);
glColor3f(0.8,0.8,0.8);
glRectf(40,20,60,25);
glColor3f(0.137,0.137,0.556);
drawString(46,21,0,GLUT_BITMAP_HELVETICA_18,"HOW_TO");
glColor3f(0.196,0.196,0.8);
glRectf(39.5,9.5,60.5,15.5);
glColor3f(0.8,0.8,0.8);
glRectf(40,10,60,15);
glColor3f(0.137,0.137,0.556);
drawString(47,11,0,GLUT_BITMAP_HELVETICA_18,"EXIT");
glPushMatrix();
glColor3f(0.8,0.8,0.8);
drawString(25.5,92,0,GLUT_BITMAP_TIMES_ROMAN_24,"COMPUTER GRAPHICS PROJECT ");
drawString(35.5,80,0,GLUT_BITMAP_TIMES_ROMAN_24,"SRIJANA");
glPopMatrix();
glColor3f(0.137,0.137,0.556);
}
最佳答案
更新
通过确保glMatrixMode在从GL_投影转换时不获取GL_MODELVIEW来修复错误
关于c++ - 在OpenGL C++中同时使用glOrtho和gluPerspective,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48541172/