OpenGL Fullscreen + SDL = no mouse focus on load

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
walaber
OGRE Expert User
OGRE Expert User
Posts: 829
Joined: Sat Oct 02, 2004 2:20 pm
Location: California, USA
Contact:

OpenGL Fullscreen + SDL = no mouse focus on load

Post by walaber »

On my Trampoline project, I have one problem left, preventing me from releasing the game. I am using SDL for all input (mouse/keyboard/joystick) based on the Wiki article. Everything works perfectly once the game is running. I get all events, and there are no problems.

However, I have 1 problem that happens on application startup that I can't figure out.

Only in fullscreen + OpenGL (directX is fine), the mouse is "stuck" in the upper-left corner of the window. when you move the mouse, it flickers between the in-game CEGUI mouse, and the hardware mouse, as if it is leaving the bounds of the window or something. Like I said, the exact same code works for DirectX full screen, and both renders in windowed-mode.

If you Alt-TAB to another application, and then go back to Trampoline, the mouse works.

here is my SDL init code:

Code: Select all

void SDLInput::initialize( Ogre::RenderWindow* win )
{
#ifdef WIN32
	char tmp[64];
	HWND hWnd;
	win->getCustomAttribute("HWND", &hWnd );
	sprintf( tmp, "SDL_WINDOWID=%d", hWnd );
	_putenv( tmp );	
#endif	// WIN32

	// initialize SDL!!
	if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE ) < 0)
		throw( Ogre::Exception(999, "error initializing SDL!", __FUNCTION__, __FILE__, __LINE__ ) );

#ifdef WIN32
	SDL_SetVideoMode( win->getWidth(), win->getHeight(), 0, 0 );
	
	SDL_SysWMinfo pInfo;
	SDL_VERSION( &pInfo.version );
	SDL_GetWMInfo( &pInfo );

	RECT r;
	GetWindowRect( pInfo.window, &r );
	SetWindowPos( pInfo.window, 0, r.left, r.top, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
#endif

	SDL_WM_GrabInput( SDL_GRAB_ON );
	SDL_ShowCursor( SDL_DISABLE );

	SDL_EnableUNICODE( 1 );
	SDL_EnableKeyRepeat( SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL );

	// joysticks
	if (SDL_NumJoysticks() > 0)
	{
		mJoystick = SDL_JoystickOpen( 0 );
		SDL_JoystickEventState( SDL_ENABLE );
	}
	else
	{
		mJoystick = NULL;
	}

}
has anyone else had this problem, and come up with a solution? I really need to solve this so I can release my game! otherwise I will have to put something in the manual (lame), or remove the OpenGL renderer entirely (really lame)

[edit] I should mention that currently I'm only dealing with the Windows platform.[/edit]
Go Go Gadget OGRE!!
Image

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

All I can think of is that the fullscreen switch hasn't quite happened yet when you init the SDL mouse - have you tried deferring it a little, or perhaps repeating the code that happens on WM_SIZE or something like that?

User avatar
walaber
OGRE Expert User
OGRE Expert User
Posts: 829
Joined: Sat Oct 02, 2004 2:20 pm
Location: California, USA
Contact:

Post by walaber »

i did try fiddling with the order a bit... but that didn't help a whole lot.

i finally solved the problem by removing the

Code: Select all

SDL_WM_GrabInput( SDL_GRAB_ON ); 
line. this allows the mouse to enter/exit the window (in windowed mode), and seems to fix the problem in full-screen mode.

thanks for the reply!
Go Go Gadget OGRE!!
Image

Post Reply