Open burito opened 5 years ago
Contents of textvr.c.txt
/*
Make sure to first...
cp OpenVR/bin/osx32/libopenvr_api.dylib .
Then compile with
clang testvr.c -IOpenVR/headers -otestvr -L. -lopenvr_api -rpath .
*/
#include <stdio.h>
#include <openvr_capi.h>
struct VR_IVRSystem_FnTable * OVR = NULL;
struct VR_IVRCompositor_FnTable * OVRC;
struct VR_IVRRenderModels_FnTable * OVRM;
S_API intptr_t VR_InitInternal( EVRInitError *peError, EVRApplicationType eType );
S_API void VR_ShutdownInternal();
S_API bool VR_IsHmdPresent();
S_API intptr_t VR_GetGenericInterface( const char *pchInterfaceVersion, EVRInitError *peError );
S_API bool VR_IsRuntimeInstalled();
S_API const char * VR_GetVRInitErrorAsSymbol( EVRInitError error );
S_API const char * VR_GetVRInitErrorAsEnglishDescription( EVRInitError error );
int main(int argc, char* argv[])
{
EVRInitError eError;
printf("About to VR_IsHmdPresent\n");
if( !VR_IsHmdPresent() )
{
printf("VR Headset is not present\n");
return 1;
}
printf("About to VR_IsRuntimeInstalled\n");
if( !VR_IsRuntimeInstalled() )
{
printf("VR Runtime is not installed\n");
return 1;
}
printf("About to VR_InitInternal\n");
VR_InitInternal(&eError, EVRApplicationType_VRApplication_Scene);
if (eError != EVRInitError_VRInitError_None)
{
printf("VR_InitInternal: %s\n", VR_GetVRInitErrorAsSymbol(eError));
return 2;
}
char fnTableName[128];
int result1 = sprintf(fnTableName, "FnTable:%s", IVRSystem_Version);
printf("About to %s\n", fnTableName);
OVR = (struct VR_IVRSystem_FnTable *)VR_GetGenericInterface(fnTableName, &eError);
if (eError != EVRInitError_VRInitError_None)
{
printf("VR_GetGenericInterface(\"%s\"): %s\n", IVRSystem_Version, VR_GetVRInitErrorAsSymbol(eError));
return 2;
}
result1 = sprintf(fnTableName, "FnTable:%s", IVRCompositor_Version);
printf("About to %s\n", fnTableName);
OVRC = (struct VR_IVRCompositor_FnTable *)VR_GetGenericInterface(fnTableName, &eError);
if (eError != EVRInitError_VRInitError_None)
{
printf("VR_GetGenericInterface(\"%s\"): %s\n", IVRCompositor_Version, VR_GetVRInitErrorAsSymbol(eError));
return 2;
}
result1 = sprintf(fnTableName, "FnTable:%s", IVRRenderModels_Version);
printf("About to %s\n", fnTableName);
OVRM = (struct VR_IVRRenderModels_FnTable *)VR_GetGenericInterface(fnTableName, &eError );
if (eError != EVRInitError_VRInitError_None)
{
printf("VR_GetGenericInterface(\"%s\"): %s\n", IVRRenderModels_Version, VR_GetVRInitErrorAsSymbol(eError));
return 2;
}
printf("About to OVRC->GetVulkanInstanceExtensionsRequired\n");
uint32_t buffer_size = OVRC->GetVulkanInstanceExtensionsRequired( NULL, 0 );
printf("Everything worked fine.\n");
return 0;
}
Just what it says on the tin.
I've written a minimalist test example demonstrating the feature.
testvr.c.txt
I haven't managed to get this program to execute its final printf() on OSX. Works just fine on windows (and I expect Linux, but haven't tested just yet).