Skip to main content
Up and Coming
May 29, 2014

Oculus Rift SDL2 OpenGL Demo

I created a simple demo to show how to use the latest Oculus SDK with SDL2 and OpenGL using SDK Rendering. You can access the source code here.

UPDATE: I updated the demo to work with the new SDK. Positional tracking is not applied to the camera, but it can easily be added. You can access the source code here. Here are two screenshots for those who are curious.

    18 replies

    Participant
    May 29, 2014
    Thanks for sharing, always helpful to have another source of reference.
    Inspiring
    May 29, 2014
    Nice work. Thanks for posting.
    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
    Participant
    May 30, 2014
    Great! Thanks for 1st working OpenGL-example (for me :) )
    Participant
    June 22, 2014
    Now, I have two problems with this example:

    1) somehow the perspective seems to be with vUp towards right side. How can ego position and lookat be changed (e.g. similar to gluLookAt)

    2) when trying to debug (with VStudio 2010), whole Visual Studio / Windows freezes after call of ovrHmd_ConfigureRendering()
    Participant
    June 22, 2014
    2) can be solved with this: viewtopic.php?f=17&t=8611&p=125523#p125523

    However the system is still badly inrepsonsive while debugging (only keyboard works)
    Participant
    June 27, 2014
    now solved 1), too. model coordinate system (RHS) was Y,Z,-X compared to Oculus one :D

    virtualroad.jpg
    Up and Coming
    August 1, 2014
    Thanks for putting this together, I was able to compile on Linux with the little changes, 'min()' is not defined, I added

    inline int max ( int a, int b ) { return a > b ? a : b; }


    And then I had a huge command line

    $ g++ `sdl2-config --cflags` -I /storage/OculusSDK-official-0.3.2/LibOVR/Src/ SDL_oculus_0_3_4.c -L /storage/OculusSDK-official-0.3.2/LibOVR/Lib/Linux/Release/x86_64/ -lovr -ludev -lGL -lGLEW -lX11 -lXrandr -lpthread `sdl2-config --libs` -o SDL_oculus


    Unfortunately the new version (which you link above) does not work.... I guess I'll have to wait for Oculus to get their act together with Linux version of SDK 0.4 :x

    Cheers,
    Simon
    Up and Coming
    August 1, 2014
    First time playing with any Oculus SDK but I got it working! Thanks! Had a bit of trouble setting it up at first but here are my VS2010 express project settings:

    Library Directories:

    ...Includes\OculusSDK\LibOVR\Lib\Win32\VS2010
    ...Includes\OpenGL\glew-1.9.0\lib
    ...Includes\SDL2-2.0.3\lib\x86

    Include Directories:

    ...Includes\SDL2-2.0.3\include
    ...Includes\OculusSDK\LibOVR\Src
    ...Includes\OpenGL\glew-1.9.0\include

    /MD set

    Libraries:

    glew32s.lib
    opengl32.lib
    libovr.lib
    ws2_32.lib
    winmm.lib
    SDL2.lib
    SDL2main.lib

    Ignore Specific Library:

    atls.lib

    Add to release folder:

    SDL2.dll

    DK2 set to extended desktop mode (crashes with console output OVRcreateDXGIFactory2 result 0x0 otherwise).
    Synthesis - Abstract Molecular Dynamics Simulator @HartLabs
    New Participant
    August 3, 2014
    Hello! Thanks for the example!
    I've been trying to cram the oculusRoomTiny example and this one together, and everything is working save the positional tracking, but I'm not sure why. The important bits are:


    static float BodyYaw(3.141592f);
    static Vector3f HeadPos(0.0f, 1.6f, -5.0f);
    HeadPos.y = ovrHmd_GetFloat(hmd, OVR_KEY_EYE_HEIGHT, HeadPos.y);

    for (int eyeIndex = 0; eyeIndex < ovrEye_Count; eyeIndex++)
    {
    ovrEyeType eye = hmd->EyeRenderOrder[eyeIndex];
    eyeRenderPose[eye] = ovrHmd_GetEyePose(hmd, eye);

    // Get view and projection matrices
    Matrix4f rollPitchYaw = Matrix4f::RotationY(BodyYaw);
    Matrix4f finalRollPitchYaw = rollPitchYaw * Matrix4f(eyeRenderPose[eye].Orientation);
    Vector3f finalUp = finalRollPitchYaw.Transform(Vector3f(0, 1, 0));
    Vector3f finalForward = finalRollPitchYaw.Transform(Vector3f(0, 0, -1));
    Vector3f shiftedEyePos = HeadPos + rollPitchYaw.Transform(eyeRenderPose[eye].Position);
    Matrix4f view = Matrix4f::LookAtRH(shiftedEyePos, shiftedEyePos + finalForward, finalUp);
    Matrix4f proj = ovrMatrix4f_Projection(eyeRenderDesc[eye].Fov, 0.01f, 10000.0f, true);
    Matrix4f MVPMatrix = proj * Matrix4f::Translation(eyeRenderDesc[eye].ViewAdjust) * view;

    glViewport(eyeRenderViewport[eye].Pos.x, eyeRenderViewport[eye].Pos.y, eyeRenderViewport[eye].Size.w, eyeRenderViewport[eye].Size.h);


    glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, &MVPMatrix.Transposed().M[0][0]);


    glDrawArrays(GL_TRIANGLES, 0, 3);


    }

    glBindVertexArray(0);

    ovrHmd_EndFrame(hmd, eyeRenderPose, &eyeTexture[0].Texture);


    The rest is essentially the above example.

    By using eyeRenderPose[eye].Position to gain shiftedEyePos, and by working that into my view matrix, I THOUGHT positional tracking would work, but no luck :(

    Any tips on what I'm doing wrong? Sorry if this is the wrong place to ask.

    Thanks!
    New Participant
    August 4, 2014
    Just wanted to say thanks for this great starting point, allowed me to dive in headfirst!