libgoatvr

view doc/1-init.rst @ 27:e819f63535b3

adding stub doc pages
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 30 Mar 2015 05:51:22 +0300
parents
children
line source
1 Initialization
2 --------------
4 Before calling any other function you need to initialize the VR library by
5 calling ``vr_init``. Similarly, ``vr_shutdown`` frees up all resources held by
6 the library.
8 Libgoatvr has a number of backend modules for interfacing with VR headsets, and
9 there might be multiple modules compiled with your version of libgoatvr. If you
10 don't want to rely on the built-in defaults, you might want to enumerate and
11 select which module to use.
13 The following example initializes the library, and prints the list of available
14 VR modules:
16 .. code:: c
18 #include <stdio.h>
19 #include <goatvr.h>
21 int main(void)
22 {
23 int i, nmod;
25 if(vr_init() == -1) {
26 fprintf(stderr, "failed to initialize goatvr\n");
27 return 1;
28 }
30 nmod = vr_module_count();
31 printf("There are %d modules:\n", nmod);
32 for(i=0; i<nmod; i++) {
33 printf(" %2d - %s\n", i, vr_module_name(i));
34 }
35 vr_shutdown();
36 return 0;
37 }
39 Running this on my computer, with the Oculus Rift DK2 connected, and oculusd
40 running, produces this output::
42 initialized LibOVR 0.4.4
43 1 Oculus HMD(s) found
44 [0]: Oculus VR - Oculus Rift DK2
45 using vr module: libovr
46 There are 2 modules:
47 0 - libovr
48 1 - null
50 The first four lines come from the initialization of the ``libovr`` module which
51 is selected by default if it's available. If however I turn off the DK2 or stop
52 the daemon, then I'm getting just the ``null`` module in this list.
54 If you'd like to override the default selected module, and use the ``null``
55 module instead of ``libovr``, which is useful during development to avoid having
56 to put the HMD on and off all the time, you can call ``vr_use_module(1)``, or
57 ``vr_use_module_named("null")``.