libgoatvr

annotate doc/1-init.rst @ 28:5136dfcea7b1

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