How come i cannot get the cube and sphere to appear in the same window? Is there something wrong with my codes? Sorry im new to opengl.
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
void init(void);
void cube(void);
void sphere(void);
int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(800,800);
glutInitWindowPosition(100,150);
glutCreateWindow(“My Project”);
glutDisplayFunc(cube);
glutDisplayFunc(sphere);
init();
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glClearDepth(1.0f);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)800/(GLfloat)800,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void cube(void)
{
glTranslatef(0,0,-5.0f);
glRotatef(-65,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1.0,0.5,1.0);
glutWireCube(2.00);
glFlush();
glutSwapBuffers();
}
void sphere(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.5,1.0);
glPushMatrix();
glutSolidSphere(5.0,20,16);
glPopMatrix();
glutSwapBuffers();
}