Question

I've created a program to display a lined cube on a white canvas but I am unsure how to multiple that cube into lets say? 10 x 10. Another question is how would I go about creating the same cube in a 3D space?

Here's my code:

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;
}
Was it helpful?

Solution

The glu library has a lot of useful tidbits like gluLookAt( xfrom, yfrom, zfrom, xto, yto, zto, xup, yup, zup );

You can scale things using glScaled( factor ) / glScalef( factor )

You should poke around Google for some GL 1.X documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top