PDA

View Full Version : Two little problems with GLUT



Morglum
10-22-2001, 04:37 AM
Hi ! I'm having some trouble... Could you please help me ?

1) How do you know when your window is about to be destroyed ? Because I need to free some memory at the
end of my program.... Is there something like glutDestroyWindowFunc ???

2) What's the best way to read the mouse in a game ?
Are glutMotionFunc &co fast enough ? I'd prefer a function to read the mouse asynchronously, much like I
prefer GetAsyncKeyState than glutKeyboardFunc....
Does such a function exist under Windows ?

Thanks for your help !
Morglum

Bob
10-22-2001, 05:34 AM
1) You don't get any message from GLUT, saying the program is about to terminate. Apart from the X-button on the window (which I believe can't be tracked), you know when the program is about to exit, cause you must call exit() (or something else) somewhere to close your program. Just free your memory there.

2) Define fast. For some, it's "fast enough", and form some it's "not fast enough".
You don't need to be able to read the mouse position asynchronously. The motionfunction is called only when the mouse moves. If you have a few variables holding the mouseposition, you don't need special function to read the mouse asynchronously, since your variables always holds the current mouseposition.
Same goes for keyboard, store the state of each key and you don'y need a special function that returns the state of a specific key.

By the way, you don'y have to free memory on exit. The OS will do it for you if you don't do it.

DFrey
10-22-2001, 05:59 AM
I'm not sure if its compatible with GLUT, but you could also put deallocation code in an atexit function.

Morglum
10-22-2001, 08:01 AM
Thanks, but I really need to know when the x button is
pressed. Windows then sends the ordinary close-window message. I'd like to intercept this message. Is there any way to do this with glut ?

And for the mouse, I really need something fast, I mean,
if my game runs at 80 fps, I'd like 80 mouse coords per second, otherwise there will be consecutive frames with
the same eye direction and my 80fps will look like a 20fps. For the keyboard, glutKeyboardFunc is useless
because it does not send more than 15 messages per sec. So my question is really : is there any function like
GetAsyncMouseState without using DX ?

Thanks !

DFrey
10-22-2001, 09:30 AM
I really need to know when the x button is pressed.
Could you clarify why you need to know at that moment? Otherwise, if all you need to do is deallocate memory or destroy objects, doing so in an atexit function seems reasonable to me.

Morglum
10-23-2001, 03:13 AM
Well, in fact, I don't know what's an atexit function.
How do you use it ?