Thread: OpenGL screen still flashes with double buffer

  1. #1
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79

    OpenGL screen still flashes with double buffer

    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??
    Nothing to see here, move along...

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    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).
    Nothing to see here, move along...

  4. #4
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    This is the drawing code:

    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();
      
    }
    And this is in the main:

    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 ();
    Nothing to see here, move along...

  5. #5
    Astrophysics student Ayreon's Avatar
    Join Date
    Mar 2009
    Location
    Netherlands
    Posts
    79
    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.
    Nothing to see here, move along...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Largest screen buffer size?
    By Ash1981 in forum C Programming
    Replies: 2
    Last Post: 01-30-2006, 04:31 AM

Tags for this Thread