Forum Discussion
webstorms
12 years agoHonored Guest
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
- cyberealityGrand ChampionYou 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.
- webstormsHonored GuestInstead 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. - iamdakHonored GuestParts 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.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 1 year ago
- 11 years ago
- 11 years ago