Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glortho and the loony bin (2D)

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14

    glortho and the loony bin (2D)

    The latter is where I'm going because the former is driving me nuts!

    Unless I'm on a completely different page, this shouldn't too difficult. My current understanding of all this viewport, clipping area, drawing malarky is presently thusly:

    under resizeGL(int w, int h)

    I edit all my windows and viewing space and all that...

    Code :
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, this->width(), 0, this->height(), 1, 1);

    Then in paintGL() or whatever:

    Code :
    glMatrixMode(GL_MODELVIEW);

    and then away you go drawing to your hearts content.

    WRONG

    All I get is pain and misery.

    if I set up my screen as above, everything works, if I set it up -1,1, nothing works. My 2D print function has its own viewport etc setup which has
    Code :
        glOrtho(0, this->width(), 0, this->height(), -1, 1);

    This is all copy pasting which is quite dangerous, so now that I'm trying to get everything to work from scratch, nothing works. I'm trying to just have a simply pain function that draws everything in one fell swoop i.e. draw one object, then another on top, then text. I don't need nor want to faff around with various matricies when I'm drawing. My case is too simple for that, YET nothing works!

    If I set -1,1, my text doesnt show, if I set 1,1, my text doesn't show, however my other objects are drawn perfectly.

    WTH! glortho should be simple, with NO 0 z axis transforms at any stage, in any shape or form in my program, to my mind, all that will happen is, if you ask for an object to be drawn, it will be drawn at the 0 location of the Cartesian axis system (which basically totally makes no sense to me since when I set my far and close z axis thingies in glortho to 1,1 I'm able to see all the objects just fine, anyway... and then if you draw something after, it will simply be drawn on top of the previous object like a sticker on a page.

    Please let me know if I am indeed crazy and openGL doesn't work the way in which I described because presently, it's doing magic under the hood for me.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Atomic_Sheep View Post
    If I set -1,1, my text doesnt show, if I set 1,1, my text doesn't show, however my other objects are drawn perfectly.
    The far distance should be greater than the near distance. Having them equal will result in some of the matrix elements being infinite. If you're drawing 2D graphics with z=0, the near distance should be negative and the far distance positive.
    Quote Originally Posted by Atomic_Sheep View Post
    WTH! glortho should be simple, with NO 0 z axis transforms at any stage, in any shape or form in my program
    If you look at the glOrtho manual page, you'll note that having nearVal=-1 and farVal=1 results in the third row being [0 0 -1 0], i.e. zero translation and unit scale factor (all of the standard GL and GLU functions for creating projection matrices negate the Z coordinate so that the modelling coordinate system is right-handed, but if you're rendering everything in the z=0 plane, this doesn't matter).

    Quote Originally Posted by Atomic_Sheep View Post
    Please let me know if I am indeed crazy and openGL doesn't work the way in which I described because presently, it's doing magic under the hood for me.
    Post a minimal complete example.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •