How to show mouse in a flipping chain?

Started by
8 comments, last by GameDev.net 18 years, 7 months ago
Hello there! This is my first post here, just found out about this game programming forum. I love when a game finally becomes alive and starts to kick your butt and for this feeling I've learned programming from the old BASIC, Pascal, C, a few ASM and now, finally, C++ and DirectX stuff, which seems to be enough to make a great game. If there is something else I should know about, please let me know... I know there is a mouse support in DirectX SDK 9.0, but I'm not realy up-to-date with this new DirectX version. I've started something in 7.0, but there is no mouse support. I am currently displaying the mouse as a sprite just before the page flip, but when rendering heavy stuff and the FPS drops, the mouse becomes "ellastic", you probably know what I mean... So, any better ideas?
Advertisement
Are you working in a window or full screen?

ace
Well, I made it run in both windowed and fullscreen:
- when in window mode, mouse data is read from the system;
- when in fullscreen, mouse data is read from buffered DirectInput (I don't use immediate data because I don't wanna miss something).

I use windowed mode especially for debugging, but the game is intended to work only in fullscreen. In both cases I display mouse in the same way, except that when windowed I hide system cursor when hovers over my client area of the window.
I know what you mean - the "elastic mouse" can even happen at high frame,
if the videocard has the next x frames in memory, ready to render.

I think sth like this will help, so it will flush all frames:

pEventQuery->Issue(D3DISSUE_END);
while(pEventQuery->GetData(NULL, 0, D3DGETDATA_FLUSH) == S_FALSE)
{
// avoid being bored while waiting for the GPU,
// so let another thread do something usefull
Sleep(0);
}

... or maybe someone else has a better solution?

PS: If you are using an older dx-version, try locking a 1-pixel rectangle
of the screenbuffer - that might also help.
visit my website at www.kalmiya.com
All I need is a cursor display solution.

Should I better display the mouse cursor on the primary surface instead of the backbuffer? In fact, I need the mouse to be independent of the frame display cycle... I thought of using overlays to do that, but I don't know... I mean overlays are nice and strange but not every video card supports them (at least not in the same matter) so...
There's just no easy solution to this problem. You have to draw the mouse cursor as a sprite of some sort, and that is tied to the framerate. I imagine you need some multi-threaded trickery (out of my ballpark) to draw the cursor independently and I assure you it would not be easy. All kinds of potential problems come to mind.

This issue is extremely important to me... I just did a beta test of my game and the #1 complaint was "sloppy mouse" and "mouse all over the place" type comments which I know are coming from people who are getting relatively poor framerates.
I haven't done this myself - so don't know where to turn. But in principle Windows handles its own mouse pointer blitting, provided you don't turn of the mouse display for Windows. Furthermore you can specify an (alpha'ed) bitmap for the Windows mouse that will be used on a per frame basis without you doing anything specific.

Except - I haven't done this myself yet, so I don't know how to enforce all of that...
I remember seeing a post about this not too long ago. Someone there suggested:

Gamedev Article

Hopefully it will give you some ideas. It's for the older DX versions (such as 7).

Chris
Chris ByersMicrosoft DirectX MVP - 2005
Have you tried using the SetCursorPosition call in IDirect3D9? I haven't tried it, but in theory it should give you access to the hardware cursor.
Thanks, Supernat02! I guess that's the best way to do it. However, I've never tried the multithread stuff so it should be fun :)

This topic is closed to new replies.

Advertisement