Example #1
0
/*--------------------------------------------------------------------------
 * 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;
    }
}
Example #2
0
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;
}
Example #3
0
/* 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;
}
Example #4
0
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 */
Example #5
0
char *
SpwErrorString (enum SpwRetVal val)
{

   if (gInitStatus != LOADED)
      {
      SiInitialize();
      if (gInitStatus == FAILED)
         {
         return NULL;
         }
      }

   return (char *) pfnSpwErrorString(val);
}
Example #6
0
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;
}
Example #7
0
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;
}
Example #8
0
void
SiOpenWinInit (SiOpenData *pData, HWND hWnd)
{
   if (gInitStatus != LOADED)
      {
      SiInitialize();
      if (gInitStatus == FAILED)
         {
         pData = NULL;
         hWnd = NULL;
         return;
         }
      }

   pfnSiOpenWinInit(pData, hWnd);
   SpwErrorVal = *pDllSpwRetVal;
}
Example #9
0
void
SiGetLibraryInfo (SiVerInfo *pInfo)
{
   if (gInitStatus != LOADED)
      {  
      SiInitialize();
      if (gInitStatus == FAILED)
         {
         pInfo = NULL;
         return;
         }

      }

   pfnSiGetLibraryInfo(pInfo);
   SpwErrorVal = *pDllSpwRetVal;
}
Example #10
0
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;
}
Example #11
0
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;
}
Example #12
0
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;
}
Example #13
0
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;
}
Example #14
0
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;
}
Example #15
0
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;
}
Example #16
0
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;
}
Example #17
0
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;
}
Example #18
0
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;
}
Example #19
0
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;
}
Example #20
0
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;
}
Example #21
0
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;

}
Example #22
0
// 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"
Example #25
0
//-----------------------------------------------------------------------------
// 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;
}