CAVEのサンプル
CAVEに入っていたサンプルプログラムを追記に書き込みました。
これは赤い球を表示するだけなので単純ですが、他のサンプルも単純です。つまり、CAVEに関する処理にはほとんど気を使わずに、OpenGLのコードに集中できます。現在はこれらのサンプルを元に前回作った星のプログラムを作り、環境の簡単な負荷テストをしようと考えています。
#include
#include
void init_gl(void);
void draw(void);
GLUquadricObj *sphereObj;
int main(int argc,char **argv) {
/* Initialize the CAVE */
CAVEConfigure(&argc,argv,NULL);
/* Give the library a pointer to the GL initialization function */
CAVEInitApplication(init_gl,0);
/* Give the library a pointer to the drawing function */
CAVEDisplay(draw,0);
/* Create the multiple processes/threads and start the display loop */
CAVEInit();
/* Wait for the escape key to be hit */
while (!CAVEgetbutton(CAVE_ESCKEY)) {
/* Nap so that this busy loop doesn't waste CPU time reset timeval struct every time for linux compatibility */
CAVEUSleep(10);
}
/* Clean up & exit */
CAVEExit();
return 0;
}
void init_gl(void) {
float redMaterial[] = { 1, 0, 0, 1 };
/* Enable light source 0 */
glEnable(GL_LIGHT0);
/* Set material to color both front and back face to a diffuse red */
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, redMaterial);
/* Create a glu quadric object */
sphereObj = gluNewQuadric();
}
void draw(void) {
/* Set clear color to black and clear both the screen and the zbuffer */
glClearColor(0., 0., 0., 0.);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
/* Turn lighting on */
glEnable(GL_LIGHTING);
/* Draw a sphere */
glPushMatrix();
glTranslatef(0.0, 4.0, -4.0);
/* Draw a sphere using GLU quadric object. Radius = 1, Slices = 8. Stacks = 8 */
gluSphere(sphereObj, 1.0, 8, 8);
glPopMatrix();
/* Turn lighting off */
glDisable(GL_LIGHTING);
}
