Swapping OpenGL's Y coordinates.

Member
Posts: 321
Joined: 2004.10
Post: #1
I've written an limited SVG (just path commands) to OpenGL parser and everything
works except the drawings are "reflected about the horizontal". Or is that rotated 180degress around the horizon in my openGL program. Here's a very rough ascii
"picture" of what's happening:

Code:
A  
BCD
E
==== becomes
E
BCD
     A

I believe I've seen a one line openGL command that can flip the Y coordinates.
but I can't find the code and I've been unsuccessful in phrasing my queries.

If this would fix my problem does anybody know this technique off the top of their heads?


Btw, is this a bug per se? or is it just that Adobe Illustrator and OpenGL has simply
defined their Y coordinates to be in different directions? Or is there something that
I should have done differently?

thanks!
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
glScalef(1, -1, 1); before you draw stuff.

or when you set up your projection matrix (instead of inverting the modelview matrix), with gluPerspective, gluOrtho etc, you are setting the coordinate system.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #3
Bingo! Thank You very much!

Quote:...before you draw stuff.

Minor quibble, but since OpenGL is a graphic's API, shouldn't this have been made the
default setting? Or does the fault lie with my drawing program when it save off the SVG file? Or is this just arbitrary decisions and I should just shut up and deal with it Smile

Isn't glScale(1,1,1) appropiate when sending text to window and incrementing y will cause text to be appended at bottom of existing text and thus be in same order as reading and writing?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
which way up y goes is irrelevant, given that you can change it so easily Rasp

Some graphics APIs (QuickDraw, Quartz, Java2D, etc) use y top-to-bottom. This is good for UIs, etc. where things tend to need to be relative to the top of the window.

Some graphics APIs (OpenGL, Postscript, Cocoa, etc) use y bottom-to-top. This is the "right" way mathematically...
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
OneSadCookie Wrote:Some graphics APIs (QuickDraw, Quartz, Java2D, etc) use y top-to-bottom..
Some graphics APIs (OpenGL, Postscript, Cocoa, etc) use y bottom-to-top..
Isn't divercity great, every time I try to do anything with graphics I have to do bloody y coordinate inversion thanks to apple's stupid non-standard coordinate system. Mad
Didn't they notice everyone was getting along fine with the book like coordinate system, inverting it kinda gets in the way of everything.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #6
unknown Wrote:Isn't divercity great, every time I try to do anything with graphics I have to do bloody y coordinate inversion thanks to apple's stupid non-standard coordinate system. Mad
Didn't they notice everyone was getting along fine with the book like coordinate system, inverting it kinda gets in the way of everything.
Ummm...

The old 2D coordinate system, with y going down, stems from the good old days when CRTs (TV) scanned from left to right and top to bottom (as that is the way the European languages are read).

Having y go up is the mathematically right way to do it, and since 3D APIs, such as OpenGL, rely heavily on linear algebra, that's how it is done. And that's how it should be done. Why some even relatively modern standards do it the other way around is a mystery to me.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #7
What you guys are calling "the right way to do it mathematically" is as arbitrary as anything else. Going bottom-to-top might make some mathematical elitists happy, and going top-to-bottom might make sense to someone thinking about text or the way the screen refreshes, but neither approach is more legitimate or "correct" than the other.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #8
If he's using an orthographic view, he could just as easily swap the top and bottom parameters and then he could have 0,0 at the top left. I do that for my UI layers in OpenGL. If he's doing this in a perspective view, then glScale probably is the only way.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  openal coordinates vs. opengl coordinates gerald 1 5,908 Feb 3, 2011 10:04 PM
Last Post: OneSadCookie
  Dynamically swapping between RAM and VRAM Shunter 7 3,703 May 22, 2009 11:44 AM
Last Post: backslash