Skip to main content
New Participant
October 2, 2013

Zoom out

Currently when I display a texture/image to the screen, it seems so close to me. Is there a trick to zoom out and make the image appear further away? Or does the image appear so near because of the image itself? (Note: I do want the image to fill the entire screen).

    3 replies

    Inspiring
    October 2, 2013
    You should not be drawing images directly onto the screen. You should create a 3D quad, and apply the texture to it. Then you can position the quad as near or far from the camera as you want.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    webstormsAuthor
    New Participant
    October 3, 2013
    Instead of using a cube and rendering the texture to it and moving in backwards to achieve a zoomed out effect, I rather wrote this simple method to take care of this:

    private void renderImage(Rectangle dst, float magnification) {
    float width, height;
    float horizontalOffset, verticalOffset;

    // Default: Fill screen horizontally
    width = 1f;
    height = dst.getHeight()/(float) dst.getWidth();


    // magnification
    width *= magnification;
    height *= magnification;

    // Offsets
    horizontalOffset = width/2f;
    verticalOffset = height/2f;

    // Do the actual OpenGL rendering
    glBegin (GL_QUADS);
    // Right top
    glTexCoord2f(0.0f, 0.0f);
    glVertex2f(-0.5f + horizontalOffset, verticalOffset);

    // Right bottom
    glTexCoord2f(0.0f, 1.0f);
    glVertex2f(-0.5f + horizontalOffset, -verticalOffset);

    // Left bottom
    glTexCoord2f(1.0f,1.0f);
    glVertex2f(-0.5f - horizontalOffset, -verticalOffset);

    // Left top
    glTexCoord2f(1.0f, 0.0f);
    glVertex2f(-0.5f - horizontalOffset, verticalOffset);
    glEnd();

    }


    The only problem is that the image seems to be stretched along the horizontal axis.
    New Participant
    October 4, 2013
    Parts of your code doesn't makes sense, but its close. Assuming you aren't applying any transformation matrices, your geometry will render points within the bounds of -1 <= x <= +1 and -1 <= y <= +1. If you were to render the points:

    (1,1) (-1,1) (-1,-1) (1,-1)

    Then you would get a quad that fills the screen perfectly but it may be too wide if you're using a standard aspect ratio. To correct for this, we'll keep the vertical axis alone and squeeze the horizontal axis by the aspect ratio. We can say the following:

    AR = ScreenHeight / ScreenWidth

    Then set that as our x value:

    (AR, 1) (-AR, 1) (-AR, -1) (AR, -1)

    This will take our full screen quad and squeeze it into a perfectly square quad. Next, for the magnification you just want to multiply by some scalar:

    zoom = 1.0
    (AR * zoom, zoom) (-AR * zoom, zoom) (-AR * zoom, -zoom) (AR * zoom, -zoom)

    And you're done! If you wanted to render twice for the rift, you can add a translation value to the coordinates and render twice. Working with matrices will beak down the exactly the same math but your way works well for simple applications.

    Good luck.