Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Hardware-like software cursor.  (Read 12155 times)
0 Members and 1 Guest are viewing this topic.
Offline blobloblob

Senior Newbie


Medals: 1
Exp: 3 years



« Posted 2016-05-01 09:40:08 »

So, here is my problem: I want to draw a cursor in OpenGL, so I can easily handle things like partial transparency and 24bpp color depth across platforms.

I've done that, by (you can guess it) drawing a simple renderd quad on top of everything in the position of cursor and hiding the original, hardware("native"?) cursor. The thing I'm running into is when the game starts to lag, the cursor lags with it - what doesn't take place when using hardware cursor. Is there a way around that lag or any well established practice on this topic? Or maybe you just have an idea how to handle this?

It's done in Lwjgl(2.9.3) , but the technicalities here may be not of importance.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2016-05-01 13:15:34 »

There is no simple solution here. As you expected: either increase the framerate or use the hardware cursor.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline theagentd
« Reply #2 - Posted 2016-05-01 15:21:52 »

A crazy solution would be to detect frame rate drops and when those happen draw a dummy frame. You'd just copy the contents of the previous frame to the screen (without the old mouse) and redraw the mouse in its new position, effectively doubling the mouse's frame rate compared to the rest of the game's. It would have a tiny bit of overhead (1 fullscreen pass for each extra frame to copy the previous one), but could help a lot if mouse smoothness is critical.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Abuse

JGO Ninja


Medals: 73


falling into the abyss of reality


« Reply #3 - Posted 2016-05-01 16:06:46 »

Wasn't that the technique used in Molyneux's Black & White?
I seem to remember the cursor & game framerates being disconnected from one-another as being a major selling point of that game.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2016-05-01 16:35:08 »

I (honestly) was thinking about that solution too - but it makes your (gameplay) framerate issues even worse, especially when vsync is on.


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline theagentd
« Reply #5 - Posted 2016-05-01 18:48:01 »

I (honestly) was thinking about that solution too - but it makes your (gameplay) framerate issues even worse, especially when vsync is on.
If it's dynamic enough and only activates at <half the monitor's refresh rate, it should be OK. It might improve the perceived responsibility.

Myomyomyo.
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2016-05-01 20:16:56 »

Preferably you would want to smear every gameplay-frame over N render-frames - but... what a contrived solution for a problem that might be fixable in a much more sensible way (aim for 60fps, you can do it!)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline blobloblob

Senior Newbie


Medals: 1
Exp: 3 years



« Reply #7 - Posted 2016-05-02 13:31:10 »

Perhaps maybe it would be possible to create an "overlay" GL context and drawable on top of the existing one? Could this be a solution, or I miss some point? What you think?
Offline jonjava
« Reply #8 - Posted 2016-05-02 13:55:05 »

Make it run at 60 FPS.

Or 24 fps for a cinematic look.

Offline CommanderKeith
« Reply #9 - Posted 2016-05-02 14:30:57 »

I (honestly) was thinking about that solution too - but it makes your (gameplay) framerate issues even worse, especially when vsync is on.
If it's dynamic enough and only activates at <half the monitor's refresh rate, it should be OK. It might improve the perceived responsibility.
Could you also just repaint the small cursor and the small 'dirty' section where it used to be painted? Might save some time.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 123
Projects: 15


★★★★★


« Reply #10 - Posted 2016-05-03 11:49:17 »

have you tried implementing mouse smoothing?

Usually done by interpolating the mouse position between either:

1) where the mouse was and where it should be (previous polled position and current polled position)
or
2) where it currently is and by predicting where it will be the next time its polled (current polled position and predicted next position).

Rather than jumping between mouse positions you can move the cursor at a constant speed between mouse positions or draw it at an interpolated position between the two positions at the time the frame is rendered.

This should hide small amounts of lag and give the appearance of smooth movement.
Offline theagentd
« Reply #11 - Posted 2016-05-03 21:01:54 »

have you tried implementing mouse smoothing?

Usually done by interpolating the mouse position between either:

1) where the mouse was and where it should be (previous polled position and current polled position)
or
2) where it currently is and by predicting where it will be the next time its polled (current polled position and predicted next position).

Rather than jumping between mouse positions you can move the cursor at a constant speed between mouse positions or draw it at an interpolated position between the two positions at the time the frame is rendered.

This should hide small amounts of lag and give the appearance of smooth movement.
This doesn't really help in this case. It's not that the mouse isn't polled often enough; it's that the screen isn't redrawn fast enough. Interpolation won't help if the mouse position only updates 10 times per second.

Myomyomyo.
Offline blobloblob

Senior Newbie


Medals: 1
Exp: 3 years



« Reply #12 - Posted 2016-05-04 09:16:36 »

@kappa
Oh, that sounds pretty interesting Smiley Though not perfect, it may be enough of a compromise. I'll probably give it a try. Do you have any examples of this or is this just idea from top of your head?
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 123
Projects: 15


★★★★★


« Reply #13 - Posted 2016-05-04 09:35:03 »

This doesn't really help in this case. It's not that the mouse isn't polled often enough; it's that the screen isn't redrawn fast enough. Interpolation won't help if the mouse position only updates 10 times per second.
If the frame drop is that large then I agree with you. However if the application is running that slow then its unlikely the other techniques mentioned above are going to help much and in general the application has serious issues which need to be addressed first.

For smaller frame drops though, mouse interpolation should work well enough.

@kappa
Oh, that sounds pretty interesting Smiley Though not perfect, it may be enough of a compromise. I'll probably give it a try. Do you have any examples of this or is this just idea from top of your head?
It's a technique used in many commerical games and triple A titles (sometimes you can even toggle it on/off in the options), IIRC (not 100% sure) it was also used in Revenge of the Titans (OpenGL game with source code).

I don't have a link to an article setting out the implementation, however the concepts at the end of the fix your game loop articles are pretty similar such as here, here and here.
Offline blobloblob

Senior Newbie


Medals: 1
Exp: 3 years



« Reply #14 - Posted 2016-05-04 09:49:34 »

Thanks Smiley I really (will, cause I can't twice in a row) appreciate that. 
Offline Icecore
« Reply #15 - Posted 2016-05-04 11:09:23 »

I've done that, by (you can guess it) drawing a simple renderd quad on top of everything in the position of cursor and hiding the original, hardware("native"?) cursor. The thing I'm running into is when the game starts to lag, the cursor lags with it - what doesn't take place when using hardware cursor. Is there a way around that lag or any well established practice on this topic? Or maybe you just have an idea how to handle this?
If you want draw small quad on top img and then move it - without redraw bottom img
1. draw main img to pixel buffer
2. then copy rec quad from main img, before draw it
3. draw quad
4. restore rec quad
5. move mouse pos – repeat from 2

If game lags – have sharp FPS – then it simple lags and need fix lags ^^

Last known State: Reassembled in Cyberspace
End Transmission....
..
.
Journey began Now)
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (579 views)
2019-09-04 15:33:17

hadezbladez (5501 views)
2018-11-16 13:46:03

hadezbladez (2398 views)
2018-11-16 13:41:33

hadezbladez (5761 views)
2018-11-16 13:35:35

hadezbladez (1220 views)
2018-11-16 13:32:03

EgonOlsen (4660 views)
2018-06-10 19:43:48

EgonOlsen (5681 views)
2018-06-10 19:43:44

EgonOlsen (3196 views)
2018-06-10 19:43:20

DesertCoockie (4094 views)
2018-05-13 18:23:11

nelsongames (5113 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!