Hi, I’ve been working on a project for a graphics class and after a lot of headache I’ve decided to just ask for a hint in the right direction.
I draw the grid like this and it works fine, the problem is when I try to use glutSolidCube to draw a cube at each grid intersection. I can’t get it working at all, maybe I’ve misunderstood how the glTranslatef function works. This is for a school project so I’d like to have some explanation rather than to just have someone post code that works.
//set camera projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, 1.0, 0.1, 100);
//set camera position and orientation
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -0.25f);
//setup the grid display list
glNewList(GRID, GL_COMPILE);
glBegin(GL_LINES);
glColor3f(0.75f, 0.75f, 0.75f);
glLineWidth(1.0f);
for(float i=-10.0; i<=10.0f; i+=1.0f)
{
glVertex3f(i, -10.0f, 0.0f);
glVertex3f(i, +10.0f, 0.0f);
}
for(float j=-10.0f; j<=10.0f; j+=1.0f)
{
glVertex3f(-10.0f, j, 0.0f);
glVertex3f(+10.0f, j, 0.0f);
}
glEnd();
glPushMatrix();
//glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
for(float i=-10.0f; i<10.0f; i+=1.0f)
for(float j=-10.0f; j<10.0f; j+=1.0f)
{
glColor3f(0.0f, 0.0f, 1.0f);
glLoadIdentity();
glTranslatef(i, j, 0.0f);
glutSolidCube(0.5f);
}
glPopMatrix();
glEndList();