【发布时间】:2015-11-08 06:27:28
【问题描述】:
这个程序使用 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);
}
这个函数用来显示房子:
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();
}
【问题讨论】:
-
首先,我认为最好使用opengl-version 3.x,其次我认为你的坐标可能太大了,通常你的窗口从-1到+1, x 和 y,但这只是一个猜测