int main(int argc, char* argv[]) { char buffer[2048]; /* string buffer for self-control list */ signal(SIGINT, SIG_IGN); vrConfigure(&argc, argv, NULL); vrStart(); signal(SIGINT, exit_application); /* TODO: it would be nice to put these above vrStart(), since */ /* it will block until all input devices are open, and this */ /* way we could be rendering something while waiting. */ /* TODO: actually, we almost *need* to have the init_gfx stuff*/ /* set before vrStart, so the window opening function will */ /* have something to call (other than vrDoNothing()). */ /* In fact, I have no idea how init_gfx() gets called at */ /* all given the current setup. */ vrFunctionSetCallback(VRFUNC_ALL_DISPLAY_INIT, vrCallbackCreate(init_gfx, 0)); vrFunctionSetCallback(VRFUNC_ALL_DISPLAY, vrCallbackCreate(draw_server_world, 0)); vrFunctionSetCallback(VRFUNC_HANDLE_USR2, vrCallbackCreate(vrDbgInfo, 0)); if (vrContext->input->num_input_devices > 0) { vrDbgPrintfN(SELDOM_DBGLVL+1, "input viewer: input device[0] version = '%s'\n", vrContext->input->input_devices[0]->version); } else { vrDbgPrintfN(SELDOM_DBGLVL+1, "input viewer: No input devices defined.\n"); } vrSystemSetName("inputs -- FreeVR inputs display application"); vrSystemSetAuthors("Bill Sherman"); list_self_controls(buffer, vrContext->input, sizeof(buffer), verbose); vrPrintf(buffer); vrSystemSetExtraInfo(buffer); vrDbgPrintf("input viewer: looping\n"); while(vrFrame()) { update_world(); } exit_application(); exit(0); }
void vrlib_shmem_init (size_t size) { vrShmemInit (size); vrConfigure (NULL, NULL, NULL); return; }
int VMDinitialize(int *argc, char ***argv) { int i; #if defined VMDMPI // hack to fix up env vars if necessary for (i=0; i<(*argc); i++) { if(!strupcmp((*argv)[i], "-vmddir")) { if((*argc) > (i + 1)) { setenv("VMDDIR", (*argv)[++i], 1); } else { msgErr << "-vmddir must specify a fully qualified path." << sendmsg; } } } vmd_mpi_init(argc, argv); // initialize MPI, fix up env vars, etc. #endif #if defined(_MSC_VER) && !defined(VMDSEPARATESTARTUP) win32vmdstart(); // get registry info etc #endif #if !defined(VMDNOMACBUNDLE) && defined(__APPLE__) macosxvmdstart(*argc, *argv); // get env variables etc #endif // Tell Tcl where the executable is located const char *argv0 = vmd_initialize_tcl((*argv)[0]); #ifdef VMDTCL // register signal handler tclhandler = Tcl_AsyncCreate(VMDTclAsyncProc, (ClientData)NULL); signal(SIGINT, (sighandler_t) VMDTclSigHandler); #endif // Let people know who we are. VMDtitle(); // Tell the user what we think about the hardware we're running on. // If VMD is compiled for MPI, then we don't print any of the normal // standalone startup messages and instead we use the special MPI-specific // node scan startup messages only. #if !defined(VMDMPI) #if defined(VMDTHREADS) int vmdnumcpus = wkf_thread_numprocessors(); msgInfo << "Multithreading available, " << vmdnumcpus << ((vmdnumcpus > 1) ? " CPUs" : " CPU") << " detected." << sendmsg; #endif long vmdcorefree = vmd_get_avail_physmem_mb(); if (vmdcorefree >= 0) { long vmdcorepcnt = vmd_get_avail_physmem_percent(); msgInfo << "Free system memory: " << vmdcorefree << "MB (" << vmdcorepcnt << "%)" << sendmsg; } #endif // Read environment variables and command line options. // Initialize customArgv with just argv0 to avoid problems with // Tcl extension. customArgv.append((char *)argv0); VMDGetOptions(*argc, *argv); #if (!defined(__APPLE__) && !defined(_MSC_VER)) && (defined(VMDOPENGL) || defined(VMDFLTK)) // If we're using X-windows, we autodetect if the DISPLAY environment // variable is unset, and automatically switch back to text mode without // requiring the user to pass the "-dispdev text" command line parameters if ((which_display == DISPLAY_WIN) && (getenv("DISPLAY") == NULL)) { which_display = DISPLAY_TEXT; } #endif #if defined(VMDTKCON) vmdcon_init(); msgInfo << "Using VMD Console redirection interface." << sendmsg; // we default to a widget mode console, unless text mode is requested. // we don't have an tcl interpreter registered yet, so it is set to NULL. // flushing pending messages to the screen, is only in text mode possible. if ((which_display == DISPLAY_TEXT) || just_print_help) { vmdcon_use_text(NULL); vmdcon_purge(); } else { vmdcon_use_widget(NULL); } #endif #ifdef VMDFLTK // Do various special FLTK initialization stuff here if ((which_display != DISPLAY_TEXT)) { // Cause FLTK to to use 24-bit color for all windows if possible // This must be done before any FLTK windows are shown for the first time. if (!Fl::visual(FL_DOUBLE | FL_RGB8)) { if (!Fl::visual(FL_RGB8)) { Fl::visual(FL_RGB); } } // Disable the use of the arrow keys for navigating buttons and other // non-text widgets, we'll try it out and see how it pans out Fl::visible_focus(0); // Disable Drag 'n Drop since the only text field in VMD is the // atomselection input and DND severely gets in the way there. Fl::dnd_text_ops(0); } #endif // Quit now if the user just wanted a list of command line options. if (just_print_help) { vmd_sleep(10); // This is here so that the user can see the message // before the terminal/shell exits... return 0; } // Set up default allocators; these may be overridden by cave or freevr. vmd_alloc = malloc; // system malloc() in the default case vmd_dealloc = free; // system free() in the default case vmd_realloc = realloc; // system realloc(), set to NULL when not available // check for a CAVE display if (DISPLAY_USES_CAVE(which_display)) { #ifdef VMDCAVE // allocate shared memory pool used to communicate with child renderers int megs = 2048; if (getenv("VMDCAVEMEM") != NULL) { megs = atoi(getenv("VMDCAVEMEM")); } msgInfo << "Attempting to get " << megs << "MB of CAVE Shared Memory" << sendmsg; grab_CAVE_memory(megs); CAVEConfigure(argc, *argv, NULL); // configure cave walls and memory use // point VMD shared memory allocators to CAVE routines vmd_alloc = malloc_from_CAVE_memory; vmd_dealloc = free_to_CAVE_memory; vmd_realloc = NULL; // no realloc() functionality is available presently #else msgErr << "Not compiled with the CAVE options set." << sendmsg; which_display = DISPLAY_WIN; #endif } // check for a FreeVR display if (DISPLAY_USES_FREEVR(which_display)) { #ifdef VMDFREEVR int megs = 2048; if (getenv("VMDFREEVRMEM") != NULL) { megs = atoi(getenv("VMDFREEVRMEM")); } msgInfo << "Attempting to get " << megs << "MB of FreeVR Shared Memory" << sendmsg; grab_FreeVR_memory(megs); // have to do this *before* vrConfigure() if // we want more than the default shared mem. vrConfigure(NULL, NULL, NULL); // configure FreeVR walls // point shared memory allocators to FreeVR routines vmd_alloc = malloc_from_FreeVR_memory; vmd_dealloc = free_to_FreeVR_memory; vmd_realloc = NULL; // no realloc() functionality is available presently #else msgErr << "Not compiled with the FREEVR options set." << sendmsg; which_display = DISPLAY_WIN; #endif } // return custom argc/argv *argc = customArgv.num(); for (i=0; i<customArgv.num(); i++) { (*argv)[i] = customArgv[i]; } return 1; // successful startup }
int main(int argc, char* argv[]) { /* TODO: do I want to ignore interrupts for all of this? or */ /* just during vrStart()? */ //signal(SIGINT, SIG_IGN); vrShmemInit(30 * 1024 * 1024); vrConfigure(&argc, argv, NULL); /* TODO: it would be nice to put these above vrStart(), since */ /* it will block until all input devices are open, and this */ /* way we could be rendering something while waiting. */ /* TODO: actually, we almost *need* to have the init_gfx stuff*/ /* set before vrStart, so the window opening function will */ /* have something to call (other than vrDoNothing()). */ /* In fact, I have no idea how init_gfx() gets called at */ /* all given the current setup. */ /* [5/30/00: I have now moved the function setting routines to*/ /* come before vrStart(). The library needs to be changed */ /* such that the incoming callbacks are stored in a holding */ /* bin, until the render/input/whatever loop is ready to */ /* update them. */ #if 1 /* TODO: unfortunately this shorthand doesn't work when there are extra */ /* arguments but these work okay. */ vrCallbackSet(VRFUNC_DISPLAY_INIT, "init_gfx", init_gfx, 0); vrCallbackSet(VRFUNC_DISPLAY_FRAME, "gfx_frame", gfx_frame, 0); vrCallbackSet(VRFUNC_DISPLAY, "draw_world", draw_world, 0); vrCallbackSet(VRFUNC_DISPLAY_SIM, "my_sim", my_sim, 0); vrCallbackSet(VRFUNC_HANDLE_USR2, "travel:vrDbgInfo", vrDbgInfo, 0); #else # if 1 /* 1/4/2003: test of possible startup race condition */ vrSetFunc(VRFUNC_DISPLAY_INIT, vrCreateNamedCallback("init_gfx", init_gfx, 0)); # endif vrSetFunc(VRFUNC_DISPLAY, vrCreateNamedCallback("draw_world", draw_world, 0)); # ifdef PERSONAL_SIMULATOR vrSetFunc(VRFUNC_DISPLAY_SIM, vrCreateNamedCallback("my_sim", my_sim, 0)); # endif vrSetFunc(VRFUNC_HANDLE_USR2, vrCreateNamedCallback("travel:vrDbgInfo", vrDbgInfo, 0)); #endif vrStart(); signal(SIGINT, exit_application); if (vrContext->input->num_input_devices > 0) { vrDbgPrintfN(SELDOM_DBGLVL+1, "TRAVEL: input device[0] version = '%s'\n", vrContext->input->input_devices[0]->version); } else { vrDbgPrintfN(SELDOM_DBGLVL+1, "TRAVEL: No input devices defined.\n"); } #if 0 if (vrDbgDo(AALWAYS_DBGLVL+1)) { vrFprintContext(stdout, vrContext, verbose); vrFprintConfig(stdout, vrContext->config, verbose); vrFprintInput(stdout, vrContext->input, verbose); } #endif if(vrContext->input->num_input_devices > 0) vrDbgPrintf("TRAVEL: input device[0] version = '%s'\n", vrContext->input->input_devices[0]->version); #if 0 /* NOTE: this isn't really necessary, so don't use for non-test applications */ update_world(); vrInputWaitForAllInputDevicesToBeOpen(); #endif vrSystemSetName("travel -- FreeVR test program"); vrSystemSetAuthors("Bill Sherman"); vrSystemSetExtraInfo("A really good program for testing the FreeVR library"); vrSystemSetStatusDescription("Application running fine"); vrInputSet2switchDescription(0, "Terminate the application"); vrInputSet2switchDescription(1, "Reset User Travel"); vrInputSet2switchDescription(2, "Move User 0.1 to the right"); vrInputSet2switchDescription(3, "Move User 0.1 to the left"); vrInputSetValuatorDescription(0, "Rotate User"); vrInputSetValuatorDescription(1, "Move User in direction of Wand"); #if 0 /* for testing */ vrInputSetNswitchDescription(0, "Do something with a switch"); vrInputSetNsensorDescription(0, "Do something with an N-sensor"); vrInputSet6sensorDescription(0, "Move the Head"); vrInputSet6sensorDescription(1, "Move the Wand"); #endif vrDbgPrintf("TRAVEL: looping\n"); #if 1 while(vrFrame()) { update_world(); } #else /* run for two frames and then quit */ vrFrame(); update_world(); vrFrame(); update_world(); #endif vrPrintf(BOLD_TEXT "TRAVEL: I guess we're all done now.\n" NORM_TEXT); exit_application(); exit(0); }