Results 1 to 7 of 7

Thread: [OpenGL/JEDI-SDL] Display Modes

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

    [OpenGL/JEDI-SDL] Display Modes

    I'm trying to expand my usage of OpenGL a little. I've been using OpenGL for ortho mode drawing only, however I'd like to get into some actual 3D stuff. So... I have some questions.

    How do I setup to draw in perspective mode with JEDI-SDL?

    How can I draw in both Ortho and perspective mode one after the other in one frame? I'd like to draw in perspective then ortho on top.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2

    Re: [OpenGL/JEDI-SDL] Display Modes

    Hi WILL

    I use the routines below to switch between 3d and 2d (ortho) views.

    [pascal]
    Procedure TRenderEngineGL.Set3dView(FOV,NearPlane,FarPlane: Single);
    Begin
    // 3d view.
    glMatrixMode(GL_PROJECTION); // Select the projection matrix.
    glLoadIdentity; // Reset the projection matrix.

    // Set up the perspective projection matrix
    gluPerspective(FOV,FWidth/FHeight,NearPlane,FarPlane);

    glMatrixMode(GL_MODELVIEW); // Select the modelview matrix.
    glLoadIdentity; // Reset the modelview matrix.
    End;
    {................................................. ......}

    {................................................. ......}
    Procedure TRenderEngineGL.Set2dView;
    Begin
    glMatrixMode(GL_PROJECTION); // Select the projection matrix.
    glLoadIdentity; // Reset the projection matrix.

    // Set up the perspective projection matrix.
    gluOrtho2d(0,FWidth,FHeight,0);

    glMatrixMode(GL_MODELVIEW); // Select the modelview matrix.
    glLoadIdentity; // Reset the modelview matrix.
    End;
    [/pascal]

    Use like so:

    Code:
    Set3dView(...);
    //draw 3d scene
    Set2dView;
    Where :

    FWidth and FHeight are the size of my window where the opengl graphics are being drawn.
    FOV is the vertical field of view...eg. 45 degrees
    NearPlane (near clipping plane) = a value > 0...eg. 0.1
    FarPlane (far clipping plane) = a value > NearPlane...eg. 1000

    I hope this helps you
    cheers,
    Paul

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

    Re: [OpenGL/JEDI-SDL] Display Modes

    Thanks Paul your advice helped a lot. I actually learned a lot while playing around with this stuff. Here is a follow-up question though; what's the trick to drawing in ortho mode on top of an already drawn 3D view? What functions do I have to avoid and what's my limitations?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #4

    Re: [OpenGL/JEDI-SDL] Display Modes

    You must make sure that you are certain wether you draw the 2d stuff without depth testing or not. Typically you would draw 2d stuff without depth testing and just render it back to front. Either that or clear the depth buffer after you've done your 3d stuff, and then render your 2d stuff with z coordinates
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  5. #5

    Re: [OpenGL/JEDI-SDL] Display Modes

    Quote Originally Posted by JSoftware
    You must make sure that you are certain wether you draw the 2d stuff without depth testing or not. Typically you would draw 2d stuff without depth testing and just render it back to front. Either that or clear the depth buffer after you've done your 3d stuff, and then render your 2d stuff with z coordinates
    I couldn't have said it better myself

    cheers,
    Paul

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

    Re: [OpenGL/JEDI-SDL] Display Modes

    I've figure out how to do this now. You guys are right about the depth. I had to adjust my own graphics unit so that when I switched to Ortho mode it would set the farthest depth distance back enough that I can still see what I drew.

    Thanks guys!
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #7

    Re: [OpenGL/JEDI-SDL] Display Modes

    Quote Originally Posted by WILL
    I've figure out how to do this now. You guys are right about the depth. I had to adjust my own graphics unit so that when I switched to Ortho mode it would set the farthest depth distance back enough that I can still see what I drew.

    Thanks guys!
    Glad to help chief
    cheers,
    Paul

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
  •