04-01-2015 07:44 AM
// DistortionFnInverse computes the inverse of the distortion function on an argument.
float LensConfig::DistortionFnInverse(float r) const
{
OVR_ASSERT((r <= 20.0f)); // fail here
...
}
SDL_Init(SDL_INIT_VIDEO);
int x = SDL_WINDOWPOS_CENTERED;
int y = SDL_WINDOWPOS_CENTERED;
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
bool debug = false;
ovr_Initialize();
osettings_.hmd = ovrHmd_Create(0);
ovrHmd hmd = osettings_.hmd;
if (hmd == NULL)
{
std::cout << "ERROR: Oculus Rift not detected" << std::endl;
hmd = ovrHmd_CreateDebug(ovrHmd_DK1);
debug = true;
}
if (hmd->ProductName[0] == '\0')
{
std::cout << "ERROR: Rift detected, display not enabled" << std::endl;
}
if (debug == false && hmd->HmdCaps & ovrHmdCap_ExtendDesktop)
{
x = hmd->WindowsPos.x;
y = hmd->WindowsPos.y;
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
int w = hmd->Resolution.w;
int h = hmd->Resolution.h;
window_ = SDL_CreateWindow("Oculus Rift SDL2 OpenGL Demo", x, y, w, h, flags);
glContext_ = SDL_GL_CreateContext(window_);
glewExperimental = GL_TRUE;
glewInit();
scene_->setOVR(&osettings_); // give to my scene OVR parameters for multicamera rendering
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWindowWMInfo(window_, &info);
osettings_.cfg.OGL.Header.API = ovrRenderAPI_OpenGL;
osettings_.cfg.OGL.Header.BackBufferSize = OVR::Sizei(hmd->Resolution.w, hmd->Resolution.h);
osettings_.cfg.OGL.Header.Multisample = 1;
#if defined(OVR_OS_WIN32)
if (!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop))
ovrHmd_AttachToWindow(hmd, info.info.win.window, NULL, NULL);
osettings_.cfg.OGL.Window = info.info.win.window;
osettings_.cfg.OGL.DC = NULL;
#elif defined(OVR_OS_LINUX)
osettings_.cfg.OGL.Disp = info.info.x11.display;
osettings_.cfg.OGL.Win = info.info.x11.window;
#endif
ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
ovrHmd_ConfigureRendering(hmd, &osettings_.cfg.Config, ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive, osettings_.eyeFov, osettings_.eyeRenderDesc);
ovrHmd_ConfigureTracking(hmd, ovrTrackingCap_Orientation | ovrTrackingCap_MagYawCorrection | ovrTrackingCap_Position, 0);
struct OculusSettings
{
public:
ovrHmd hmd;
GLuint frameBuffer;
GLuint texture;
GLuint renderBuffer;
OVR::Sizei renderTargetSize;
ovrFovPort eyeFov[2];
ovrRecti eyeRenderViewport[2];
ovrGLTexture eyeTexture[2];
ovrGLConfig cfg;
ovrEyeRenderDesc eyeRenderDesc[2];
};
04-01-2015 01:45 PM
04-02-2015 01:42 AM
osettings_.eyeFov[0] = hmd->DefaultEyeFov[0];
osettings_.eyeFov[1] = hmd->DefaultEyeFov[1];
ovrHmd_ConfigureRendering(hmd, &osettings_.cfg.Config, ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp | ovrDistortionCap_Overdrive, osettings_.eyeFov, osettings_.eyeRenderDesc);