PDA

View Full Version : Coordinates while drawing with OpenGL and GLUT



curiousOne
05-12-2010, 07:11 PM
Hello everyone!
I have a project in OpenGl (and GLUT), basically its an image editor. I have to have a pallet with 16 colors, a drawing area and some functions, like the Pixel Drawing (you click on the drawing area and it will draw a pixel which is the color of your choice)
There is also some other functions, but they don't really matter...
So, for me to know each area (the pallet area and the drawing area), I saved their coordinates in variables (as integers), and every time I click, I have a test to see if its on the drawing area or on the pallet (if its on the drawing area it will draw a pixel on the screen, if its on the pallet it will choose another color).
However, for some reason, my coordinates are completely out! The pixels are not drawn where I click, the color pallet is completely out and in a random spot, just as the drawing area.
I drew the graphic interface using the OpenGl vertex functions, and it came out just fine. I am sure I am testing with the right coordinates (I checked thousands of times), and the mouse coordinates are also correct (I tested it by printing them on the screen)
Anyone know what this problem might be?
My boyfriend told me that the GLUT coordinates are opposite to the OpenGL coordinates, but when I tried changing them, everything was still wrong.
I am thinking it has something to do with the GLUT coordinates, but I've tried everything, but so far nothing works! Does anyone know what it could be???
Thank you very much for any kind of help.

Dark Photon
05-13-2010, 07:07 AM
However, for some reason, my coordinates are completely out! The pixels are not drawn where I clickAnyone know what this problem might be?
Use gluUnProject to take window-space positions and map them back through your PROJECTION and MODELVIEW transforms to get an object-space position. Assuming the same MODELVIEW and PROJECTION is active when you're drawing the thing represented by the mouse clicks/drags, this'll give you the appropriate positions to draw.


My boyfriend told me that the GLUT coordinates are opposite to the OpenGL coordinates...
A quick search of the GLUT docs says that the x,y mouse position GLUT feeds you are relative to the upper-left being 0,0 and increasing down and to the right.

OpenGL window coordinates are indeed (IIRC) relative to the "lower"-left corner being 0,0.

So what you need to pass into gluUnProject is not the x,y mouse pos GLUT gives you, but rather x,(yres-1)-y.