Skip to main content
New Participant
May 2, 2014

0.3.1 OpenGL Rendering issue

I'm trying to use Oculus Rift with our existing OpenSG enviroment . OpenSG is a 3D engine based on OpenGL.

I have created 2 differents FBO viewport, one for each eye, and i have rendered my scene in a single 1280x800 shared texture. (a red background with some planets moving around, just for testing purposes).

I'm trying to apply OVR distortion but this is what i get:

cacca.jpg

This is my how i set up the SDK:


OculusVR->eyes[0].Eye = ovrEye_Left;
OculusVR->eyes[1].Eye = ovrEye_Right;
OculusVR->eyes[0].Fov = OculusVR->HMDDesc.DefaultEyeFov[0];
OculusVR->eyes[1].Fov = OculusVR->HMDDesc.DefaultEyeFov[1];
OculusVR->eyes[0].TextureSize = RenderTargetSize;
OculusVR->eyes[1].TextureSize = RenderTargetSize;
OculusVR->eyes[0].RenderViewport.Pos = Vector2i(0,0);
OculusVR->eyes[0].RenderViewport.Size = Sizei(RenderTargetSize.w / 2, RenderTargetSize.h);
OculusVR->eyes[1].RenderViewport.Pos = Vector2i((RenderTargetSize.w + 1) / 2, 0);
OculusVR->eyes[1].RenderViewport.Size = OculusVR->eyes[0].RenderViewport.Size;

cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
cfg.OGL.Header.RTSize = Sizei(OculusVR->HMDDesc.Resolution.w, OculusVR->HMDDesc.Resolution.h);
cfg.OGL.Header.Multisample = 1;


HWND windowHandle = FindWindow(NULL,"OpenSG First Application");

cfg.OGL.Window = windowHandle;
cfg.OGL.GdiDc = GetDC(windowHandle);
cfg.OGL.WglContext = wglGetCurrentContext();
EyeTexture[0].OGL.Header.API = ovrRenderAPI_OpenGL;
EyeTexture[0].OGL.Header.TextureSize = RenderTargetSize;
EyeTexture[0].OGL.Header.RenderViewport = OculusVR->eyes[0].RenderViewport;
EyeTexture[0].OGL.TexId = fboTexture->getGLId();
EyeTexture[1]=EyeTexture[0];
EyeTexture[1].OGL.Header.RenderViewport = OculusVR->eyes[1].RenderViewport;
ovrHmd_ConfigureRendering(OculusVR->HMD,&cfg.Config, 0, DistortionCaps, OculusVR->eyes, OculusVR->EyeRenderDesc);


glUseProgramTROIA = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");

glutMainLoop();


And this is my rending loop:

   
glUseProgramTROIA(0);

window->activate();
window->frameInit();
window->renderAllViewports(renderAction);

ovrFrameTiming hmdFrameTiming = ovrHmd_BeginFrame(OculusVR->HMD, 0);

Posef movePose = ovrHmd_GetSensorState(OculusVR->HMD, hmdFrameTiming.ScanoutMidpointSeconds).Predicted.Pose;

float HeadPitch, HeadRoll, HeadYaw;
OculusVR->getEyePosition( HeadYaw, HeadPitch, HeadRoll);

for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
{
OculusVR->eye = OculusVR->HMDDesc.EyeRenderOrder[eyeIndex];
OculusVR->eyeRenderPose[OculusVR->eye] = ovrHmd_BeginEyeRender(OculusVR->HMD, OculusVR->eye);

OVR::Matrix4f l_ProjectionMatrix = ovrMatrix4f_Projection(OculusVR->EyeRenderDesc[OculusVR->eye].Desc.Fov, 0.3f, 100.0f, true);
OVR::Quatf l_Orientation = OVR::Quatf(OculusVR->eyeRenderPose[OculusVR->eye].Orientation);
OVR::Matrix4f l_ModelViewMatrix = OVR::Matrix4f(l_Orientation.Inverted());

// matrix to OpenGL...
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMultMatrixf(&(l_ProjectionMatrix.Transposed().M[0][0]));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Translate for specific eye based on IPD...
glTranslatef(OculusVR->EyeRenderDesc[OculusVR->eye].ViewAdjust.x, OculusVR->EyeRenderDesc[OculusVR->eye].ViewAdjust.y,
OculusVR->EyeRenderDesc[OculusVR->eye].ViewAdjust.z);
// Multiply with orientation retrieved from sensor...
glMultMatrixf(&(l_ModelViewMatrix.Transposed().M[0][0]));


ovrHmd_EndEyeRender(OculusVR->HMD, OculusVR->eye, OculusVR->eyeRenderPose[ OculusVR->eye], &EyeTexture[ OculusVR->eye].Texture);
}

glDisable(GL_CULL_FACE);

glDisable(GL_DEPTH_TEST);
ovrHmd_EndFrame(OculusVR->HMD);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);

    3 replies

    Inspiring
    May 2, 2014
    Do the changes listed here help at all?
    viewtopic.php?f=34&t=8235#p112715
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    Inspiring
    May 4, 2014
    See this thread for a similar problem and potential solution. The Current SDK sends the wrong number of indices into the draw call, by quite a large factor. Depending on how the card drivers and GPU memory is laid out, this can manifest as the attempt to draw one of the meshes triggering drawing part of the other, but with misaligned vertices.

    There's a fix mentioned in that thread. I've applied a similar fix to my Github version of the SDK here.
    Brad Davis - Developer for High Fidelity Co-author of Oculus Rift in Action
    New Participant
    May 5, 2014
    Changing just one line as suggested by cybereality, it started to work. Thank you guys!