PDA

View Full Version : Changing OpenGL settings



11-02-2003, 01:50 AM
I have a program in which I want the user to be able to change light and clear colors at run time. I have a class called COpenGLManager that takes care of everything with OpenGL. I has these member functions to change colors:



void COpenGLManager::SetBGColor(GLfloat r, GLfloat g, GLfloat b)
{
m_afClearColor[0] = r;
m_afClearColor[1] = g;
m_afClearColor[2] = b;
glClearColor(m_afClearColor[0], m_afClearColor[1], m_afClearColor[2], 1.0);
}

void COpenGLManager::SetAmbient(GLfloat r, GLfloat g, GLfloat b)
{
m_afAmbientLight[0] = r;
m_afAmbientLight[1] = g;
m_afAmbientLight[2] = b;
glLightfv(GL_LIGHT0, GL_AMBIENT, m_afAmbientLight);

(And so on for diffuse and specular light)
For some reason, calling these functions won't change the color. However, if I move the calls to glLight/glClearColor to the drawing function the colors are changes as they should. Does anyone have a clue to what might be wrong?

11-02-2003, 03:42 AM
Due to the way that graphics hardware and indeed operating systems are designed, OpenGL calls will normally only be valid from a single thread.

Your best approach is probably to store the user's input and set a flag saying the data needs updating, then from your rendering thread reset the flag and call the correct function.

11-02-2003, 05:04 AM
Ok, thanks!