Teen Programmers Unite  
 

 

Return to forum top

OpenGL Mouse Coordinates vs. Regular Thinking

Posted by 142857 [send private reply] at May 20, 2003, 09:08:07 PM

I am starting to use OpenGL, and when I get info from the mouse, it seems like the y is kind of inverted.

int winOut = 500; //size of window
//...
glOrtho(0, winOut, 0, winOut, -1, 1);
//...
void mouse(blah blah blah)
{
//now:
y = winOut - y; //just so I can work with it
//mouse starts from upper-left part of window, we think of window starting from lower-left. or maybe the other way around. but anyway...
//...
}

It seems wrong that I would have to do this. Is there something I'm doing wrong, or is this just how it has to be?

Thanks

Posted by AngelOD [send private reply] at May 21, 2003, 12:02:16 PM

"mouse starts from upper-left part of window, we think of window starting from lower-left."

Afaik it's quite normal for the mouse to start in the upper-left corner, atleast in 2D worlds. 3D is different, although the viewing space is, in 99.9% of the cases, still in 2D.

I'm definately not an expert on OpenGL (hardly know anything about it, though I'm considering learning it), but hey.. :o)

Posted by Psion [send private reply] at May 21, 2003, 01:02:44 PM

Who cares? You can't make any argument that either choice is "the natural way," so just convert as necessary. Library references should tell you what coordinate systems they use.

Posted by 142857 [send private reply] at May 21, 2003, 02:49:13 PM

ok thanks

Posted by CViper [send private reply] at May 21, 2003, 05:11:07 PM

In windows (0,0) is usually the top left corner. In OpenGL it really depends on how you define the viewport/projection.

I use gluOrtho2D( 0, width, height, 0 ), which makes the coordinate system in OpenGL identical to the one used by windows (ie. top-left is the origin, ...).

Posted by 142857 [send private reply] at May 21, 2003, 08:00:50 PM

Ah, CViper, okay.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.