Ok, I got the problem. I have a while loop in my display function. So all the mouse events are being buffered and my mouse() handling callback routine is called only when I get out of the while() loop.

Is there any way that one can interrupt the display() routine and process mouse events ?

THanks.

Hi all,

I am trying to capture mouse events in my OpenGL program but haven't been able to do so. I am running on Linux....following is how I am doing it.

// In main()

glutMouseFunc(mouse);

// Mouse handling function

void mouse(int button, int status, int x, int y)
{
//
}

Its as simple as that but I don't know why mouse clicks are not captured. Does this involve anything apart from what I am doing - e.g. setting the viewport(which I have done as well) etc.

Please let me know if you know the reason..

Thanks.

[This message has been edited by blitz (edited 07-20-2003).]

Some guy

07-19-2003, 03:40 PM

Do other people codes like the one below works? http://www.lighthouse3d.com/opengl/glut/index.php3?9

nexusone

07-19-2003, 06:14 PM

Works fine for me in linux (Redhat 9.0), are you wanting to capture mouse clicks outside the window that you opened?

Can you show us more of the code in your mouse(....) routine?

Originally posted by blitz:
Hi all,

I am trying to capture mouse events in my OpenGL program but haven't been able to do so. I am running on Linux....following is how I am doing it.

// In main()

glutMouseFunc(mouse);

// Mouse handling function

void mouse(int button, int status, int x, int y)
{
//
}

Its as simple as that but I don't know why mouse clicks are not captured. Does this involve anything apart from what I am doing - e.g. setting the viewport(which I have done as well) etc.

Please let me know if you know the reason..

Thanks.

nexusone

07-20-2003, 04:24 AM

Have not tryed his example, but I did not see any problem with the example.

Originally posted by Some guy:
Do other people codes like the one below works? http://www.lighthouse3d.com/opengl/glut/index.php3?9

blitz

07-20-2003, 02:17 PM

There isnt much in the mouse() handling function. I am just trying to write something to stdout to check whether I am able to capture mouse events. Since I am not checking for any conditions such as left button click etc, I am not even restricting it to certain events only. So whatever is there inside the mouse processing function should work. I am also not trying to capture clicks outside my display window. Don't know why its not working

Originally posted by blitz:
Hi all,

I am trying to capture mouse events in my OpenGL program but haven't been able to do so. I am running on Linux....following is how I am doing it.

// In main()

glutMouseFunc(mouse);

// Mouse handling function

void mouse(int button, int status, int x, int y)
{
//
}

Its as simple as that but I don't know why mouse clicks are not captured. Does this involve anything apart from what I am doing - e.g. setting the viewport(which I have done as well) etc.

Please let me know if you know the reason..

Thanks.

nexusone

07-20-2003, 02:29 PM

Don't you think that the function would work better if you had some code inside of it????

Ok, I got the problem. I have a while loop in my display function. So all the mouse events are being buffered and my mouse() handling callback routine is called only when I get out of the while() loop.

Is there any way that one can interrupt the display() routine and process mouse events ?

THanks.

Originally posted by blitz:
Ok, I got the problem. I have a while loop in my display function. So all the mouse events are being buffered and my mouse() handling callback routine is called only when I get out of the while() loop.

Is there any way that one can interrupt the display() routine and process mouse events ?

THanks.

Hi all,

I am trying to capture mouse events in my OpenGL program but haven't been able to do so. I am running on Linux....following is how I am doing it.

// In main()

glutMouseFunc(mouse);

// Mouse handling function

void mouse(int button, int status, int x, int y)
{
//
}

Its as simple as that but I don't know why mouse clicks are not captured. Does this involve anything apart from what I am doing - e.g. setting the viewport(which I have done as well) etc.

Please let me know if you know the reason..

Thanks.

[This message has been edited by blitz (edited 07-20-2003).]

abhijeet_maharana

07-21-2003, 02:10 AM

What does the while loop do in the display function? Is it required for rendering or r u trying to block for input(which is very unlikely) ?

Deiussum

07-21-2003, 05:24 AM

Using an endless loop in the display function isn't a very good practice. I'm assuming by saying you have a while() loop, you mean that it's endless, anyway.

If you are trying to do animation, you should be using either a timer function or the idle function to post a new display message.

VB 6, had a function called DoEvents that you could use to force processing of events if you absolutely HAD to have an endless loop, or a loop that took a lot of time somewhere. In the Win32 API, you could use the PeekMessage stuff to process messages within your while loop. Not sure what the equivalent is in Linux.

nexusone

07-21-2003, 06:45 AM

You don't want to be interrupting the display routine!

The only thing that should be in your display routine is the drawing of the 3D scene. Any control functions should be done outside of the display routine.

Can you explain more about what you are trying to do? This would help us give you a pointer on how it should be done.

From what I see you don't have a mouse problem but a problem in how you are trying to write the program.

Now also could be what you are trying to do can not be done using the GLUT library and you maybe will need to switch to another library for mouse input like SDL or use x-windows functions.

Originally posted by blitz:
Ok, I got the problem. I have a while loop in my display function. So all the mouse events are being buffered and my mouse() handling callback routine is called only when I get out of the while() loop.

Is there any way that one can interrupt the display() routine and process mouse events ?

THanks.

GlutterFly

07-21-2003, 08:19 AM

Well, im still only an amature as far as opengl goes but here is my best help.

Your program should run something like this:

1.Calculations
2.Display
3.Mouse and keyboard
4.Repeat

Inside the mouse and keyboard functions you use the keys to modify variables that will change portions of the code in the calculations. And the scene is then drawn based on the calculations. I think perhaps your problem is you are trying to use the mouse to "dynamically" or in real time effect your drawing routines. But, from my knowledge that does not work. Instead, try and pinpoint the variables that you need to change and pass values to and from your mouse/keyboard functions. To further diagnose this problem we will need to see more of your code.

Deiussum

07-21-2003, 09:49 AM

This is a good example of why people should have a good idea of how event-driven programming in a windowed system works before attempting to do any serious OpenGL programming.