Results 1 to 3 of 3

Thread: [OpenGL] 3D Objects and Effects in Ortho

  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    [OpenGL] 3D Objects and Effects in Ortho

    Hey does anyone know how to go about drawing something in 3D in Ortho mode? I'm having a bit of trouble. My standard way of setting up Ortho Mode doesn't seem to allow this.

    I use the following...

    Code:
    procedure BeginOrtho;
    var
     Width, Height: Single;
     ViewPort: TViewPortArray;
    begin
       glGetIntegerv(GL_VIEWPORT, @ViewPort[0]);
       Width := ViewPort[2];
       Height := ViewPort[3];
    
       glDisable(GL_DEPTH_TEST);       //turn off z buffer
       glMatrixMode(GL_PROJECTION);     //set projection matrix
       glPushMatrix;             //push it
       glLoadIdentity();           //reset
       glOrtho(0, Width, Height, 0, 0, 100); //ortho view
       glMatrixMode(GL_MODELVIEW);      //return to modelview
       glLoadIdentity();           //reset
    end;
    
    procedure EndOrtho;
    begin
       glEnable(GL_DEPTH_TEST);        //turn on z buffer
       glMatrixMode(GL_PROJECTION);      //set projection matrix
       glPopMatrix;              //restore projection
       glMatrixMode(GL_MODELVIEW);       //set modelview matrix
       glLoadIdentity();            //reset
    end;
    I then would use it somewhat like this...

    Code:
    BeginOrtho;
        glPushMatrix;                //Save Current Matrix
         glTranslatef((ScreenWidth div 2 - TileSize div 2) - (Player.X * TileSize) + ScreenX,
               (ScreenHeight div 2 - TileSize div 2) - (Player.Y * TileSize) + ScreenY, 0);
         if (OLD_WATER) then
          glCallList(List_DrawWater[AniCounter mod 18]);
         glCallList(List_DrawFloor);
         glCallList(List_DrawSwitches);
        glPopMatrix;
    EndOrtho;
    Any ideas or information appreciated. Thanks.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2

    Re: [OpenGL] 3D Objects and Effects in Ortho

    What is not working? E.g. you cannot draw 3d in ortho mode. You can however use the z buffer for layering 2D.
    I do not like your glortho setup. You could try this:
    Code:
    glViewport(0,0,800,600); //optional
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,800,0,600,-100,100);
    glMatrixMode(GL_MODELVIEW);
    http://3das.noeska.com - create adventure games without programming

  3. #3
    PGDCE Developer de_jean_7777's Avatar
    Join Date
    Nov 2006
    Location
    Bosnia and Herzegovina (Herzegovina)
    Posts
    287

    Re: [OpenGL] 3D Objects and Effects in Ortho

    E.g. you cannot draw 3d in ortho mode.
    As I understand ortho(orthographic) mode, you should be able to render 3D objects in it, though there is no perspective(things do not get smaller with distance). You render it the way you normally do for perspective projections.

    The trick is in the glOrtho() call as this sets up your viewing frustum. The glOrtho call is like this:
    Code:
    procedure glOrtho(left, right, bottom, top, near, far: GLdouble);
    You must make sure you render your model within the coordinates(frustum) you passed to the glOrtho call, and that your model fits into the frustum. Any polygons outside the frustum are not rendered. This requires a bit of experimentation.

    For 3D rendering with ortho I usually do this glOrtho(-x, x, -y, y, znear, zfar) where x is the half the frustum width, y is half the frustum height. znear and zfar is the frustum length(starting and ending point). The orthographic frustum is a box, unlike the perspective frustum which usually widens with depth.

    Other than the frustum, there is no difference with perspective and orthographic projection when it comes to rendering. For example, the Blender program can use both perspective and ortographic projections to render the scene and all models there are(it's 3D in either case).
    Existence is pain

Bookmarks

Posting Permissions

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