I am not well versed with openGL, but I am currently working on a code which uses the technology to draw buildings on a canvas. The old implementation was only for loading/drawing buildings previously defined in a file.
Recently, I added the option of moving/creating new buildings to the code. The problem is that whenever either of the actions is done, I have to redraw all the buildings in the scenario. The code resets the canvas and in a loop starts drawing all the buildings again.
I was wondering if it is possible to redraw just a particular building (a building in this case is made of 6 planes/GL_QUADS). By that I mean not touch the other buildings and only redraw on of them.
If so, how can the same be achieved?
P.S. I am quite ready to make a large change if required.
The only reliable way to do this is to use framebuffer objects (FBOs). The contents of the back buffer become undefined when swapping buffers, and the contents of the front buffer become undefined whenever the window system feels like it. So you’d need to render the scene to a FBO then blit that to the screen. The FBO’s contents only change when you explicitly render to it.
But note that when you “erase” an object, you need to determine whether any other objects overlap the erased region and redraw those.
If you’re planning to use incremental updates because redrawing the entire scene is too slow, you should first consider whether you can make drawing faster (e.g. replacing legacy glBegin/glEnd code with glDrawElements and VBOs).
Thanks for the answer. I’ll look into frame-buffer objects (I’ll be using QOpenGLFramebufferObjects as I have a dependency on Qt in my code).
I didn’t understand the second point for erase object part though. As from what I get, I’ll be drawing all buildings into separate frame buffers and blitting them onto the canvas after I reset it to avoid having to “draw” the buildings again and instead use the pre-created buildings instead.
As for glDrawElements, I’ll look into it. I don’t have much idea on how it works yet.
That will also work, and avoids the need to “erase” objects.