Results 1 to 4 of 4

Thread: Going from ortho to perspective

  1. #1

    Going from ortho to perspective

    I have a working project of 2D texturemaps.
    Using glOrthof(0, 320 ,0, 480 , -1.0f, 1.0f); everything is fine and works as desired.

    I'd now like to be able to rotate some of the textures in x and y axis (flipping them on screen). (I'm already using the z-axis rotation)
    Of course this requires perspective since the ortho is crushing everything. (x and y rotations just show the images as a bar)
    If I switch out glOrthof and replace it with glFrustumf then no images show up.
    I've probably have been working so long I'm overlooking something obvious. It's been awhile since I've used OpenGL for 3D.
    Not planning to turn it into a full 3D model, just to be able to flip some flat images.

    I've tried different far/near parameters.
    Do I need to:
    setup depth buffers?
    glEnable(GL_DEPTH_TEST); ?
    glDepthFunc(GL_LEQUAL); ?

    glClear(GL_DEPTH_BUFFER_BIT); ?

    here's the basic texture drawing code:
    glBindTexture(GL_TEXTURE_2D, _name);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    Do I need to supply a different value for z (other than 0) in the texturemap vertices?


  2. #2
    Senior Member
    Join Date
    May 2006

    Re: Going from ortho to perspective

    You don't need to set up the depth buffer if you know in which order the objects should be drawn. You need a projection matrix that is equivalent to your orthoprojection at the Z-plane you are using. I assume it's Z=0, though I wonder why you're using 3-component vertex data.

    The exact values to use for glFrustumf depend on what field-of-view angle you want and the depth of the largest object you want to rotate (the view volume needs to be big enough so objects don't get clipped by the near and far planes). Then you need to add a translation to center the view volume on (160, 240, 0).
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum |

  3. #3

    Re: Going from ortho to perspective

    Thanks. I'll give it a try.

  4. #4

    Re: Going from ortho to perspective

    I ended up doing a translation as you suggested - I reversed the offsets and added a Z axis offset as well with experimentation


    gluPerspective(60, (GLfloat)320.0f/480.0f, 0.5f, 1500.0f);
    // routine I found on web which calculates glFrustumf as:
    // glFrustumf (-.1924, .1924, -.2886, 0.5f, 1500.0f);
    glTranslatef(-160, -240,-430); // correctly center


    I would assume there's a math formula to get the correct Z distance to match the default ortho
    but I haven't looked into it yet.

Similar Threads

  1. Perspective View
    By thesidisticme in forum OpenVG
    Replies: 3
    Last Post: 05-12-2010, 11:00 AM
  2. Perspective correction on Mali
    By himman in forum OpenGL ES
    Replies: 1
    Last Post: 01-06-2010, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean