Function:cs2socb
From S2PLOT
cs2socb
Register function that will draw direct OpenGL graphics when called.
Prototype
void cs2socb(void *oglfn);
Description
Register function that will draw direct OpenGL graphics when called. This is a highly advanced capability of s2plot that is open to many potential pitfalls. Only experienced OpenGL programmers should attempt to use it! Use NULL argument to disable this callback. The coordinate system for drawing geometry in this function is the viewport one. The OpenGL callback must be of the form:
void oglfn(void).
See Also
cs2scb | Set the callback function; can be null to cancel callback. |
cs2sncb | Set the function to call when number-keys pressed. |
cs2shcb | Set the handle callback function for when a handle is (de)selected |
Code Example
/* This function should only be used by experienced OpenGL programmers */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "s2plot.h"
#include "s2opengl.h"
#include "s2glut.h"
void openglcb(void);
int main(int argc, char *argv[])
{
float x[10], y[10], z[10]; /* Arrays of coordinate points */
int N = 10; /* Number of points */
int i; /* Loop variable */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
for (i=0;i<N;i++) {
x[i] = drand48()*2.0 - 1.0; /* Random (x,y,z) coordinates */
y[i] = drand48()*2.0 - 1.0;
z[i] = drand48()*2.0 - 1.0;
}
s2sci(S2_PG_YELLOW); /* Set colour */
s2slw(4); /* Set line width */
s2line(N, x, y, z); /* Draw the poly-line */
cs2socb(openglcb); /* Register an OpenGL callback */
s2show(1); /* Open the s2plot window */
return 1;
}
/* an opengl callback */
void openglcb(void) {
static float phase = 0.;
float vx = 2. + 0.5 * sin(phase * M_PI * 2.);
glBegin(GL_QUADS);
glColor3f(0.8, vx * 0.25, 0.0);
glVertex3f(-vx, -vx, -2.);
glVertex3f(-vx, vx, -2.);
glVertex3f( vx, vx, -2.);
glVertex3f( vx, -vx, -2.);
glEnd();
phase = phase + 0.001;
while (phase > 1.) {
phase -= 1.;
}
}
Back to S2PLOT function list.