Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
seac02developer's avatar
seac02developer
Honored Guest
12 years ago

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

  • 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.
  • Changing just one line as suggested by cybereality, it started to work. Thank you guys!