concept Rift display in category oculus rift

This is an excerpt from Manning's book Oculus Rift in Action.
In addition to the cable extending to the headset, the control box, figure 1.7, also has a DC power connector, a USB mini-B female port, and DVI and HDMI female ports. It has 5 buttons, one for power, and two each for controlling brightness and contrast on the display. It also has a small blue LED in the center of the Oculus VR logo that glows blue when the Rift display is active.
While the Rift display is essentially a monitor from the perspective of a computer, from the perspective of a user it doesn’t have the same functionality as a conventional flat panel monitor. If you plug it in, your computer is likely to attempt to extend the desktop to this new display. This is problematic as interacting with operating system created windows that are being rendered to the Rift is problematic at best. Significant portions of the display aren’t actually visible to the user unless you remove the lenses and hold the Rift at a distance.
One solution to the problem is to clone the Rift display to another of your computers monitors, but this can have a negative impact on the performance of applications which are rendering to it.
With the 0.4.x series of the Oculus software, the new runtime enables something called Direct HMD mode. The intent of this is to actually hide the Rift display from the OS level interface for working with monitors, thus preventing the problems with the desktop being extended to the display. At the same time, the SDK provides functions that allow applications to continue to target the Rift display with Direct3D or OpenGL rendering systems, in order to allow VR applications to function.
Listing 2.5 Rendering to the display
#include "Common.h" class RiftDisplay : public GlfwApp { #A ovrHmd hmd; public: RiftDisplay() { hmd = ovrHmd_Create(0); #B if (!hmd) { #B hmd = ovrHmd_CreateDebug(ovrHmd_DK2); #B } #B if (!hmd) { #B FAIL("Unable to detect Rift display"); #B } #B } virtual GLFWwindow * createRenderingTarget( #C glm::uvec2 & outSize, glm::ivec2 & outPosition) { #C GLFWwindow * window = nullptr; bool extendedMode = ovrHmdCap_ExtendDesktop & hmd->HmdCaps; #D outPosition = glm::ivec2( #E hmd->WindowsPos.x, #E hmd->WindowsPos.y); #E outSize = glm::uvec2( #E hmd->Resolution.w, #E hmd->Resolution.h); #E if (extendedMode) { #F GLFWmonitor * monitor = #H glfw::getMonitorAtPosition(outPosition); #H if (nullptr != monitor) { #H const GLFWvidmode * mode = glfwGetVideoMode(monitor); #H outSize = glm::uvec2(mode->width, mode->height); #H } glfwWindowHint(GLFW_DECORATED, 0); #I window = glfw::createWindow(outSize, outPosition); #I } else { window = glfw::createSecondaryScreenWindow(outSize); #J void * nativeWindowHandle = #K glfw::getNativeWindowHandle(window); #K if (nullptr != nativeWindowHandle) { #K ovrHmd_AttachToWindow(hmd, nativeWindowHandle, #K nullptr, nullptr); #K } } return window; } void draw() { glm::uvec2 eyeSize = getSize(); eyeSize.x /= 2; glm::uvec2 eyeSize = getSize(); eyeSize.x /= 2; glEnable(GL_SCISSOR_TEST); glScissor(0, 0, eyeSize.x, eyeSize.y); #L glClearColor(1, 0, 0, 1); #L glClear(GL_COLOR_BUFFER_BIT); #L glScissor(eyeSize.x, 0, eyeSize.x, eyeSize.y); #M glClearColor(0, 0, 1, 1); #M glClear(GL_COLOR_BUFFER_BIT); #M glDisable(GL_SCISSOR_TEST); } }; RUN_OVR_APP(RiftDisplay); #A GlfwApp is a wrapper class which encapsulates and abstracts OpenGL and platform-dependent issues #B Locate the headset device #C Our parent class calls this method to create the OpenGL window #D This is the standard for detecting if the Rift is running in Direct or Extended mode #E We start off by assuming the HMD size and position values are valid for use #F Extended and Direct mode window setup are significantly different #H In extended mode we need to query the resolution of the Rift. #I We also need to make sure that the created window does not include window decorations #J In direct mode, we simply create a window wherever we want, but we should use the Rift native resolution for the size. #K Direct HMD mode requires that you tell the SDK the native window handle you’re using to render Rift content. #L For our drawing method, we want to display the color red on the left eye half of the display, so we set up a scissor region and clear it, with the clear color set to red. #M For the right eye, we change the scissor region and the clear color and again clear the displayThis class exposes the complexity of creating an output window for the Rift display. Even this example is significantly smaller than it could be because we’re pushing a lot code into helper methods and a new helper parent class
GlfwApp.