strange issue with glOrthox and glFrustumx

Help
ffelagund
2005-02-07
2013-04-17
  • ffelagund

    ffelagund - 2005-02-07

    Hello, I'm getting a weird behaviour when I try to change the projection matrix. If i use glOrthox, I get a mesh rotating from right to left, but if I try glFrustumx, the axis seems inverted, because the rotation is left to right and I'm looking the mesh turned upside down. Here are the functions I'm using. Maybe anyone could help me :)
    (P.S: I tried these functions in a normal OpenGL application (without the fixed point part) and works as spected).

    void Perspective (GLfloat fovy, GLfloat aspect, GLfloat zNear,  GLfloat zFar)
    {
      GLfixed xmin, xmax, ymin, ymax, aspectFixed, znearFixed;    
     
      aspectFixed = FixedFromFloat(aspect);
      znearFixed = FixedFromFloat(zNear);

      ymax = MultiplyFixed(znearFixed, FixedFromFloat((GLfloat)tan(fovy * 3.1415962f / 360.0f))); 
      ymin = -ymax;

      xmin = MultiplyFixed(ymin, aspectFixed);
      xmax = MultiplyFixed(ymax, aspectFixed); 
      glFrustumx(xmin, xmax, ymin, ymax, znearFixed, FixedFromFloat(zFar));
    }
    //----------------------------------------------------------------------------
    void SetOrtho()
    {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();   
      glOrthox(FixedFromInt(-20), FixedFromInt(20),
               FixedFromInt(-20), FixedFromInt(20),
               FixedFromInt(20) , FixedFromInt(-20));
      glMatrixMode(GL_MODELVIEW);
      SetWindowText(hWnd, L"OpenGLES ortho");
    }
    //----------------------------------------------------------------------------
    void SetPerspective()
    {
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();     
      RECT r;
      GetWindowRect(hWnd, &r);   
      static float ratio = (float)(r.right - r.left)/(r.bottom - r.top);
      Perspective(45.0f,ratio, 1.0f, 40.0f);
      glMatrixMode(GL_MODELVIEW);
      SetWindowText(hWnd, L"OpenGLES perspective");
    }
    //----------------------------------------------------------------------------
    mesh rotation are obtained as is:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

      glLoadIdentity();
      if(!drawInOrtho)   
        glTranslatex(0, 0, FixedFromInt(-30));

      glRotatex(FixedFromInt(45), ONE, 0, 0);
      glRotatex(FixedFromInt(rotation++), 0, ONE,0);
    //draw mesh

     
    • Hans-Martin Will

      Interesting. Why again are you flipping the sign for the depth component in glOrthox?

      - HM

       
    • ffelagund

      ffelagund - 2005-02-09

      Well, it has a simple answer, I wrote this code after a long programming session (about 10h). Definitively, the error was the orthox parameters. Sorry for disturb with this noob question :)

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks