View Full Version : Redrawing Scene
04-06-2008, 08:28 AM
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
how can i make it re-draw circle 3 only with the rest of scene intact?
thanks in advance :)
04-06-2008, 11:25 AM
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,
04-07-2008, 12:32 AM
Thanks jason..what you said is useful :)
what i want is to save the state of my scene,how can i dow that with Gl.gldrawbuffer ?
04-07-2008, 04:46 AM
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
04-07-2008, 10:55 PM
thanks dletozeun ! that really helped :)
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 ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.