I'm working on a project that offloads some rendering to a native plugin I wrote for Unity, in order to make use of instancing and other advanced graphics features. I'm developing it for a cross-platform release, but I work with a Mac so testing is done primarily with OpenGL. At this point, the plugin only renders a quad to the center of the screen colored with hex values. The plugin works as expected in a blank Unity project, but as soon as I incorporate it into my Oculus project, it begins behaving erratically.
In the Rift, the plugin's geometry draws twice, one time stretching across both eyes and another time drawing only within the bounds of the right eye. Additionally, any primitive colors I apply to the geometry are lost and the geometry appears to pick up surrounding colors; on a black screen with red text, the geometry will be mostly black with some red bleeding into the lines. As soon as my green terrain is loaded, the geometry drawn by the plugin becomes green.
Below is a screenshot of the geometry being drawn in a blank Unity project with nothing else:
And here is a screenshot of the same geometry being drawn on top of my Oculus Rift application:
Here's the creation of the vertices that I'm rendering (three coordinates and color):
Vertex verts[4] =
{
{ -0.5f, 0.5f, 0, 0xFF0000ff },
{ 0.5f, 0.5f, 0, 0xFFff0000 },
{ 0.5f, -0.5f, 0, 0xFF00ff00 },
{ -0.5f, -0.5f, 0, 0xFFff0000 },
};
Here's the draw function, called every frame within the plugin:
// OpenGL case
if (g_DeviceType == kGfxRendererOpenGL)
{
//initialize model view matrices
glMatrixMode (GL_MODELVIEW);
float modelMatrix[16] =
{
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
};
glLoadMatrixf (modelMatrix); //assign our matrix to the current MatrixMode
//initialize projection matrix
glMatrixMode (GL_PROJECTION);
projectionMatrix[10] = 2.0f; //tweak projection matrix to match D3D
projectionMatrix[14] = -1.0f;
glLoadMatrixf (projectionMatrix);
// Vertex layout
glVertexPointer (3, GL_FLOAT, sizeof(verts[0]), &verts[0].x);
glEnableClientState (GL_VERTEX_ARRAY);
glColorPointer (4, GL_UNSIGNED_BYTE, sizeof(verts[0]), &verts[0].color);
glEnableClientState (GL_COLOR_ARRAY);
glDrawArrays(GL_LINE_LOOP, 0, 4);
}
Any insight from experienced native plugin/Rift graphics coders would be appreciated!