Forum Discussion
anarkavre
11 years agoHonored Guest
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.
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
- yellowCapHonored GuestThanks for sharing, always helpful to have another source of reference.
- cyberealityGrand ChampionNice work. Thanks for posting.
- kerm1tHonored GuestGreat! Thanks for 1st working OpenGL-example (for me :) )
- kerm1tHonored GuestNow, 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() - kerm1tHonored Guest2) 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) - kerm1tHonored Guest
- mungewellHonored GuestThanks 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 - HartLabsHonored GuestFirst 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). - alexlfHonored GuestHello! 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! - HeffExplorerJust wanted to say thanks for this great starting point, allowed me to dive in headfirst!
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 months ago
- 2 years ago
- 1 year ago
- 2 days ago