How to set the background color?

The background color of my scene is black by default. How can I change this color? Can this be done through opengl commands, or is this specific to the GUI libraries that one uses for the generation of the windows…

Hi
im new but i think the background color is the color u use to clear the window.
the comand to change this color is glClearColor(x,x,x,x) the x parameters are float with range from 0.0 to 1.0 if im not mistaken.

I thought so too, but didn’t work for me that way. I think glClearColor, initialises the color bits of the buffer. This I think, has no relation to the background color of the screen.

Originally posted by vandana_pv:
I thought so too, but didn’t work for me that way. I think glClearColor, initialises the color bits of the buffer. This I think, has no relation to the background color of the screen.

yes it does initialise the color bit buffer, but you need to use it RGBA mode and call glClear(GL_COLOR_BUFFER_BIT) so it uses the new background color

[This message has been edited by Batsu (edited 07-07-2002).]

Yes, I checked my code again and it had all of the above, but it still displays the background as black. What do I do now?

i guess that you ARE changing the parameters to something else other than 0.0

Sorry but thats all i can say for now, im just started

When you say background color, what do you mean exactly? do you mean the color that the scene is cleared to when you use glClear(GL_COLOR_BUFFER_BIT)? Or do you perchance mean the color that you set the window too when it’s first created. (e.g. the hbrBackground used in the WNDCLASS used in the RegisterClass method of the Win32 API)

If you mean the latter, it’s possible that you are letting Windows handle the default behavior on the WM_ERASEBKGND message. You should be returning true on this message so that you notify Windows that this message has been handled and it won’t try and clear it for you.

If you mean the former, all you have to do is use glClearColor to set the color. Make sure you do this AFTER the window has been created and an appropriate pixelformat has been set for the window, and the GL context has been created. If you try and use any gl* functions before you create the HGLRC, they will fail.

All the above assumes you are programming for Windows, BTW.

Sorry for all the confusion I created. The glClearColor method was working just fine. I made a very stupid mistake in my code, due to which I thought the screen was not being set to another color. I am very sorry and thanks for all the help.