Mouse noise?

Blitz3D Forums/Blitz3D Programming/Mouse noise?

Jimmy(Posted 2011) [#1]
I found a weird behaviour in the mouse movement of B3D, anyone seen this or even better knows how to fix it?
I get an occasional very visible "90 degree bump", it appears every now and then, some kind of noise? The platform I use is XP SP3 and it has no problems whatsoever using the mouse in other applications, only B3D has this problem?

To illustrate what I mean here's a snapshot of it
http://img718.imageshack.us/i/snapshotp.jpg/

This is one of many tests i made. Nothing special about it. But it should show the bump every now and then..

Graphics 800,600,16,2 ; windows mode
;Graphics 800,600,16 ; fullscreen mode
Repeat
x=MouseX():y=MouseY():d=MouseDown(1)
; if d then plot x,y
If drawing=True Then Line ox,oy,x,y
If (drawing=False) And (d=True) Then drawing=True:Plot x,y
If d=False And drawing=True Then drawing=False: Line ox,oy,x,y
ox=x:oy=y
If drawing=True Then Color 255,0,0:Plot 1,1 Else Color 0,0,0:Plot 1,1
Color 255,255,255
Until MouseDown(2)


Warner(Posted 2011) [#2]
Try using the BackBuffer() to see if the bump still appears.
Graphics 800,600,16,2 ; windows mode
SetBuffer BackBuffer()
;Graphics 800,600,16 ; fullscreen mode
Repeat
x=MouseX():y=MouseY():d=MouseDown(1)
; if d then plot x,y
If drawing=True Then Line ox,oy,x,y
If (drawing=False) And (d=True) Then drawing=True:Plot x,y
If d=False And drawing=True Then drawing=False: Line ox,oy,x,y
ox=x:oy=y
If drawing=True Then Color 255,0,0:Plot 1,1 Else Color 0,0,0:Plot 1,1
Color 255,255,255
Flip
Until MouseDown(2)



Jimmy(Posted 2011) [#3]
Thank you! that did the trick, glad being able to fix that but the fullscreen now gets an annoying flicker and slowness. The Windowsmode version works without flickering and is abit faster but still very slow. But I guess that could be the result having a slow computer now.

Here's what you get with just doodling on a 1.2Ghz:
http://img593.imageshack.us/f/snapshotk.jpg/

You get a "polygonish" look from slow updates. Perhaps it's just the performance of the computer now, If so I'm abit dissapointed of the performance for reference my old 466mhz notebook got 60hz frame update within B3D, while now my 1.2Ghz netbook has more like 6hz frameupdate doing nothing demanding at all.) Mind you it plays HD movies perfect and handles Windows very snappy. But 3D and especially B3B, even 2d drawing and plot commands it seem to do so slow. Gonna need replace PLOT with WRITEFAST right away. And assume hardware accelaration has changed lots thru the years and B3D's support of it has not?


Yasha(Posted 2011) [#4]
hardware accelaration has changed lots thru the years


Yep. There isn't any!

3D cards don't handle the pixel-crunching of pure 2D operations like Plot or WritePixelFast very well, because it's not what they're optimised to do. It's possible that your 466MHz machine is so old that it still has a dedicated 2D accelerator of some kind, which your newer netbook doesn't.

For most purposes nowadays drawing is done using a 2D-in-3D solution (perfectly positioned textured quads), which is both more powerful, as you get the fun alpha/scale/rotation effects for free, and generally a LOT faster than using the 2D engine, as it benefits from the 3D card.


Warner(Posted 2011) [#5]
Perhaps you could change Graphics to Graphics3D? I've heard complaints about the regular Graphics mode not working correctly.

In Blitz3D, the mouse coords are polled. Say, each frame, the application determines where the mouse is. The longer a frame takes, the more interval there will be between two polls.
Using "Flip False" decreases the wait time needed for each Flip. However, it increases the CPU usage of your program much more. (Usually up to a 100%) A way to deal with that is using a small Delay after Flip. This, however, will again slow down the polls.


Jimmy(Posted 2011) [#6]
GRAPHICS3D sadly made no difference but FLIP FALSE did brought back the original speed but also original noisebug, but It occurs less frequently
it might be okay solution accepting the fact you cannot get anything as perfect as you want here..

Also tried doing 2D using 3D techniques before on this particular machine but everything seem to become either slow or very slow..
To me it's an enigma that things gets so slow in B3D and general 3D spplications while WIN itself gets such wounderful acceleration
itself when moving windows, scrolling browser content, drawing fontsplines etc.

I don't have a clue but It seem to me that the machine DOES have descent 2D acc (not used by Blitz3D, and terrible 3D acc that IS used by Blitz3D)?

I'm thinking ways to improve update of input at least? Is there a way to force blitz to update mouse more than once per screen refresh?

Last edited 2011


Warner(Posted 2011) [#7]
Maybe you could look into using the default windows API for reading the mouse coordinates?

For this program to run, you need to create a userlib. Instructions are included in the comment at the start of the program.

Edit: ow, yes, and did you tried disabling DebugMode?

Last edited 2011


Jimmy(Posted 2011) [#8]
Thanks, that seem to work, but also at exit it freezes the machine? (though if I exit by rightclicking taskbar instead of pressing esc it doesn't).

About debugmode it's already off.

That was weird that it freezes..

Last edited 2011


Jimmy(Posted 2011) [#9]
Made some progress! Taking the original code without the backbuffer which works in very nice speed fullscreen, and replacing xmouse and ymouse with that windows API it gave perfect results! very happy, well until I will need to add layers.. ontop of this ;)

Don't want to sound ignorant or anything but using Windows API is very new to me, where would be a great beginners place to learn it and looking up this kind of references? For example I would be keen to look for mousebuttons etc aswell.


Warner(Posted 2011) [#10]
How come you have no freeze anymore? It would be a good idea to investigate that a bit further before it becomes a bigger problem later on.
About API, Microsoft's Msdn describes all these functions in detail. Usually with a Visual Basic example. These API's are functions that are in DLL's that are provided with Windows. Hence the .lib "something.dll" at the start of a decls file.
Usually, a search on this site will help finding out what api you need.
For instance this search (Google)
"api mousebutton site:blitzbasic.com"

edit: I believe that for mousebuttons, you can use api_GetAsyncKeyState% with keycode 0 or 1.
msdn: http://msdn.microsoft.com/en-us/library/ms646293(v=vs.85).aspx

Last edited 2011


Jimmy(Posted 2011) [#11]
Thank you! It seem to be the 0 argument of GRAPHICS / GRAPHICS3D or the GRAPHICS3D statement itself that made the freezing.

I forgot to paste the final code that did work for sharing, so here it is:

mousebank = CreateBank(8)
;Graphics3D 800,600,16,2
Graphics 800,600,16
;SetBuffer BackBuffer()
Repeat
;For temp=1 To 10
;x=MouseX():y=MouseY()
d=MouseDown(1)
api_GetCursorPos(mousebank):x = PeekInt(mousebank, 0):y = PeekInt(mousebank, 4)

If drawing=True Then Line ox,oy,x,y
If d=True Then drawing=True
If d=False And drawing=True Then drawing=False
ox=x:oy=y

;next

If drawing=True Then Color 255,0,0:Plot 1,1 Else Color 0,0,0:Plot 1,1
Color 255,255,255
;Flip False
Until MouseDown(2)


Last edited 2011

Last edited 2011


Kryzon(Posted 2011) [#12]
It's gonna be tough developing in Blitz3D without using the Graphics3D command. Very limiting.

Until v1.79 Blitz3D used DirectInput for handling mouse and keyboard. Now it just uses standard Windows messages (this was due to some users reporting mouse\keyboard lockups).

Since then there are a couple of undocumented commands that may help you:
EnableDirectInput() and DirectInputEnabled().

EnableDirectInput(enable)
Sets which input handler is used by your app. 'True' sets it to DirectInput, 'false' sets it to Windows messages (the default).

DirectInputEnabled()
Returns 'True' in case the mouse and keyboard are being handled by DirectInput, false if not.