2 liyanfolfol liyanfolfol 于 2013.07.03 16:47 提问

关于OpenGL问题,请高手帮忙Review一下代码

下面的代码是我写的,不知道为什么要表示的东西没有被显示,而一直都是黑画页。
代码如下:
oid CBuild::GlRealize()
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,400);
glutInitWindowPosition(100,100);
glutCreateWindow("Building");
Init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}
void CBuild::display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW )
glBegin(GL_TRIANGLES); // Start Drawing A Triangle
glColor3f(1.0f,0.0f,0.0f); // Set Top Point Of Triangle To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // First Point Of The Triangle
glColor3f(0.0f,1.0f,0.0f); // Set Left Point Of Triangle To Green
glVertex3f(-1.0f,-1.0f, 0.0f); // Second Point Of The Triangle
glColor3f(0.0f,0.0f,1.0f); // Set Right Point Of Triangle To Blue
glVertex3f( 1.0f,-1.0f, 0.0f); // Third Point Of The Triangle
glEnd(); // Done Drawing The Triangle
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0
glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW )
glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=0.15f;
glFlush();
// Decrease The Rotation Variable For The Quad ( NEW )
/*
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();

glColor3f(1.0,1.0,1.0);
glBegin(GL_LINES);
glVertex2f(50.0,-50.0);
glVertex2f(100.0,-200.0);
glVertex2f(300.0,-200.0);
glEnd();

glFlush();

  */

}
void CBuild::reshape(int w,int h)
{
glViewport(0,w,0,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,w,0,h);
}
void CBuild::Init()
{

glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);               // Black Background
glClearDepth(1.0f);                                 // Depth Buffer Setup
glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
glDepthFunc(GL_LEQUAL);                             // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Really Nice Perspective Calculations

// glClearColor(0.0,0.0,0.0,0.0);
// glShadeModel(GL_FLAT);
// glClearDepth(1.0);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
// glOrtho(0.0,1.0,0.0,1.0,1.0,1.0);

}

Csdn user default icon
上传中...
上传图片
插入图片