Results 1 to 8 of 8

Thread: How to set the background color?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Hyderabad,Andhra Pradesh, India
    Posts
    8

    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...

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2002
    Posts
    13

    Re: How to set the background color?

    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.
    ¿Que es lo imposible, sino el fracaso de los cobardes?

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Hyderabad,Andhra Pradesh, India
    Posts
    8

    Re: How to set the background color?

    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.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2002
    Posts
    13

    Re: How to set the background color?

    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).]
    ¿Que es lo imposible, sino el fracaso de los cobardes?

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Hyderabad,Andhra Pradesh, India
    Posts
    8

    Re: How to set the background color?

    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?

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2002
    Posts
    13

    Re: How to set the background color?

    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
    ¿Que es lo imposible, sino el fracaso de los cobardes?

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: How to set the background color?

    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.
    Deiussum
    Software Engineer and OpenGL enthusiast

  8. #8
    Junior Member Newbie
    Join Date
    Jun 2002
    Location
    Hyderabad,Andhra Pradesh, India
    Posts
    8

    Re: How to set the background color?

    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.

Similar Threads

  1. how to set viewport background color
    By linuxxy in forum OpenGL ES
    Replies: 0
    Last Post: 09-16-2011, 12:11 AM
  2. MRT with different background color
    By miujin in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 04-08-2011, 04:43 AM
  3. photo with certain color as background
    By beginner620824 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-28-2003, 05:16 AM
  4. Background color does not change
    By jpummill in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 03-26-2002, 10:55 AM
  5. Background color
    By amstel in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-17-2002, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean