openvr_test1
diff src/main.cc @ 0:806d30b46748
OpenVR test initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 13 Apr 2016 09:39:37 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.cc Wed Apr 13 09:39:37 2016 +0300 1.3 @@ -0,0 +1,85 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <assert.h> 1.7 +#include <SDL2/SDL.h> 1.8 +#include <GL/glew.h> 1.9 +#include "app.h" 1.10 + 1.11 +static bool handle_event(SDL_Event *ev); 1.12 + 1.13 +static SDL_Window *win; 1.14 +static SDL_GLContext ctx; 1.15 +static bool quit; 1.16 + 1.17 +int main(int argc, char **argv) 1.18 +{ 1.19 + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); 1.20 + int winx = SDL_WINDOWPOS_UNDEFINED; 1.21 + int winy = SDL_WINDOWPOS_UNDEFINED; 1.22 + 1.23 + if(!(win = SDL_CreateWindow("OpenVR test", winx, winy, 1024, 640, SDL_WINDOW_OPENGL))) { 1.24 + fprintf(stderr, "failed to open window\n"); 1.25 + return 1; 1.26 + } 1.27 + if(!(ctx = SDL_GL_CreateContext(win))) { 1.28 + fprintf(stderr, "failed to create OpenGL context\n"); 1.29 + return 1; 1.30 + } 1.31 + int xsz, ysz; 1.32 + SDL_GetWindowSize(win, &xsz, &ysz); 1.33 + app_reshape(xsz, ysz); 1.34 + 1.35 + if(!app_init()) { 1.36 + return 1; 1.37 + } 1.38 + 1.39 + for(;;) { 1.40 + SDL_Event ev; 1.41 + while(SDL_PollEvent(&ev)) { 1.42 + if(!handle_event(&ev) || quit) { 1.43 + goto done; 1.44 + } 1.45 + } 1.46 + 1.47 + app_draw(); 1.48 + assert(glGetError() == GL_NO_ERROR); 1.49 + } 1.50 + 1.51 +done: 1.52 + app_shutdown(); 1.53 + SDL_Quit(); 1.54 + return 0; 1.55 +} 1.56 + 1.57 +void app_swap_buffers() 1.58 +{ 1.59 + SDL_GL_SwapWindow(win); 1.60 +} 1.61 + 1.62 +void app_quit() 1.63 +{ 1.64 + quit = true; 1.65 +} 1.66 + 1.67 +static bool handle_event(SDL_Event *ev) 1.68 +{ 1.69 + switch(ev->type) { 1.70 + case SDL_QUIT: 1.71 + return false; 1.72 + 1.73 + case SDL_KEYDOWN: 1.74 + case SDL_KEYUP: 1.75 + app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED); 1.76 + break; 1.77 + 1.78 + case SDL_WINDOWEVENT: 1.79 + if(ev->window.event == SDL_WINDOWEVENT_RESIZED) { 1.80 + app_reshape(ev->window.data1, ev->window.data2); 1.81 + } 1.82 + break; 1.83 + 1.84 + default: 1.85 + break; 1.86 + } 1.87 + return true; 1.88 +} 1.89 \ No newline at end of file