title: What is The Correct View Matrix For The HUD Camera?
body: <p>I'm using OpenSceneGraph in Android with GLES2.</p>
  
  <p>I have two cameras: one for the scene and the other for the HUD. The scene camera is the main camera in my osgViewer. My trouble is with the HUD's camera. I am trying to add an OSG geometry to the 2D scene (HUD camera) but can't seem to get it to show up.</p>
  
  <p>I'm using custom shaders to manipulate the geometry's position. To my understanding the projection matrix is correct but I think the problem may be with the view matrix since I'm using two cameras. I've tried setting the HUD's view to be the scene's initial view but to no avail. Please correct me if I am wrong in this.</p>
  
  <pre><code>   // New camera for the HUD
     hud_camera = new osg::Camera;
  
     // Set the camera's view properties
     hud_camera-&gt;setProjectionMatrix(
        osg::Matrix::ortho2D(0, 1280, 0, 696));
     hud_camera-&gt;setReferenceFrame(osg::Transform::ABSOLUTE_RF);
     hud_camera-&gt;setViewMatrix(osg::Matrix::identity());
     hud_camera-&gt;setViewport(0, 0, 1280, 696);
  
     // Clear the depth buffer
     hud_camera-&gt;setClearMask(GL_DEPTH_BUFFER_BIT);
  
     // Draw the subgraph after the main camera view and don't allow this camera
     // to grab evente focurs from the main camera
     hud_camera-&gt;setRenderOrder(osg::Camera::POST_RENDER);
     hud_camera-&gt;setAllowEventFocus(false);
  
  
     osg::Geode *       geode;
     osg::Geometry *    geom;
     osg::Vec3Array *   vertices;
     osg::Program *     program;
  
     // Create the geode and geometry to hold the crosshair image
     geode = new osg::Geode;
     geom = new osg::Geometry;
     geode-&gt;addDrawable(geom);
     hud_camera-&gt;addChild(geode);
  
     // Set the vertices
     vertices = new osg::Vec3Array;
     vertices-&gt;push_back(osg::Vec3(0.0, 0.0, 0.0));
     vertices-&gt;push_back(osg::Vec3(1.0, 0.0, 0.0));
     vertices-&gt;push_back(osg::Vec3(1.0, 0.0, 1.0));
     vertices-&gt;push_back(osg::Vec3(0.0, 0.0, 1.0));
     geom-&gt;setVertexArray(vertices);
  
     // set colors
     osg::Vec4Array* colors = new osg::Vec4Array;
     colors-&gt;push_back(osg::Vec4(1.0, 0.0, 0.0, 1.0));
     colors-&gt;push_back(osg::Vec4(0.0, 1.0, 0.0, 1.0));
     colors-&gt;push_back(osg::Vec4(0.0, 0.0, 1.0, 1.0));
     colors-&gt;push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0));
     geom-&gt;setVertexAttribArray(7, colors);
     geom-&gt;setVertexAttribBinding(7, osg::Geometry::BIND_PER_VERTEX);
  
     // Set primitive set
     geom-&gt;addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
     geom-&gt;setUseVertexBufferObjects(true);
  
     // Vertex Shader
     char vertSource[] =
     "attribute vec4 osg_Vertex;\n"
     "attribute vec4 a_col;"
     "uniform mat4 osg_ModelViewProjectionMatrix;\n"
     "uniform mat4 proj_matrix;\n"
     "uniform mat4 view_matrix;\n"
     "varying vec4 v_col;"
     "void main(void)\n"
     "{\n"
     "gl_Position = view_matrix * proj_matrix * osg_Vertex;\n"
     "v_col = a_col;\n"
     "}\n";
  
     // Fragment shader
     char fragSource[] =
     "precision mediump float;\n"
     "varying vec4 v_col;"
     "void main(void)\n"
     "{\n"
     "gl_FragColor = v_col;\n"
     "}\n";
  
     // Set the shaders
     program = new osg::Program;
     program-&gt;setName("Crosshair Shader");
     program-&gt;addShader(new osg::Shader(osg::Shader::VERTEX, vertSource));
     program-&gt;addShader(new osg::Shader(osg::Shader::FRAGMENT, fragSource));
     program-&gt;addBindAttribLocation("a_col", 7);
  
     osg::StateSet* state = geode-&gt;getOrCreateStateSet();
     state-&gt;addUniform(
        new osg::Uniform("proj_matrix", hud_camera-&gt;getProjectionMatrix()));
     state-&gt;addUniform(
        new osg::Uniform("view_matrix", hud_camera-&gt;getViewMatrix());
  
     // Add the program shaders
     geode-&gt;getOrCreateStateSet()-&gt;setAttributeAndModes(
        program, osg::StateAttribute::ON );
  
     // Needs no lighting or any depth for a 2D image
     geode-&gt;getOrCreateStateSet()-&gt;setMode(GL_LIGHTING, osg::StateAttribute::OFF);
     state-&gt;setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
  </code></pre>
  
  <p>Afterwards I attach the <strong>hud_camera</strong> as a child to the scene data. Also the scene camera is doing nothing special other than looking at a particular point in the scene.</p>
  
  <p>I do know for a fact that the geometry is being created. By using this in the vertex shader:</p>
  
  <p><strong>gl_Position = osg_ModelViewProjectionMatrx * osg_Vertex</strong></p>
  
  <p>I can see it off to the left in the scene.</p>