glGetError problem

I am writing a multithreaded MFC program. There are two threads: One
does some processing on each of several models and sends messages to the
second, which draws the models.

The second thread has two methods that may be activated by the messages
from the first. One is OnPaint, and the other is my own DrawModel.
DrawModel is called for each model and the OnPaint is called to start
the next frame. The OnPaint method draws some axis, swaps the back
buffer into the front, and the clears the back buffer, in that order.
This all works fine. If I call glGetError in this method it returns
GL_NO_ERROR.

The DrawModel method works fine in that it gets called and does all the
non openGL stuff in it. But none of the openGL commands are executed
and if I call glGetError I get GL_INVALID_OPERATION. If I loop around
only calling glGetError and reporting the error, I still get
GL_INVALID_OPERATION every time, which makes me think that the
glGetError funtion itself is causing an error.

Any ideas what could be wrong? I use the OnPaint method by calling the
InvalidateRect(NULL, FALSE) method. Is there something that
InvalidateRedt does that I need to do when I call DrawModel?

I’m a little bit confused by your description, but here are two things to check.

  1. If you have no context bound in the current thread, calling glGetError() is itself an error. Make sure you are calling it from the rendering thread.

  2. Never call glGetError() inside a begin/end, as that will cause an error.

You need to call wglMakeCurrent() with the current HDC on entry to your Draw routine.

It’s a good idea to also call it again with NULL context on exit, especially in case of multiple views or threads.