Forum Discussion

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

ovrHmd_EndFrame() called before ovrHmd_BeginFrame()?

Hello,

I asked this in another post but perhaps it is better I ask it in a separate thread.

I am getting some peculiar messages from the Oculus SDK:

The debug messages are coming from the CAPI_HMDState.h file saying that ovrHmd_EndFrame() was called before ovrHmd_BeginFrame(). However, as you can see from my loop below, I am calling ovr_BeginFrame() before ovrHmd_EndFrame().

What gives?

Why does the SDK believe that I am calling ovrHmd_EndFrame() without calling ovrHmd_BeginFrame()?

Thank you for your time:


static ovrFrameTiming Current_Frame = ovrHmd_BeginFrame(Main_HMD, 0);

static ovrPosef Main_HMD_eyeRenderPose[2];
static ovrMatrix4f OculusRiftProjection[2];
static ovrMatrix4f OculusRiftView[2];
static OVR::Vector3f Main_HMD_HeadPos(0.0f, 1.6f, -5.0f);
static ovrTrackingState HmdState;

ovrVector3f hmdToEyeViewOffset[2] = { Main_EyeRenderDesc[0].HmdToEyeViewOffset, Main_EyeRenderDesc[1].HmdToEyeViewOffset };
ovrHmd_GetEyePoses(Main_HMD, 0, hmdToEyeViewOffset, Main_HMD_eyeRenderPose, &HmdState);

Main_HMD_HeadPos.y = ovrHmd_GetFloat(Main_HMD, OVR_KEY_EYE_HEIGHT, Main_HMD_HeadPos.y);

glBindFramebuffer(GL_FRAMEBUFFER, OculusRiftFrameBufferID);

glUseProgram(MainOpenGLShaderProgramID);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

for (GLint CurrentEyeIndex = 0; CurrentEyeIndex < ovrEye_Count; ++CurrentEyeIndex)
{

ovrEyeType CurrentEye = Main_HMD->EyeRenderOrder[CurrentEyeIndex];

glViewport(
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Pos.x,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Pos.y,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Size.w,
Main_EyeTexture[CurrentEyeIndex].Texture.Header.RenderViewport.Size.h
);

OculusRiftProjection[CurrentEyeIndex] = ovrMatrix4f_Projection(Main_EyeRenderDesc[CurrentEyeIndex].Fov,
1.0f, 1000.0f, true);

for (int o = 0; o < 4; o++) {
for (int i = 0; i < 4; i++) {
ProjectionMatrix[o][i] = OculusRiftProjection[CurrentEyeIndex].M[o][i];
}
}

ProjectionMatrix = glm::transpose(ProjectionMatrix);

ViewMatrix = glm::toMat4(glm::quat(
Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.w,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.x,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.y,
-Main_HMD_eyeRenderPose[CurrentEyeIndex].Orientation.z
));

for (auto & C : Cubes) {

C.RotateMe(0.001f);
C.DrawMe();

}

}

ovrHmd_EndFrame(Main_HMD, Main_HMD_eyeRenderPose, &Main_EyeTexture[0].Texture);

Main_HMD_FrameIndex += 1;

glfwPollEvents();

2 Replies

  • "tmason101" wrote:


    static ovrFrameTiming Current_Frame = ovrHmd_BeginFrame(Main_HMD, 0);
    ^^^^^^


    Because you're declaring the ovrFrameTiming as static, the initialization only happens the first time you run through this code block. The second time you go through it ovrHmd_BeginFrame won't be called, hence the error.
  • "jherico" wrote:
    "tmason101" wrote:


    static ovrFrameTiming Current_Frame = ovrHmd_BeginFrame(Main_HMD, 0);
    ^^^^^^


    Because you're declaring the ovrFrameTiming as static, the initialization only happens the first time you run through this code block. The second time you go through it ovrHmd_BeginFrame won't be called, hence the error.


    Thanks! That did it.

    As promised, I'll post my complete example up for people to view in a moment.