This final section is the heart of the porting discussion. We present some source code as a means to illustrate how GLUT concepts map to VR Juggler.
1 void main(int argc, char* argv[])
{
/* initialize the application data here */
OnApplicationInit();
5
/* create a window to render graphics in
* In VR Juggler, window creation is done for you based on your configuration file
* settings.
*/
10 glutInitWindowSize( 640, 480 );
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
glutCreateWindow( "GLUT application" );
15 /* display callbacks.
* NOTE: the first time OnIdle is called is when you should
* initialize the display context for each window
* (doing this is analogous to VR Juggler's
* vrj::GlApp::contextInit() function)
20 */
glutReshapeFunc( OnReshape );
glutIdleFunc( OnIdle );
glutDisplayFunc( OnIdle );
25 /* tell glut to not call the keyboard callback repeatedly
* when holding down a key. (uses edge triggering, like the mouse does)
*/
glutIgnoreKeyRepeat( 1 );
30 /* keyboard callback functions. */
glutKeyboardFunc( OnKeyboardDown );
glutKeyboardUpFunc( OnKeyboardUp );
glutSpecialFunc( OnSpecialKeyboardDown );
glutSpecialUpFunc( OnSpecialKeyboardUp );
35
/* mouse callback functions... */
glutMouseFunc( OnMouseClick );
glutMotionFunc( OnMousePos );
glutPassiveMotionFunc( OnMousePos );
40
/* start the application loop, your callbacks will now be called
* time for glut to sit and spin. In Juggler this is the same as the while(1)
* (see below)
*/
45 glutMainLoop();
} 1 class MyApplication : public vrj::GlApp
{
public:
// Data callbacks (Do not put OpenGL code here)
5 virtual void init();
virtual void preFrame();
virtual void intraFrame();
virtual void postFrame();
10 // OpenGL callbacks (put only OpenGL code here)
virtual void contextInit();
virtual void draw();
};
15 int main(int argc, char* argv[])
{
// configure kernel with *.config files
vrj::Kernel* kernel = vrj::Kernel::instance(); // Get the kernel
for(int i=1; i<argc; i++)
20 {
// loading config file passed on command line...
kernel->loadConfigFile(argv[i]);
}
25 // start the kernel
kernel->start();
// set the application for the kernel to run
MyApplication* application = new MyApplication();
30 kernel->setApplication(application);
// Block until the kernel exits.
kernel->waitForKernelStop();
35 return 0;
}