Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: FBOs and Viewports

Threaded View

  1. #1

    FBOs and Viewports

    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
    Code :
    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
    Code :
    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.
    Last edited by FrankBoltzmann; 07-13-2014 at 05:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •