vrheights

changeset 0:ccbd444939a1

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 22 Sep 2014 18:36:24 +0300
parents
children d06e4e24f922
files src/game.cc src/game.h src/main.cc src/opengl.cc src/opengl.h vrheights.sln vrheights.vcxproj vrheights.vcxproj.filters
diffstat 8 files changed, 296 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/game.cc	Mon Sep 22 18:36:24 2014 +0300
     1.3 @@ -0,0 +1,29 @@
     1.4 +#include <stdio.h>
     1.5 +#include "opengl.h"
     1.6 +#include "game.h"
     1.7 +#include "goatvr.h"
     1.8 +
     1.9 +bool game_init()
    1.10 +{
    1.11 +	init_opengl();
    1.12 +
    1.13 +	if(vr_init() == -1) {
    1.14 +		return false;
    1.15 +	}
    1.16 +
    1.17 +	glEnable(GL_DEPTH_TEST);
    1.18 +	glEnable(GL_CULL_FACE);
    1.19 +}
    1.20 +
    1.21 +void game_cleanup()
    1.22 +{
    1.23 +	vr_shutdown();
    1.24 +}
    1.25 +
    1.26 +void game_update(long tm);
    1.27 +void game_display();
    1.28 +void game_reshape(int x, int y);
    1.29 +void game_keyboard(int key, bool pressed);
    1.30 +void game_mouse_button(int bn, bool state, int x, int y);
    1.31 +void game_mouse_motion(int x, int y);
    1.32 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/game.h	Mon Sep 22 18:36:24 2014 +0300
     2.3 @@ -0,0 +1,16 @@
     2.4 +#ifndef GAME_H_
     2.5 +#define GAME_H_
     2.6 +
     2.7 +bool game_init();
     2.8 +void game_cleanup();
     2.9 +
    2.10 +void game_update(long tm);
    2.11 +void game_display();
    2.12 +void game_reshape(int x, int y);
    2.13 +void game_keyboard(int key, bool pressed);
    2.14 +void game_mouse_button(int bn, bool state, int x, int y);
    2.15 +void game_mouse_motion(int x, int y);
    2.16 +
    2.17 +void exit_game();	/* defined in main.cc */
    2.18 +
    2.19 +#endif	/* GAME_H_ */
    2.20 \ No newline at end of file
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main.cc	Mon Sep 22 18:36:24 2014 +0300
     3.3 @@ -0,0 +1,94 @@
     3.4 +#include <stdio.h>
     3.5 +#include <stdlib.h>
     3.6 +#include <SDL2/SDL.h>
     3.7 +#include "game.h"
     3.8 +
     3.9 +static bool init();
    3.10 +static void cleanup();
    3.11 +static void handle_event(SDL_Event *ev);
    3.12 +
    3.13 +static bool done;
    3.14 +static SDL_Window *win;
    3.15 +static SDL_GLContext ctx;
    3.16 +
    3.17 +int main(int argc, char **argv)
    3.18 +{
    3.19 +	if(!init()) {
    3.20 +		return 1;
    3.21 +	}
    3.22 +
    3.23 +	for(;;) {
    3.24 +		SDL_Event ev;
    3.25 +		while(SDL_PollEvent(&ev)) {
    3.26 +			handle_event(&ev);
    3.27 +			if(done) break;
    3.28 +		}
    3.29 +
    3.30 +		game_update(SDL_GetTicks());
    3.31 +		game_display();
    3.32 +	}
    3.33 +
    3.34 +	cleanup();
    3.35 +	return 0;
    3.36 +}
    3.37 +
    3.38 +void exit_game()
    3.39 +{
    3.40 +	done = true;
    3.41 +}
    3.42 +
    3.43 +static bool init()
    3.44 +{
    3.45 +	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
    3.46 +		fprintf(stderr, "failed to initialize SDL\n");
    3.47 +		return false;
    3.48 +	}
    3.49 +
    3.50 +	win = SDL_CreateWindow("vrheights", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
    3.51 +		1280, 800, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
    3.52 +	if(!win) {
    3.53 +		fprintf(stderr, "failed to create window\n");
    3.54 +		return false;
    3.55 +	}
    3.56 +
    3.57 +	if(!(ctx = SDL_GL_CreateContext(win))) {
    3.58 +		fprintf(stderr, "failed to create OpenGL context\n");
    3.59 +		return false;
    3.60 +	}
    3.61 +
    3.62 +	return game_init();
    3.63 +}
    3.64 +
    3.65 +static void cleanup()
    3.66 +{
    3.67 +	game_cleanup();
    3.68 +	SDL_Quit();
    3.69 +}
    3.70 +
    3.71 +static void handle_event(SDL_Event *ev)
    3.72 +{
    3.73 +	switch(ev->type) {
    3.74 +	case SDL_WINDOWEVENT:
    3.75 +		if(ev->window.event == SDL_WINDOWEVENT_RESIZED) {
    3.76 +			game_reshape(ev->window.data1, ev->window.data2);
    3.77 +		}
    3.78 +		break;
    3.79 +
    3.80 +	case SDL_KEYDOWN:
    3.81 +	case SDL_KEYUP:
    3.82 +		game_keyboard(ev->key.keysym.sym, ev->key.state == SDL_PRESSED);
    3.83 +		break;
    3.84 +
    3.85 +	case SDL_MOUSEBUTTONDOWN:
    3.86 +	case SDL_MOUSEBUTTONUP:
    3.87 +		game_mouse_button(ev->button.button, ev->button.state == SDL_PRESSED, ev->button.x, ev->button.y);
    3.88 +		break;
    3.89 +
    3.90 +	case SDL_MOUSEMOTION:
    3.91 +		game_mouse_motion(ev->motion.x, ev->motion.y);
    3.92 +		break;
    3.93 +
    3.94 +	default:
    3.95 +		break;
    3.96 +	}
    3.97 +}
    3.98 \ No newline at end of file
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/opengl.cc	Mon Sep 22 18:36:24 2014 +0300
     4.3 @@ -0,0 +1,7 @@
     4.4 +#include "opengl.h"
     4.5 +
     4.6 +bool init_opengl()
     4.7 +{
     4.8 +	glewInit();
     4.9 +	return true;
    4.10 +}
    4.11 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/opengl.h	Mon Sep 22 18:36:24 2014 +0300
     5.3 @@ -0,0 +1,8 @@
     5.4 +#ifndef OPENGL_H_
     5.5 +#define OPENGL_H_
     5.6 +
     5.7 +#include <GL/glew.h>
     5.8 +
     5.9 +bool init_opengl();
    5.10 +
    5.11 +#endif	/* OPENGL_H_ */
    5.12 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/vrheights.sln	Mon Sep 22 18:36:24 2014 +0300
     6.3 @@ -0,0 +1,22 @@
     6.4 +
     6.5 +Microsoft Visual Studio Solution File, Format Version 12.00
     6.6 +# Visual Studio 2013
     6.7 +VisualStudioVersion = 12.0.30723.0
     6.8 +MinimumVisualStudioVersion = 10.0.40219.1
     6.9 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "vrheights", "vrheights.vcxproj", "{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}"
    6.10 +EndProject
    6.11 +Global
    6.12 +	GlobalSection(SolutionConfigurationPlatforms) = preSolution
    6.13 +		Debug|Win32 = Debug|Win32
    6.14 +		Release|Win32 = Release|Win32
    6.15 +	EndGlobalSection
    6.16 +	GlobalSection(ProjectConfigurationPlatforms) = postSolution
    6.17 +		{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Debug|Win32.ActiveCfg = Debug|Win32
    6.18 +		{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Debug|Win32.Build.0 = Debug|Win32
    6.19 +		{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Release|Win32.ActiveCfg = Release|Win32
    6.20 +		{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}.Release|Win32.Build.0 = Release|Win32
    6.21 +	EndGlobalSection
    6.22 +	GlobalSection(SolutionProperties) = preSolution
    6.23 +		HideSolutionNode = FALSE
    6.24 +	EndGlobalSection
    6.25 +EndGlobal
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/vrheights.vcxproj	Mon Sep 22 18:36:24 2014 +0300
     7.3 @@ -0,0 +1,92 @@
     7.4 +<?xml version="1.0" encoding="utf-8"?>
     7.5 +<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     7.6 +  <ItemGroup Label="ProjectConfigurations">
     7.7 +    <ProjectConfiguration Include="Debug|Win32">
     7.8 +      <Configuration>Debug</Configuration>
     7.9 +      <Platform>Win32</Platform>
    7.10 +    </ProjectConfiguration>
    7.11 +    <ProjectConfiguration Include="Release|Win32">
    7.12 +      <Configuration>Release</Configuration>
    7.13 +      <Platform>Win32</Platform>
    7.14 +    </ProjectConfiguration>
    7.15 +  </ItemGroup>
    7.16 +  <PropertyGroup Label="Globals">
    7.17 +    <ProjectGuid>{1B3B97CD-5F66-4FE4-86B6-684A5AABCBAF}</ProjectGuid>
    7.18 +    <Keyword>Win32Proj</Keyword>
    7.19 +    <RootNamespace>vrheights</RootNamespace>
    7.20 +  </PropertyGroup>
    7.21 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
    7.22 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    7.23 +    <ConfigurationType>Application</ConfigurationType>
    7.24 +    <UseDebugLibraries>true</UseDebugLibraries>
    7.25 +    <PlatformToolset>v120</PlatformToolset>
    7.26 +    <CharacterSet>MultiByte</CharacterSet>
    7.27 +  </PropertyGroup>
    7.28 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    7.29 +    <ConfigurationType>Application</ConfigurationType>
    7.30 +    <UseDebugLibraries>false</UseDebugLibraries>
    7.31 +    <PlatformToolset>v120</PlatformToolset>
    7.32 +    <WholeProgramOptimization>true</WholeProgramOptimization>
    7.33 +    <CharacterSet>MultiByte</CharacterSet>
    7.34 +  </PropertyGroup>
    7.35 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
    7.36 +  <ImportGroup Label="ExtensionSettings">
    7.37 +  </ImportGroup>
    7.38 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    7.39 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    7.40 +  </ImportGroup>
    7.41 +  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    7.42 +    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    7.43 +  </ImportGroup>
    7.44 +  <PropertyGroup Label="UserMacros" />
    7.45 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    7.46 +    <LinkIncremental>true</LinkIncremental>
    7.47 +  </PropertyGroup>
    7.48 +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    7.49 +    <LinkIncremental>false</LinkIncremental>
    7.50 +  </PropertyGroup>
    7.51 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    7.52 +    <ClCompile>
    7.53 +      <PrecompiledHeader>
    7.54 +      </PrecompiledHeader>
    7.55 +      <WarningLevel>Level3</WarningLevel>
    7.56 +      <Optimization>Disabled</Optimization>
    7.57 +      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    7.58 +    </ClCompile>
    7.59 +    <Link>
    7.60 +      <SubSystem>Windows</SubSystem>
    7.61 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    7.62 +      <AdditionalDependencies>SDL2.lib;SDL2main.lib;opengl32.lib;glew32.lib;libgoatvr.lib;goat3d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    7.63 +    </Link>
    7.64 +  </ItemDefinitionGroup>
    7.65 +  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    7.66 +    <ClCompile>
    7.67 +      <WarningLevel>Level3</WarningLevel>
    7.68 +      <PrecompiledHeader>
    7.69 +      </PrecompiledHeader>
    7.70 +      <Optimization>MaxSpeed</Optimization>
    7.71 +      <FunctionLevelLinking>true</FunctionLevelLinking>
    7.72 +      <IntrinsicFunctions>true</IntrinsicFunctions>
    7.73 +      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    7.74 +    </ClCompile>
    7.75 +    <Link>
    7.76 +      <SubSystem>Windows</SubSystem>
    7.77 +      <GenerateDebugInformation>true</GenerateDebugInformation>
    7.78 +      <EnableCOMDATFolding>true</EnableCOMDATFolding>
    7.79 +      <OptimizeReferences>true</OptimizeReferences>
    7.80 +      <AdditionalDependencies>SDL2.lib;SDL2main.lib;opengl32.lib;glew32.lib;libgoatvr.lib;goat3d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    7.81 +    </Link>
    7.82 +  </ItemDefinitionGroup>
    7.83 +  <ItemGroup>
    7.84 +    <ClCompile Include="src\game.cc" />
    7.85 +    <ClCompile Include="src\main.cc" />
    7.86 +    <ClCompile Include="src\opengl.cc" />
    7.87 +  </ItemGroup>
    7.88 +  <ItemGroup>
    7.89 +    <ClInclude Include="src\game.h" />
    7.90 +    <ClInclude Include="src\opengl.h" />
    7.91 +  </ItemGroup>
    7.92 +  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    7.93 +  <ImportGroup Label="ExtensionTargets">
    7.94 +  </ImportGroup>
    7.95 +</Project>
    7.96 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/vrheights.vcxproj.filters	Mon Sep 22 18:36:24 2014 +0300
     8.3 @@ -0,0 +1,28 @@
     8.4 +<?xml version="1.0" encoding="utf-8"?>
     8.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     8.6 +  <ItemGroup>
     8.7 +    <Filter Include="src">
     8.8 +      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
     8.9 +      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;h;inc;inl</Extensions>
    8.10 +    </Filter>
    8.11 +  </ItemGroup>
    8.12 +  <ItemGroup>
    8.13 +    <ClCompile Include="src\main.cc">
    8.14 +      <Filter>src</Filter>
    8.15 +    </ClCompile>
    8.16 +    <ClCompile Include="src\game.cc">
    8.17 +      <Filter>src</Filter>
    8.18 +    </ClCompile>
    8.19 +    <ClCompile Include="src\opengl.cc">
    8.20 +      <Filter>src</Filter>
    8.21 +    </ClCompile>
    8.22 +  </ItemGroup>
    8.23 +  <ItemGroup>
    8.24 +    <ClInclude Include="src\game.h">
    8.25 +      <Filter>src</Filter>
    8.26 +    </ClInclude>
    8.27 +    <ClInclude Include="src\opengl.h">
    8.28 +      <Filter>src</Filter>
    8.29 +    </ClInclude>
    8.30 +  </ItemGroup>
    8.31 +</Project>
    8.32 \ No newline at end of file