title: Draw an object on an OpenCV image using OpenGL
body: <p>I have been trying to draw a 3D cube using opengl over a camera stream from opencv but unsuccessful. Added setOpenGlDrawCallback but it's not overlaying the opengl image onto opencv image. Following is the code.</p>
  
  <p><strong>trackingmanager.h</strong> is the header file of class which takes care of devices/frames/etc.
  <strong>frameprocessor.h</strong> is the header file of class used to do some processing on the frame obtained from the camera.</p>
  
  <p>The namedWindow is being initialized in <strong>trackingmanager.cpp</strong> by,</p>
  
  <blockquote>
    <p>namedWindow(wnd_name, WINDOW_OPENGL);</p>
  </blockquote>
  
  <p>I can see the opengl image being drawn to the same window if I do not render the opencv fram to this window. (Comment out tm->renderFrame()).</p>
  
  <p>Also, I get to see following messages on run, </p>
  
  <blockquote>
    <p>1] init done 
    2] Opengl support available</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  #include "trackingmanager.h"
  #include "frameprocessor.h"
  #include &lt;GL/glut.h&gt;
  
  using namespace std;
  static void renderObject(void *param);
  vector&lt;vector&lt;Point&gt; &gt; square;
  
  int main(int argc, char **argv)
  {
      TrackingManager *tm = new TrackingManager();
      FrameProcessor *processor = new FrameProcessor();
      setOpenGlContext(tm-&gt;wnd_name);
      setOpenGlDrawCallback(tm-&gt;wnd_name, renderObject, NULL);
  
      while(tm-&gt;getFrame()){
          square = processor-&gt;process(&amp;tm-&gt;frame);
          tm-&gt;renderFrame();
          updateWindow(tm-&gt;wnd_name);
  
          int key = waitKey(10);
          if(key == 27){
              tm-&gt;releaseCamera();
              break;
          }
      }
      setOpenGlDrawCallback(tm-&gt;wnd_name, NULL, NULL);
      return 0;
  }
  
  static void renderObject(void* param)
  {
       glLoadIdentity();
       glClearColor (0.0, 0.0, 0.0, 0.0);
       glClear (GL_COLOR_BUFFER_BIT);
       glColor3f (1.0, 1.0, 1.0);
       glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
       glTranslated(0.0, 0.0, -1.0);
  
       glRotatef( 55, 1, 0, 0 );
       glRotatef( 45, 0, 1, 0 );
       glRotatef( 0, 0, 0, 1 );
  
       static const int coords[6][4][3] = {
          { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 }   },
          { { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 }   },
          { { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
           { { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
          { { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
          { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
      };
  
      for (int i = 0; i &lt; 6; ++i) {
           glColor3ub( i*20, 100+i*10, i*42 );
           glBegin(GL_QUADS);
           for (int j = 0; j &lt; 4; ++j) {
                glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]);
            }
            glEnd();
      }
  }
  </code></pre>