Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:18:49+00:00 2026-05-27T12:18:49+00:00

This question changed a lot since it was first asked because I didn’t understand

  • 0

This question changed a lot since it was first asked because I didn’t understand how little I knew about what I was asking. And one issue, regarding resizing, was clouding my ability to understand the larger issue of creating and using the framebuffer. If you just need a framebuffer jump to the answer… for history I’ve left the original question intact.


Newbie question. I’ve got a GL project I’m working on and am trying to develop a selection strategy using unique colors. Most discussion/tutorials revolve around drawing the selectable entities in the back buffer and calculating the selection when a user clicks somewhere. I want the selection buffer to be persistent so I can quickly calculate hits on any mouse movement and will not redraw the selection buffer unless display or object geometry changes.

It would seem that the best choice would be a dedicated framebuffer object. Here’s my issue. On top of being completely new to framebuffer objects, I am curious. Am I better off deleting and recreating the frambuffer object on window size events or creating it once at the maximum screen resolution and then using what may be just a small portion of it. I’ve got my events working properly to only call the framebuffer routine once for what could be a stream of many resize events, yet I’m concerned about GPU memory fragmentation, or other issues, recreating the buffer, possibly many times.

Also, will a framebuffer object (texture & depth) even behave coherently when using just a portion of it.

Ideas? Am I completely offbase?

EDIT:
I’ve got my framebuffer object setup and working now at the windows dimensions, and I resize it with the window. I think my issue was classic “overthink”. While it is certainly true that deleting/recreating objects on the GPU should be avoided when possible. As long as it is handled correctly the resizes are relatively few.

What I found works is to set a flag and mark the buffer as dirty on window resize, then wait for a normal mouse event before resizing the buffer. A normal mouse enter or move signals you’re done dragging the window to size and are ready to get back to work. The buffers recreated once. Also, since the main framebuffer is generally resized for every window size event in the pipeline, it would stand to reason that resizing a framebuffer isn’t going to burn a hole in your laptop.

Crisis averted, carry on!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:18:50+00:00Added an answer on May 27, 2026 at 12:18 pm

    I mentioned in the question that I was overthinking the problem. The main reason for that is because the problem was bigger than the question. The problem was, not only did I not know how to control the framebuffer, I didn’t know how to create one. There are so many options and none of the web resources seemed to specifically address what I was trying do, so I struggled with it. If you’re also struggling with how to move your selection routine to a unique color scheme with a persistent buffer, or are just at a complete loss as to framebuffers and offscreen rendering, read on.

    I’ve got my OpenGL canvas defined as a class, and I needed a “Selection Buffer Object.” I added this to the private members of the class.

    unsigned int sbo;
    unsigned int sbo_pixels;
    unsigned int sbo_depth;
    bool sbo_dirty;
    void setSelectionBuffer();
    

    In both my resize handler and OpenGL initialization I set the dirty flag for the selection buffer.

    sbo_dirty = true;
    

    At the begining of my mouse handler I check for the dirty bit and setSelectionBuffer(); if appropriate.

    if(sbo_dirty) setSelectionBuffer();
    

    This tackles my initial concerns about multiple delete/recreates of the buffer. The selection buffer isn’t resized until the mouse pointer reenters the client area, after resizing the window. Now I just had to figure out the buffer…

    void BFX_Canvas::setSelectionBuffer()
    {
        if(sbo != 0) // delete current selection buffer if it exists
        {
            glDeleteFramebuffersEXT(1, &sbo);
            glDeleteRenderbuffersEXT(1, &sbo_depth);
            glDeleteRenderbuffersEXT(1, &sbo_pixels);
            sbo = 0;
        }
    
        // create depth renderbuffer
        glGenRenderbuffersEXT(1, &sbo_depth);
        // bind to new renderbuffer
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, sbo_depth);
        // Set storage for depth component, with width and height of the canvas
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, canvas_width, canvas_height);
        // Set it up for framebuffer attachment
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, sbo_depth);
        // rebind to default renderbuffer
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    
        // create pixel renderbuffer
        glGenRenderbuffersEXT(1, &sbo_pixels);
        // bind to new renderbuffer
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, sbo_pixels);
        // Create RGB storage space(you might want RGBA), with width and height of the canvas
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, canvas_width, canvas_height);
        // Set it up for framebuffer attachment
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, sbo_pixels);
        // rebind to default renderbuffer
        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    
        // create framebuffer object
        glGenFramebuffersEXT(1, &sbo);
        // Bind our new framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sbo);
        // Attach our pixel renderbuffer
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, sbo_pixels);
        // Attach our depth renderbuffer
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, sbo_depth);
    
        // Check that the wheels haven't come off
        GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
        if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
        {
            // something went wrong
            // Output an error to the console
            cout << "Selection buffer creation failed" << endl;
            // restablish a coherent state and return
            glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
            sbo_dirty = false;
            sbo = 0;
            return;
        }
    
        // rebind back to default framebuffer
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
        // cleanup and go home
        sbo_dirty = false;
        Refresh(); // force a screen draw
    }
    

    Then at the end of my render function I test for the sbo, and draw to it if it seems to be ready.

    if((sbo) && (!sbo_dirty)) // test that sbo exists and is ready
    {
        // disable anything that's going to affect color such as...
        glDisable(GL_LIGHTING);
        glDisable(GL_LINE_SMOOTH);
        glDisable(GL_POINT_SMOOTH);
        glDisable(GL_POLYGON_SMOOTH);
    
        // bind to our selection buffer
        // it inherits current transforms/rotations
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sbo);
        // clear it
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        // draw selectables
        // for now i'm just drawing my object
        if (object) object->draw();
    
        // reenable that stuff from before
        glEnable(GL_POLYGON_SMOOTH);
        glEnable(GL_POINT_SMOOTH);
        glEnable(GL_LINE_SMOOTH);
        glEnable(GL_LIGHTING);
    
        // blit to default framebuffer just to see what's going on
        // delete this bit once selection is setup and working properly.
        glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, sbo);
        glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
        glBlitFramebufferEXT(0, 0, canvas_width, canvas_height,
                             0, 0, canvas_width/3, canvas_height/3,
                             GL_COLOR_BUFFER_BIT, GL_LINEAR);
    
        // We're done here, bind back to default buffer.
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    }
    

    That gives me this…

    screenshot

    At this point I believe everything is in place to actually draw selectable items to the buffer, and use mouse move events to test for hits. And I’ve got an onscreen thumbnail to show how bad things are blowing up.

    I hope this was as big a help to you, as it would have been to me a week ago. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: Facebook's API has changed a lot since this question was posted. This question
I have already posted a question about this, but the situation has changed sufficiently
First of all, I know there are a lot of questions about this topic.
I know this isn't a programming question, but since a lot of people here
I have previously asked this question and since I already accepted an answer, I
This question is connected to my other question but I changed the logic a
This question is about programming small microcontrollers without an OS. In particular, I'm interested
First of all, I apologize for yet another interface question. I thought that this
This is my fourth question here in about two weeks... I think I have
This is not exactly a technical question, since I know C kind of enough

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.