Setting Up the Project Files
To start, make sure that the Project Virtua libraries are properly setup in your project, as well as the Oculus Rift SDK headers. This will ensure that you can properly access the methods from the library. You can find a quick tutorial on setting up the Project Virtua files here: http://projectvirtua.wikia.com/wiki/Installing. Once that is done, you are all set to start getting into the code!Creating an Oculus Rift Object
As I said previously, I'm not going to go over the code for creating the window and object models, but it's very easy to do so using this library. The real meat of this is creating the Oculus Rift object to use in your code. Doing so is very easy still:
OculusRift rift(false, testWindow.renderingContext, testWindow.windowHandle, testWindow.deviceContext);
This will create an Oculus Rift object named "Rift", that does not create a fake Oculus Rift when disconnected, uses our testWindow's rendering context, window handle, and device context. To check that the Oculus Rift was properly detected, simply use rift.isConnected() to get the boolean status. When rendering, you can use the following code: //Attempts to render to OculusRift
if (rift.StartRender())
{
//Renders left eye
rift.StartEyeRender(Left, viewOffsetMatrix);
{
rift.getPerspectiveMatrix(Left, perspectiveMatrix);
drawGLScene(program, perspectiveMatrix, (viewOffsetMatrix * viewMatrix));
}
rift.EndEyeRender(Left);
//Renders right eye
rift.StartEyeRender(Right, viewOffsetMatrix);
{
rift.getPerspectiveMatrix(Right, perspectiveMatrix);
drawGLScene(program, perspectiveMatrix, (viewOffsetMatrix * viewMatrix));
}
rift.EndEyeRender(Right);
//Frame buffering is not handled automatically!
pv_glBindFramebuffer(PV_GL_FRAMEBUFFER, 0);
glDisable(GL_DEPTH_TEST);
rift.EndRender();
glEnable(GL_DEPTH_TEST);
// Ocuus Rift sets clear depth to 0, reset that here.
glClearDepth(1);
}
The final scene rendered without the Rift as well. |
Source Code
You can find the source code for this test project here, as well as the resources files here. While this tutorial was fairly quick, I hope it will help people get setup and using Project Virtua for the Oculus Rift side. I plan to try and do one or two more of these to show off some of the other nice features soon.
Feel free to post any comments or questions below!
Feel free to post any comments or questions below!
No comments:
Post a Comment