private bool StartupOVR() { EVRInitError error = EVRInitError.Driver_Failed; vr = OpenVR.Init(ref error, EVRApplicationType.VRApplication_Overlay); if (error != EVRInitError.None) { Debug.WriteLine("OpenVR Init Error: " + error.ToString()); return(false); } overlay = OpenVR.Overlay; EVROverlayError overlayError = overlay.CreateOverlay("Jstf_ovr_cards", "OpenVR Cards System Overlay", ref overlayHandle); if (overlayError != EVROverlayError.None) { OpenVR.Shutdown(); Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString()); return(false); } /*overlayError = overlay.SetOverlayFromFile(overlayHandle, AssetsPath + "overlay.png"); * if (overlayError != EVROverlayError.None) * { * CleanupOVR(); * Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString()); * return false; * }*/ overlayError = overlay.SetOverlayInputMethod(overlayHandle, VROverlayInputMethod.Mouse); if (overlayError != EVROverlayError.None) { CleanupOVR(); Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString()); return(false); } overlayTexture = new Texture_t { eType = ETextureType.OpenGL, eColorSpace = EColorSpace.Auto, handle = (IntPtr)textureId }; overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture); if (overlayError != EVROverlayError.None) { CleanupOVR(); Debug.WriteLine("OpenVR Overlay Error: " + overlayError.ToString()); return(false); } HmdId = OpenVR.k_unTrackedDeviceIndex_Hmd; for (uint i = HmdId + 1; i < OpenVR.k_unMaxTrackedDeviceCount; i++) { if (vr.IsTrackedDeviceConnected(i)) { ETrackedDeviceClass cls = vr.GetTrackedDeviceClass(i); if (cls == ETrackedDeviceClass.Controller) { ETrackedControllerRole rl = vr.GetControllerRoleForTrackedDeviceIndex(i); if (rl == ETrackedControllerRole.LeftHand) { LeftControllerId = i; Debug.WriteLine("Found Left Controller"); } else if (rl == ETrackedControllerRole.RightHand) { RightControllerId = i; Debug.WriteLine("Found Right Controller"); } } } } mat = new HmdMatrix34_t { m0 = 1, m1 = 0, m2 = 0, m3 = 0f, m4 = 0, m5 = 1, m6 = 0, m7 = 0.1f, m8 = 0, m9 = 0, m10 = 1, m11 = 0f }; overlayError = overlay.SetOverlayTransformTrackedDeviceRelative(overlayHandle, RightControllerId, ref mat); if (overlayError != EVROverlayError.None) { Debug.WriteLine("Cannot bind overlay to Tracked device."); Debug.WriteLine("Error: " + overlayError.ToString()); CleanupOVR(); return(false); } overlayError = overlay.SetOverlayWidthInMeters(overlayHandle, 0.2f); if (overlayError != EVROverlayError.None) { Debug.WriteLine("Cannot set overlay size."); Debug.WriteLine("Error: " + overlayError.ToString()); CleanupOVR(); return(false); } overlayError = overlay.SetOverlayAlpha(overlayHandle, 1); if (overlayError != EVROverlayError.None) { Debug.WriteLine("Cannot set overlay alpha."); Debug.WriteLine("Error: " + overlayError.ToString()); CleanupOVR(); return(false); } overlayError = overlay.SetOverlayColor(overlayHandle, 1, 1, 1); if (overlayError != EVROverlayError.None) { Debug.WriteLine("Cannot set overlay color."); Debug.WriteLine("Error: " + overlayError.ToString()); CleanupOVR(); return(false); } #if DEBUG Debug.WriteLine("OpenVR Startup Complete"); #endif return(true); }
/** * Set an overlay's color */ public void SetColor(float red, float green, float blue) { ReportError(overlay.SetOverlayColor(handle, red, green, blue)); }