PDA

View Full Version : About Mouse clicks and rectangles



DeSeis
11-28-2001, 01:58 AM
Hi all
I got a question. How do I check if a mouse click was clicked in a specific rectangle? On MFC u had a function PointInRect to check it. How do u check in OpenGL?
Thanks

Bob
11-28-2001, 02:21 AM
With OpenGL, you can't, cause it doesn't provide any input functions at all.

nemesis
11-28-2001, 03:29 AM
Hello!

As Bob says, OpenGL is just a graphics library and doesn't have this kind of functions.
One the other hand, you can use gluProject() to get the x,y screen coords of the rectangle and check if the mouse position is inside.

- nemesis -

11-30-2001, 01:31 AM
There is way to find out if the user has clicked inside a rectangle.
You can use the backbuffer and color different objects in the scene to differen colors and then check the pixel value when u go into selection mode.
For furher information look in the red book under the chapter now that you know, it mentions this technique and u can also look the technique up on the web.

endo
11-30-2001, 08:29 AM
you can use gluUnProject(...) to obtain the object coords and go from there. I did it recently for a circle and it seems to work well

Turbo_Pascal
12-01-2001, 09:46 AM
Originally posted by Bob:
With OpenGL, you can't, cause it doesn't provide any input functions at all.

well, opengl give you a powerfull way to know which polygon what clicke with the mouse.
However implementing this is requerid severals instrucctions.

The first one is used when you are drawing your scene,

Glloadname(1); //value 1 asigned
glbegin(gl_triangles)
vertex3f(x,y,x)
.
.
glend()

Glloadname(2); //value 2 asigned
glbegin(gl_triangles)
vertex3f(x,y,x)
.
.
glend()

The glloadname() function will assing a numeric value to all next opengl polys,

now when the user click on the polygon you have to render the scene using the gl_select mode

glRenderMode(GL_SELECT); //select mode
draw_scene; // draw scene.

then you get which numerics values was assigned for the poly that the user did click.

hits:= glRenderMode(GL_RENDER);

now check if "hits" is value 1 or 2.

**********************************
That was a resumed way to do this, but for implement that you have to do a lot more setups, but i least i am pointing you what instructions you have to check:

glloadname()
glGetIntegerv ();
glRenderMode();
glloadidentity();
gluPickMatrix();
gluperspective();
glInitNames;
glPushName();

or if you have acces to the red book (can be dowloaded somewhere) check the "select and feedbakc" section.


good luck

tp.