Search code examples
openglgraphicsdirectshow

OpenGL based directshow transform Filter - INVALID OPERATION


I am trying to develop a OpenGL based DirectShow transform filter that rotates image at arbitrary angle specified by user. I use very basic sample of image rotation making use of glRotatef. The rotation code works very well as standalone windows application. But gives error when calling through Directshow filters.

Additional Information:

  1. Standalone OpenGL rotate application works good without any error at any stage. The same OpenGL code is not working as part of Directshow filter.
  2. All OpenGL calls before Transform function of Directshow filter succeeds without any GLErrors.
  3. All OpenGL calls after Transform function of DirectShow Filter throws error as INVALID OPERATION (Error code 1282).
  4. I am making use of Visual Studio 2008 and not using any OpenGL 3rd party libraries like GLUT or something else.

I suspect it looks more or less like a threaded issues. I have sample directshow application that initializes capture filter, adds opengl rotation transform filter and video renderer. While initializing I used CoInitializeEx with COINIT_MULTITHREADED and also COINIT_APARTMENTTHREADED. Neither gives any improvement in threading.

What kind of approach would work out in fixing up this issue?


Solution

  • I have fixed this issue by creating OpenGL context during first call to Transform function. This makes OpenGL context to be of same thread as OpenGL drawing functions.

    Reference links that helped

    GlGenTextures keeps returing 0's

    https://www.opengl.org/wiki/Common_Mistakes#Extensions_and_OpenGL_Versions

    Textures not working with OpenGL

    Thank you for people corrected my question posted.

    EDIT: This such threading issues was due to problem in sharing of device context between threads. It can be handled by using wglShareList API to share context between two different thread. This has fixed the issue I have posted.

    https://www.opengl.org/wiki/OpenGL_and_multithreading

    https://www.opengl.org/wiki/Platform_specifics:_Windows

    Hope this would be helpful for people who stuck in same boat:-)