> On 02/06/12 13:59, Shon Pritchett wrote:
> > Hello Everyone,
> >
> > I am using a GlWindow to display some images off disk in sequential order.  
> > I'm having some trouble getting the GlWindow to refresh in a timely fashion.
> >
> > I am using the add_timeout function to register my opengl setup code and 
> > then I'm using the repeat_timeout function to update the screen at a fixed 
> > interval the intention being every 1/60th of a second. In the update 
> > function I'm only displaying a QUAD with a texture on it and then swapping 
> > that texture out at every fixed tick.
> >
> > Is there some way to force the window to update faster?
>
>       Probably an issue for the fltk.opengl group.
>       Are you saying the add_timeout() function is triggering /slower/ than 
> 60fps?
>
>       Maybe try adding some code to detect your actual FPS rate.
>
>       What does your timer function do to retrigger drawing?
>       Is it just calling redraw(), or something else?
>
>       Do you suspect FLTK is slowing it down, or perhaps something
>       else such as opengl's buffer swapping is slowing it down?
>       Have you enabled double buffering, etc?
>
>       I suggest moving this thread -> fltk.opengl, as likely
>       this will get into the specifics of opengl programming
>       that will be noise to most folks on fltk.general.
>
>       When you open a new thread there, I suggest posting
>       a simple single file /compilable/ example that does
>       as you describe, and include code that shows the FPS rate
>       and tell us what your FPS rate is.
>
>       Perhaps the issue is something specific with your platform
>       hardware (graphics/monitor combo) or software (X windows, opengl
>       drivers, etc), or it might be a usage issue; we can't tell until
>       we see code.
>
>       Certainly opengl should be able to go really fast.


My apologies for using the general forum if this should be in the opengl forum. 
 I'm hoping whatever I'm doing wrong isn't specific to opengl but I could be 
wrong.

My problem isn't so much FPS but whether calling redraw is enough to refresh 
the screen. I can live with a much lower FPS otherwise.

The add_timeout function is triggering only once if my GlWindow is invalid.  If 
so, when I can add_time, I make the window valid again and call the 
repeat_timeout function.  The repeat_timeout function is not triggering at 
60FPS as best I can discern.

Here is the function called during "add_timeout"

boost::any OpenGlInterface::opengl_setup( boost::any instance_ptr )
{
  OpenGlInterface *pInstance(boost::any_cast<OpenGlInterface*>(instance_ptr));

  glGetIntegerv(GL_MAX_TEXTURE_SIZE,&pInstance->m_max_texture_size);

  glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
  glEnable(GL_LIGHTING);
  glEnable(GL_TEXTURE_2D);
  glShadeModel(GL_FLAT);
  glPixelStoref(GL_UNPACK_ALIGNMENT,1);

  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glClear(GL_DEPTH_BUFFER_BIT);

  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glClearColor(1,0,1,0);
  glClearStencil(0);
  glClearDepth(1.0f);

  // set up light colors (ambient, diffuse, specular)
  GLfloat ambientLightComponent[] = {1.0f,1.0f,1.0f,1.0f};
  GLfloat diffuseLightComponent[] = {.8f,.8f,.8f,1.0f};
  GLfloat specularLightComponent[] ={1.0f,1.0f,1.0f,1.0f};
  glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLightComponent);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLightComponent);
  glLightfv(GL_LIGHT0,GL_SPECULAR,specularLightComponent);

  // position the light
  float lightPosition[4] = {0,0,0,1};
  glLightfv(GL_LIGHT0,GL_POSITION,lightPosition);

  glEnable(GL_LIGHT0);

  // Setup the view volume
  (GL_PROJECTION);
  glLoadIdentity();

  OglDisplayWindow *glwin(0);
  pInstance->m_pVST->Get_Glwin_capture_feed(glwin);
  glOrtho(
    -glwin->x()/2,  //  left of origin
    glwin->x()/2,   //  right of origin
    glwin->y()/2,   //  above of origin
    -glwin->y()/2,  //  below of origin
    -1,             //  near clipping plane
    1);             //  far clipping plane

  // position the camera in the view volume
  (GL_MODELVIEW);
  glLoadIdentity();

  gluLookAt(
    // camera position
    0,
    0,
    1.2,
    // look at point
    0,
    0,
    0,
    // up vector
    0,
    1,
    0);

  if (GlErrorChecker::CheckGlErrorState(std::cerr))
  {
    return boost::any();
  }//end if

  glwin->redraw();

  return boost::any();
}//end function


Here is the function called during "repeat_timeout"

boost::any OpenGlInterface::opengl_update( boost::any pgl_instance )
{
  OpenGlInterface *pInstance(boost::any_cast<OpenGlInterface*>(pgl_instance));

  static unsigned int texture_ID(0);

  if (!pInstance->m_img_info.empty())
  {
    //load_images(image_list->front(),texture_ID);
    //texture_ID = pInstance->m_img_info.front();

    create_texture(pInstance->m_img_info.front(),texture_ID);

    pInstance->m_img_info.pop_front();
  }//end if

  //  the created texture should be bound but making sure won't hurt.
  glBindTexture(
    GL_TEXTURE_2D,
    texture_ID);

  /************************************************************************/
  /* Now that we have the image data we can begin drawing it to screen    */
  /************************************************************************/

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  /************************************************************************/
  /* Draw a full screen QUAD that will be painted with the opengl texture */
  /* that we are still bound to.                                          */
  /*                                                                      */
  /* A QUAD in opengl lingo is a typically two triangle polygons which    */
  /* share vertexes such that they form an object with 4 outer sides.     */
  /************************************************************************/


  //  finally move the object
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  //  clip the object view space first
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glBegin(GL_QUADS);
  glTexCoord2f(0.0,0.0);glVertex3i(-1,-1,-1);
  glTexCoord2f(0.0,1.0);glVertex3i(1,-1,-1);
  glTexCoord2f(1.0,1.0);glVertex3i(1,1,-1);
  glTexCoord2f(1.0,0.0);glVertex3i(-1,1,-1);
  glEnd();
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();

  if (GlErrorChecker::CheckGlErrorState(std::cerr))
  {
    // An error occurred generating the Opengl texture.
    glDeleteTextures(1,&texture_ID);
    texture_ID = 0;
  }//end if

  return boost::any();
}//end function

I'm only calling redraw.
My GlWindow is embedded within a doublebuffered window but I have not 
explicitly enabled double bufferring in the GlWindow.
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to