| GLUT | CAVElib |
|---|---|
#include <unistd.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <dms/dms.h>
void drawEverything(void);
void key(unsigned char k, int x, int y);
void idle(void);
float height=0;
GLUquadric * quadric;
int main(int argc, char *argv[])
{
/* Initialize, & open the window */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB |
GLUT_DOUBLE |
GLUT_DEPTH);
glutCreateWindow("example");
/* Set callback functions */
glutDisplayFunc(drawEverything);
glutKeyboardFunc(key);
glutIdleFunc(idle);
/* Create the quadric object */
quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_LINE);
/* Start GLUT's event loop */
glutMainLoop();
return 0;
}
void drawEverything(void)
{
/* Clear the window */
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
/* Load the perspective projection */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 1.0, 10.0);
glMatrixMode(GL_MODELVIEW);
/* Set up a view transformation */
glLoadIdentity();
glTranslatef(0.0, 0.0, -6.0);
/* Draw the bouncing ball */
glColor3f(1.0, 0.9, 0.0);
glTranslatef(0.0, height, 0.0);
glutWireSphere(1.0, 16, 16);
/* Display the result */
glutSwapBuffers();
}
void idle(void)
{
/* Update the bouncing ball's data */
height = fabs(sin(dms::currentTime()))
* 4;
glutPostRedisplay();
}
void key(unsigned char k, int x, int y)
{
/* Quit the program when Escape is hit */
if (k == 27)
exit(0);
}
|
#include <unistd.h>
#include <math.h>
#include <cave_ogl.h>
#include <GL/gl.h>
#include <dms/dms.h>
void drawEverything(void);
void initGraphics(void);
void updateData(void);
float height=0;
GLUquadric * quadric;
int main(int argc, char *argv[])
{
/* Initialize, & open the window */
CAVEConfigure(&argc,argv,NULL);
CAVEInit();
/* Set callback functions */
CAVEInitApplication(initGraphics, 0);
CAVEFrameFunction(updateData, 0);
CAVEDisplay(drawEverything, 0);
/* Loop until Escape is hit */
while (!CAVEgetbutton(CAVE_ESCKEY))
usleep(10000);
CAVEExit();
}
void initGraphics(void)
{
/* Create the quadric object */
quadric = gluNewQuadric();
gluQuadricDrawStyle(quadric, GLU_LINE);
}
void drawEverything(void)
{
/* Clear the window */
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
/* Draw the bouncing ball */
glColor3f(1.0, 0.9, 0.0);
glTranslatef(0.0, height, 0.0);
gluSphere(quadric, 1.0, 24, 16);
}
void updateData(void)
{
/* Update the bouncing ball's data */
height = fabs(sin(dms::currentTime()))
* 4;
}
|
The only GLUT functions that can be used in a CAVElib program are the font rendering (glutBitmapCharacter(), etc) and object rendering (glutSolidSphere(), etc) functions.
In a "serious" CAVE application, the calculations (updateData()) are run in the main process, not the graphics process. This requires using shared memory (which adds complications), and is not vital in our applications.