I try to run OpenGL in a MFC-dialog based Application. It works fine except for diffuse light control. It simply does not want to work at all, that means no diffuse light at all.
The same code for initialization and drawing used in a win32 window application works fine! Of course the place where you call the init routines is different from win32 to mfc
I don´t use textures but use Color-Material. Again, the same calls and light initializations, viewport, view, normals and objects (actually only 2 dummy triangles) and so on for both applications: Win32 app works fine for diffuse light control, MFC dialog base no diffuse light at all for color material. Any idea?
Put glGetError in various places in both win32 and MFC version of you application. Sometimes moving the code can cause such problems.
I had such error once. Rendering to texture didn’t work (I could clear it but I couldtn’t render any polygon) because some of my previous code generated an error. When I moved rendering to texture before that code everything started to work again, so I placed glGetError after that suspicious block of code and got GL_INVALID_OPERATION returned.
Sometimes, even if everything is working fine you may have errors in your code that can affect your application after some minor changes that shouldn’t normally have any consequences.
Originally posted by Stefan_L_01:
[b]
What is strange is that a call like this worked too:
if ( ErrID = glGetError() ) Break();
but this failed (!!) :
if ( glGetError() ) Break();
[/b]
Such behavior often indicate error in the program which was masked when compiler modified layout of local variables. For example something like damaged stack or use of uninitialized variable.
Actually the program is so simple that there can hardly occur an error.
It´s interesting that Break() isn´t called, but without the code line the code doesn´t work.
It´s getting even more unpredictable if you jump for drawings in other functions, for example
CWorld::Draw()
{
…
MyObject.Draw();
…
}
where additional opengl drawing calls are done. So far i can´t see a defined behaviour.
Now after leaving the function, fDif was not valid anymore because it was deleted. All later drawing calls failed this way, or at least the diffuse drawing.
Using a member variable for fDif, keeping it valid and thus accessible for OpenGL all time, solved the problem finally
Originally posted by Stefan_L_01:
Actually the program is so simple that there can hardly occur an error.
This is very bad assumption. Even more so in cases of programs that utilize complex frameworks like MFC.
[b]
I assumed that a light call like this
glLightfv(GL_LIGHT0,GL_DIFFUSE, fDif);
will immediatly update the light by the info in fDif, but there is probalby only the POINTER fDif stored. The documentation makes no remark about it.
[/b]
The glLightfv immediately updates the light parameters. It does not store the pointer. The error is somewhere else and changing the variable to the member one only masked it.