I made this with Xcode 3, running Santa Rosa MacBook. All the frameworks and such are linked properly. When I run the code, the window pops up, but the screen is white. When I move another window over it or bring up widgets, it seems to refresh the screen and i can see the cube. The second problem is that the camera is supposed to rotate around the cube but doesn't, it seems to only call glutDisplayFunc once.
I gave my teacher my code, and he ran it on his Linux environment and it worked fine. I don't understand what is happening. I can run a simple program I have just displaying a square, so i know how to compile OpenGL code correctly. Any help?
double transform_eyex()
{
tempx = (cos(theta) * eyex) + (sin(theta) * eyez);
return tempx;
}
double transform_eyez()
{
tempz = (-sin(theta) * eyex) + (cos(theta) * eyez);
return tempz;
}
void display(void)
{
theta += 0.1;
eyex = transform_eyex();
eyez = transform_eyez();
// set up new view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, 1.0, 1.0, 10000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyex, 5.0, eyez, //eye
0.0, 0.0, 0.0, //target
0.0, 1.0, 0.0); // up
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw triangles
draw_cube_face();
draw_cube_back();
glFlush();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("cube");
init_mod();
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutIdleFunc(glutPostRedisplay);
glutMainLoop();
}
I gave my teacher my code, and he ran it on his Linux environment and it worked fine. I don't understand what is happening. I can run a simple program I have just displaying a square, so i know how to compile OpenGL code correctly. Any help?
double transform_eyex()
{
tempx = (cos(theta) * eyex) + (sin(theta) * eyez);
return tempx;
}
double transform_eyez()
{
tempz = (-sin(theta) * eyex) + (cos(theta) * eyez);
return tempz;
}
void display(void)
{
theta += 0.1;
eyex = transform_eyex();
eyez = transform_eyez();
// set up new view
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, 1.0, 1.0, 10000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyex, 5.0, eyez, //eye
0.0, 0.0, 0.0, //target
0.0, 1.0, 0.0); // up
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw triangles
draw_cube_face();
draw_cube_back();
glFlush();
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("cube");
init_mod();
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(display);
glutIdleFunc(glutPostRedisplay);
glutMainLoop();
}