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

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


Case 2) Texture.

  • $\begingroup$ "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? $\endgroup$ – user1118321 Jul 28 '18 at 0:40
  • $\begingroup$ 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. $\endgroup$ – PaulHK Jul 28 '18 at 6:24
  • $\begingroup$ @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 $\endgroup$ – gallickgunner Jul 28 '18 at 10:22
  • $\begingroup$ 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) $\endgroup$ – PaulHK Jul 30 '18 at 2:10
  • $\begingroup$ 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. $\endgroup$ – gallickgunner Jul 30 '18 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.