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: Perspective projection stretches at -certain- aspect ratios?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    20

    Perspective projection stretches at -certain- aspect ratios?

    (Stretches horizontally, that is.)

    I've been developing my demo in 640x480, and all along it has looked a little stretched (my cube is maybe 10-15% broader than it is tall) when running in a window. My desktop native res is 1680x1050, FWIW.

    After spending a while checking my manually-constructed perspective projection matrix, and thinking I needed a post-step to convert to window coordinates -- till I read somewhere that this is done in the pipeline between the vertex and fragment shaders (not sure if this is true).

    So I changed the window resolution, and suddenly, at 640x320, everything looks fine. So does it at any 2:1 ratio. (1:1 goes without saying.) If I set the window to 840x525 (half my desktop res in x and y), I get a very wide, spinning cube (looks about 2:1).

    What is going on? FWIW, here's my perspective projection:
    Code :
     
        public Matrix4 getStandardProjectionMatrix(float fovYDeg, float aspectRatio, float near, float far)
        {
            Matrix4 result = new Matrix4();
     
            float fovYRad = fovYDeg * 180f / (float)PI; 
            float d = 1f/(float)(tan(fovYRad / 2));
     
     
            result.val[Matrix4.M00] = d / aspectRatio;
            result.val[Matrix4.M11] = d;
            result.val[Matrix4.M22] = (far + near) / (near - far);
            result.val[Matrix4.M23] = (2 * far * near) / (near - far);
            result.val[Matrix4.M32] = -1f;
     
            return result;
        }
     
        private void render()
        {    
            ...
            projectionMatrix = getStandardProjectionMatrix(60f, DISPLAY_WIDTH/DISPLAY_HEIGHT, 0.1f, 10000f);
            mvpMatrix = projectionMatrix.mul(viewMatrix.mul(modelMatrix));
            ...
        }

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    20
    Sorted -- it was this.

Posting Permissions

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