HowToC:OpenGLCB

From S2PLOT

Revision as of 23:47, 13 December 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

How to use an OpenGL callback function

S2PLOT allows you to register a function which is called every refresh cycle, after most other geometry has been drawn, but before the screen buffers are swapped. You can use this function to call explicit OpenGL functions if you like. This is an advanced feature, but very easy to use. Here's an example of an OpenGL callback function that draws a plane. The use of the glPushAttrib and glPopAttrib functions is very important!

// define an S2PLOT OpenGL callback function */
void openglcb(void) {
  // store the state
  glPushAttrib(GL_ALL_ATTRIB_BITS);

  // turn on blending
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

  // draw a transparent orange quad
  glBegin(GL_QUADS);
  glColor4f(0.8, 0.3, 0.0, 0.5);
  glVertex3f(-3., -3., -3.);
  glVertex3f(-3.,  3., -3.);
  glVertex3f( 3.,  3., -3.);
  glVertex3f( 3., -3., -3.);
  glEnd();

  // restore the state
  glPopAttrib();
}
Personal tools