Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: OIS & SDL  (Read 1204 times)

hug0

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 2
    • View Profile
OIS & SDL
« on: November 18, 2009, 07:47:11 AM »

Hi all,
for some reason I want to use SDL (as window) and OIS (as inputsystem), working with LINUX.
I got the following error with the example attached (works fine without the createInputObject line).
Thanks for any hints and ideas!
HUG0

Code: [Select]
X Error of failed request:  BadAccess (attempt to access private resource denied)
  Major opcode of failed request:  2 (X_ChangeWindowAttributes)
  Serial number of failed request:  7
  Current serial number in output stream:  9

Code: [Select]
#include <iostream>
#include <sstream>
//SDL
#include <SDL.h>
#include <SDL_syswm.h>
#include <SDL_opengl.h>
//OIS
#include <OISMouse.h>
#include <OISKeyboard.h>
#include <OISJoyStick.h>
#include <OISInputManager.h>

using namespace std;

int main()
{
//********* SDL ********
  SDL_Surface* mp_screen;
  size_t m_windowHandle;
  int m_width = 800;
  int m_height = 600;

  // initialize the SDL library
  if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    cout << "Failed to initialize the SDL library: " << SDL_GetError() << endl;

  SDL_WM_SetCaption("OIS SDL MOUSE test", NULL );

  // create the window
  int flags = SDL_OPENGL | SDL_RESIZABLE;
  int bitsperpixel = 16;
  mp_screen = SDL_SetVideoMode(m_width, m_height, bitsperpixel, flags );

  // fill info variable to get handle
  SDL_SysWMinfo info;
  SDL_VERSION(&info.version);
  SDL_GetWMInfo(&info);

  m_windowHandle = *( reinterpret_cast<std::size_t*>(&(info.info.x11.window)) );

//******* OIS ******
  OIS::ParamList pl;
  OIS::InputManager *mInputSystem;
  OIS::Mouse        *mMouse;
  OIS::Keyboard     *mKeyboard;

  ostringstream windowHndStr;
  windowHndStr << m_windowHandle;
  pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));

  mInputSystem = OIS::InputManager::createInputSystem( pl );

  mMouse = static_cast<OIS::Mouse*>(mInputSystem->createInputObject(OIS::OISMouse, false));

  int wait;
  cin >> wait;

  return 0;
}
« Last Edit: November 18, 2009, 07:49:44 AM by hug0 »
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
Re: OIS & SDL
« Reply #1 on: November 22, 2009, 08:26:49 AM »

The problem is the X11 mouse. Only one listener can be registered at any time on x11. SDL apparently is taking over it. Not sure if SDL provides a way not to. I have not found a method to take back the registered listener on that platform. What you want may not be possible... if you need SDL graphics, you will probably also have to use SDL input. Though, you may be able to use OIS joysticks + SDL.
Logged