34 #include <SDL_opengl.h>
39 static auto const WIDTH = 1920;
40 static auto const HEIGHT = 1080;
46 int main(
int argc,
char *argv[]) {
53 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
54 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
57 auto window = SDL::createWindow(
"OSVR", SDL_WINDOWPOS_UNDEFINED,
58 SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT,
59 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
61 std::cerr <<
"Could not create window: " << SDL_GetError() << std::endl;
66 SDL::GLContext glctx(window.get());
69 SDL_GL_SetSwapInterval(1);
74 if (!display.valid()) {
75 std::cerr <<
"\nCould not get display config (server probably not "
76 "running or not behaving), exiting."
81 std::cout <<
"Waiting for the display to fully start up, including "
82 "receiving initial pose update..."
84 while (!display.checkStartup()) {
87 std::cout <<
"OK, display startup status is good!" << std::endl;
91 #ifndef __ANDROID__ // Don't want to pop up the on-screen keyboard
92 SDL::TextInput textinput;
97 while (SDL_PollEvent(&e)) {
104 if (SDL_SCANCODE_ESCAPE == e.key.keysym.scancode) {
110 if (e.type == SDL_QUIT) {
122 SDL_GL_SwapWindow(window.get());
142 glClearColor(0, 0, 0, 1.0f);
143 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
154 glMatrixMode(GL_MODELVIEW);
156 glMultMatrixd(viewMat);
162 glViewport(static_cast<GLint>(viewport.left),
163 static_cast<GLint>(viewport.bottom),
164 static_cast<GLsizei>(viewport.width),
165 static_cast<GLsizei>(viewport.height));
177 glMatrixMode(GL_PROJECTION);
179 glMultMatrixd(projMat);
183 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.
Matrix transforms column vectors (default)
Column-major memory order (default)
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 ...
void render(osvr::clientkit::DisplayConfig &disp)
The "wrapper" for rendering to a device described by OSVR.
Matrix takes vectors from a right-handed coordinate system (default)
Class wrapping OSVR_DisplayConfig objects, optionally managing shared ownership.
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)
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.