Skip to content

Getting Started

TJ Horner edited this page Jul 12, 2021 · 2 revisions

Thanks for trying out OVRSharp! We hope this guide will assist you so you can get an OpenVR overlay up and running within minutes.

Prerequisites

To start, make sure your project is compatible with the .NET Standard 2.0 target. We recommend using .NET 5.0 or later with your project. Download OVRSharp from NuGet and add it to your project’s dependencies.

Build your project to make sure everything still works! You should also see an openvr_api.dll in your project’s output directory, next to your executable. You should ship this with your app when the time comes.

Connecting to OpenVR

Before you use any OpenVR APIs, you will need to initialize a connection to the OpenVR runtime (i.e., SteamVR). With OVRSharp, this is done with the Application class. You can either use this class directly in your code, or extend it to provide your own functionality. In this guide, we will be doing the latter.

public class MyCoolApp : Application {
  public MyCoolApp() : base(ApplicationType.Overlay) { }
}

You might have noticed we are initializing it with ApplicationType.Overlay. The OpenVR API needs to know which type of application we are writing, since it will give us different permissions or react differently depending on the type. You can read about the differences in application types here.

Since we will be making an overlay, we’ll use ApplicationType.Overlay.

Now that we have our Application, we can initialize it in our entry point.

public class Program {
  public void Main() {
    var app = new MyCoolApp();
  }
}

When instantiated, Applications will internally initialize the OpenVR API with your specified ApplicationType. This means we can now use other OpenVR APIs!

Creating an Overlay

Since we have an Application all set up, we can now use the Overlay class to create an overlay within the OpenVR compositor.

Inside of our MyCoolApp class, we can add an overlay property and instantiate it in the constructor.

public class MyCoolApp : Application {
  private Overlay overlay;

  public MyCoolApp() : base(ApplicationType.Overlay) {
    // You can also extend the `Overlay` class yourself, but for
    // demonstration we will be instantiating it directly.
    overlay = new Overlay("my_cool_overlay", "My Cool Overlay");
  }
}

To prevent our program from closing instantly, add Console.ReadLine() to the end of your Main method.

Now if you run your program and look in the Overlay Viewer (in SteamVR, located under Developer -> Overlay Viewer), you should see your new overlay in the list as my_cool_overlay. Congratulations! You just took the first steps in creating an awesome OpenVR overlay.

Take a look at the Overlay API to see what's possible from here: https://github.com/OVRTools/OVRSharp/blob/master/OVRSharp/Overlay.cs

You can also look at some projects that use OVRSharp to create overlays, like WhereIsForward.

Clone this wiki locally