Hey guys,
I have a teeny tiny problem with marrying my openGL application and the Oculus Rift. Since it's an openGL problem, I thought I might as well ask here.
To those who might not be familiar, the Oculus is a head mounted display (besides other stuff). Since the Rift's screen is viewed through convex lenses, the rendered image has to be distorted ("barrel distortion") to compensate for these lenses.
I have successfully implemented the neccessary shaders, I am rendering to a framebuffer (from two viewports, to simulate the view through two separate eyes) and I'm trying to get that framebuffer to the screen, but distorted.
My results can be seen in the images:
Click image for larger version. 

Name:	framebufferexample.jpg 
Views:	28 
Size:	3.6 KB 
ID:	1269
Click image for larger version. 

Name:	processedframebufferexample.jpg 
Views:	28 
Size:	6.4 KB 
ID:	1270
As you can see in the first pic, I am getting both my viewpoints in the undistorted framebuffer (which I disabled to take this picture, but that doesn't matter afaik).
In the distorted image however, I have only one central view. How could that be?
As to code, I got
Code :
void MainWindow::paint_to_frameBuffer()
{
    glPushAttrib( GL_TEXTURE_BIT | GL_DEPTH_TEST | GL_LIGHTING );
 
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_CULL_FACE);
 
    // Render to our framebuffer
    glBindFramebuffer(GL_FRAMEBUFFER, gl_frame_buffer);
    // Render to screen (for debugging)
//    glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    // draw left viewpoint
    setUpCamera(OVR::Util::Render::StereoEye_Left);
    drawEverything();
 
    // draw right viewpoint
    setUpCamera(OVR::Util::Render::StereoEye_Right);
 
    drawEverything();
 
    glPopAttrib();
}
for rendering the FB and
Code :
void MainWindow::paint_to_display()
{
    // dumb way to display the frame buffer as a full screen quad, but hey...
    glPushAttrib(GL_TEXTURE_BIT | GL_DEPTH_TEST | GL_LIGHTING );
 
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
 
    // Render to the screen
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
    // reset the screen params.
    glViewport(0, 0, this->width(), this->height());
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
    // clear the screen.
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
    // setup the post process shader.
    glUseProgram(gl_fragment_shader_program);
 
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, gl_frame_buffer_texture);
 
    gl_uniform_1i("texture0", 0);
 
    // render right eye with distortion shader
    renderEyePatch(OVR::Util::Render::StereoEye_Right);
 
    // render left eye with distortion shader
    renderEyePatch(OVR::Util::Render::StereoEye_Left);
 
 
    // clean up.
    glBindTexture(GL_TEXTURE_2D, 0);
    glUseProgram(0);
    glPopAttrib();
}
to get everything on screen.
The function setUpCamera() basically is glViewport for two eyes. renderEyePatch() goes
Code :
void MainWindow::renderEyePatch(OVR::Util::Render::StereoEye eye)
{
        // apply distortion stuff, pass values to shader etc etc
 
        // render the quad on display.
        switch(eye)
        {
        case OVR::Util::Render::StereoEye_Left:
            // render the quad for the eye patch on Oculus display.
            glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer_eye_1);
            glEnableVertexAttribArray(0);
            glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
 
            glBindBuffer(GL_ARRAY_BUFFER, m_uv_buffer_eye_1);
            glEnableVertexAttribArray(1);
            glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
 
            glDrawArrays(GL_QUADS, 0, 4);
 
            glBindBuffer(GL_ARRAY_BUFFER, 0);
            glEnableVertexAttribArray(0);
            glEnableVertexAttribArray(1);
            break;
        case OVR::Util::Render::StereoEye_Right:
            // render the quad for the eye patch on Oculus display.
            glBindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer_eye_2);
            glEnableVertexAttribArray(0);
            glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
 
            glBindBuffer(GL_ARRAY_BUFFER, m_uv_buffer_eye_2);
            glEnableVertexAttribArray(1);
            glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);
 
            glDrawArrays(GL_QUADS, 0, 4);
 
            glBindBuffer(GL_ARRAY_BUFFER, 0);
            glEnableVertexAttribArray(0);
            glEnableVertexAttribArray(1);
            break;
        default:
            break;
        }
}

I took a lot of the code from this example, for example the shaders start at line 536.
If any "guru" might have the slightest idea as to why only one of my viewports is distorted, please let me know. Thanks!