<p>Consider a ray tracer written in OpenGL and using GLFW as a window toolkit. There are basically 2 options to display the ray-traced image.</p>

<p><strong>1) Create a <code>RenderBuffer</code> with image and blit this to the default framebuffer.</strong></p>

<p><strong>2) Render the scene to a texture and use a full screen quad to display that texture.</strong></p>

<p>What if I want to render the scene in a resolution that is different from the window size? How do I handle rescaling of images.</p>

<p><strong>Case 1)</strong> Render to high resolution image/texture and display to low resolution window.</p>

<p>I don't know how should I handle for downscaling the texture/image in both cases. I am particularly interested in the <code>Renderbuffer</code> approach though. </p>

<p><strong>Case 2)</strong> Render to low resolution image/texture and display to high resolution window.</p>

<p>I am pretty sure case 2 could be easy to implement through textures by setting the filter to <code>LINEAR</code> or <code>NEAREST</code> perhaps, the sampling function would automatically upscale it?</p>

<p>I am not sure what would happen to the renderBuffer approach in either case. I have read though that <code>Blit</code> between buffers of different sizes are supported.</p>

<p>Also in both cases, how would I handle the aspect ratio?</p>

<p><strong>EDIT</strong>:- What I mean by handling aspect ratio is, to my knowledge there are two ways I could handle it. </p>

<p>1) Either stretch the whole image to fit the window.</p>

<p>2) Or make it "fit" to the window like Windows 7 wallpaper setting. This way the original aspect ratio of the Image will be maintained. Any space not covered by the image would be black in the window.</p>

<p>Here is a crappy painting to show what I mean.</p>

<p><a href="https://i.sstatic.net/GvnOF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GvnOF.png" alt="enter image description here"></a></p>

<p>Now if the Red window is my RBO/Texture  and Black Window is the actual window ( default framebuffer) opened by GLFW. Left and right show two cases when either the RBO is greater or smaller than the default framebuffer with varying aspect ratio.</p>

<p>There are two ways, Either fit or stretch. I want to know if OpenGL provides functions for these sorts of settings or it does some or part of these things automatically. Plus I want to know this thing for both </p>

<p>Case 1) RBO </p>

<p>and </p>

<p>Case 2) Texture. </p>

CC BY-SA 4.0
2018-07-28T00:40:39.677Z
"how would I handle the aspect ratio?" How do you want to handle it? You can fit it all in. You can do a uniform scale until the output is filled. You can non-uniformly stretch in an infinite number of ways. What do you want the output to look like?
user1118321
CC BY-SA 4.0
2018-07-28T06:24:22.327Z
Aspect ratio should be independent of render target resolution. You would render to your texture using information from your view frustum (view-projection matrix) which contains the aspect ratio, this should be set to the same aspect ratio as your window. That will ensure once the texture is stretched to your window it will have a matching aspect ratio.
PaulHK
CC BY-SA 4.0
2018-07-28T10:22:03.883Z
@user1118321 - Check my edited post.
and, PaulHK - Yes the kernel will use the view frustum's aspect ratio. I want to know if OpenGL automatically stretches or is there a function for this. Refer to the update post
gallickgunner
CC BY-SA 4.0
2018-07-30T02:10:58.683Z
OpenGL doesn't come with any functions to match aspect ratios. In your case you may just want to draw a fullscreen quad, which is the easiest primitive to setup (vertices are NDC coords between -1 to 1, no transformation in vertex shader required)
PaulHK
CC BY-SA 4.0
2018-07-30T02:14:46.750Z
Hmm, isn't there any other method (I mean an algorithm not openGL function) to fit the image maintaining the aspect ratio? As in a way of determining the amount of space covered by a particular resolution image in a particular low size window when made to fit to the window.
gallickgunner
CC BY-SA 4.0
2018-07-30T02:39:56.820Z
Thanks - I'll look into it. Also what in your opinion would be faster. blitting once or texturing on quad. While the first lets me bypass the shader pipeline, I've heard that blitting is slow. Some people say it's faster tho.
gallickgunner
<opengl><texture><image>
OpenGL - Fit High/Low Resolution Image/Texture to a particular size Window
gallickgunner
# OpenGL - Fit High/Low Resolution Image/Texture to a particular size Window

(Asked by: username_0 on 2018-07-27)

Consider a ray tracer written in OpenGL and using GLFW as a window toolkit. There are basically 2 options to display the ray-traced image.

**1) Create a `RenderBuffer` with image and blit this to the default framebuffer.**

**2) Render the scene to a texture and use a full screen quad to display that texture.**

What if I want to render the scene in a resolution that is different from the window size? How do I handle rescaling of images.

**Case 1)** Render to high resolution image/texture and display to low resolution window.

I don't know how should I handle for downscaling the texture/image in both cases. I am particularly interested in the `Renderbuffer` approach though.

**Case 2)** Render to low resolution image/texture and display to high resolution window.

I am pretty sure case 2 could be easy to implement through textures by setting the filter to `LINEAR` or `NEAREST` perhaps, the sampling function would automatically upscale it?

I am not sure what would happen to the renderBuffer approach in either case. I have read though that `Blit` between buffers of different sizes are supported.

Also in both cases, how would I handle the aspect ratio?

**EDIT**:- What I mean by handling aspect ratio is, to my knowledge there are two ways I could handle it.

1) Either stretch the whole image to fit the window.

2) Or make it "fit" to the window like Windows 7 wallpaper setting. This way the original aspect ratio of the Image will be maintained. Any space not covered by the image would be black in the window.

Here is a crappy painting to show what I mean.

[![enter image description here](https://i.sstatic.net/GvnOF.png)](https://i.sstatic.net/GvnOF.png)

Now if the Red window is my RBO/Texture and Black Window is the actual window ( default framebuffer) opened by GLFW. Left and right show two cases when either the RBO is greater or smaller than the default framebuffer with varying aspect ratio.

There are two ways, Either fit or stretch. I want to know if OpenGL provides functions for these sorts of settings or it does some or part of these things automatically. Plus I want to know this thing for both

Case 1) RBO

and

Case 2) Texture.

**Tags:** opengl, texture, image

> **Comments:**
> **username_1**: "how would I handle the aspect ratio?" How do you want to handle it? You can fit it all in. You can do a uniform scale until the output is filled. You can non-uniformly stretch in an infinite number of ways. What do you want the output to look like?  
> **username_2**: Aspect ratio should be independent of render target resolution. You would render to your texture using information from your view frustum (view-projection matrix) which contains the aspect ratio, this should be set to the same aspect ratio as your window. That will ensure once the texture is stretched to your window it will have a matching aspect ratio.  
> **username_0**: @username_1 - Check my edited post. and, username_2 - Yes the kernel will use the view frustum's aspect ratio. I want to know if OpenGL automatically stretches or is there a function for this. Refer to the update post  
> **username_2**: OpenGL doesn't come with any functions to match aspect ratios. In your case you may just want to draw a fullscreen quad, which is the easiest primitive to setup (vertices are NDC coords between -1 to 1, no transformation in vertex shader required)  
> **username_0**: Hmm, isn't there any other method (I mean an algorithm not openGL function) to fit the image maintaining the aspect ratio? As in a way of determining the amount of space covered by a particular resolution image in a particular low size window when made to fit to the window.  
> **username_0**: Thanks - I'll look into it. Also what in your opinion would be faster. blitting once or texturing on quad. While the first lets me bypass the shader pipeline, I've heard that blitting is slow. Some people say it's faster tho.  

---

## 0 answers

