Forum Discussion

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

Having trouble getting output with libovr and OpenGL

Hi, I'm trying to start Oculus DK2 development using straight OpenGL, and I'm not having much luck. I'm able to initialize everything, but no matter what I try I can't seem to get any output to the Oculus. Can someone spot the error in my code?

#include <iostream>

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WGL
#include <GLFW/glfw3native.h>

#include <OVR_CAPI_GL.h>

#include <boost/scope_exit.hpp>

int main()
{
ovr_Initialize();
BOOST_SCOPE_EXIT(void)
{
ovr_Shutdown();
} BOOST_SCOPE_EXIT_END;

ovrHmd hmd = ovrHmd_Create(0);
BOOST_SCOPE_EXIT(hmd)
{
ovrHmd_Destroy(hmd);
} BOOST_SCOPE_EXIT_END;

ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation, 0);

if(!hmd)
{
return 1;
}

if(!glfwInit())
{
return 1;
}
BOOST_SCOPE_EXIT(void)
{
glfwTerminate();
} BOOST_SCOPE_EXIT_END;

glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
GLFWwindow *win = glfwCreateWindow(hmd->Resolution.w, hmd->Resolution.h, "Test", NULL, NULL);
if(win == NULL)
{
return 1;
}
BOOST_SCOPE_EXIT(win)
{
glfwDestroyWindow(win);
} BOOST_SCOPE_EXIT_END;

glfwMakeContextCurrent(win);

ovrHmd_AttachToWindow(hmd, glfwGetWin32Window(win), NULL, NULL);

glewExperimental = GL_TRUE;
if(glewInit() != GLEW_OK)
{
return 1;
}

ovrSizei tex0Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, hmd->DefaultEyeFov[0], 1.0f);
ovrSizei tex1Size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Right, hmd->DefaultEyeFov[1], 1.0f);

GLuint eyeBuffers[2];
glGenFramebuffers(2, eyeBuffers);

GLuint eyeTextures[2];
glGenTextures(2, eyeTextures);

glBindFramebuffer(GL_FRAMEBUFFER, eyeBuffers[0]);
glBindTexture(GL_TEXTURE_2D, eyeTextures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, tex0Size.w, tex0Size.h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, eyeTextures[0], 0);

glBindFramebuffer(GL_FRAMEBUFFER, eyeBuffers[1]);
glBindTexture(GL_TEXTURE_2D, eyeTextures[1]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, tex1Size.w, tex1Size.h, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, eyeTextures[1], 0);

ovrPosef pose[2];
ovrGLTexture eyesGL[2];

eyesGL[0].OGL.Header.API = eyesGL[1].OGL.Header.API = ovrRenderAPI_OpenGL;

eyesGL[0].OGL.Header.TextureSize = tex0Size;
eyesGL[0].OGL.Header.RenderViewport.Size = tex0Size;
eyesGL[0].OGL.Header.RenderViewport.Pos.x = 0;
eyesGL[0].OGL.Header.RenderViewport.Pos.y = 0;
eyesGL[0].OGL.TexId = eyeTextures[0];

eyesGL[1].OGL.Header.TextureSize = tex1Size;
eyesGL[1].OGL.Header.RenderViewport.Size = tex1Size;
eyesGL[1].OGL.Header.RenderViewport.Pos.x = tex0Size.w;
eyesGL[1].OGL.Header.RenderViewport.Pos.y = 0;
eyesGL[1].OGL.TexId = eyeTextures[1];

ovrGLConfig cfg;
cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
cfg.OGL.Header.BackBufferSize = hmd->Resolution;
cfg.OGL.Header.Multisample = 0;

ovrEyeRenderDesc eyeRenderDesc[2];

ovrHmd_ConfigureRendering(hmd, &cfg.Config, ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp, hmd->DefaultEyeFov, eyeRenderDesc);

unsigned int frameCount = 0;
ovrPosef headPose[2];

glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
while(true)
{
ovrHmd_BeginFrame(hmd, frameCount);
for(int i = 0; i < 2; ++i)
{
ovrEyeType eye = hmd->EyeRenderOrder[i];
headPose[eye] = ovrHmd_GetHmdPosePerEye(hmd, eye);
glBindFramebuffer(GL_FRAMEBUFFER, eyeBuffers[eye]);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
ovrHmd_EndFrame(hmd, headPose, &eyesGL[0].Texture);
++frameCount;
}

return 0;
}


Thank you in advance, I'm pulling my hair out over this.
No RepliesBe the first to reply