68 lines
1.8 KiB
Markdown
68 lines
1.8 KiB
Markdown
# Linux-VR-Compositor
|
|
|
|
```C
|
|
#define GL_GLEXT_PROTOTYPES
|
|
#include <GL/gl.h> // must include OpenGL before including the Linux VR Compositor header
|
|
|
|
#include <lvrc.h>
|
|
|
|
void main()
|
|
{
|
|
//
|
|
// Initialize OpenHMD device as usual
|
|
ohmd_context * ctx = ohmd_ctx_create();
|
|
ohmd_device * hmd = ...;
|
|
|
|
//
|
|
// Create instance, the only public object exposed by the API
|
|
struct lvrcInstance * compositor = lvrcCreateInstance(hmd);
|
|
|
|
//
|
|
// Initialize Linux VR Compositor SwapChain
|
|
bool bSwapChainCreated = lvrcInitSwapChain(compositor);
|
|
|
|
//
|
|
// Initialize OpenGL using EGL
|
|
// This is mostly as usual, the only change is that you must use the provided NativeDisplay/NativeWindow
|
|
EGLDisplay display = eglGetDisplay(lvrcSwapChainGetNativeDisplay(compositor));
|
|
EGLContext context = eglCreateContext(display, ...);
|
|
EGLSurface surface = eglCreateWindowSurface(display, lvrcSwapChainGetNativeWindow(compositor), ...);
|
|
|
|
eglMakeCurrent(display, surface, surface, >context);
|
|
|
|
//
|
|
// The compositor needs to create some resources that will be used during frame composition
|
|
// NOTE : the EGL context MUST be bound when calling this function
|
|
bool bCompositorInit = lvrcInitFrameResources(compositor);
|
|
|
|
//
|
|
// Main Loop
|
|
while (true)
|
|
{
|
|
ohmd_ctx_update(ctx); // Update OpenHMD as usual
|
|
|
|
lvrcBeginFrame(compositor);
|
|
|
|
... // Render to left & right textures as usual
|
|
|
|
lvrcSubmitFrameLeft(compositor, left_texture);
|
|
|
|
lvrcSubmitFrameRight(compositor, right_texture);
|
|
|
|
eglSwapBuffers(display, surface); // Swap buffers as usual
|
|
|
|
lvrcEndFrame(compositor);
|
|
}
|
|
|
|
lvrcReleaseFrameResources(compositor);
|
|
|
|
// You should destroy your EGL context here
|
|
|
|
lvrcReleaseSwapChain(compositor);
|
|
|
|
lvrcDestroyInstance(compositor);
|
|
|
|
ohmd_ctx_destroy(ctx);
|
|
}
|
|
```
|