Reputation: 6867
I'm creating an application in OpenGL in which I'm using glOrtho()
with origin in top left corner:
glOrtho(0.0, width, height, 0.0, 0.0, 1.0);
I haven't found it was wrong until I tried to render outline font, which appeared upside-down. After searching information about it, I came across site on which I read that my origin should start from bottom left corner.
I knew OpenGL is using bottom left corner origin, but I found it easier for me to use top left one. I just had to flip all textures horizontally and everything was ok. But yes, the problem appeared with those outline fonts which are appearing upside-down.
Now to change origin place, I'd have to change a bunch of code so if it's not necessary, I'd really like to avoid this.
So my question is: Is my approach with top left origin very wrong? And if not, is there any way to make those outline fonts appear properly?
Upvotes: 1
Views: 956
Reputation: 162317
Now to change origin place, I'd have to change a bunch of code so if it's not necessary, I'd really like to avoid this.
You can change the projectio whenever you like to. Use a origin in bottom left for your text, and origin in top left for everything else. You'll have to adjust for your text initial position being flipped, though, but that's not very difficult to take into account.
Or, you could simply apply a local scale(1,-1,1); to mirror the text upside down (depending on your text library this might interfere with its internal transformation setup though).
Upvotes: 2
Reputation: 17278
You are rendering that font somewhere, right? How are you rendering it, and what is stopping you from applying a vertical mirror transform matrix at that time?
I.e. if you are doing this the old-fashioned, obsolete way:
glScalef( 1, -1, 1 );
glCallList(font); // Or whatever you are doing to render the outline font
Or if you are using shaders, have your vertex Shader do something like this:
Vec4 position = aPosition;
position.y = -1 * position.y;
gl_Position = aMVPMatrix * position
This all being pseudo-code, of course.
Upvotes: 4
Reputation: 101
You can typically fix this without changing your data by using a proper texture matrix.
Upvotes: 1