OpenVR學習01 成功打開了VR設備

目標是生成一個exe文件, 打開VR設備, 打開後, 這個exe就執行結束了, 但VR設備還處於運行狀態git

並無指定哪一種VR設備, 但打開當前的SteamVR - HTC VIVEgithub

記錄項目配置:shell

VS2010api

附加包含目錄:app

C:\OSG64\openvr108\headers;ui

附加庫目錄:this

C:\OSG64\openvr108\lib\win64;spa

附加依賴項:code

openvr_api.lib
glu32.lib
opengl32.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib文檔

 

代碼:

#include "main.h"// 只不過爲了VS2010不報錯
#include<openvr.h>

int main()
{
    vr::EVRApplicationType _type = vr::EVRApplicationType::VRApplication_Scene;
    vr::HmdError *peError =new vr::HmdError;    
    vr::VR_Init(peError, _type );
}

 

相關文檔的內容:

Initialization and Cleanup

Because the OpenVR API causes the game to connect to any attached VR hardware, it is not initialized automatically. To initialize the API and get access to the vr::IVRSystem interface call the vr::VR_Init function. To close down your connection to the hardware and release your vr::IVRSystem interface, call vr::VR_Shutdown.

vr::IVRSystem *vr::VR_Init( vr::HmdError*peError, vr::EVRApplicationType eApplicationType )

eApplicationType must be one of:

  • VRApplication_Scene - A 3D application that will be drawing an environment.
  • VRApplication_Overlay - An application that only interacts with overlays or the dashboard.
  • VRApplication_Background - The application will not start SteamVR. If it is not already running the call with VR_Init will fail with VRInitError_Init_NoServerForBackgroundApp.
  • VRApplication_Utility - The application will start up even if no hardware is present. Only the IVRSettings and IVRApplications interfaces are guaranteed to work. This application type is appropriate for things like installers.

The call will return a vr::IVRSystem pointer that allows the game to call other OpenVR API methods. If something fails the call will return NULL and peError will be set to an error code that indicates what the problem was. peError - The error code that occurred or vr::VRInitError_None if there was no error. See vr::HmdError for possible error codes.

void vr::VR_Shutdown()

Shuts down the connection to the VR hardware and cleans up the OpenVR API. The vr::IVRSystem pointer returned by vr::VR_Init will be invalid after this call is made.

相關文章
相關標籤/搜索