Archived

This topic is now archived and is closed to further replies.

MasterWorks

DX8 custom mouse cursor issues

Recommended Posts

Hey all, I''m having some trouble using a custom mouse cursor with Direct3D 8. I have a 2D game but I''m using D3D for effects such as alpha blending, etc. Anyways, I know how to use SetCursorProperties, etc. to set a surface to a custom mouse cursor, but I don''t like the idea of having to manually update the cursor every frame since it''s quite possible that this game will run slowly on certain machines. As long as the mouse cursor remains framerate independent, the slowdown won''t be all that irritating as far as gameplay is concerned. So, basically I want to know if there''s some combination of DirectInput and Direct3D that will allow me to specify my own cursor but not have to manually reposition it each frame. The SDK says that it''s possible to use a method so that "the cursor is updated at at least 50% of the refresh rate. So far, I''ve had no luck achieving any such thing. Also, I''m using Visual Basic so no multithreaded or otherwise ridiculously complex solutions please. :-) C++ code is fine, if you have it, since I can convert it easily if I understand the concept. Many thanks - Jay Wheeler MasterWorks Software

Share this post


Link to post
Share on other sites
Just use a D3DXSprite for the cursor, and get the cursor using the GetCursorPos() windows function. I am doing that and it seems to work fine.

Share this post


Link to post
Share on other sites
Ummm... this may seem really obvious, but I had the reverse problem - I couldn''t get rid of the mouse cursor (also in VB).

Here''s the thing... when I run the DXapp, the normal windows cursor is displayed. If I change the Mousepointer to 99 and then set a .ico file in the Mousesomething property on the Form, I get a custom-looking mouse in my game. Then, when I want to hide it, I just set the .ico to a blank pic.

It doesn''t look too fancy, and I suspect that it''s going to be a lot more work to animate and coolerise than using a DX cursor whatnot, but... it works. I can move about and click things, which is the important bit, yeh?



I have plenty of talent and vision, I just don''''t give a damn.

Share this post


Link to post
Share on other sites
to get rid of the mouse cursor in windows, simply call
  
ShowCursor(FALSE);

and to show it again call
  
ShowCursor(TRUE);

These calls must be properly nested for it to work correctly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you are using the mouse with DirectInput in foreground mode and exclusive access:

  

LPDIRECTINPUT8 di = NULL; //DirectInput interface

LPDIRECTINPUTDEVICE8 did_mouse = NULL; //Mouse device


/* initialize DirectInput and mouse device... */

did_mouse->SetCooperativeLevel(hMainWindow, DISCL_EXCLUSIVE | DISCL_FOREGROUND)



the Windows cursor will automatically disappear when DirectInput starts and reappear when you shut down DirectInput...

Share this post


Link to post
Share on other sites
Thanks for the replies, but I think you guys are missing the point. I have no problem hiding and showing the cursor, and even moving it around.

The problem is that if my game runs at only 10FPS, so will the mouse cursor, since obviously I can''t draw the mouse cursor any more frequently than the game loop.

Does anybody know how to use a custom (color) mouse cursor AND not have to move it around "manually" so that the cursor ALWAYS gets 30+ fps, regardless of the frame rate??

-Jay

Share this post


Link to post
Share on other sites
Hi Jay,

I think that in VB you''re in a bit of troublesome spot since you can''t do multi-threaded very easilly. You said you didn''t want all kinds of weird threading stuff, so that leaves out that as an option. Basically, you have to be drawing your mouse cursor in-between your BeginScene and your EndScene instructions, otherwise it isn''t going to work.

So... if you want a custom cursor that is rendered by DX, you have to have it Frame-Dependant.

If you''re happier with a non-DX cursor, you''ll just need to tell Windows to use a custom mouse cursor and leave it up to your Windows mouse handler to move the mouse about.

In VB you can set the custom pointer using the standard Form properties, but if you want it animated you''re going to have to setup a loop independantly of your main render loop (or maybe just use an animated cursor file...)... to do a loop independantly of your main loop you can use the Timer control, but that is unreliable since you''ll probably have to use DoEvents in your render loop to make it work. A more reliable method would be to just create a small ActiveX control that uses apartment threading and place it on your main form.

Personally, I''d just change the default cursor to a game-themed one and leave it at that.

I have plenty of talent and vision, I just don''''t give a damn.

Share this post


Link to post
Share on other sites