Skip to main content
kojack
Honored Contributor
March 30, 2013

Ogre3D Integration

I grabbed the Oculus sdk earlier today and have been working on a sample of using it with the open source 3d engine Ogre3D.

I've got the rendering working fairly well and I wrote a parser to load the tuscany scene from the sdk. Head tracking is almost implemented.

Since I don't have an actual oculus rift, I'll give out a test version soon to see if it works for anyone else.

http://www.ogre3d.org/forums/viewtopic.php?f=5&t=76970



Edited in Latest Status:
06/04/2013
Source (MIT licensed) released at https://bitbucket.org/rajetic/ogreoculus

08/04/2013
Latest binary demo: https://bitbucket.org/rajetic/ogreoculus/downloads/OgreOculusDemo1_v0.5.1.7z

    38 replies

    New Participant
    October 27, 2013
    indeed, managing multiple vps may not be always usefull outside public presentations and stuff :idea:
    altrough if it's of any use, i finally nailed the compositor issues! with this class it's possible to create cameras and viewports with ease. there would be a fair amount of improvements to do tough, but at least it's possible to create many vps without crashes. it's basically a class to wrap ogre functions into something safer/easier to use ( at least for me)

    in my stuff, i implemented it in a gameManager class extending Ogre::FrameListener and Ogre::WindowEventListner

    (i'm also making my little 3d engine, but i don't want to publish it, at least not yet )
    http://pastebin.com/wpGvyLa2
    http://pastebin.com/6JNgerHJ

    it might look redundent but it could provide more controls to automate stuff that always have to be done the same way

    i'm a bit busy with the actual project i'd like to make with the rift now, so i won't be able to post more stuff in this thread, but i hope it continues!
    New Participant
    April 23, 2014
    Hi everybody,

    I'm trying to integrate OGRE (1.9 version) with the latest Oculus Rift SDK (0.3.1 version).
    In particular, I have to use the Direct3D9 render system and I'd like to use the SDK distortion rendering approach.

    What I've done so far is:

    • Create a custom render loop where buffer swapping isn't called

    • Create two RTT texture where the scene is rendered from two different cameras (left and right eye)

    • Call ovrHmd_BeginFrame and ovrHmd_EndFrame in frameStarted and frameEnded callbacks

    • Call ovrHmd_BeginEyeRender and ovrHmd_EndEyeRender in preRenderTargetUpdate and postRenderTargetUpdate callbacks


    I can see my scene rendered distorted for a moment, but after that the output is a mess.
    Sometimes I see a completely black window, sometimes I see this: http://i.imgur.com/mALc04F.jpg (blue and white are the background colors of left and right eye viewports).

    Digging in the Oculus Rift SDK sources, I've discovered that the DistortionRenderer::RenderBothDistortionMeshes (inside CAPI_D3D9_Util.cpp) method, which is invocated in the ovrHmd_EndFrame function, causes the issue.
    In particular, I suspect all is related to the setting of pixel and vertex shaders which happens in that method.


    [Edit]

    Adding these two lines at the end of the DistortionRenderer::RenderBothDistortionMeshes method fixes the issue:


    ...

    device->SetPixelShader(NULL);
    device->SetVertexShader(NULL);

    //Revert render state
    RevertAllStates();


    Is it a bug?
    New Participant
    November 4, 2014
    Any updates on this project? I can't compile ... :oops:

    somehow the library includes does not work properly:

    1>c:\oculussdk\ogreoculus\ogreoculus\ogreoculus.cpp(15): fatal error C1083: Cannot open include file: 'OVR.h': No such file or directory

    Obvisiouly the path in the .sln file are set relatively. If I correct the path to point to my OculusSDK, I receive this error:

    --
    1>c:\ogreoculus\ogreoculus\ogreoculus.cpp(73): error C2027: use of undefined type 'OVR::SensorDevice'
    1> c:\ogreoculus\ogreoculus\ogreoculus.h(26) : see declaration of 'OVR::SensorDevice'
    1>c:\ogreoculus\ogreoculus\ogreoculus.cpp(73): error C2227: left of '->Release' must point to class/struct/union/generic type
    1>c:\ogreoculus\ogreoculus\ogreoculus.cpp(77): error C2027: use of undefined type 'OVR::HMDDevice'

    ...

    Anyone could help me on this? Thanks in advance!!
    Up and Coming
    November 10, 2014
    kojack is working on a new version using SDK 0.4.x, but it seems to be more difficult to get it to run in Ogre than 0.3.x was.

    I don't know if it helps, but you can use this version to work with Ogre (1.9) and the SDK 0.4.x, as long as you're fine with running in extended mode. Direct mode is more involved, (see first link).
    New Participant
    November 13, 2014
    "ueczz" wrote:
    kojack is working on a new version using SDK 0.4.x, but it seems to be more difficult to get it to run in Ogre than 0.3.x was.

    I don't know if it helps, but you can use this version to work with Ogre (1.9) and the SDK 0.4.x, as long as you're fine with running in extended mode. Direct mode is more involved, (see first link).


    thanks, that helped a lot! That example works just fine!
    Inspiring
    June 9, 2015
    If anybody find it interesting here, this is a verry simple implementation of the 0.6 SDK with Ogre.

    http://pastebin.com/y2EMhmT2

    I just pasted the code I use in several files in my project, there is two classes, OculusInterface that init/shutdown the lib and configure the HMD and all that good stuff, and the OgreOculusRender that create the scene, a window, cameras, get the rift tracking state and render. Rendering is done by calling the method OgreOculusRender::RenderOneFrame()
    updateTime get's it's timing from the Rift SDK, since it's the Oculus Compositor that actually present frames to rift's screen, it should be safe to think that the "deltaTime" of the render is the one expected. (haven't check it but if it's like the old "deltaSeconds", maybe it's only returning 1/75 on a DK2 and 1/60 on a DK1... :roll:)

    The implementation isn't ideal because I'm basicly rendering to a texture then copying it to the current swapTexture provided by the SDK. It's done in OpenGL only here, by calling glCopyImageSubData(). It's happening in vram and apparently don't waste that much compute power by frame. Howerver, it's seems to be the simpler way to do it with Ogre, since you can't RTT to a texture that wasn't created by Ogre's TextureManager. (Need to modify Ogre to be able to create an Ogre::GLTexture with an existing texture id, I haven't the time to do that, I tried but I found it wasn't worth the effort for me.)

    So, since the new SDK is a bit "magic" everything works as advertised, Direct mode ( *\o/*), The new compositor system is really simple to understand, I just basicly put my rendering on it but interesting things seems possible with the layer system
    CV1+Touch; Running on GTX980 - 4770K - 32GB DDR3 Developer at LIV
    Inspiring
    June 9, 2015
    Great news.
    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
    Up and Coming
    September 26, 2015
    I just found this thread, which would probably have been helpful when trying to integrate SDK 0.7.0

    https://github.com/raymond-w-ko/dk2test

    Anyways, here is my solution for integrating OGRE 2.0 with the SDK 0.7.0. I had chosen to use the OpenGL 3+ render system since the OpenGL 2 and fixed function pipeline stuff cause severe stuttering issues.

    Unlike Ybalrid's solution, the extra copy from Ogre RenderTexture to Oculus swap texture is not necessary, and modifying the Ogre engine is also not necessary. However, this is at the cost of using illegal C++, with redefining private to public, and casting to dummy subclasses. This works fine in practice with MSVC though and is self contained enough.

    SDL 2.0 is used for windowing and events.

    I have also add debug mirroring mode and the ability to use WASD to increase or reduce render texture resolution and FOV in case performance needs to drop to keep up with FPS. This also served as a nice test for resource destruction.