Many problems - no mouse, no sound, slow drawing

Archives Forums/Linux Discussion/Many problems - no mouse, no sound, slow drawing

matt!(Posted 2011) [#1]
I'm trying to build my game on Linux, but there are many issues.

1. No mouse
(plus: 2. No sound and 3. Slow drawing speed)

The following code shows the mouse issue. It works well in Windows and Mac OSX, but does not work in Linux.
It should enable mouse control of the square, confined to the window.

Any ideas?

Strict
Local ScreenWidth:Int = 240, ScreenHeight:Int = 320
Graphics ScreenWidth*2, ScreenHeight*2
SetVirtualResolution ScreenWidth, ScreenHeight

Local myX:Int, myY:Int
Local CenterX:Int = ScreenWidth / 2
Local CenterY:Int = ScreenHeight / 2
Local inWindow:Int = False
MoveMouse CenterX, CenterY
HideMouse()

While Not KeyDown (KEY_ESCAPE)
	Cls
	
	Select WaitEvent()
	End Select
	
	Select EventID()
	Case EVENT_APPSUSPEND, EVENT_MOUSELEAVE
		inWindow = False
	Case EVENT_MOUSEENTER
		inWindow = True
	End Select

	If (inWindow) Then
		myX:+(MouseX() - CenterX)
		myY:+(MouseY() - CenterY)
		MoveMouse CenterX, CenterY
	EndIf

	If myX < 0 Then myX = 0
	If myX > ScreenWidth - 1 Then myX = ScreenWidth - 1
	If myY < 0 Then myY = 0
	If myY > ScreenHeight - 1 Then myY = ScreenHeight - 1
	
	SetColor 0, 255, 0
	DrawRect myX - 10, myY - 10, 20, 20
	SetColor 255, 255, 255
	Plot myX, myY

	Flip
	
Wend


Last edited 2011


Htbaa(Posted 2011) [#2]
Slow drawing speed could be because you haven't installed the right graphics card driver. Try installing the propitiatory driver for your video card.

Gotta warn you about it though, because for me (on 2 systems, one ATI, the other NVidia) they totally screw up, so I'm using the open source drivers, though a bit slower.

What Linux distribution do you use?


matt!(Posted 2011) [#3]
I'm using Ubuntu...

11.10 running on VMware Fusion with VMware Tools graphics acceleration
10.04 running on an IBM ThinkPad X31

Same issues on both. Setup used: http://www.blitzbasic.com/Community/posts.php?topic=88613

Did you try the above code example? Can you move the square around the window with the mouse?

Thanks

Last edited 2011


markcw(Posted 2011) [#4]
Hi matt, I fiddled with your code and got it working in linux.

There is a bug with the mouseenter mouseleave events in linux, they don't appear to work. So this needs a bug report for that which I have commented in my version of your code.

Also, a PollSystem was needed just before Flip to update the screen in linux.

Strict
Local ScreenWidth:Int = 240, ScreenHeight:Int = 320
Graphics ScreenWidth*2, ScreenHeight*2
SetVirtualResolution ScreenWidth, ScreenHeight

Local myX:Int, myY:Int
Local CenterX:Int = ScreenWidth / 2
Local CenterY:Int = ScreenHeight / 2
Local inWindow:Int = False, mouseadd:Int ' bug in linux: mouseadd should add 2 when move mouse into window
MoveMouse CenterX, CenterY
HideMouse() ' comment this line to test mouseenter/leave bug

While Not KeyDown (KEY_ESCAPE)
	Cls
	DrawText inWindow+" "+mouseadd+" "+myX+" "+myY,0,0 ' debug text

	Select WaitEvent()
	End Select
	
	Select EventID()
	Case EVENT_APPSUSPEND, EVENT_MOUSELEAVE
		inWindow = False
		mouseadd:+1
	Case EVENT_MOUSEENTER
		inWindow = True
		mouseadd:+1
	End Select
	
'	If (inWindow) Then
		myX:+(MouseX() - CenterX)
		myY:+(MouseY() - CenterY)
		MoveMouse CenterX, CenterY ' comment this line to test mouseenter/leave bug
'	EndIf

	If myX < 0 Then myX = 0
	If myX > ScreenWidth - 1 Then myX = ScreenWidth - 1
	If myY < 0 Then myY = 0
	If myY > ScreenHeight - 1 Then myY = ScreenHeight - 1

	SetColor 0, 255, 0
	DrawRect myX - 10, myY - 10, 20, 20
	SetColor 255, 255, 255
	Plot myX, myY
	
	PollSystem() ' needed just before flip in linux to update screen
	Flip
	
Wend



matt!(Posted 2011) [#5]
Awesome! Many thanks. Quite elegant debugging there.

I'll file a bug. And I'll try PollSystem to see if it fixes my slow graphics. Fingers crossed!

Last edited 2011


Armitage 1982(Posted 2011) [#6]
For the Sound Problem, did you try using another audio driver ?

		?Linux
		
			' Fix the sound under Linux :)
			If EnableOpenALAudio() Then
				SetAudioDriver("openal")
			Else
				SetAudioDriver("FreeAudio")
			End If

		?


Also, I'm not experienced with Openal.
I discover recently that my game stopped emitting sounds after loading a few ogg music.
No error, just a silence... Yeah I know, Linux...

Shouldn't you use virtualMouseX() / virtualMouseY() when using SetVirtualResolution() too ?


matt!(Posted 2011) [#7]
I had tried the SetAudioDriver - no luck.
As a test, I have sound when playing a YouTube video.

Yes, you should use VirtualMouseX/Y but in this instance I do not care about the actual position of the mouse as I am using delta movements to track the position for my own mouse cursor that is locked to the window. See here: http://www.blitzbasic.com/Community/posts.php?topic=92561#1115928

Even after PollSystem the graphics in my game are slow.
Windows version runs perfectly under Wine.

Last edited 2011


skidracer(Posted 2011) [#8]
For sound you could try the BlitzMax Pulse Audio driver.


matt!(Posted 2011) [#9]
Have tried it and posted in that thread with my results (not good).

Last edited 2011


Armitage 1982(Posted 2011) [#10]
Also, don't forget that Linux is a nightmare with proprietary driver.
For example, GraphicsModes() only return the current mode with my configuration. And when I switch to full screen the window is enlarge to both dual monitor view (which is ugly).
So maybe there is something particular with your sound card ? I say maybe... since I have no clue about Linux.