# HG changeset patch # User John Tsiombikas # Date 1411400184 -10800 # Node ID ccbd444939a113b73b01e2c466861080c5c07141 initial commit diff -r 000000000000 -r ccbd444939a1 src/game.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/game.cc Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,29 @@ +#include +#include "opengl.h" +#include "game.h" +#include "goatvr.h" + +bool game_init() +{ + init_opengl(); + + if(vr_init() == -1) { + return false; + } + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +} + +void game_cleanup() +{ + vr_shutdown(); +} + +void game_update(long tm); +void game_display(); +void game_reshape(int x, int y); +void game_keyboard(int key, bool pressed); +void game_mouse_button(int bn, bool state, int x, int y); +void game_mouse_motion(int x, int y); + diff -r 000000000000 -r ccbd444939a1 src/game.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/game.h Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,16 @@ +#ifndef GAME_H_ +#define GAME_H_ + +bool game_init(); +void game_cleanup(); + +void game_update(long tm); +void game_display(); +void game_reshape(int x, int y); +void game_keyboard(int key, bool pressed); +void game_mouse_button(int bn, bool state, int x, int y); +void game_mouse_motion(int x, int y); + +void exit_game(); /* defined in main.cc */ + +#endif /* GAME_H_ */ \ No newline at end of file diff -r 000000000000 -r ccbd444939a1 src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cc Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,94 @@ +#include +#include +#include +#include "game.h" + +static bool init(); +static void cleanup(); +static void handle_event(SDL_Event *ev); + +static bool done; +static SDL_Window *win; +static SDL_GLContext ctx; + +int main(int argc, char **argv) +{ + if(!init()) { + return 1; + } + + for(;;) { + SDL_Event ev; + while(SDL_PollEvent(&ev)) { + handle_event(&ev); + if(done) break; + } + + game_update(SDL_GetTicks()); + game_display(); + } + + cleanup(); + return 0; +} + +void exit_game() +{ + done = true; +} + +static bool init() +{ + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { + fprintf(stderr, "failed to initialize SDL\n"); + return false; + } + + win = SDL_CreateWindow("vrheights", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + 1280, 800, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + if(!win) { + fprintf(stderr, "failed to create window\n"); + return false; + } + + if(!(ctx = SDL_GL_CreateContext(win))) { + fprintf(stderr, "failed to create OpenGL context\n"); + return false; + } + + return game_init(); +} + +static void cleanup() +{ + game_cleanup(); + SDL_Quit(); +} + +static void handle_event(SDL_Event *ev) +{ + switch(ev->type) { + case SDL_WINDOWEVENT: + if(ev->window.event == SDL_WINDOWEVENT_RESIZED) { + game_reshape(ev->window.data1, ev->window.data2); + } + break; + + case SDL_KEYDOWN: + case SDL_KEYUP: + game_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED); + break; + + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + game_mouse_button(ev->button.button, ev->button.state == SDL_PRESSED, ev->button.x, ev->button.y); + break; + + case SDL_MOUSEMOTION: + game_mouse_motion(ev->motion.x, ev->motion.y); + break; + + default: + break; + } +} \ No newline at end of file diff -r 000000000000 -r ccbd444939a1 src/opengl.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.cc Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,7 @@ +#include "opengl.h" + +bool init_opengl() +{ + glewInit(); + return true; +} \ No newline at end of file diff -r 000000000000 -r ccbd444939a1 src/opengl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/opengl.h Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,8 @@ +#ifndef OPENGL_H_ +#define OPENGL_H_ + +#include + +bool init_opengl(); + +#endif /* OPENGL_H_ */ \ No newline at end of file diff -r 000000000000 -r ccbd444939a1 vrheights.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vrheights.sln Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vrheights", "vrheights.vcxproj", "{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Debug|Win32.ActiveCfg = Debug|Win32 + {1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Debug|Win32.Build.0 = Debug|Win32 + {1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Release|Win32.ActiveCfg = Release|Win32 + {1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 000000000000 -r ccbd444939a1 vrheights.vcxproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vrheights.vcxproj Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,92 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF} + Win32Proj + vrheights + + + + Application + true + v120 + MultiByte + + + Application + false + v120 + true + MultiByte + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + SDL2.lib;SDL2main.lib;opengl32.lib;glew32.lib;libgoatvr.lib;goat3d.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + + + Windows + true + true + true + SDL2.lib;SDL2main.lib;opengl32.lib;glew32.lib;libgoatvr.lib;goat3d.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r ccbd444939a1 vrheights.vcxproj.filters --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vrheights.vcxproj.filters Mon Sep 22 18:36:24 2014 +0300 @@ -0,0 +1,28 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inc;inl + + + + + src + + + src + + + src + + + + + src + + + src + + + \ No newline at end of file