Ogre + SDL getting no mouse events

Problems building or running the engine, queries about how to use features etc.
Post Reply
joepace
Gnoblar
Posts: 4
Joined: Mon May 16, 2005 4:48 am

Ogre + SDL getting no mouse events

Post by joepace » Mon May 16, 2005 5:12 am

Im trying to add SDL input to the basic Ogre examples, everything i have seems to be right but no mouse event is ever triggered, but I get and respond to Keyboard events just fine.

OgreFrameListener(Code below) has ExampleFrameListener as a base class, is there anything in that which would prevent mouse messages getting through to this point?

Is there any extra initialisation that needs to be done to get mouse working, like joysticks do? What i've read infers KB and Mouse both work after you init SDL. I cant see how its possible to be getting one without the other.

Code: Select all

bool OgreFrameListener::frameStarted(const FrameEvent &evt)
    {
		if(mWindow->isClosed()) return false;

		std::fstream filestr;

		Vector3 transVector = Vector3::ZERO;
		int Key;
		
		SDL_Event event;
		while(SDL_PollEvent(&event))
		{		
			switch(event.type)
			{
				case SDL_MOUSEBUTTONDOWN:
						filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
						filestr << "MOUSE_BUTTONDOWN\n";
						filestr.close();
						break;
				case SDL_MOUSEMOTION:			
						filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
						filestr << "MOUSE_MOTION\n";
						filestr.close();
					break;

				case SDL_KEYDOWN:  
					Key = GetApplication()->mInput->GetKey(event.key.keysym.sym);
					if( Key == DOWN )
					{					
							filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
							filestr << "KEY_HIT_DOWN\n";
							filestr.close();
							transVector.z += mMove;							
					}
					else if( Key == UP )
					{
							filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
							filestr << "KEY_HIT_UP\n";
							filestr.close();
							transVector.z -= mMove;							
						
					}
					else if( Key == LEFT )
					{
							filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
							filestr << "KEY_HIT_LEFT\n";
							filestr.close();
							transVector.x -= mMove;							
							
					}
					else if( Key == RIGHT )
					{
							filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
							filestr << "KEY_HIT_RIGHT\n";
							filestr.close();
							transVector.x += mMove;							
						
					}

					else if( Key == QUIT )
					{
							filestr.open ("debuglog.txt", std::fstream::out | std::fstream::app);
							filestr << "KEY_HIT_QUIT\n";
							filestr.close();						
							return 0;							
					}

					break;

				case SDL_QUIT:
					return 0;
					break;

				default:
					break;
					
			}
		}
0 x

User avatar
Raven
Goblin
Posts: 203
Joined: Wed Mar 23, 2005 1:07 pm
Location: Melbourne, Australia
Contact:

Post by Raven » Mon May 16, 2005 5:28 am

You will need to add a mouse listener to the OgreFrameListener so that it will listen for mouse input
0 x
I used up all my sick days, so I'm calling in dead.

joepace
Gnoblar
Posts: 4
Joined: Mon May 16, 2005 4:48 am

Post by joepace » Mon May 16, 2005 5:48 am

OK thanks, i'll try that, but i thought that was for Ogre's simple input system only.
0 x

joepace
Gnoblar
Posts: 4
Joined: Mon May 16, 2005 4:48 am

Post by joepace » Mon May 16, 2005 7:20 am

OK, now i worked out i can actually get Mouse messages, but only for a split second before SDL passes control to Ogres render window.

And then only if i choose OK in Ogres config dialog by pressing Enter and not by mouse click(I assume the MOUSEBUTTONUP must do something like select the SDL window).

It doesnt seem to matter whether the MouseListener is included as suggested above.

The code commented out is the Motorsport method, but has includes which didnt come with ogre, is that superior to the FindWindow method?or even required?

This is with WinXP.

Code: Select all

if(mRoot->showConfigDialog())
        {
            // If returned true, user clicked OK so initialise
            // Here we choose to let the system create a default rendering window by passing 'true'

			// Initialise Ogre
			char tmp[64] = "Play Window";
			mWindow = mRoot->initialise(true, tmp);

			// Initialise SDL

#ifdef WIN32
			// Allow SDL to use the window Ogre just created
			HWND hWnd = FindWindow(tmp, 0);
			sprintf(tmp, "SDL_WINDOWID=%d", hWnd);
			_putenv(tmp);

/*
#ifdef WIN32
 
    char tmp2[64];
    Ogre::Win32Window* ow32_win = static_cast<Ogre::Win32Window*>(mWindow);
    if (ow32_win != NULL)
    {
        sprintf(tmp2, "SDL_WINDOWID=%d", ow32_win->getWindowHandle());
        _putenv(tmp2);
    }

*/

			if (!mWindow->isFullScreen())
			{
				// This is necessary to allow the window to move
				//  on WIN32 systems. Without this, the window resets
				//  to the smallest possible size after moving.
				mInput->Initialise(mWindow->getWidth(), mWindow->getHeight());				
			}
			else
			{
				mInput->Initialise(0, 0);
			}
#else
			mInput->Initialise();
#endif
		}
		else
		{
			return false;
		}
0 x

User avatar
BRAINLESS
Goblin
Posts: 282
Joined: Tue Jan 04, 2005 6:56 pm
Location: The Netherlands

Post by BRAINLESS » Mon May 16, 2005 9:34 pm

0 x
Proud member of the OpenFRAG Game Development community

joepace
Gnoblar
Posts: 4
Joined: Mon May 16, 2005 4:48 am

Post by joepace » Tue May 17, 2005 3:38 am

Thanks BRAINLESS, but that is what my code is already based on. It passes the SDL keyboard messages to the ogre render window, but the mouse just gets lost.

The Win32Window casting is not mentioned in the wiki on this topic, should i assume the FindWindow method was the accepted way?
0 x

User avatar
BRAINLESS
Goblin
Posts: 282
Joined: Tue Jan 04, 2005 6:56 pm
Location: The Netherlands

Post by BRAINLESS » Sat May 21, 2005 3:49 pm

a little late perhaps, but the reason we use FindWindow rather then casting it to Win32Window is: it works for both OpenGL and DirectX9. Casting only works for OpenGL.
0 x
Proud member of the OpenFRAG Game Development community

Post Reply