๐Ÿ”ŒIntegrating Native Applications

Bring support for the Looking Glass display to your application

Overview

Integrating with the Bridge SDK consists of five steps:

  1. Configure a shared GPU rendering context

  2. Initialize Bridge to spawn a post-processing thread and allocate resources

  3. Create a Looking Glass window using the shared rendering context

  4. Render views of a 3D scene into a framebuffer object

  5. Trigger the Bridge post-processing step with the framebuffer object

This method of integration works for all Looking Glass displays. It is supported on Windows and MacOS using OpenGL. It is supported on Windows using DirectX 11 and 12. It is supported on MacOS using Metal. This method will apply a special transformation function that will map each diode on the Looking Glass display to the correct color corresponding to the direction of light emitted from the diode. This was previously the responsibility of the developer using HoloPlay Core. This example will demonstrate the aforementioned steps using OpenGL.

Configure a Shared GPU Rendering Context

The first step is to configure a GPU rendering context. This example code uses GLFW with GLAD:

// initialize glfw
if (!glfwInit()) return -1;

// create preview window
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 800, "Bridge SDK example", nullptr, nullptr);

if (!window) {
	glfwTerminate();
	return -1;
}
glfwMakeContextCurrent(window);

Initialize Bridge

The second step is to initialize Bridge. This step is required before calling any other Bridge functions.

initialize_bridge("Bridge SDK example");

// query the available Looking Glass displays
int lkg_display_count = 0;
std::vector<unsigned long> lkg_displays;
get_displays(&lkg_display_count, nullptr);
lkg_displays.resize(lkg_display_count);
get_displays(&lkg_display_count, lkg_displays.data());

Create a Looking Glass window

The third step is to create a window that can be used to render to a Looking Glass display.

// perform any desired queries on the Looking Glass displays
std::wstring serial;
std::vector<std::wstring> lkg_display_serials;
int serial_count = 0;

// query all connected Looking Glass displays
for (auto it : lkg_displays) {
    get_device_serial_for_display(it, &serial_count, nullptr);
    serial.resize(serial_count);
    get_device_serial_for_display(it, &serial_count, serial.data());
    lkg_display_serials.push_back(serial);
}

// Note: callers are required to allocate enough memory for return parameters \
of variable length

// create window using configuration from the target Looking Glass display
unsigned long lkg_wnd;
instance_window_gl(&lkg_wnd, lkg_displays.front());

Render Views of a 3D Scene

The fourth step is to render a 3D scene into a framebuffer object using a quilt layout.

// Configure your 3D scene geometry and rendering pipeline...

// Get idealized rendering parameters for the display
get_default_quilt_settings(lkg_wnd, &lkg_aspect, &lkg_quilt_w, &lkg_quilt_h, &lkg_vx, &lkg_vy);
lkg_view_w  = int(float(lkg_quilt_w) / float(lkg_vx));
lkg_view_h = int(float(lkg_quilt_h) / float(lkg_vy));

// Configure texture for the framebuffer
glGenTextures(1, &lkg_render_texture);
glBindTexture(GL_TEXTURE_2D, lkg_render_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lkg_quilt_w, lkg_quilt_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);

// Configure the renderbuffer for depth
glGenRenderbuffers(1, &lkg_depth_buffer);
glBindRenderbuffer(GL_RENDERBUFFER, lkg_depth_buffer); 
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, lkg_quilt_w, lkg_quilt_h);

// Configure the shared framebuffer object
glGenFramebuffers(1, &lkg_render_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, lkg_render_fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lkg_render_texture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, lkg_depth_buffer);

// Render views into framebuffer using quilt layout
glBindFramebuffer(GL_FRAMEBUFFER, lkg_render_fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float cam_dist = 0.005f;
float cam_offset = -(float)(lkg_vx * lkg_vy - 1) / 2.0f * cam_dist;
for (int y = 0; y < lkg_vx; y++) {
	for (int x = 0; x < lkg_vy; x++) {
		glViewport(x*lkg_view_w, y*lkg_view_h, lkg_view_w, lkg_view_h);
		
		// drawScene(your_shader, your_geometry, cam_offset);
		
		cam_offset += cam_dist;
    }
}

Trigger the Bridge Post-Processing

The fifth and last step consists of trigger the post-processing shader pipeline necessary to apply the Looking Glass optical transformation.

draw_interop_quilt_texture_gl(lkg_wnd, 
                              lkg_render_texture,
                              PixelFormats::RGBA,
                              lkg_quilt_w,
                              lkg_quilt_h,
                              lkg_vx,
                              lkg_vy,
                              1.0f,
                              1.0f);

Note: Upon termination the application should also call uninitialize_bridge when deallocating any other resources used by the program.

Last updated

Change request #502: August 18 Changes