Skip to main content
gamedev.net
🔒 Locked

opengl: how to detect double click?

Started by nickme 7 replies 8.7k views
Original Post
nickme
nickme
hi
is there a way to detect double mouse clicks?
thanks
21st Century Moose
21st Century Moose
No - OpenGL is for graphics only, not input.

Perhaps you mean GLUT or something similar instead?
Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
nickme
nickme

No - OpenGL is for graphics only, not input.

Perhaps you mean GLUT or something similar instead?


yes, i meant glut

thanks
nickme
nickme

GLUT doesn't provide double click detection out of the box. You need to manually time single clicks to detect a double click. This is another thread discussing this idea.


hi,
thanks for the reply. i wonder can i get the coordinate (window x & y values) where the double clicks occurred? i need that info for my program to work.
thanks
SiCrane
SiCrane
The coordinates are passed as the x and y to the callback registered with glutMouseFunc().
nickme
nickme
hi,

how do i differentiate a single click and a double click?

let's see my subroutine for handling mouse click:

void mouseButton(int button, int state, int x, int y) {
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_UP) {
xpos = W[C].l+(GLdouble)x*deltax-0.5*swx_size,
ypos = W[C].t-(GLdouble)y*deltay-0.5*swy_size;
move_cursor();
}
break;
default:
break;}
}

i am complete lost in implementing glutTimerFunc(). i am still looking at other's tutorials. i only want to execute move_cursor() when there is a single click and execute Zoom_in() when it is a double click. where should i place glutTimerFunc()? before move_cursor()?

thanks
ssrun
ssrun
Generally speaking, a "single click" event will always be fired off before the "double click" event. In Actionscript 3, a double click causes two events to be fired, what you need to do is code in such away that the action being done on the single click even naturally flows into the double click event. For example, single clicking a unit may select that particular one but double click it will select all units of that type. The flow works naturally as the first click event will select it and then the double click event will notice that the unit is selected and then search the rest of the game world for units of the same type to select.
nickme
nickme
hi,

another related problem. when i pressed an arrow key, the response was almost immediate, but when i click the mouse button, there was a delay. is it my applicaton or glut's problem?

i still working on the double click. i will post when something happened.

thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.