/*-------------------------------------------------------------------------- * Function: SbInit() * * Description: * This function initializes the Spaceball and opens ball for use. * * * Args: None * * * Return Value: * int res result of SiOpen, =0 if Fail =1 if it Works * *--------------------------------------------------------------------------*/ int SbInit() { int res; /* result of SiOpen, to be returned */ SiOpenData oData; /* OS Independent data to open ball */ /*init the SpaceWare input library */ if (SiInitialize() == SPW_DLL_LOAD_ERROR) { MessageBox(hWndMain,"Error: Could not load SiAppDll dll files", NULL, MB_ICONEXCLAMATION); } SiOpenWinInit (&oData, hWndMain); /* init Win. platform specific data */ SiSetUiMode(devHdl, SI_UI_ALL_CONTROLS); /* Config SoftButton Win Display */ /* open data, which will check for device type and return the device handle to be used by this function */ if ( (devHdl = SiOpen ("sbtest32", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData)) == NULL) { SiTerminate(); /* called to shut down the SpaceWare input library */ res = 0; /* could not open device */ return res; } else { res = 1; /* opened device succesfully */ return res; } }
void SiTerminate(void) { /* It is unlikely that the function table will not have been loaded by the time this is called, but we'll cover the bases anyhow */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */ return; } /* if we weren't returning void, we'd do error handling here */ } pfnSiTerminate(); SpwErrorVal = *pDllSpwRetVal; /* Unload the DLL to prevent memory leaks */ FreeLibrary(ghDll); /* change status in case someone reinitializes */ gInitStatus = NOT_LOADED; }
/* check if can open a handle to the spaceball, load the driver functions and start receiving input from the spaceball */ int SPW_CheckForSpaceballWin32(void * win) { char classname[25]; SiOpenData oData; if (Spw_DeviceHandle == SI_NO_HANDLE) { if (SiInitialize() != SPW_DLL_LOAD_ERROR) { GetClassName((HWND)win, classname, sizeof(classname)); SiOpenWinInit(&oData, (HWND)win); Spw_DeviceHandle = SiOpen(classname, SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData); if (Spw_DeviceHandle != SI_NO_HANDLE) { SiSetUiMode(Spw_DeviceHandle, SI_UI_ALL_CONTROLS); return TRUE; } else { SiTerminate(); return FALSE; } } else return FALSE; } else return TRUE; }
void InitializeSpaceball(SPW_WINPARAM dpy, SPW_WINDOW win, SiSpwHandlers *DspHandlers, SpaceballControlStruct *scs) { #ifdef OS_WIN32 SiOpenData oData; if (SiInitialize() == SPW_DLL_LOAD_ERROR) { MessageBox(NULL,"Error: Could not load SiAppDll dll files", NULL, MB_ICONEXCLAMATION); } SiOpenWinInit (&oData, win); if (!(scs->devHdl = SiOpen ("Widget World", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData))) { SiTerminate(); MessageBox( win, "Sorry - No supported Spacetec IMC device available.\n", NULL, MB_OK ); if (win) DestroyWindow(win); ExitProcess(1); } SiSetUiMode(scs->devHdl, SI_UI_ALL_CONTROLS); #else /* X11 */ if (!SPW_InputCheckForSpaceball(dpy, win, "Widget World")) { printf ("Sorry - No Spaceball found.\n"); exit(0); } #endif DspHandlers->button.func = SbButtonEvent; DspHandlers->motion.func = SbMotionEvent; DspHandlers->zero.func = SbMotionEvent; DspHandlers->exception.func = NULL; DspHandlers->button.data = (void *)(scs); DspHandlers->motion.data = (void *)(scs); DspHandlers->zero.data = (void *)(scs); DspHandlers->exception.data = NULL; #ifndef OS_WIN32 spw_dispatch->display = dpy; spw_dispatch->spwbw = NULL; #endif } /* end of InitializeSpaceball */
char * SpwErrorString (enum SpwRetVal val) { if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return NULL; } } return (char *) pfnSpwErrorString(val); }
enum SpwRetVal SiSetTypeMask (SiTypeMask *pTMask, int type1, ...) { if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } /* stub function -> return a happy value */ return SPW_NO_ERROR; }
void SiGetEventWinInit (SiGetEventData *pData, UINT msg, WPARAM wParam, LPARAM lParam) { if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return; } } pfnSiGetEventWinInit(pData, msg, wParam, lParam); SpwErrorVal = *pDllSpwRetVal; }
void SiOpenWinInit (SiOpenData *pData, HWND hWnd) { if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { pData = NULL; hWnd = NULL; return; } } pfnSiOpenWinInit(pData, hWnd); SpwErrorVal = *pDllSpwRetVal; }
void SiGetLibraryInfo (SiVerInfo *pInfo) { if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { pInfo = NULL; return; } } pfnSiGetLibraryInfo(pInfo); SpwErrorVal = *pDllSpwRetVal; }
enum SpwRetVal SiRezero (SiHdl hdl) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiRezero(hdl); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
enum SpwRetVal SiGetDeviceInfo (SiHdl hdl, SiDevInfo *pInfo) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiGetDeviceInfo(hdl, pInfo); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
enum SpwRetVal SiGetDevicePort (SiDevID devID, SiDevPort *pPort) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiGetDevicePort(devID, pPort); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
enum SpwRetVal SiSetUiMode (SiHdl hdl, SPWuint32 mode) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiSetUiMode(hdl, mode); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
SPWbool SiIsSpaceWareEvent(SiGetEventData *pData, SiHdl *pHdl) { SPWbool tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_FALSE; } } tmpRetVal = pfnSiIsSpaceWareEvent(pData, pHdl); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
enum SpwRetVal SiGrabDevice (SiHdl hdl, SPWbool exclusive) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiGrabDevice(hdl, exclusive); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
int SiDispatch (SiHdl hdl, SiGetEventData *pData, SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers) { int tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return 0; } } tmpRetVal = pfnSiDispatch(hdl, pData, pEvent, pDHandlers); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
int SiButtonReleased (SiSpwEvent *pEvent) { int tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { SpwErrorVal = SPW_DLL_LOAD_ERROR; return SI_NO_BUTTON; } } tmpRetVal = pfnSiButtonReleased(pEvent); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
int SiGetNumDevices (void) { int tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */ return -1; } } tmpRetVal = pfnSiGetNumDevices(); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
SiDevID SiDeviceIndex (int idx) { SiDevID tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */ return SI_NO_DEVICE; } } tmpRetVal = pfnSiDeviceIndex(idx); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
enum SpwRetVal SiGetEvent (SiHdl hdl, int flags, SiGetEventData *pData, SiSpwEvent *pEvent) { enum SpwRetVal tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { return SPW_DLL_LOAD_ERROR; } } tmpRetVal = pfnSiGetEvent(hdl, flags, pData, pEvent); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
SiHdl SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode, SiOpenData *pData) { SiHdl tmpRetVal; /* temporary return value */ if (gInitStatus != LOADED) { SiInitialize(); if (gInitStatus == FAILED) { SpwErrorVal = SPW_DLL_LOAD_ERROR; return NULL; } } tmpRetVal = pfnSiOpen(pAppName, devID, pTMask, mode, pData); SpwErrorVal = *pDllSpwRetVal; return tmpRetVal; }
// SpaceBall_Create(): LWInstance SpaceBall_Create( void *data, void *context, LWError *error ) { // Check for LWSN; if so, exit now unsigned long sysid = ( unsigned long )global( LWSYSTEMID_GLOBAL, GFUSE_TRANSIENT ); if( (sysid & LWSYS_TYPEBITS) != LWSYS_LAYOUT ) return &instance_count; if( instance_count > 0 ) { *error = "SpaceBall Error: Only one instance of the driver can be activate at a time"; return NULL; } instance_count++; // Get some globals command = (LWCommandFunc *)global( "LW Command Interface", GFUSE_ACQUIRE ); instance_update = (LWInstUpdate *)global( LWINSTUPDATE_GLOBAL, GFUSE_ACQUIRE ); hdi = (HostDisplayInfo *)global( LWHOSTDISPLAYINFO_GLOBAL, GFUSE_ACQUIRE ); message = (LWMessageFuncs *)global( LWMESSAGEFUNCS_GLOBAL, GFUSE_ACQUIRE ); // Hijack Layout's window function orig_window_proc = (WNDPROC)SetWindowLong( hdi->window, GWL_WNDPROC, (long)SpaceBallWindowProc ); // Load Settings LoadSettings(); // Initialize the SpaceBall drivers SiInitialize(); SiOpenWinInit (&oData, hdi->window); SiSetUiMode(hdl, (open_config_on_startup ? SI_UI_ALL_CONTROLS : SI_UI_NO_CONTROLS ) ); hdl = SiOpen ("Lightwave 3D (Layout)", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData); if( hdl == SI_NO_HANDLE) { SpaceBall_End(); *error = "SpaceBall Error: Couldn't open spaceball drivers"; return NULL; } error = NULL; return &instance_count; }
// Windows code to talk to Spaceball device static void vmd_setupwin32spaceball(wgldata *glwsrv) { SiOpenData oData; enum SpwRetVal res; // init the sball pointer to NULL by default, used to determine if we // had a healthy init later on. glwsrv->sball = NULL; switch (SiInitialize()) { case SPW_NO_ERROR: break; case SPW_DLL_LOAD_ERROR: msgInfo << "Spaceball driver not installed. Spaceball interface disabled." << sendmsg; return; default: msgInfo << "Spaceball did not initialize properly. Spaceball interface disabled." << sendmsg; return; } SiOpenWinInit(&oData, glwsrv->hWnd); // init win platform data SiSetUiMode(glwsrv->sball, SI_UI_ALL_CONTROLS); // config softbutton display // actually start a connection to the device now that the UI mode // and window system data are setup. glwsrv->sball = SiOpen("VMD", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData); if ((glwsrv->sball == NULL) || (glwsrv->sball == SI_NO_HANDLE)) { SiTerminate(); // shutdown spaceware input library msgInfo << "Spaceball is unresponsive. Spaceball interface disabled." << sendmsg; glwsrv->sball = NULL; // NULL out the handle for sure. return; } res = SiBeep(glwsrv->sball, "CcCc"); // beep the spaceball if ((glwsrv->sball != NULL) && (glwsrv->sball != SI_NO_HANDLE)) msgInfo << "Spaceball found, software interface initialized." << sendmsg; }
switch (siEvent.type) { case SI_MOTION_EVENT: emit sixDof( vec3(md[SI_TX], md[SI_TY], -md[SI_TZ]), vec3(md[SI_RX], md[SI_RY], md[SI_RZ])); break; default: break; } return true; } return false; } SpwRetVal result = SiInitialize(); int cnt = SiGetNumDevices(); SiDevID devId = SiDeviceIndex(0); SiOpenData siData; SiOpenWinInit(&siData, (HWND)riftRenderWidget.effectiveWinId()); si = SiOpen("app", devId, SI_NO_MASK, SI_EVENT, &siData); installNativeEventFilter(this); #endif /* yes: Loading shader from "c:/Users/bdavis/AppData/Local/Oculus Rift in Action/ShadertoyVR/shadertoy/Xlf3D8.json" Loading shader from "c:/Users/bdavis/AppData/Local/Oculus Rift in Action/ShadertoyVR/shadertoy/XsjXR1.json"
//----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { Instance = hInstance; InitCommonControls(); // A monospaced font FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0, FW_REGULAR, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); if(!FixedFont) FixedFont = (HFONT)GetStockObject(SYSTEM_FONT); // Create the root windows: one for control, with text, and one for // the graphics CreateMainWindows(); ThawWindowPos(TextWnd); ThawWindowPos(GraphicsWnd); ShowWindow(TextWnd, SW_SHOWNOACTIVATE); ShowWindow(GraphicsWnd, SW_SHOW); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc) InitHeaps(); // A filename may have been specified on the command line; if so, then // strip any quotation marks, and make it absolute. char file[MAX_PATH] = ""; if(strlen(lpCmdLine)+1 < MAX_PATH) { char *s = lpCmdLine; while(*s == ' ' || *s == '"') s++; strcpy(file, s); s = strrchr(file, '"'); if(s) *s = '\0'; } if(*file != '\0') { GetAbsoluteFilename(file); } #ifdef HAVE_SPACEWARE // Initialize the SpaceBall, if present. Test if the driver is running // first, to avoid a long timeout if it's not. HWND swdc = FindWindow("SpaceWare Driver Class", NULL); if(swdc != NULL) { SiOpenData sod; SiInitialize(); SiOpenWinInit(&sod, GraphicsWnd); SpaceNavigator = SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod); SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS); } #endif // Call in to the platform-independent code, and let them do their init SS.Init(); if(strcmp(file, "")) SS.OpenFile(file); // And now it's the message loop. All calls in to the rest of the code // will be from the wndprocs. MSG msg; DWORD ret; while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) { #ifdef HAVE_SPACEWARE // Is it a message from the six degree of freedom input device? if(ProcessSpaceNavigatorMsg(&msg)) goto done; #endif // A message from the keyboard, which should be processed as a keyboard // accelerator? if(msg.message == WM_KEYDOWN) { if(ProcessKeyDown(msg.wParam)) goto done; } if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) { // If the user presses the Alt key when the text window has focus, // then that should probably go to the graphics window instead. SetForegroundWindow(GraphicsWnd); } // None of the above; so just a normal message to process. TranslateMessage(&msg); DispatchMessage(&msg); done: SS.DoLater(); } #ifdef HAVE_SPACEWARE if(swdc != NULL) { if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator); SiTerminate(); } #endif // Write everything back to the registry FreezeWindowPos(TextWnd); FreezeWindowPos(GraphicsWnd); // Free the memory we've used; anything that remains is a leak. SK.Clear(); SS.Clear(); return 0; }