/// <summary> /// Initializes all Oculus functionality. /// </summary> /// <param name="initializationParameters"> /// Initialization parameters to pass to the ovr_Initialize call. /// </param> /// <remarks> /// Library init/shutdown, must be called around all other OVR code. /// No other functions calls besides ovr_InitializeRenderingShim are allowed /// before ovr_Initialize succeeds or after ovr_Shutdown. /// </remarks> public bool Initialize(OVRTypes.InitParams initializationParameters = null) { if (Initialized) { throw new InvalidOperationException("The Oculus wrapper has already been initialized."); } /* * // Ensure that the DllOvr.dll is loaded, using the bitness matching that of the current process. * LoadDllOvr(); */ OVRTypes.Result success = OVR.Initialize(initializationParameters); if (success < OVRTypes.Result.Success) { return(false); } Initialized = true; return(true); }
/// <summary> /// Configures the specified windows handler. /// </summary> /// <param name="windowsHandler">The windows handler.</param> public override void Configure(IntPtr windowsHandler) { base.Configure(windowsHandler); this.Oculus = new Wrap(); // Initialize the Oculus runtime. OVRTypes.InitParams initializationParameters = new OVRTypes.InitParams(); initializationParameters.Flags = OVRTypes.InitFlags.RequestVersion; initializationParameters.RequestedMinorVersion = 0; #if DEBUG initializationParameters.Flags |= OVRTypes.InitFlags.Debug; #endif bool success = this.Oculus.Initialize(initializationParameters); if (!success) { Console.WriteLine("OVR Error: Failed to initialize the Oculus runtime library."); return; } // Use the head mounted display. OVRTypes.GraphicsLuid graphicsLuid; this.Hmd = this.Oculus.Hmd_Create(out graphicsLuid); if (this.Hmd == null) { Console.WriteLine("OVR Error: Oculus Rift not detected."); return; } if (this.Hmd.ProductName == string.Empty) { Console.WriteLine("OVR Error: The HMD is not enabled."); return; } }
public OculusPlayback() { log = new Log.Logger("Oculus"); initializationParameters = new OVRTypes.InitParams() { LogCallback = (_, level, msg) => { switch (level) { case OVRTypes.LogLevel.Info: case OVRTypes.LogLevel.Debug: log.Info(msg); break; case OVRTypes.LogLevel.Error: log.Error(msg); break; } } }; initializationParameters.Flags |= OVRTypes.InitFlags.RequestVersion; initializationParameters.Flags |= OVRTypes.InitFlags.MixedRendering; }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); InitShader(); InitBuffer(); // Define initialization parameters with debug flag. OVRTypes.InitParams initializationParameters = new OVRTypes.InitParams(); initializationParameters.Flags = OVRTypes.InitFlags.Debug; // Initialize the Oculus runtime. bool success = wrap.Initialize(initializationParameters); if (!success) { MessageBox.Show("Failed to initialize the Oculus runtime library.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error); Exit(); return; } // Use the head mounted display. OVRTypes.GraphicsLuid graphicsLuid; hmd = wrap.Hmd_Create(out graphicsLuid); if (hmd == null) { MessageBox.Show("Oculus Rift not detected.", "Uh oh", MessageBoxButtons.OK, MessageBoxIcon.Error); Exit(); return; } if (hmd.ProductName == string.Empty) { MessageBox.Show("The HMD is not enabled.", "There's a tear in the Rift", MessageBoxButtons.OK, MessageBoxIcon.Error); Exit(); return; } Console.WriteLine("SDK Version: " + wrap.GetVersionString()); try { for (int i = 0; i < 2; i++) { OVRTypes.Sizei idealTextureSize = hmd.GetFovTextureSize((OVRTypes.EyeType)i, hmd.DefaultEyeFov[i], 1); eyeRenderTexture[i] = new TextureBuffer(wrap, hmd, true, true, idealTextureSize, 1, IntPtr.Zero, 1); eyeDepthBuffer[i] = new DepthBuffer(eyeRenderTexture[i].GetSize(), 0); } // Note: the mirror window can be any size, for this sample we use 1/2 the HMD resolution windowSize = new OVRTypes.Sizei(hmd.Resolution.Width / 2, hmd.Resolution.Height / 2); //For image displayed at ordinary monitor - copy of Oculus rendered one. OVRTypes.MirrorTextureDesc mirrorTextureDescription = new OVRTypes.MirrorTextureDesc(); mirrorTextureDescription.Format = OVRTypes.TextureFormat.R8G8B8A8_UNORM_SRGB; mirrorTextureDescription.Width = windowSize.Width; mirrorTextureDescription.Height = windowSize.Height; mirrorTextureDescription.MiscFlags = OVRTypes.TextureMiscFlags.None; // Create the texture used to display the rendered result on the computer monitor. OVRTypes.Result result; result = hmd.CreateMirrorTextureGL(mirrorTextureDescription, out mirrorTexture); WriteErrorDetails(wrap, result, "Failed to create mirror texture."); layerFov = layers.AddLayerEyeFov(); layerFov.Header.Flags = OVRTypes.LayerFlags.TextureOriginAtBottomLeft; // OpenGL Texture coordinates start from bottom left layerFov.Header.Type = OVRTypes.LayerType.EyeFov; // Configure the mirror read buffer uint texId; result = mirrorTexture.GetBufferGL(out texId); WriteErrorDetails(wrap, result, "Failed to retrieve the texture from the created mirror texture buffer."); //Rendertarget for mirror desktop window GL.GenFramebuffers(1, out mirrorFbo); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, mirrorFbo); GL.FramebufferTexture2D(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, texId, 0); GL.FramebufferRenderbuffer(FramebufferTarget.ReadFramebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, 0); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, 0); // Turn off vsync to let the compositor do its magic this.VSync = VSyncMode.Off; //wglSwapIntervalEXT(0); // FloorLevel will give tracking poses where the floor height is 0 result = hmd.SetTrackingOriginType(OVRTypes.TrackingOrigin.FloorLevel); WriteErrorDetails(wrap, result, "Failed to set tracking origin type."); GL.Enable(EnableCap.DepthTest); //DO NOT DELETE IT IN FUTURE UPDATES! } catch { // Release all resources Dispose(layers); if (mirrorFbo != 0) GL.DeleteFramebuffers(1, ref mirrorFbo); Dispose(mirrorTexture); for (int eyeIndex = 0; eyeIndex < 2; ++eyeIndex) { Dispose(eyeRenderTexture[eyeIndex]); Dispose(eyeDepthBuffer[eyeIndex]); } // Disposing the device, before the hmd, will cause the hmd to fail when disposing. // Disposing the device, after the hmd, will cause the dispose of the device to fail. // It looks as if the hmd steals ownership of the device and destroys it, when it's shutting down. // device.Dispose(); Dispose(hmd); Dispose(wrap); } }