View Full Version : How to get mouse coordinates of only polygon area

04-08-2010, 03:33 AM
I have an image (jpg or gif). I open this image using opengl. Now using GL_POINTS & GL_LINES i create a polygon on this image. Now when i move my mouse cursor on image.
1)how do i know if my mouse cursor is inside the polygon or outside the polygon of that mage & i want the mouse coordinates of cursor if its inside the polygon?
2)i have few points displyed in the image. Now i create a polygon on the image such that it covers just few points of the image.
Now what i want is the mouse cursor coordinates of only those points which is inside the polygon not the whole image to be displayed..HOw is it?
Help me out as soon as possible

Andy Gilbert
04-08-2010, 03:43 AM
One easy way is use the glReadPixels function.

Check for it being not the background color?

Probably not a correct way but was just a thought. :)


04-08-2010, 03:56 AM
No i wont get using that...
i just want the mouse cursor coordinates of those points inside the polygon not the whole image points.
if you can please explain me an example or small code..
Or else if you know please tel me how to get or filter only data which is thier in the polygon not whole image..
the image data is stored in a file ..now what i want is the small portion of that image data.How do i get it. i mean using opengl cant we clip that polygon image data to whole image data & get it..I am very new to opengl..SO i dont know how to do ..Help me out..

04-08-2010, 05:28 AM
You could use the passive mouse function..print all the coordinates..(usng printf in case youre using C)

So you can get all the coodinates on the command prompt,

//The Mouse passive function
void Pass_Mouse(int x,int y)
printf("\n%d %d",x, (winh - y));
So the coords appear on the cmd prompt behind.
This is what i generally do to get the current mouse pos.
So basically note down the coordinates when youre in the polygon.Hope i asnwer your question

Im a neginner too..You said you opened .GIF images right? Can you plese explain how you did it??I opened bmps they were pretty simple.But i found the .gif format pretty complex.
Can you please share how you opened it?? Any links will also be really helpful.Thanks.

04-08-2010, 08:55 PM
Ya using passive function i am getting coordinates of everyting i mean whole image & even the polygon..But i just want to print the coordinates of only polygon not whole image that i am not getting..
Then i used bmp images not gif images..i coverted gif to bmp & used it..I opened bmp images..If you need to know how to open bmp images using opengl i shall tel you..

04-09-2010, 02:21 AM
You need all the points that make up the polygon, and the coordinates of the mouse, and then do a point-in-polygon test of the current mouse position with the polygon. If it passes, your mouse is in the polygon. If it fails, its not.

04-09-2010, 06:39 AM
Thanks Revathy, but i could open bmp images..I wanted to know about .gif

I have a problem creating a bmp though.ie im taking a 'screenshot' of the window using glReadpixels..But im not able to initialise the bmp headers properly,thus not able to create a standard bmp.

If you have tried it, it would be great if you could share about it.Thanks.

04-11-2010, 09:35 PM
Check out this links for opening a bmp image

* http://www.opengl.org/resources/faq/technical/fonts.htm
* http://freeglut.sourceforge.net/docs/api.php#FontRendering
* http://www.opengl.org/resources/features/fontsurvey/ (From 2004)
* http://www.opengl.org/wiki/Fonts
* http://quesoglc.sourceforge.net/