36 #include <SDL_opengl.h>
41 static auto const WIDTH = 1920;
42 static auto const HEIGHT = 1080;
48 int main(
int argc,
char *argv[]) {
55 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
56 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
59 auto window = SDL::createWindow(
"OSVR", SDL_WINDOWPOS_UNDEFINED,
60 SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT,
61 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
63 std::cerr <<
"Could not create window: " << SDL_GetError() << std::endl;
68 SDL::GLContext glctx(window.get());
71 SDL_GL_SetSwapInterval(1);
85 std::cerr <<
"Error starting up the joint client/server" << std::endl;
100 if (!display.valid()) {
101 std::cerr <<
"\nCould not get display config, exiting." << std::endl;
105 std::cout <<
"Waiting for the display to fully start up, including "
106 "receiving initial pose update..."
108 while (!display.checkStartup()) {
111 std::cout <<
"OK, display startup status is good!" << std::endl;
115 #ifndef __ANDROID__ // Don't want to pop up the on-screen keyboard
116 SDL::TextInput textinput;
121 while (SDL_PollEvent(&e)) {
128 if (SDL_SCANCODE_ESCAPE == e.key.keysym.scancode) {
134 if (e.type == SDL_QUIT) {
146 SDL_GL_SwapWindow(window.get());
166 glClearColor(0, 0, 0, 1.0f);
167 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
178 glMatrixMode(GL_MODELVIEW);
180 glMultMatrixd(viewMat);
186 glViewport(static_cast<GLint>(viewport.left),
187 static_cast<GLint>(viewport.bottom),
188 static_cast<GLsizei>(viewport.width),
189 static_cast<GLsizei>(viewport.height));
201 glMatrixMode(GL_PROJECTION);
203 glMultMatrixd(projMat);
207 glMatrixMode(GL_MODELVIEW);
void draw_cube(double radius)
Fixed-function pipeline OpenGL code to draw a cube.
void forEachSurface(F OSVR_CLIENTKIT_FUNCTOR_REF functor)
Constant for the number of elements in the matrices we use - 4x4.
Client context object: Create and keep one in your application. Handles lifetime management and provi...
Wrapper for a viewer, eye, and surface bound to a display config. DOES NOT provide lifetime managemen...
bool getViewMatrix(OSVR_MatrixConventions flags, double mat[OSVR_MATRIX_SIZE])
Attempt to get the view matrix.
Header containing some helper code for using SDL2 in a C++11 environment.
OSVR_JointClientOpts osvrJointClientCreateOptions()
Creates an empty OSVR_JointClientOpts.
Matrix transforms column vectors (default)
Column-major memory order (default)
void render(osvr::clientkit::DisplayConfig &disp)
The "wrapper" for rendering to a device described by OSVR.
OSVR_ClientContext osvrJointClientInit(const char applicationIdentifier[], OSVR_JointClientOpts opts)
Initialize the library, starting up a "joint" context that also contains a server.
void forEachEye(F OSVR_CLIENTKIT_FUNCTOR_REF functor)
void getProjectionMatrix(double near, double far, OSVR_MatrixConventions flags, double matrix[OSVR_MATRIX_SIZE]) const
Gets the projection matrix.
Wrapper for a viewer and eye bound to a display config. DOES NOT provide lifetime management for the ...
struct OSVR_JointClientContextOptsObject * OSVR_JointClientOpts
Opaque typedef for options used when starting up a joint client context. Serves as a queue for config...
struct OSVR_ClientContextObject * OSVR_ClientContext
Opaque handle that should be retained by your application. You need only and exactly one...
OSVR_ReturnCode osvrJointClientOptionsTriggerHardwareDetect(OSVR_JointClientOpts opts)
Queues up a trigger for hardware detection.
Matrix takes vectors from a right-handed coordinate system (default)
OSVR_ReturnCode osvrJointClientOptionsAutoloadPlugins(OSVR_JointClientOpts opts)
Queues up the autoloading of plugins. May only be called once per options object. ...
void renderScene()
A simple dummy "draw" function - note that drawing occurs in "room space" by default. (that is, in this example, the modelview matrix when this function is called is initialized such that it transforms from world space to view space)
Class wrapping OSVR_DisplayConfig objects, optionally managing shared ownership.
Matrix maps the near and far planes to signed Z values (in the range [-1, 1]) (default) ...
RelativeViewport getRelativeViewport() const
Gets the video-input-relative viewport corresponding to this surface.