1

我已经创建了一个程序来在白色画布上显示一个带衬里的立方体,但我不确定如何将该立方体组合成多个?10 x 10。另一个问题是如何在 3D 空间中创建相同的立方体?

这是我的代码:

void drawScene(void)
{
    int i, j;

    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0, 0.0, 0.0);
    glLoadIdentity();

     glTranslatef(0.0, 0.0, -25.0); 
    glutWireCube(5.0); // Box.
    glColor3f(1.0, 0.0, 0.0);

    for(i=5; i<5; i++)
    {
        for (j = -5; j < 5; j++)
        {

            glPushMatrix();
            glTranslatef(i*5, j*5, -35.0);
            glColor3f(1.0, 1.0, 0);
            glutSolidCube(5.0);
            glColor3f(0.0, 0.0, 1.0);
            glutWireCube(5.0);
            glPopMatrix();
        }
    }

glFlush();

}

void setup(void)
{
    glClearColor(1.0, 1.0, 1.0, 0.0);
}

void resize (int w, int h)
{
    glViewport(0, 0, (GLsizei)w, (GLsizei)h); 
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-10.0, 10.0, -10.0, 10.0, 10.0, 100.0);
    glMatrixMode(GL_MODELVIEW);
}

void KeyInput(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 27:
        exit(0);
    break;
    default:
    break;
    }
}


int main(int argc, char **argv) 
{
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
   glutInitWindowSize(500,500); /* Size of the Program Window */
   glutInitWindowPosition(100,100);
   glutCreateWindow("Box.cpp"); 
   setup();
   glutDisplayFunc(drawScene); 
   glutReshapeFunc(resize);
   glutKeyboardFunc(KeyInput);
   glutMainLoop(); 

   return 0;
}
4

1 回答 1

0

glu 库有很多有用的花絮,比如gluLookAt( xfrom, yfrom, zfrom, xto, yto, zto, xup, yup, zup );

您可以使用glScaled( factor )/glScalef( factor )

您应该在 Google 上搜索一些 GL 1.X 文档。

于 2013-02-25T20:53:02.393 回答