Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

easlern

OGL display problem

This topic is 6023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could someone please explain to me why this window does not refresh correctly? I have two red spheres, a big one and a little one orbiting it. As it stands, I have to force it with glutPostRedisplay() to get it to calculate and display the new position of the orbiting object. I have modified example 5-9 from the red book to create this. I''m not sure how to use the code formatting tag or whatever so here goes: #include <GL/glut.h> #include <stdlib.h> GLfloat diffuseMaterial[4] = {1.0, 0.0, 0.0, 1.0}; GLfloat angle = 0; GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};; void init (void){ GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH); glEnable (GL_DEPTH_TEST); glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuseMaterial); glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf (GL_FRONT, GL_SHININESS, 25.0); glLightfv (GL_LIGHT0, GL_POSITION, light_position); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); } void display (void){ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere (1.0, 30, 26); angle += 0.5; if (angle > 360) angle -= 360; glLoadIdentity(); glPushMatrix(); // glLoadIdentity(); glRotatef (angle, 0.0, 0.0, 1.0); glTranslatef (0.0, 1.2, 0.0); //glRotatef (angle, 0.0, 0.0, 1.0); glutSolidSphere (0.2, 20, 16); //glLightfv (GL_LIGHT0, GL_POSITION, light_position); glPopMatrix(); glutSwapBuffers(); } void reshape (int w, int h){ glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-1.5, 1.5, -1.5 * (GLfloat)h / (GLfloat)w, 1.5 * (GLfloat)h / (GLfloat)w, -10.0, 10.0); else glOrtho (-1.5 * (GLfloat)w / (GLfloat)h, 1.5 * (GLfloat)w / (GLfloat)h, -1.5, 1.5, -10.0, 10.0); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); } void mouse (int button, int state, int x, int y){ glutPostRedisplay(); } int main (int args, char** argv){ glutInit (&args, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init(); glutDisplayFunc (display); glutReshapeFunc (reshape); glutMouseFunc (mouse); glutMainLoop(); return 0; }

Share this post


Link to post
Share on other sites
Advertisement
I got it to work using glutIdleFunc (display) but I know I shouldn''t have to do this, because I''ve never had to tell glut to display before. What am I missing?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!