openvr_test1

view 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 source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include <SDL2/SDL.h>
5 #include <GL/glew.h>
6 #include "app.h"
8 static bool handle_event(SDL_Event *ev);
10 static SDL_Window *win;
11 static SDL_GLContext ctx;
12 static bool quit;
14 int main(int argc, char **argv)
15 {
16 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
17 int winx = SDL_WINDOWPOS_UNDEFINED;
18 int winy = SDL_WINDOWPOS_UNDEFINED;
20 if(!(win = SDL_CreateWindow("OpenVR test", winx, winy, 1024, 640, SDL_WINDOW_OPENGL))) {
21 fprintf(stderr, "failed to open window\n");
22 return 1;
23 }
24 if(!(ctx = SDL_GL_CreateContext(win))) {
25 fprintf(stderr, "failed to create OpenGL context\n");
26 return 1;
27 }
28 int xsz, ysz;
29 SDL_GetWindowSize(win, &xsz, &ysz);
30 app_reshape(xsz, ysz);
32 if(!app_init()) {
33 return 1;
34 }
36 for(;;) {
37 SDL_Event ev;
38 while(SDL_PollEvent(&ev)) {
39 if(!handle_event(&ev) || quit) {
40 goto done;
41 }
42 }
44 app_draw();
45 assert(glGetError() == GL_NO_ERROR);
46 }
48 done:
49 app_shutdown();
50 SDL_Quit();
51 return 0;
52 }
54 void app_swap_buffers()
55 {
56 SDL_GL_SwapWindow(win);
57 }
59 void app_quit()
60 {
61 quit = true;
62 }
64 static bool handle_event(SDL_Event *ev)
65 {
66 switch(ev->type) {
67 case SDL_QUIT:
68 return false;
70 case SDL_KEYDOWN:
71 case SDL_KEYUP:
72 app_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
73 break;
75 case SDL_WINDOWEVENT:
76 if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
77 app_reshape(ev->window.data1, ev->window.data2);
78 }
79 break;
81 default:
82 break;
83 }
84 return true;
85 }