PDA

View Full Version : need help pls



moonie
06-03-2003, 08:41 PM
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();
}

SThomas
06-03-2003, 10:05 PM
move the cube and sphere rendering code into the same display function, and make sure you only clear the viewport with glClear() once.

errno
06-03-2003, 10:22 PM
you can't register mutiple display func. you must make a function which draw the cube and the sphere:
void display(void)
{
cube();
sphere();
}

moonie
06-03-2003, 11:19 PM
ok thanks i manage to get it to work. http://www.opengl.org/discussion_boards/ubb/smile.gif