Results 1 to 9 of 9

Thread: Creating Low resolution output using glBlitFrameBuffer

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    13

    Creating Low resolution output using glBlitFrameBuffer

    Totally noob on this but this is what I have:

    Code :
    glBindFramebuffer(GL_READ_FRAMEBUFFER , 0);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo[0]);
    glBlitFramebuffer(0, 0, 640, 480, 0, 0, 320, 240, GL_COLOR_BUFFER_BIT , GL_NEAREST);
     
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo[0]);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER , 0);
    glBlitFramebuffer(0, 0, 320, 240, 0, 0, 640, 480, GL_COLOR_BUFFER_BIT, GL_NEAREST);

    My thought are that I first set FBO:'0' to be read from and FBO:'fbo[0]' to be drawn onto.

    Then I take a 640x480 frame from '0' and draw it on a small 320x240 frame on 'fbo[0]'.

    Then I switch READ/DRAW and take the little 320x240 frame and draw it onto '0' as a 640x480 frame.

    Maybe I completely don't understand how this works since the code does nothing to the output.

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    -- render into your low-res FBO, then copy the content onto the screen
    Code :
    /* render to low-res FBO */
    glViewport(0, 0, mywidth, myheight);
    glBindFramebuffer(GL_FRAMEBUFFER, myfbo);
     
    ... render here ...
     
    /* copy to screen */
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glBlitFramebuffer(
    0, 0, mywidth, myheight,
    0, 0, screenwidth, screenheight,
    GL_COLOR_BUFFER_BIT, GL_NEAREST);

    check for GL errors + FBO completeness
    https://www.khronos.org/opengl/wiki/OpenGL_Error
    https://www.khronos.org/opengl/wiki/...mebufferStatus

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    13
    Nothing gets drawn:

    Code :
    	glClear(GL_COLOR_BUFFER_BIT);
     
    	/* render to low-res FBO */
    	glViewport(0, 0, RES_WIDTH, RES_HEIGHT);
    	glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);
     
    	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(triangle), triangle, GL_STATIC_DRAW);
    	glEnableVertexAttribArray(0);
    	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
    	glDrawArrays(GL_TRIANGLES, 0, 3);
    	glDisableVertexAttribArray(0);
     
    	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    	glBlitFramebuffer(
    		0, 0, RES_WIDTH, RES_HEIGHT,
    		0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
    		GL_COLOR_BUFFER_BIT, GL_NEAREST);
     
    	glutSwapBuffers();
     
    	glutPostRedisplay();

  4. #4
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    do you have a valid framebuffer object with a color attachment ? how did you build "fbo[0]" ? the code looks OK so far

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    13
    changed fbo[0] to fbo

    Code :
    GLuint fbo;
    glGenFramebuffers(1, &fbo);
    printf("FBO: %d\n", fbo);
    output: 1

    I don't know about color attatchment. Googled a bunch but there's almost always seems to be a "texture" example which I dont know how to translate to this.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,100
    A framebuffer object (created with glGenFramebuffers) is just a container; you have to create the drawing "surfaces" (textures or renderbuffers) separately, then attach them with glFramebufferTexture2D or glFramebufferRenderbuffer.

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    13
    That works! Thanks! here's the the whole fbo init if someone else needs
    (texture stuff's copied from a tutorial, maybe I can delete some to make it cleaner?)
    :
    Code :
    	glGenFramebuffers(1, &fbo);
    	printf("FBO: %d\n", fbo);
    	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    	// The texture we're going to render to
    	GLuint renderedTexture;
    	glGenTextures(1, &renderedTexture);
     
    	// "Bind" the newly created texture : all future texture functions will modify this texture
    	glBindTexture(GL_TEXTURE_2D, renderedTexture);
     
    	// Give an empty image to OpenGL ( the last "0" )
    	glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, RES_WIDTH, RES_HEIGHT, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);
     
    	// Poor filtering. Needed !
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
    	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0);
     
    	// Set the list of draw buffers.
    	GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
    	glDrawBuffers(1, DrawBuffers); // "1" is the size of DrawBuffers

    EDIT: Yes glTexParameteri and draw buffers could be removed

  8. #8
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    maybe you find this FBO-related list of code examples useful:
    -- renderbuffer
    -- viewport
    -- scaling
    -- MultiRenderTargets (renderbuffers)
    -- depth / stencil
    -- depth / stencil (textures)
    -- multisample (textures)

    there are also several books out there with useful examples:
    https://www.khronos.org/developers/books
    (hint: some of them can be found as .pdf online)

    the wiki has also examples:
    https://www.khronos.org/opengl/wiki/...nsion_Examples

    some tutorials are really good, others a bit difficult to understand:
    https://sites.google.com/site/john87connor/home


    @ texparameters:
    if you want to sample from those textures later, you have to set proper texparameters

    @ glDrawbuffer(s):
    if you have more that 1 color attachment, you have to specify in which you want to render

    @ glReadBuffer():
    if you have more that 1 color attachment, you have to specify from which you want to read

    both, glReadBuffer and glDrawBuffer(s) will be stored in the FBO
    https://www.khronos.org/opengl/wiki/...ject_Structure

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2017
    Posts
    13
    Cool thanks john!

Similar Threads

  1. Replies: 9
    Last Post: 07-03-2012, 06:30 AM
  2. glBlitFramebuffer tip
    By skynet in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-25-2010, 07:25 AM
  3. Creating a window bigger than the screen resolution
    By imported_dimensionX in forum OpenGL: GLSL
    Replies: 5
    Last Post: 03-04-2005, 06:50 PM
  4. Frame buffer resolution with high resolution textures ?
    By totof in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-25-2003, 06:26 AM
  5. High resolution ploting of OpenGL Output
    By fstaats in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-17-2002, 03:54 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
  •  
Proudly hosted by Digital Ocean