HowToC:OpenGLCB

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 23:44, 13 December 2007
Dbarnes (Talk | contribs)

← Previous diff
Current revision
Dbarnes (Talk | contribs)
(How to use an OpenGL callback function)
Line 1: Line 1:
==How to use an OpenGL callback function== ==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:+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!
 + 
 +<code><pre>
 +// 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();
 +}
 +</pre></code>

Current revision

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