Redrawing Scene

hey guys,im using OpenGl with C#…so i have this 3 circles,i want a

certain circle to be redrawn when a user selects it with mouse WITHOUT

re-drawing the whole scene, i.e.i have the following fucntion called in

paint event:


how can i make it re-draw circle 3 only with the rest of scene intact?

thanks in advance :slight_smile:

Even if you just kept redrawing certain parts of the scene to the back buffer, when you swap the buffers there’s no guarantee that the back buffer will remain unchanged (with WGL, at least, you can hint that you want the back buffer to be swapped or copied, but it’s still not a guarantee).

You could draw directly onto the front buffer, by calling glDrawBuffer(GL_FRONT) before drawing your circle, remembering to restore glDrawBuffer to it’s previous value before continuing. Your updates will be erased, however, if something else causes the entire scene to be repainted (such as dragging another window over it, or resizing the window). Also, unless you are really careful about keeping track of what state things are in, this could really complicate things when stuff starts getting drawn all over the place; especially if you have more than one context in your program.

Really, the most reliable way to do it, is to redraw the entire scene every time (sorry I don’t know C# at all) the selection state of a circle changes:

Draw_Circle_1 (bool IsSelected);
Draw_Circle_2 (bool IsSelected);
Draw_Circle_3 (bool IsSelected);

Draw_Circle_1(SelectedCircle == 1);
Draw_Circle_2(SelectedCircle == 2);
Draw_Circle_3(SelectedCircle == 3);

Where SelectedCircle is some integer that you update when the user clicks with the mouse… perhaps 0 means nothing is selected. You’d redraw the scene any time SelectedCircle changes. The Draw_Circle_* functions there just take a boolean flag indicating whether the circle should be drawn as selected or not (maybe its color changes or something).

Also: Doing it that way also sets you up for easily doing more complex things in the future, such as having multiple selected circles, or selecting the circles in other ways besides using the mouse and still keeping the scene drawn properly. There are a lot of advantages to calling all of your drawing code only through your one scene repainting function, instead of drawing things all over the place in your code.

Hope that helps,

Thanks jason…what you said is useful :slight_smile:
what i want is to save the state of my scene,how can i dow that with Gl.gldrawbuffer ?

if you want to save the framebuffer state you can draw your scene in a texture using framebuffer objects (FBO). You can find more information about FBO here:

Make sure that your graphic card support the fbo extension: GL_EXT_framebuffer_object

thanks dletozeun ! that really helped :slight_smile:
can i ask for one more thing? i need to know i the user has selected a certain circle with mouse…i know it has something to do with GL.Select and GL.Initnames but i still cant figure it out…

can you provide me with a simple application to demonstrate it? all things i’ve found where in C++…

thanks again :wink: