Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL函数显示房屋不工作_C++_Opengl - Fatal编程技术网

C++ OpenGL函数显示房屋不工作

C++ OpenGL函数显示房屋不工作,c++,opengl,C++,Opengl,这个程序使用opengl显示一所房子 输出只是显示一个空白屏幕,没有其他内容,我也没有做任何更改窗口位置和大小的工作 我不知道怎么了 #include<Gl/glut.h> GLfloat square[][2]={{100,200},{100,100},{200,100},{200,200}};//coordinates of the vertices of the square part of the house GLfloat door[][2]={{125,150},{125

这个程序使用opengl显示一所房子 输出只是显示一个空白屏幕,没有其他内容,我也没有做任何更改窗口位置和大小的工作 我不知道怎么了

#include<Gl/glut.h>
GLfloat square[][2]={{100,200},{100,100},{200,100},{200,200}};//coordinates of the vertices of the square part of the house
GLfloat door[][2]={{125,150},{125,100},{175,100},{175,150}};// coordinates of the door
GLfloat roof[][2]={{50,200},{250,200},{150,300}};// coordinates of the roof
void Myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,500.0,0.0,500.0);
glMatrixMode(GL_MODELVIEW);
}

由于您使用的是双缓冲窗口,因此显示函数必须在最后调用
glutSwapBuffers()
。有关双缓冲的更多详细信息,请参见。

首先,我认为最好使用opengl 3.x版,其次我认为您的坐标可能太大,通常您的窗口从-1到+1,x和y都是,但这只是一个猜测
void drawHouse()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0,1,1);
glBegin(GL_POLYGON);  display the square part of the house
glVertex2fv(square[0]);
glVertex2fv(square[1]);
glVertex2fv(square[2]);
glVertex2fv(square[3]);
glEnd();
glColor3f(1,0,1);
glBegin(GL_POLYGON);  display the roof
glVertex2fv(door[0]);
glVertex2fv(door[1]);
glVertex2fv(door[2]);
glVertex2fv(door[3]);
glEnd();
glColor3f(1,0,0);
glBegin(GL_TRIANGLES);  display the triangle
glVertex2fv(roof[0]);
glVertex2fv(roof[1]);
glVertex2fv(roof[2]);
glVertex2fv(roof[3]);
glEnd();
glFlush();
}

int main(int argv, char** argc)
   {
     glutInit(&argv,argc);
     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
     glutCreateWindow("House Drawing which rotates\n");
     glutInitWindowPosition(100,100);
     glutInitWindowSize(1000,1000);
     Myinit();
     glutDisplayFunc(drawHouse);
     glutMainLoop();
}