I'm trying to draw a moving object in an openGL window. The problem is that even without anything moving yet, the screen flashes like crazy and it uses my cpu for about 95%. I already used double buffering, what more can I do??
Printable View
I'm trying to draw a moving object in an openGL window. The problem is that even without anything moving yet, the screen flashes like crazy and it uses my cpu for about 95%. I already used double buffering, what more can I do??
Are you sure you're not clearing the on-screen buffer?
The only thing you should be doing with the on-screen buffer is copying to it when you've finished a paint cycle of the off-screen buffer.
Actually I'm not sure what I'm doing. I copied the buffer method from an example program. But the only thing different in my program is the stuff I draw (Just a couple of lines).
This is the drawing code:
And this is in the main:Code:void progDisplay (void)
{
/* Clear the redering window */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int i=0;
float x0,y0,x1,y1=0.0;
/* Draw a grid */
glColor3f (0.2, 0.2, 0.2);
for(i = 1; i < 60; i++) //vertical
{
drawLine (XMIN+i, YMAX, XMIN+i, YMIN);
}
for(i = 1; i < 40; i++) //horizontal
{
drawLine (XMIN, YMIN+i, XMAX, YMIN+i);
}
/* Pointless border. */
glColor3f (1.0, 1.0, 1.0);
drawLine (XMIN+2.0, YMIN+2.0, XMAX-2.0, YMIN+2.0);
drawLine (XMAX-2.0, YMIN+2.0, XMAX-2.0, YMAX-3.0);
drawLine (XMAX-2.0, YMAX-3.0, XMIN+2.0, YMAX-3.0);
drawLine (XMIN+2.0, YMAX-3.0, XMIN+2.0, YMIN+2.0);
/* Borders of the pinball machine. */
glColor3f (0.0, 0.0, 1.0);
drawLine (XMIN+3.0, YMIN+10.0, XMIN+3.0, YMAX-14.0); //Left Side (LS)
drawLine (XMIN+23.0, YMIN+10.0, XMIN+23.0, YMAX-14.0); //RS
drawLine (XMIN+3.0, YMIN+10.0, XMIN+9.0, YMIN+6.0); //BottemLeft (BL)
drawLine (XMIN+23.0, YMIN+10.0, XMIN+17.0, YMIN+6.0); //BottemLeft (BL)
drawCircle (13.0, 26.0, 10.0, 0.5); //Circled topshape (C)
/* Yellow text. */
glColor3f (1.0, 1.0, 0.0);
printText (XMIN+1.0, YMAX-2.0,
"Text.");
/* Flush the pipeline, and swap the buffers. */
glFlush ();
glutSwapBuffers();
/* Increase timestep */
t += 1;
printf("time : %d \n", t);
/* Request a re-draw for animation purposes */
glutPostRedisplay();
}
Code:
/* Initialization. */
glutInit (&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );//new
/* Initialization of the window. */
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (WINSIZE_X, WINSIZE_Y);
glutInitWindowPosition (WINPOS_X, WINPOS_Y);
/* Create the window. */
current_window = glutCreateWindow (FRAME_TITLE);
/* Initialize program. */
progInit ();
/* Stuff. */
//glutTimerFunc (0, progTimer, 0);
glutReshapeFunc (progReshape);
glutDisplayFunc (progDisplay);
//glutIdleFunc (progDisplay); /* not a clue what to do with this*/
glutKeyboardFunc (progKeyboard);
/* Event handling loop. */
glutMainLoop ();
Meanwhile I got around the flashing screen problem by going into 'game mode'. This mode puts it in full screen, and it works.
It has worked for quite some time by now, but i thought i'd let people know that this topic is resolved.