Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing Background Color in openGL

10,023 views
Skip to first unread message

Apurv Verma

unread,
Aug 31, 2011, 5:22:06 PM8/31/11
to
Hii all,
I am working on an openGL turtle library implementation. One of the
things that I need to do is to change the background color to a
specified color. If I do a simple glClear() then this simply erases
everything that has been drawn previously.
Is there a function to change the background color? If not is there a
inbuilt support in openGL to save the currently drawn figure so that I
can clear the screen and redraw the saved figure which gives the
impression that the background has changed.

thanks and regards,
Apurv

Andrew Baldwin

unread,
Aug 31, 2011, 6:22:49 PM8/31/11
to

I may be missing something in your description, but it sounds like you
want glClearColor.

http://www.opengl.org/sdk/docs/man4/xhtml/glClearColor.xml

Andy V

unread,
Aug 31, 2011, 8:17:29 PM8/31/11
to
Most OpenGL programs redraw the entire scene (from a scene graph, which can be as simple as an array) when a change needs to take place. This makes changing the background color just using glClearColor (as Andrew Baldwin suggests) and then clearing and redrawing the scene as normal.

OpenGL does NOT keep track of your primitives for you.* This means that you need to keep track of them on your own.

--
Andy V

* Well, you can use display lists to get OpenGL to remember primitives. Have display() call display list 1 (which is not yet defined). When you add the first object (line segment or whatever), put its primitives in display list 1 and end it with a call to display list 2. The next object goes in display list 2, plus the call to display list 3. To make things a bit easier for the implementation, you can build multiple objects into a single display list rather than use one list per object. In the modern OpenGL era, this is considered poor style and restricts you to implementations that support display lists.

Apurv Verma

unread,
Sep 1, 2011, 2:45:03 AM9/1/11
to

glClearColor(0,0,0,0) would clear the entire screen to black and not
preserve whatever was drawn on it. I just want the background to be
changed to some other color.

T. Schroeder

unread,
Sep 1, 2011, 5:33:40 AM9/1/11
to

how about to change the color values? (0,0,0,0) as RGBA in a range of
0.0 - 1.0f


Wolfgang.Draxinger

unread,
Sep 1, 2011, 12:46:46 PM9/1/11
to
On Wed, 31 Aug 2011 23:45:03 -0700 (PDT)
Apurv Verma <dap...@gmail.com> wrote:

> glClearColor(0,0,0,0) would clear the entire screen to black and not
> preserve whatever was drawn on it. I just want the background to be
> changed to some other color.

OpenGL is not a scene graph. You can't change individual things after
drawing a scene, because that's not the way OpenGL works. You want
something changed, you redraw the whole scene. You want to change the
background color: You redraw the whole scene, starting with a clear,
but clear to the new desired background color.


Wolfgang

Miles Bader

unread,
Sep 5, 2011, 2:04:14 AM9/5/11
to
"Wolfgang.Draxinger" <Wolfgang....@physik.uni-muenchen.de> writes:
> OpenGL is not a scene graph.

I think this should be the first sentence in any OpenGL intro (with
suitable explanation)... :]

When I was learning OpenGL, this was the key realization for me --
before that I was just soooo confused; afterwards I was still
confused, but suddenly tons of stuff made sense where they didn't
before, and I could actually start making some progress in learning...

-Miles

--
Any man who is a triangle, has thee right, when in Cartesian Space,
to have angles, which when summed, come to know more, nor no less,
than nine score degrees, should he so wish. [TEMPLE OV THEE LEMUR]

Nobody

unread,
Sep 6, 2011, 8:29:48 PM9/6/11
to
On Mon, 05 Sep 2011 15:04:14 +0900, Miles Bader wrote:

> "Wolfgang.Draxinger" <Wolfgang....@physik.uni-muenchen.de> writes:
>> OpenGL is not a scene graph.
>
> I think this should be the first sentence in any OpenGL intro (with
> suitable explanation)... :]
>
> When I was learning OpenGL, this was the key realization for me --
> before that I was just soooo confused; afterwards I was still
> confused, but suddenly tons of stuff made sense where they didn't
> before, and I could actually start making some progress in learning...

The confusion isn't specific to OpenGL. People had the same confusion
moving from DOS-style programming (you draw something on the framebuffer,
it stays there) to GUI programming (having to service redraw requests as
and when they occur).

0 new messages