Imagine I have a window of 1280x720 and I have an FBO of the same size. When drawing my scene, I draw it to my FBO using glViewport(640,360,1280,720) which is the top right corner of the window. Now I want to draw the top right corner of the FBO in the bottom left corner of the back buffer. I set glViewport(0,0,640,360). What else should I do?
I’ve been battling over this the past couple of days and I think it may be something really simple but I can’t picture it right now.
Here’s my ideas:
1. Create a rectangle from (0,0,0) to (1280,720,0) and UV coordinates from (0,0) to (1,1). Set projection matrix as
glm::ortho(640,360,1280,720,-1,1);
and no view matrix (identity), which will effectively render the top right corner of the rectangle with UV coordinates from (0.5,0.5) to (1,1) if I use texture()
, which I can use to access the FBO’s texture for each pixel to get the correct colour. gl_FragCoord
would only give me coordinates from (0,0) to (640,360) so it’s rather useless here. Is this correct?
2. Create a rectangle from (0,0,0) to (1280,720,0) and UV coordinates from (0,0) to (1280,720). Set same matrices as (1) but this time getting UV coordinates from (640,360) to (1280,720) and thus using texelFetch()
to get the correct colour for my pixel. Is this EQUALLY correct? What’s the difference between these two approaches, really?
3. I think now it gets overly complicated for no reason: Create a rectangle from (0,0,0) to (1,1,0) and UV coordinates from (0,0) to (1,1). Set projection as
glm::ortho(0.5,1,0.5,1,-1,1);
which will effectively render the top right corner of the rectangle with UV coordinates from (0.5,0.5) to (1,1). Then using texture()
to get the colour values of the top right corner of the texture attached to the FBO. Is this ALSO correct?
That sure seems like a lot of ways to do the same thing. If so, wouldn’t I benefit from using (3) due to the fact that I don’t need to know the size of my FBO and all I really need to do is provide a viewport in terms of ratios?
Let me know what you think.