├── .gitattributes ├── LICENSE ├── QuakeBspViewerVR.exe ├── QuakeBspViewerVR.sln ├── QuakeBspViewerVR.vcxproj ├── QuakeBspViewerVR.vcxproj.filters ├── README.md ├── SDL2.dll ├── contrib ├── SDL │ ├── BUGS.txt │ ├── COPYING.txt │ ├── README-SDL.txt │ ├── README.txt │ ├── WhatsNew.txt │ ├── include │ │ ├── SDL.h │ │ ├── SDL_assert.h │ │ ├── SDL_atomic.h │ │ ├── SDL_audio.h │ │ ├── SDL_bits.h │ │ ├── SDL_blendmode.h │ │ ├── SDL_clipboard.h │ │ ├── SDL_config.h │ │ ├── SDL_cpuinfo.h │ │ ├── SDL_egl.h │ │ ├── SDL_endian.h │ │ ├── SDL_error.h │ │ ├── SDL_events.h │ │ ├── SDL_filesystem.h │ │ ├── SDL_gamecontroller.h │ │ ├── SDL_gesture.h │ │ ├── SDL_haptic.h │ │ ├── SDL_hints.h │ │ ├── SDL_joystick.h │ │ ├── SDL_keyboard.h │ │ ├── SDL_keycode.h │ │ ├── SDL_loadso.h │ │ ├── SDL_log.h │ │ ├── SDL_main.h │ │ ├── SDL_messagebox.h │ │ ├── SDL_mouse.h │ │ ├── SDL_mutex.h │ │ ├── SDL_name.h │ │ ├── SDL_opengl.h │ │ ├── SDL_opengl_glext.h │ │ ├── SDL_opengles.h │ │ ├── SDL_opengles2.h │ │ ├── SDL_opengles2_gl2.h │ │ ├── SDL_opengles2_gl2ext.h │ │ ├── SDL_opengles2_gl2platform.h │ │ ├── SDL_opengles2_khrplatform.h │ │ ├── SDL_pixels.h │ │ ├── SDL_platform.h │ │ ├── SDL_power.h │ │ ├── SDL_quit.h │ │ ├── SDL_rect.h │ │ ├── SDL_render.h │ │ ├── SDL_revision.h │ │ ├── SDL_rwops.h │ │ ├── SDL_scancode.h │ │ ├── SDL_shape.h │ │ ├── SDL_stdinc.h │ │ ├── SDL_surface.h │ │ ├── SDL_system.h │ │ ├── SDL_syswm.h │ │ ├── SDL_test.h │ │ ├── SDL_test_assert.h │ │ ├── SDL_test_common.h │ │ ├── SDL_test_compare.h │ │ ├── SDL_test_crc32.h │ │ ├── SDL_test_font.h │ │ ├── SDL_test_fuzzer.h │ │ ├── SDL_test_harness.h │ │ ├── SDL_test_images.h │ │ ├── SDL_test_log.h │ │ ├── SDL_test_md5.h │ │ ├── SDL_test_random.h │ │ ├── SDL_thread.h │ │ ├── SDL_timer.h │ │ ├── SDL_touch.h │ │ ├── SDL_types.h │ │ ├── SDL_version.h │ │ ├── SDL_video.h │ │ ├── begin_code.h │ │ └── close_code.h │ └── lib │ │ ├── x64 │ │ ├── SDL2.dll │ │ ├── SDL2.lib │ │ ├── SDL2main.lib │ │ └── SDL2test.lib │ │ └── x86 │ │ ├── SDL2.dll │ │ ├── SDL2.lib │ │ ├── SDL2main.lib │ │ └── SDL2test.lib ├── glew-1.11.0 │ ├── LICENSE.txt │ ├── README.txt │ ├── TODO.txt │ ├── bin │ │ ├── Release MX │ │ │ ├── Win32 │ │ │ │ └── glew32mx.dll │ │ │ └── x64 │ │ │ │ └── glew32mx.dll │ │ └── Release │ │ │ ├── Win32 │ │ │ ├── glew32.dll │ │ │ ├── glewinfo.exe │ │ │ ├── glewinfo.txt │ │ │ └── visualinfo.exe │ │ │ └── x64 │ │ │ ├── glew32.dll │ │ │ ├── glewinfo.exe │ │ │ └── visualinfo.exe │ ├── doc │ │ ├── advanced.html │ │ ├── basic.html │ │ ├── build.html │ │ ├── credits.html │ │ ├── glew.css │ │ ├── glew.html │ │ ├── glew.png │ │ ├── glew.txt │ │ ├── glxew.html │ │ ├── gpl.txt │ │ ├── index.html │ │ ├── install.html │ │ ├── khronos.txt │ │ ├── log.html │ │ ├── mesa.txt │ │ ├── new.png │ │ ├── ogl_sm.jpg │ │ └── wglew.html │ ├── include │ │ └── GL │ │ │ ├── glew.h │ │ │ ├── glxew.h │ │ │ └── wglew.h │ └── lib │ │ ├── Release MX │ │ ├── Win32 │ │ │ ├── glew32mx.lib │ │ │ └── glew32mxs.lib │ │ └── x64 │ │ │ ├── glew32mx.lib │ │ │ └── glew32mxs.lib │ │ └── Release │ │ ├── Win32 │ │ ├── glew32.lib │ │ └── glew32s.lib │ │ └── x64 │ │ ├── glew32.lib │ │ └── glew32s.lib └── stb_image │ ├── stb_image.c │ └── stb_image.h ├── glew32.dll ├── images ├── q3vr1.png ├── q3vr2.png ├── q3vr_youtube.png ├── qbsp1.png └── qbsp3.png ├── maps └── ntkjidm2.bsp ├── res ├── Basic.fsh ├── Basic.vsh ├── Font.fsh ├── Font.vsh ├── OVRFrustum.fsh ├── OVRFrustum.vsh ├── font.png └── missing.png ├── run.bat └── src ├── Application.cpp ├── Application.hpp ├── Frustum.cpp ├── Frustum.hpp ├── InputHandlers.cpp ├── InputHandlers.hpp ├── Math.cpp ├── Math.hpp ├── StringHelpers.cpp ├── StringHelpers.hpp ├── Utils.cpp ├── Utils.hpp ├── common ├── BspMap.hpp └── StatsUI.hpp ├── main.cpp ├── q3bsp ├── Q3Bsp.hpp ├── Q3BspLoader.cpp ├── Q3BspLoader.hpp ├── Q3BspMap.cpp ├── Q3BspMap.hpp ├── Q3BspPatch.cpp ├── Q3BspPatch.hpp ├── Q3BspRenderHelpers.hpp ├── Q3BspStatsUI.cpp └── Q3BspStatsUI.hpp └── renderer ├── Camera.cpp ├── Camera.hpp ├── CameraDirector.cpp ├── CameraDirector.hpp ├── Font.cpp ├── Font.hpp ├── OVRCameraFrustum.cpp ├── OVRCameraFrustum.hpp ├── OVRTrackerChaperone.cpp ├── OVRTrackerChaperone.hpp ├── OculusVR.cpp ├── OculusVR.hpp ├── OculusVRDebug.cpp ├── OculusVRDebug.hpp ├── OpenGL.cpp ├── OpenGL.hpp ├── RenderContext.cpp ├── RenderContext.hpp ├── Shader.hpp ├── ShaderManager.cpp ├── ShaderManager.hpp ├── Texture.cpp ├── Texture.hpp ├── TextureManager.cpp └── TextureManager.hpp /.gitattributes: -------------------------------------------------------------------------------- 1 | contrib/* linguist-vendored -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Krzysztof Kondrak 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /QuakeBspViewerVR.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/QuakeBspViewerVR.exe -------------------------------------------------------------------------------- /QuakeBspViewerVR.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuakeBspViewerVR", "QuakeBspViewerVR.vcxproj", "{74D78140-348F-4C55-9D29-C41940DBC100}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {74D78140-348F-4C55-9D29-C41940DBC100}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {74D78140-348F-4C55-9D29-C41940DBC100}.Debug|Win32.Build.0 = Debug|Win32 16 | {74D78140-348F-4C55-9D29-C41940DBC100}.Release|Win32.ActiveCfg = Release|Win32 17 | {74D78140-348F-4C55-9D29-C41940DBC100}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Quake BSP map viewer with Oculus Rift support 2 | ================ 3 | 4 | This is a BSP tree OpenGL renderer written in C++. It handles basic geometry and curved patch rendering but with no support for game-specific shaders, entities etc. It implement PVS and frustum culling so performance is optimal. At the moment only Quake III Arena maps are supported but an interface is provided for adding other BSP versions in the future. 5 | 6 | A separate no_vr branch contains code without any OculusVR dependencies if you're just interested in focusing solely on OpenGL renderer. 7 | 8 | Youtube demo: 9 | 10 | [![Screenshot](images/q3vr_youtube.png?raw=true)](https://www.youtube.com/watch?v=pAGLW82ryBc) 11 | 12 | Screenshots: 13 | 14 | ![Screenshot](images/qbsp1.png?raw=true) 15 | ![Screenshot](images/qbsp3.png?raw=true) 16 | ![Screenshot](images/q3vr1.png?raw=true) 17 | ![Screenshot](images/q3vr2.png?raw=true) 18 | Usage 19 | ----- 20 | Running the viewer: 21 | 22 | QuakeBspViewerVR.exe <path-to-bsp-file> 23 | 24 | Running the viewer in VR: 25 | 26 | QuakeBspViewerVR.exe <path-to-bsp-file> -vr 27 | 28 | In non-VR mode, use tilde key (~) to toggle statistics menu on/off. In VR mode, toggle between statistics, VR debug data and IR tracking camera frustum rendering (if camera is available). SPACE key will recenter your tracking position. Press M to toggle between different mirror modes. Note that you must have Quake III Arena textures and models unpacked in the root directory if you want to see proper texturing. To move around use the WASD keys. RF keys lift you up/down and QE keys let you do the barrel roll (in non-VR mode only). 29 | 30 | Dependencies 31 | ------- 32 | This project uses following external libraries: 33 | 34 | - GLEW extension library 35 | - [stb_image](https://github.com/nothings/stb) library for texture loading 36 | - SDL2 library for window/input 37 | - VR support requires OculusVR SDK 1.3+ and Oculus Home installed 38 | 39 | References 40 | ------- 41 | This viewer was made using following resources: 42 | - http://www.mralligator.com/q3/ 43 | - http://graphics.cs.brown.edu/games/quake/quake3.html 44 | 45 | Known issues 46 | ------- 47 | Certain BSP leaves containing doors, moving platforms etc. may not render correctly with PVS enabled. This is because they are handled differently by the original game. 48 | 49 | Todo 50 | ---- 51 | Here's a list of ideas that could be fun to implement over time: 52 | 53 | - add support for older bsp formats (ie. Quake1, Quake2) 54 | - render map entities (weapons, armor, other pickups) 55 | - support loading data from pk3/pak files 56 | - add support for rendering Quake 3 shaders 57 | - bsp patch tesselation on the fly 58 | -------------------------------------------------------------------------------- /SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/SDL2.dll -------------------------------------------------------------------------------- /contrib/SDL/BUGS.txt: -------------------------------------------------------------------------------- 1 | 2 | Bugs are now managed in the SDL bug tracker, here: 3 | 4 | http://bugzilla.libsdl.org/ 5 | 6 | You may report bugs there, and search to see if a given issue has already 7 | been reported, discussed, and maybe even fixed. 8 | 9 | 10 | You may also find help on the SDL mailing list. Subscription information: 11 | 12 | http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org 13 | 14 | Bug reports are welcome here, but we really appreciate if you use Bugzilla, as 15 | bugs discussed on the mailing list may be forgotten or missed. 16 | 17 | -------------------------------------------------------------------------------- /contrib/SDL/COPYING.txt: -------------------------------------------------------------------------------- 1 | 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | 21 | -------------------------------------------------------------------------------- /contrib/SDL/README-SDL.txt: -------------------------------------------------------------------------------- 1 | 2 | Please distribute this file with the SDL runtime environment: 3 | 4 | The Simple DirectMedia Layer (SDL for short) is a cross-platform library 5 | designed to make it easy to write multi-media software, such as games and 6 | emulators. 7 | 8 | The Simple DirectMedia Layer library source code is available from: 9 | http://www.libsdl.org/ 10 | 11 | This library is distributed under the terms of the zlib license: 12 | http://www.zlib.net/zlib_license.html 13 | 14 | -------------------------------------------------------------------------------- /contrib/SDL/README.txt: -------------------------------------------------------------------------------- 1 | 2 | Simple DirectMedia Layer 3 | 4 | (SDL) 5 | 6 | Version 2.0 7 | 8 | --- 9 | http://www.libsdl.org/ 10 | 11 | Simple DirectMedia Layer is a cross-platform development library designed 12 | to provide low level access to audio, keyboard, mouse, joystick, and graphics 13 | hardware via OpenGL and Direct3D. It is used by video playback software, 14 | emulators, and popular games including Valve's award winning catalog 15 | and many Humble Bundle games. 16 | 17 | More extensive documentation is available in the docs directory, starting 18 | with README.md 19 | 20 | Enjoy! 21 | Sam Lantinga (slouken@libsdl.org) 22 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL.h 24 | * 25 | * Main include header for the SDL library 26 | */ 27 | 28 | 29 | #ifndef _SDL_H 30 | #define _SDL_H 31 | 32 | #include "SDL_main.h" 33 | #include "SDL_stdinc.h" 34 | #include "SDL_assert.h" 35 | #include "SDL_atomic.h" 36 | #include "SDL_audio.h" 37 | #include "SDL_clipboard.h" 38 | #include "SDL_cpuinfo.h" 39 | #include "SDL_endian.h" 40 | #include "SDL_error.h" 41 | #include "SDL_events.h" 42 | #include "SDL_filesystem.h" 43 | #include "SDL_joystick.h" 44 | #include "SDL_gamecontroller.h" 45 | #include "SDL_haptic.h" 46 | #include "SDL_hints.h" 47 | #include "SDL_loadso.h" 48 | #include "SDL_log.h" 49 | #include "SDL_messagebox.h" 50 | #include "SDL_mutex.h" 51 | #include "SDL_power.h" 52 | #include "SDL_render.h" 53 | #include "SDL_rwops.h" 54 | #include "SDL_system.h" 55 | #include "SDL_thread.h" 56 | #include "SDL_timer.h" 57 | #include "SDL_version.h" 58 | #include "SDL_video.h" 59 | 60 | #include "begin_code.h" 61 | /* Set up for C function definitions, even when using C++ */ 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /* As of version 0.5, SDL is loaded dynamically into the application */ 67 | 68 | /** 69 | * \name SDL_INIT_* 70 | * 71 | * These are the flags which may be passed to SDL_Init(). You should 72 | * specify the subsystems which you will be using in your application. 73 | */ 74 | /* @{ */ 75 | #define SDL_INIT_TIMER 0x00000001 76 | #define SDL_INIT_AUDIO 0x00000010 77 | #define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ 78 | #define SDL_INIT_JOYSTICK 0x00000200 /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */ 79 | #define SDL_INIT_HAPTIC 0x00001000 80 | #define SDL_INIT_GAMECONTROLLER 0x00002000 /**< SDL_INIT_GAMECONTROLLER implies SDL_INIT_JOYSTICK */ 81 | #define SDL_INIT_EVENTS 0x00004000 82 | #define SDL_INIT_NOPARACHUTE 0x00100000 /**< compatibility; this flag is ignored. */ 83 | #define SDL_INIT_EVERYTHING ( \ 84 | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \ 85 | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \ 86 | ) 87 | /* @} */ 88 | 89 | /** 90 | * This function initializes the subsystems specified by \c flags 91 | */ 92 | extern DECLSPEC int SDLCALL SDL_Init(Uint32 flags); 93 | 94 | /** 95 | * This function initializes specific SDL subsystems 96 | * 97 | * Subsystem initialization is ref-counted, you must call 98 | * SDL_QuitSubSystem for each SDL_InitSubSystem to correctly 99 | * shutdown a subsystem manually (or call SDL_Quit to force shutdown). 100 | * If a subsystem is already loaded then this call will 101 | * increase the ref-count and return. 102 | */ 103 | extern DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags); 104 | 105 | /** 106 | * This function cleans up specific SDL subsystems 107 | */ 108 | extern DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags); 109 | 110 | /** 111 | * This function returns a mask of the specified subsystems which have 112 | * previously been initialized. 113 | * 114 | * If \c flags is 0, it returns a mask of all initialized subsystems. 115 | */ 116 | extern DECLSPEC Uint32 SDLCALL SDL_WasInit(Uint32 flags); 117 | 118 | /** 119 | * This function cleans up all initialized subsystems. You should 120 | * call it upon all exit conditions. 121 | */ 122 | extern DECLSPEC void SDLCALL SDL_Quit(void); 123 | 124 | /* Ends C function definitions when using C++ */ 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | #include "close_code.h" 129 | 130 | #endif /* _SDL_H */ 131 | 132 | /* vi: set ts=4 sw=4 expandtab: */ 133 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_bits.h 24 | * 25 | * Functions for fiddling with bits and bitmasks. 26 | */ 27 | 28 | #ifndef _SDL_bits_h 29 | #define _SDL_bits_h 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /** 40 | * \file SDL_bits.h 41 | */ 42 | 43 | /** 44 | * Get the index of the most significant bit. Result is undefined when called 45 | * with 0. This operation can also be stated as "count leading zeroes" and 46 | * "log base 2". 47 | * 48 | * \return Index of the most significant bit, or -1 if the value is 0. 49 | */ 50 | SDL_FORCE_INLINE int 51 | SDL_MostSignificantBitIndex32(Uint32 x) 52 | { 53 | #if defined(__GNUC__) && __GNUC__ >= 4 54 | /* Count Leading Zeroes builtin in GCC. 55 | * http://gcc.gnu.org/onlinedocs/gcc-4.3.4/gcc/Other-Builtins.html 56 | */ 57 | if (x == 0) { 58 | return -1; 59 | } 60 | return 31 - __builtin_clz(x); 61 | #else 62 | /* Based off of Bit Twiddling Hacks by Sean Eron Anderson 63 | * , released in the public domain. 64 | * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog 65 | */ 66 | const Uint32 b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; 67 | const int S[] = {1, 2, 4, 8, 16}; 68 | 69 | int msbIndex = 0; 70 | int i; 71 | 72 | if (x == 0) { 73 | return -1; 74 | } 75 | 76 | for (i = 4; i >= 0; i--) 77 | { 78 | if (x & b[i]) 79 | { 80 | x >>= S[i]; 81 | msbIndex |= S[i]; 82 | } 83 | } 84 | 85 | return msbIndex; 86 | #endif 87 | } 88 | 89 | /* Ends C function definitions when using C++ */ 90 | #ifdef __cplusplus 91 | } 92 | #endif 93 | #include "close_code.h" 94 | 95 | #endif /* _SDL_bits_h */ 96 | 97 | /* vi: set ts=4 sw=4 expandtab: */ 98 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_blendmode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_blendmode.h 24 | * 25 | * Header file declaring the SDL_BlendMode enumeration 26 | */ 27 | 28 | #ifndef _SDL_blendmode_h 29 | #define _SDL_blendmode_h 30 | 31 | #include "begin_code.h" 32 | /* Set up for C function definitions, even when using C++ */ 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * \brief The blend mode used in SDL_RenderCopy() and drawing operations. 39 | */ 40 | typedef enum 41 | { 42 | SDL_BLENDMODE_NONE = 0x00000000, /**< no blending 43 | dstRGBA = srcRGBA */ 44 | SDL_BLENDMODE_BLEND = 0x00000001, /**< alpha blending 45 | dstRGB = (srcRGB * srcA) + (dstRGB * (1-srcA)) 46 | dstA = srcA + (dstA * (1-srcA)) */ 47 | SDL_BLENDMODE_ADD = 0x00000002, /**< additive blending 48 | dstRGB = (srcRGB * srcA) + dstRGB 49 | dstA = dstA */ 50 | SDL_BLENDMODE_MOD = 0x00000004 /**< color modulate 51 | dstRGB = srcRGB * dstRGB 52 | dstA = dstA */ 53 | } SDL_BlendMode; 54 | 55 | /* Ends C function definitions when using C++ */ 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | #include "close_code.h" 60 | 61 | #endif /* _SDL_blendmode_h */ 62 | 63 | /* vi: set ts=4 sw=4 expandtab: */ 64 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_clipboard.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_clipboard.h 24 | * 25 | * Include file for SDL clipboard handling 26 | */ 27 | 28 | #ifndef _SDL_clipboard_h 29 | #define _SDL_clipboard_h 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Function prototypes */ 40 | 41 | /** 42 | * \brief Put UTF-8 text into the clipboard 43 | * 44 | * \sa SDL_GetClipboardText() 45 | */ 46 | extern DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text); 47 | 48 | /** 49 | * \brief Get UTF-8 text from the clipboard, which must be freed with SDL_free() 50 | * 51 | * \sa SDL_SetClipboardText() 52 | */ 53 | extern DECLSPEC char * SDLCALL SDL_GetClipboardText(void); 54 | 55 | /** 56 | * \brief Returns a flag indicating whether the clipboard exists and contains a text string that is non-empty 57 | * 58 | * \sa SDL_GetClipboardText() 59 | */ 60 | extern DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); 61 | 62 | 63 | /* Ends C function definitions when using C++ */ 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #include "close_code.h" 68 | 69 | #endif /* _SDL_clipboard_h */ 70 | 71 | /* vi: set ts=4 sw=4 expandtab: */ 72 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_cpuinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_cpuinfo.h 24 | * 25 | * CPU feature detection for SDL. 26 | */ 27 | 28 | #ifndef _SDL_cpuinfo_h 29 | #define _SDL_cpuinfo_h 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | /* Need to do this here because intrin.h has C++ code in it */ 34 | /* Visual Studio 2005 has a bug where intrin.h conflicts with winnt.h */ 35 | #if defined(_MSC_VER) && (_MSC_VER >= 1500) && (defined(_M_IX86) || defined(_M_X64)) 36 | #include 37 | #ifndef _WIN64 38 | #define __MMX__ 39 | #define __3dNOW__ 40 | #endif 41 | #define __SSE__ 42 | #define __SSE2__ 43 | #elif defined(__MINGW64_VERSION_MAJOR) 44 | #include 45 | #else 46 | #ifdef __ALTIVEC__ 47 | #if HAVE_ALTIVEC_H && !defined(__APPLE_ALTIVEC__) 48 | #include 49 | #undef pixel 50 | #endif 51 | #endif 52 | #ifdef __MMX__ 53 | #include 54 | #endif 55 | #ifdef __3dNOW__ 56 | #include 57 | #endif 58 | #ifdef __SSE__ 59 | #include 60 | #endif 61 | #ifdef __SSE2__ 62 | #include 63 | #endif 64 | #endif 65 | 66 | #include "begin_code.h" 67 | /* Set up for C function definitions, even when using C++ */ 68 | #ifdef __cplusplus 69 | extern "C" { 70 | #endif 71 | 72 | /* This is a guess for the cacheline size used for padding. 73 | * Most x86 processors have a 64 byte cache line. 74 | * The 64-bit PowerPC processors have a 128 byte cache line. 75 | * We'll use the larger value to be generally safe. 76 | */ 77 | #define SDL_CACHELINE_SIZE 128 78 | 79 | /** 80 | * This function returns the number of CPU cores available. 81 | */ 82 | extern DECLSPEC int SDLCALL SDL_GetCPUCount(void); 83 | 84 | /** 85 | * This function returns the L1 cache line size of the CPU 86 | * 87 | * This is useful for determining multi-threaded structure padding 88 | * or SIMD prefetch sizes. 89 | */ 90 | extern DECLSPEC int SDLCALL SDL_GetCPUCacheLineSize(void); 91 | 92 | /** 93 | * This function returns true if the CPU has the RDTSC instruction. 94 | */ 95 | extern DECLSPEC SDL_bool SDLCALL SDL_HasRDTSC(void); 96 | 97 | /** 98 | * This function returns true if the CPU has AltiVec features. 99 | */ 100 | extern DECLSPEC SDL_bool SDLCALL SDL_HasAltiVec(void); 101 | 102 | /** 103 | * This function returns true if the CPU has MMX features. 104 | */ 105 | extern DECLSPEC SDL_bool SDLCALL SDL_HasMMX(void); 106 | 107 | /** 108 | * This function returns true if the CPU has 3DNow! features. 109 | */ 110 | extern DECLSPEC SDL_bool SDLCALL SDL_Has3DNow(void); 111 | 112 | /** 113 | * This function returns true if the CPU has SSE features. 114 | */ 115 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE(void); 116 | 117 | /** 118 | * This function returns true if the CPU has SSE2 features. 119 | */ 120 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE2(void); 121 | 122 | /** 123 | * This function returns true if the CPU has SSE3 features. 124 | */ 125 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE3(void); 126 | 127 | /** 128 | * This function returns true if the CPU has SSE4.1 features. 129 | */ 130 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE41(void); 131 | 132 | /** 133 | * This function returns true if the CPU has SSE4.2 features. 134 | */ 135 | extern DECLSPEC SDL_bool SDLCALL SDL_HasSSE42(void); 136 | 137 | /** 138 | * This function returns true if the CPU has AVX features. 139 | */ 140 | extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX(void); 141 | 142 | /** 143 | * This function returns true if the CPU has AVX2 features. 144 | */ 145 | extern DECLSPEC SDL_bool SDLCALL SDL_HasAVX2(void); 146 | 147 | /** 148 | * This function returns the amount of RAM configured in the system, in MB. 149 | */ 150 | extern DECLSPEC int SDLCALL SDL_GetSystemRAM(void); 151 | 152 | 153 | /* Ends C function definitions when using C++ */ 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | #include "close_code.h" 158 | 159 | #endif /* _SDL_cpuinfo_h */ 160 | 161 | /* vi: set ts=4 sw=4 expandtab: */ 162 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_error.h 24 | * 25 | * Simple error message routines for SDL. 26 | */ 27 | 28 | #ifndef _SDL_error_h 29 | #define _SDL_error_h 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Public functions */ 40 | /* SDL_SetError() unconditionally returns -1. */ 41 | extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 42 | extern DECLSPEC const char *SDLCALL SDL_GetError(void); 43 | extern DECLSPEC void SDLCALL SDL_ClearError(void); 44 | 45 | /** 46 | * \name Internal error functions 47 | * 48 | * \internal 49 | * Private error reporting function - used internally. 50 | */ 51 | /* @{ */ 52 | #define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM) 53 | #define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED) 54 | #define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param)) 55 | typedef enum 56 | { 57 | SDL_ENOMEM, 58 | SDL_EFREAD, 59 | SDL_EFWRITE, 60 | SDL_EFSEEK, 61 | SDL_UNSUPPORTED, 62 | SDL_LASTERROR 63 | } SDL_errorcode; 64 | /* SDL_Error() unconditionally returns -1. */ 65 | extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code); 66 | /* @} *//* Internal error functions */ 67 | 68 | /* Ends C function definitions when using C++ */ 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #include "close_code.h" 73 | 74 | #endif /* _SDL_error_h */ 75 | 76 | /* vi: set ts=4 sw=4 expandtab: */ 77 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_gesture.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_gesture.h 24 | * 25 | * Include file for SDL gesture event handling. 26 | */ 27 | 28 | #ifndef _SDL_gesture_h 29 | #define _SDL_gesture_h 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | #include "SDL_video.h" 34 | 35 | #include "SDL_touch.h" 36 | 37 | 38 | #include "begin_code.h" 39 | /* Set up for C function definitions, even when using C++ */ 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | typedef Sint64 SDL_GestureID; 45 | 46 | /* Function prototypes */ 47 | 48 | /** 49 | * \brief Begin Recording a gesture on the specified touch, or all touches (-1) 50 | * 51 | * 52 | */ 53 | extern DECLSPEC int SDLCALL SDL_RecordGesture(SDL_TouchID touchId); 54 | 55 | 56 | /** 57 | * \brief Save all currently loaded Dollar Gesture templates 58 | * 59 | * 60 | */ 61 | extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(SDL_RWops *dst); 62 | 63 | /** 64 | * \brief Save a currently loaded Dollar Gesture template 65 | * 66 | * 67 | */ 68 | extern DECLSPEC int SDLCALL SDL_SaveDollarTemplate(SDL_GestureID gestureId,SDL_RWops *dst); 69 | 70 | 71 | /** 72 | * \brief Load Dollar Gesture templates from a file 73 | * 74 | * 75 | */ 76 | extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src); 77 | 78 | 79 | /* Ends C function definitions when using C++ */ 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #include "close_code.h" 84 | 85 | #endif /* _SDL_gesture_h */ 86 | 87 | /* vi: set ts=4 sw=4 expandtab: */ 88 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_loadso.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_loadso.h 24 | * 25 | * System dependent library loading routines 26 | * 27 | * Some things to keep in mind: 28 | * \li These functions only work on C function names. Other languages may 29 | * have name mangling and intrinsic language support that varies from 30 | * compiler to compiler. 31 | * \li Make sure you declare your function pointers with the same calling 32 | * convention as the actual library function. Your code will crash 33 | * mysteriously if you do not do this. 34 | * \li Avoid namespace collisions. If you load a symbol from the library, 35 | * it is not defined whether or not it goes into the global symbol 36 | * namespace for the application. If it does and it conflicts with 37 | * symbols in your code or other shared libraries, you will not get 38 | * the results you expect. :) 39 | */ 40 | 41 | #ifndef _SDL_loadso_h 42 | #define _SDL_loadso_h 43 | 44 | #include "SDL_stdinc.h" 45 | #include "SDL_error.h" 46 | 47 | #include "begin_code.h" 48 | /* Set up for C function definitions, even when using C++ */ 49 | #ifdef __cplusplus 50 | extern "C" { 51 | #endif 52 | 53 | /** 54 | * This function dynamically loads a shared object and returns a pointer 55 | * to the object handle (or NULL if there was an error). 56 | * The 'sofile' parameter is a system dependent name of the object file. 57 | */ 58 | extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile); 59 | 60 | /** 61 | * Given an object handle, this function looks up the address of the 62 | * named function in the shared object and returns it. This address 63 | * is no longer valid after calling SDL_UnloadObject(). 64 | */ 65 | extern DECLSPEC void *SDLCALL SDL_LoadFunction(void *handle, 66 | const char *name); 67 | 68 | /** 69 | * Unload a shared object from memory. 70 | */ 71 | extern DECLSPEC void SDLCALL SDL_UnloadObject(void *handle); 72 | 73 | /* Ends C function definitions when using C++ */ 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | #include "close_code.h" 78 | 79 | #endif /* _SDL_loadso_h */ 80 | 81 | /* vi: set ts=4 sw=4 expandtab: */ 82 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef _SDL_main_h 23 | #define _SDL_main_h 24 | 25 | #include "SDL_stdinc.h" 26 | 27 | /** 28 | * \file SDL_main.h 29 | * 30 | * Redefine main() on some platforms so that it is called by SDL. 31 | */ 32 | 33 | #ifndef SDL_MAIN_HANDLED 34 | #if defined(__WIN32__) 35 | /* On Windows SDL provides WinMain(), which parses the command line and passes 36 | the arguments to your main function. 37 | 38 | If you provide your own WinMain(), you may define SDL_MAIN_HANDLED 39 | */ 40 | #define SDL_MAIN_AVAILABLE 41 | 42 | #elif defined(__WINRT__) 43 | /* On WinRT, SDL provides a main function that initializes CoreApplication, 44 | creating an instance of IFrameworkView in the process. 45 | 46 | Please note that #include'ing SDL_main.h is not enough to get a main() 47 | function working. In non-XAML apps, the file, 48 | src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled 49 | into the app itself. In XAML apps, the function, SDL_WinRTRunApp must be 50 | called, with a pointer to the Direct3D-hosted XAML control passed in. 51 | */ 52 | #define SDL_MAIN_NEEDED 53 | 54 | #elif defined(__IPHONEOS__) 55 | /* On iOS SDL provides a main function that creates an application delegate 56 | and starts the iOS application run loop. 57 | 58 | See src/video/uikit/SDL_uikitappdelegate.m for more details. 59 | */ 60 | #define SDL_MAIN_NEEDED 61 | 62 | #elif defined(__ANDROID__) 63 | /* On Android SDL provides a Java class in SDLActivity.java that is the 64 | main activity entry point. 65 | 66 | See README-android.txt for more details on extending that class. 67 | */ 68 | #define SDL_MAIN_NEEDED 69 | 70 | #elif defined(__NACL__) 71 | /* On NACL we use ppapi_simple to set up the application helper code, 72 | then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before 73 | starting the user main function. 74 | All user code is run in a separate thread by ppapi_simple, thus 75 | allowing for blocking io to take place via nacl_io 76 | */ 77 | #define SDL_MAIN_NEEDED 78 | 79 | #endif 80 | #endif /* SDL_MAIN_HANDLED */ 81 | 82 | #ifdef __cplusplus 83 | #define C_LINKAGE "C" 84 | #else 85 | #define C_LINKAGE 86 | #endif /* __cplusplus */ 87 | 88 | /** 89 | * \file SDL_main.h 90 | * 91 | * The application's main() function must be called with C linkage, 92 | * and should be declared like this: 93 | * \code 94 | * #ifdef __cplusplus 95 | * extern "C" 96 | * #endif 97 | * int main(int argc, char *argv[]) 98 | * { 99 | * } 100 | * \endcode 101 | */ 102 | 103 | #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) 104 | #define main SDL_main 105 | #endif 106 | 107 | /** 108 | * The prototype for the application's main() function 109 | */ 110 | extern C_LINKAGE int SDL_main(int argc, char *argv[]); 111 | 112 | 113 | #include "begin_code.h" 114 | #ifdef __cplusplus 115 | extern "C" { 116 | #endif 117 | 118 | /** 119 | * This is called by the real SDL main function to let the rest of the 120 | * library know that initialization was done properly. 121 | * 122 | * Calling this yourself without knowing what you're doing can cause 123 | * crashes and hard to diagnose problems with your application. 124 | */ 125 | extern DECLSPEC void SDLCALL SDL_SetMainReady(void); 126 | 127 | #ifdef __WIN32__ 128 | 129 | /** 130 | * This can be called to set the application class at startup 131 | */ 132 | extern DECLSPEC int SDLCALL SDL_RegisterApp(char *name, Uint32 style, 133 | void *hInst); 134 | extern DECLSPEC void SDLCALL SDL_UnregisterApp(void); 135 | 136 | #endif /* __WIN32__ */ 137 | 138 | 139 | #ifdef __WINRT__ 140 | 141 | /** 142 | * \brief Initializes and launches an SDL/WinRT application. 143 | * 144 | * \param mainFunction The SDL app's C-style main(). 145 | * \param reserved Reserved for future use; should be NULL 146 | * \return 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more 147 | * information on the failure. 148 | */ 149 | extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved); 150 | 151 | #endif /* __WINRT__ */ 152 | 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | #include "close_code.h" 158 | 159 | #endif /* _SDL_main_h */ 160 | 161 | /* vi: set ts=4 sw=4 expandtab: */ 162 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_messagebox.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef _SDL_messagebox_h 23 | #define _SDL_messagebox_h 24 | 25 | #include "SDL_stdinc.h" 26 | #include "SDL_video.h" /* For SDL_Window */ 27 | 28 | #include "begin_code.h" 29 | /* Set up for C function definitions, even when using C++ */ 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * \brief SDL_MessageBox flags. If supported will display warning icon, etc. 36 | */ 37 | typedef enum 38 | { 39 | SDL_MESSAGEBOX_ERROR = 0x00000010, /**< error dialog */ 40 | SDL_MESSAGEBOX_WARNING = 0x00000020, /**< warning dialog */ 41 | SDL_MESSAGEBOX_INFORMATION = 0x00000040 /**< informational dialog */ 42 | } SDL_MessageBoxFlags; 43 | 44 | /** 45 | * \brief Flags for SDL_MessageBoxButtonData. 46 | */ 47 | typedef enum 48 | { 49 | SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, /**< Marks the default button when return is hit */ 50 | SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 /**< Marks the default button when escape is hit */ 51 | } SDL_MessageBoxButtonFlags; 52 | 53 | /** 54 | * \brief Individual button data. 55 | */ 56 | typedef struct 57 | { 58 | Uint32 flags; /**< ::SDL_MessageBoxButtonFlags */ 59 | int buttonid; /**< User defined button id (value returned via SDL_ShowMessageBox) */ 60 | const char * text; /**< The UTF-8 button text */ 61 | } SDL_MessageBoxButtonData; 62 | 63 | /** 64 | * \brief RGB value used in a message box color scheme 65 | */ 66 | typedef struct 67 | { 68 | Uint8 r, g, b; 69 | } SDL_MessageBoxColor; 70 | 71 | typedef enum 72 | { 73 | SDL_MESSAGEBOX_COLOR_BACKGROUND, 74 | SDL_MESSAGEBOX_COLOR_TEXT, 75 | SDL_MESSAGEBOX_COLOR_BUTTON_BORDER, 76 | SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND, 77 | SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, 78 | SDL_MESSAGEBOX_COLOR_MAX 79 | } SDL_MessageBoxColorType; 80 | 81 | /** 82 | * \brief A set of colors to use for message box dialogs 83 | */ 84 | typedef struct 85 | { 86 | SDL_MessageBoxColor colors[SDL_MESSAGEBOX_COLOR_MAX]; 87 | } SDL_MessageBoxColorScheme; 88 | 89 | /** 90 | * \brief MessageBox structure containing title, text, window, etc. 91 | */ 92 | typedef struct 93 | { 94 | Uint32 flags; /**< ::SDL_MessageBoxFlags */ 95 | SDL_Window *window; /**< Parent window, can be NULL */ 96 | const char *title; /**< UTF-8 title */ 97 | const char *message; /**< UTF-8 message text */ 98 | 99 | int numbuttons; 100 | const SDL_MessageBoxButtonData *buttons; 101 | 102 | const SDL_MessageBoxColorScheme *colorScheme; /**< ::SDL_MessageBoxColorScheme, can be NULL to use system settings */ 103 | } SDL_MessageBoxData; 104 | 105 | /** 106 | * \brief Create a modal message box. 107 | * 108 | * \param messageboxdata The SDL_MessageBoxData structure with title, text, etc. 109 | * \param buttonid The pointer to which user id of hit button should be copied. 110 | * 111 | * \return -1 on error, otherwise 0 and buttonid contains user id of button 112 | * hit or -1 if dialog was closed. 113 | * 114 | * \note This function should be called on the thread that created the parent 115 | * window, or on the main thread if the messagebox has no parent. It will 116 | * block execution of that thread until the user clicks a button or 117 | * closes the messagebox. 118 | */ 119 | extern DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid); 120 | 121 | /** 122 | * \brief Create a simple modal message box 123 | * 124 | * \param flags ::SDL_MessageBoxFlags 125 | * \param title UTF-8 title text 126 | * \param message UTF-8 message text 127 | * \param window The parent window, or NULL for no parent 128 | * 129 | * \return 0 on success, -1 on error 130 | * 131 | * \sa SDL_ShowMessageBox 132 | */ 133 | extern DECLSPEC int SDLCALL SDL_ShowSimpleMessageBox(Uint32 flags, const char *title, const char *message, SDL_Window *window); 134 | 135 | 136 | /* Ends C function definitions when using C++ */ 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | #include "close_code.h" 141 | 142 | #endif /* _SDL_messagebox_h */ 143 | 144 | /* vi: set ts=4 sw=4 expandtab: */ 145 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_name.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef _SDLname_h_ 23 | #define _SDLname_h_ 24 | 25 | #if defined(__STDC__) || defined(__cplusplus) 26 | #define NeedFunctionPrototypes 1 27 | #endif 28 | 29 | #define SDL_NAME(X) SDL_##X 30 | 31 | #endif /* _SDLname_h_ */ 32 | 33 | /* vi: set ts=4 sw=4 expandtab: */ 34 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_opengles.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 1.X API headers. 26 | */ 27 | 28 | #ifdef __IPHONEOS__ 29 | #include 30 | #include 31 | #else 32 | #include 33 | #include 34 | #endif 35 | 36 | #ifndef APIENTRY 37 | #define APIENTRY 38 | #endif 39 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_opengles2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_opengles2.h 24 | * 25 | * This is a simple file to encapsulate the OpenGL ES 2.0 API headers. 26 | */ 27 | #ifndef _MSC_VER 28 | 29 | #ifdef __IPHONEOS__ 30 | #include 31 | #include 32 | #else 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #else /* _MSC_VER */ 39 | 40 | /* OpenGL ES2 headers for Visual Studio */ 41 | #include "SDL_opengles2_khrplatform.h" 42 | #include "SDL_opengles2_gl2platform.h" 43 | #include "SDL_opengles2_gl2.h" 44 | #include "SDL_opengles2_gl2ext.h" 45 | 46 | #endif /* _MSC_VER */ 47 | 48 | #ifndef APIENTRY 49 | #define APIENTRY GL_APIENTRY 50 | #endif 51 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_opengles2_gl2platform.h: -------------------------------------------------------------------------------- 1 | #ifndef __gl2platform_h_ 2 | #define __gl2platform_h_ 3 | 4 | /* $Revision: 10602 $ on $Date:: 2010-03-04 22:35:34 -0800 #$ */ 5 | 6 | /* 7 | * This document is licensed under the SGI Free Software B License Version 8 | * 2.0. For details, see http://oss.sgi.com/projects/FreeB/ . 9 | */ 10 | 11 | /* Platform-specific types and definitions for OpenGL ES 2.X gl2.h 12 | * 13 | * Adopters may modify khrplatform.h and this file to suit their platform. 14 | * You are encouraged to submit all modifications to the Khronos group so that 15 | * they can be included in future versions of this file. Please submit changes 16 | * by sending them to the public Khronos Bugzilla (http://khronos.org/bugzilla) 17 | * by filing a bug against product "OpenGL-ES" component "Registry". 18 | */ 19 | 20 | /*#include */ 21 | 22 | #ifndef GL_APICALL 23 | #define GL_APICALL KHRONOS_APICALL 24 | #endif 25 | 26 | #ifndef GL_APIENTRY 27 | #define GL_APIENTRY KHRONOS_APIENTRY 28 | #endif 29 | 30 | #endif /* __gl2platform_h_ */ 31 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_platform.h 24 | * 25 | * Try to get a standard set of platform defines. 26 | */ 27 | 28 | #ifndef _SDL_platform_h 29 | #define _SDL_platform_h 30 | 31 | #if defined(_AIX) 32 | #undef __AIX__ 33 | #define __AIX__ 1 34 | #endif 35 | #if defined(__HAIKU__) 36 | #undef __HAIKU__ 37 | #define __HAIKU__ 1 38 | #endif 39 | #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__) 40 | #undef __BSDI__ 41 | #define __BSDI__ 1 42 | #endif 43 | #if defined(_arch_dreamcast) 44 | #undef __DREAMCAST__ 45 | #define __DREAMCAST__ 1 46 | #endif 47 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) 48 | #undef __FREEBSD__ 49 | #define __FREEBSD__ 1 50 | #endif 51 | #if defined(hpux) || defined(__hpux) || defined(__hpux__) 52 | #undef __HPUX__ 53 | #define __HPUX__ 1 54 | #endif 55 | #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE) 56 | #undef __IRIX__ 57 | #define __IRIX__ 1 58 | #endif 59 | #if (defined(linux) || defined(__linux) || defined(__linux__)) 60 | #undef __LINUX__ 61 | #define __LINUX__ 1 62 | #endif 63 | #if defined(ANDROID) || defined(__ANDROID__) 64 | #undef __ANDROID__ 65 | #undef __LINUX__ /* do we need to do this? */ 66 | #define __ANDROID__ 1 67 | #endif 68 | 69 | #if defined(__APPLE__) 70 | /* lets us know what version of Mac OS X we're compiling on */ 71 | #include "AvailabilityMacros.h" 72 | #include "TargetConditionals.h" 73 | #if TARGET_OS_IPHONE 74 | /* if compiling for iPhone */ 75 | #undef __IPHONEOS__ 76 | #define __IPHONEOS__ 1 77 | #undef __MACOSX__ 78 | #else 79 | /* if not compiling for iPhone */ 80 | #undef __MACOSX__ 81 | #define __MACOSX__ 1 82 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 83 | # error SDL for Mac OS X only supports deploying on 10.5 and above. 84 | #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1050 */ 85 | #endif /* TARGET_OS_IPHONE */ 86 | #endif /* defined(__APPLE__) */ 87 | 88 | #if defined(__NetBSD__) 89 | #undef __NETBSD__ 90 | #define __NETBSD__ 1 91 | #endif 92 | #if defined(__OpenBSD__) 93 | #undef __OPENBSD__ 94 | #define __OPENBSD__ 1 95 | #endif 96 | #if defined(__OS2__) 97 | #undef __OS2__ 98 | #define __OS2__ 1 99 | #endif 100 | #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE) 101 | #undef __OSF__ 102 | #define __OSF__ 1 103 | #endif 104 | #if defined(__QNXNTO__) 105 | #undef __QNXNTO__ 106 | #define __QNXNTO__ 1 107 | #endif 108 | #if defined(riscos) || defined(__riscos) || defined(__riscos__) 109 | #undef __RISCOS__ 110 | #define __RISCOS__ 1 111 | #endif 112 | #if defined(__sun) && defined(__SVR4) 113 | #undef __SOLARIS__ 114 | #define __SOLARIS__ 1 115 | #endif 116 | 117 | #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) 118 | /* Try to find out if we're compiling for WinRT or non-WinRT */ 119 | /* If _USING_V110_SDK71_ is defined it means we are using the v110_xp or v120_xp toolset. */ 120 | #if (defined(_MSC_VER) && (_MSC_VER >= 1700) && !_USING_V110_SDK71_) /* _MSC_VER==1700 for MSVC 2012 */ 121 | #include 122 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 123 | #undef __WINDOWS__ 124 | #define __WINDOWS__ 1 125 | /* See if we're compiling for WinRT: */ 126 | #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 127 | #undef __WINRT__ 128 | #define __WINRT__ 1 129 | #endif 130 | #else 131 | #undef __WINDOWS__ 132 | #define __WINDOWS__ 1 133 | #endif /* _MSC_VER < 1700 */ 134 | #endif /* defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) */ 135 | 136 | #if defined(__WINDOWS__) 137 | #undef __WIN32__ 138 | #define __WIN32__ 1 139 | #endif 140 | #if defined(__PSP__) 141 | #undef __PSP__ 142 | #define __PSP__ 1 143 | #endif 144 | 145 | /* The NACL compiler defines __native_client__ and __pnacl__ 146 | * Ref: http://www.chromium.org/nativeclient/pnacl/stability-of-the-pnacl-bitcode-abi 147 | */ 148 | #if defined(__native_client__) 149 | #undef __LINUX__ 150 | #undef __NACL__ 151 | #define __NACL__ 1 152 | #endif 153 | #if defined(__pnacl__) 154 | #undef __LINUX__ 155 | #undef __PNACL__ 156 | #define __PNACL__ 1 157 | /* PNACL with newlib supports static linking only */ 158 | #define __SDL_NOGETPROCADDR__ 159 | #endif 160 | 161 | 162 | #include "begin_code.h" 163 | /* Set up for C function definitions, even when using C++ */ 164 | #ifdef __cplusplus 165 | extern "C" { 166 | #endif 167 | 168 | /** 169 | * \brief Gets the name of the platform. 170 | */ 171 | extern DECLSPEC const char * SDLCALL SDL_GetPlatform (void); 172 | 173 | /* Ends C function definitions when using C++ */ 174 | #ifdef __cplusplus 175 | } 176 | #endif 177 | #include "close_code.h" 178 | 179 | #endif /* _SDL_platform_h */ 180 | 181 | /* vi: set ts=4 sw=4 expandtab: */ 182 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_power.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef _SDL_power_h 23 | #define _SDL_power_h 24 | 25 | /** 26 | * \file SDL_power.h 27 | * 28 | * Header for the SDL power management routines. 29 | */ 30 | 31 | #include "SDL_stdinc.h" 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /** 40 | * \brief The basic state for the system's power supply. 41 | */ 42 | typedef enum 43 | { 44 | SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */ 45 | SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ 46 | SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ 47 | SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */ 48 | SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */ 49 | } SDL_PowerState; 50 | 51 | 52 | /** 53 | * \brief Get the current power supply details. 54 | * 55 | * \param secs Seconds of battery life left. You can pass a NULL here if 56 | * you don't care. Will return -1 if we can't determine a 57 | * value, or we're not running on a battery. 58 | * 59 | * \param pct Percentage of battery life left, between 0 and 100. You can 60 | * pass a NULL here if you don't care. Will return -1 if we 61 | * can't determine a value, or we're not running on a battery. 62 | * 63 | * \return The state of the battery (if any). 64 | */ 65 | extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *secs, int *pct); 66 | 67 | /* Ends C function definitions when using C++ */ 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | #include "close_code.h" 72 | 73 | #endif /* _SDL_power_h */ 74 | 75 | /* vi: set ts=4 sw=4 expandtab: */ 76 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_quit.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_quit.h 24 | * 25 | * Include file for SDL quit event handling. 26 | */ 27 | 28 | #ifndef _SDL_quit_h 29 | #define _SDL_quit_h 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | 34 | /** 35 | * \file SDL_quit.h 36 | * 37 | * An ::SDL_QUIT event is generated when the user tries to close the application 38 | * window. If it is ignored or filtered out, the window will remain open. 39 | * If it is not ignored or filtered, it is queued normally and the window 40 | * is allowed to close. When the window is closed, screen updates will 41 | * complete, but have no effect. 42 | * 43 | * SDL_Init() installs signal handlers for SIGINT (keyboard interrupt) 44 | * and SIGTERM (system termination request), if handlers do not already 45 | * exist, that generate ::SDL_QUIT events as well. There is no way 46 | * to determine the cause of an ::SDL_QUIT event, but setting a signal 47 | * handler in your application will override the default generation of 48 | * quit events for that signal. 49 | * 50 | * \sa SDL_Quit() 51 | */ 52 | 53 | /* There are no functions directly affecting the quit event */ 54 | 55 | #define SDL_QuitRequested() \ 56 | (SDL_PumpEvents(), (SDL_PeepEvents(NULL,0,SDL_PEEKEVENT,SDL_QUIT,SDL_QUIT) > 0)) 57 | 58 | #endif /* _SDL_quit_h */ 59 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_rect.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_rect.h 24 | * 25 | * Header file for SDL_rect definition and management functions. 26 | */ 27 | 28 | #ifndef _SDL_rect_h 29 | #define _SDL_rect_h 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | #include "SDL_pixels.h" 34 | #include "SDL_rwops.h" 35 | 36 | #include "begin_code.h" 37 | /* Set up for C function definitions, even when using C++ */ 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** 43 | * \brief The structure that defines a point 44 | * 45 | * \sa SDL_EnclosePoints 46 | * \sa SDL_PointInRect 47 | */ 48 | typedef struct SDL_Point 49 | { 50 | int x; 51 | int y; 52 | } SDL_Point; 53 | 54 | /** 55 | * \brief A rectangle, with the origin at the upper left. 56 | * 57 | * \sa SDL_RectEmpty 58 | * \sa SDL_RectEquals 59 | * \sa SDL_HasIntersection 60 | * \sa SDL_IntersectRect 61 | * \sa SDL_UnionRect 62 | * \sa SDL_EnclosePoints 63 | */ 64 | typedef struct SDL_Rect 65 | { 66 | int x, y; 67 | int w, h; 68 | } SDL_Rect; 69 | 70 | /** 71 | * \brief Returns true if point resides inside a rectangle. 72 | */ 73 | SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r) 74 | { 75 | return ( (p->x >= r->x) && (p->x < (r->x + r->w)) && 76 | (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE; 77 | } 78 | 79 | /** 80 | * \brief Returns true if the rectangle has no area. 81 | */ 82 | SDL_FORCE_INLINE SDL_bool SDL_RectEmpty(const SDL_Rect *r) 83 | { 84 | return ((!r) || (r->w <= 0) || (r->h <= 0)) ? SDL_TRUE : SDL_FALSE; 85 | } 86 | 87 | /** 88 | * \brief Returns true if the two rectangles are equal. 89 | */ 90 | SDL_FORCE_INLINE SDL_bool SDL_RectEquals(const SDL_Rect *a, const SDL_Rect *b) 91 | { 92 | return (a && b && (a->x == b->x) && (a->y == b->y) && 93 | (a->w == b->w) && (a->h == b->h)) ? SDL_TRUE : SDL_FALSE; 94 | } 95 | 96 | /** 97 | * \brief Determine whether two rectangles intersect. 98 | * 99 | * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. 100 | */ 101 | extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A, 102 | const SDL_Rect * B); 103 | 104 | /** 105 | * \brief Calculate the intersection of two rectangles. 106 | * 107 | * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. 108 | */ 109 | extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A, 110 | const SDL_Rect * B, 111 | SDL_Rect * result); 112 | 113 | /** 114 | * \brief Calculate the union of two rectangles. 115 | */ 116 | extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A, 117 | const SDL_Rect * B, 118 | SDL_Rect * result); 119 | 120 | /** 121 | * \brief Calculate a minimal rectangle enclosing a set of points 122 | * 123 | * \return SDL_TRUE if any points were within the clipping rect 124 | */ 125 | extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points, 126 | int count, 127 | const SDL_Rect * clip, 128 | SDL_Rect * result); 129 | 130 | /** 131 | * \brief Calculate the intersection of a rectangle and line segment. 132 | * 133 | * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. 134 | */ 135 | extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect * 136 | rect, int *X1, 137 | int *Y1, int *X2, 138 | int *Y2); 139 | 140 | /* Ends C function definitions when using C++ */ 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | #include "close_code.h" 145 | 146 | #endif /* _SDL_rect_h */ 147 | 148 | /* vi: set ts=4 sw=4 expandtab: */ 149 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_revision.h: -------------------------------------------------------------------------------- 1 | #define SDL_REVISION "hg-10001:e12c38730512" 2 | #define SDL_REVISION_NUMBER 10001 3 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef _SDL_test_h 31 | #define _SDL_test_h 32 | 33 | #include "SDL.h" 34 | #include "SDL_test_common.h" 35 | #include "SDL_test_font.h" 36 | #include "SDL_test_random.h" 37 | #include "SDL_test_fuzzer.h" 38 | #include "SDL_test_crc32.h" 39 | #include "SDL_test_md5.h" 40 | #include "SDL_test_log.h" 41 | #include "SDL_test_assert.h" 42 | #include "SDL_test_harness.h" 43 | #include "SDL_test_images.h" 44 | #include "SDL_test_compare.h" 45 | 46 | #include "begin_code.h" 47 | /* Set up for C function definitions, even when using C++ */ 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /* Global definitions */ 53 | 54 | /* 55 | * Note: Maximum size of SDLTest log message is less than SDL's limit 56 | * to ensure we can fit additional information such as the timestamp. 57 | */ 58 | #define SDLTEST_MAX_LOGMESSAGE_LENGTH 3584 59 | 60 | /* Ends C function definitions when using C++ */ 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | #include "close_code.h" 65 | 66 | #endif /* _SDL_test_h */ 67 | 68 | /* vi: set ts=4 sw=4 expandtab: */ 69 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_assert.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | * 32 | * Assert API for test code and test cases 33 | * 34 | */ 35 | 36 | #ifndef _SDL_test_assert_h 37 | #define _SDL_test_assert_h 38 | 39 | #include "begin_code.h" 40 | /* Set up for C function definitions, even when using C++ */ 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /** 46 | * \brief Fails the assert. 47 | */ 48 | #define ASSERT_FAIL 0 49 | 50 | /** 51 | * \brief Passes the assert. 52 | */ 53 | #define ASSERT_PASS 1 54 | 55 | /** 56 | * \brief Assert that logs and break execution flow on failures. 57 | * 58 | * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). 59 | * \param assertDescription Message to log with the assert describing it. 60 | */ 61 | void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2); 62 | 63 | /** 64 | * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters. 65 | * 66 | * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). 67 | * \param assertDescription Message to log with the assert describing it. 68 | * 69 | * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired. 70 | */ 71 | int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(2); 72 | 73 | /** 74 | * \brief Explicitly pass without checking an assertion condition. Updates assertion counter. 75 | * 76 | * \param assertDescription Message to log with the assert describing it. 77 | */ 78 | void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...) SDL_PRINTF_VARARG_FUNC(1); 79 | 80 | /** 81 | * \brief Resets the assert summary counters to zero. 82 | */ 83 | void SDLTest_ResetAssertSummary(); 84 | 85 | /** 86 | * \brief Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR. 87 | */ 88 | void SDLTest_LogAssertSummary(); 89 | 90 | 91 | /** 92 | * \brief Converts the current assert summary state to a test result. 93 | * 94 | * \returns TEST_RESULT_PASSED, TEST_RESULT_FAILED, or TEST_RESULT_NO_ASSERT 95 | */ 96 | int SDLTest_AssertSummaryToTestResult(); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | #include "close_code.h" 102 | 103 | #endif /* _SDL_test_assert_h */ 104 | 105 | /* vi: set ts=4 sw=4 expandtab: */ 106 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_compare.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_compare.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | Defines comparison functions (i.e. for surfaces). 33 | 34 | */ 35 | 36 | #ifndef _SDL_test_compare_h 37 | #define _SDL_test_compare_h 38 | 39 | #include "SDL.h" 40 | 41 | #include "SDL_test_images.h" 42 | 43 | #include "begin_code.h" 44 | /* Set up for C function definitions, even when using C++ */ 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /** 50 | * \brief Compares a surface and with reference image data for equality 51 | * 52 | * \param surface Surface used in comparison 53 | * \param referenceSurface Test Surface used in comparison 54 | * \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy. 55 | * 56 | * \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ. 57 | */ 58 | int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error); 59 | 60 | 61 | /* Ends C function definitions when using C++ */ 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | #include "close_code.h" 66 | 67 | #endif /* _SDL_test_compare_h */ 68 | 69 | /* vi: set ts=4 sw=4 expandtab: */ 70 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_crc32.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_crc32.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | Implements CRC32 calculations (default output is Perl String::CRC32 compatible). 33 | 34 | */ 35 | 36 | #ifndef _SDL_test_crc32_h 37 | #define _SDL_test_crc32_h 38 | 39 | #include "begin_code.h" 40 | /* Set up for C function definitions, even when using C++ */ 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | 46 | /* ------------ Definitions --------- */ 47 | 48 | /* Definition shared by all CRC routines */ 49 | 50 | #ifndef CrcUint32 51 | #define CrcUint32 unsigned int 52 | #endif 53 | #ifndef CrcUint8 54 | #define CrcUint8 unsigned char 55 | #endif 56 | 57 | #ifdef ORIGINAL_METHOD 58 | #define CRC32_POLY 0x04c11db7 /* AUTODIN II, Ethernet, & FDDI */ 59 | #else 60 | #define CRC32_POLY 0xEDB88320 /* Perl String::CRC32 compatible */ 61 | #endif 62 | 63 | /** 64 | * Data structure for CRC32 (checksum) computation 65 | */ 66 | typedef struct { 67 | CrcUint32 crc32_table[256]; /* CRC table */ 68 | } SDLTest_Crc32Context; 69 | 70 | /* ---------- Function Prototypes ------------- */ 71 | 72 | /** 73 | * \brief Initialize the CRC context 74 | * 75 | * Note: The function initializes the crc table required for all crc calculations. 76 | * 77 | * \param crcContext pointer to context variable 78 | * 79 | * \returns 0 for OK, -1 on error 80 | * 81 | */ 82 | int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext); 83 | 84 | 85 | /** 86 | * \brief calculate a crc32 from a data block 87 | * 88 | * \param crcContext pointer to context variable 89 | * \param inBuf input buffer to checksum 90 | * \param inLen length of input buffer 91 | * \param crc32 pointer to Uint32 to store the final CRC into 92 | * 93 | * \returns 0 for OK, -1 on error 94 | * 95 | */ 96 | int SDLTest_crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32); 97 | 98 | /* Same routine broken down into three steps */ 99 | int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32); 100 | int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32); 101 | int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32); 102 | 103 | 104 | /** 105 | * \brief clean up CRC context 106 | * 107 | * \param crcContext pointer to context variable 108 | * 109 | * \returns 0 for OK, -1 on error 110 | * 111 | */ 112 | 113 | int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext); 114 | 115 | 116 | /* Ends C function definitions when using C++ */ 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | #include "close_code.h" 121 | 122 | #endif /* _SDL_test_crc32_h */ 123 | 124 | /* vi: set ts=4 sw=4 expandtab: */ 125 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_font.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_font.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | #ifndef _SDL_test_font_h 31 | #define _SDL_test_font_h 32 | 33 | #include "begin_code.h" 34 | /* Set up for C function definitions, even when using C++ */ 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /* Function prototypes */ 40 | 41 | #define FONT_CHARACTER_SIZE 8 42 | 43 | /** 44 | * \brief Draw a string in the currently set font. 45 | * 46 | * \param renderer The renderer to draw on. 47 | * \param x The X coordinate of the upper left corner of the character. 48 | * \param y The Y coordinate of the upper left corner of the character. 49 | * \param c The character to draw. 50 | * 51 | * \returns Returns 0 on success, -1 on failure. 52 | */ 53 | int SDLTest_DrawCharacter( SDL_Renderer *renderer, int x, int y, char c ); 54 | 55 | /** 56 | * \brief Draw a string in the currently set font. 57 | * 58 | * \param renderer The renderer to draw on. 59 | * \param x The X coordinate of the upper left corner of the string. 60 | * \param y The Y coordinate of the upper left corner of the string. 61 | * \param s The string to draw. 62 | * 63 | * \returns Returns 0 on success, -1 on failure. 64 | */ 65 | int SDLTest_DrawString( SDL_Renderer * renderer, int x, int y, const char *s ); 66 | 67 | 68 | /* Ends C function definitions when using C++ */ 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | #include "close_code.h" 73 | 74 | #endif /* _SDL_test_font_h */ 75 | 76 | /* vi: set ts=4 sw=4 expandtab: */ 77 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_harness.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_harness.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | Defines types for test case definitions and the test execution harness API. 32 | 33 | Based on original GSOC code by Markus Kauppila 34 | */ 35 | 36 | #ifndef _SDL_test_harness_h 37 | #define _SDL_test_harness_h 38 | 39 | #include "begin_code.h" 40 | /* Set up for C function definitions, even when using C++ */ 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | 46 | /* ! Definitions for test case structures */ 47 | #define TEST_ENABLED 1 48 | #define TEST_DISABLED 0 49 | 50 | /* ! Definition of all the possible test return values of the test case method */ 51 | #define TEST_ABORTED -1 52 | #define TEST_STARTED 0 53 | #define TEST_COMPLETED 1 54 | #define TEST_SKIPPED 2 55 | 56 | /* ! Definition of all the possible test results for the harness */ 57 | #define TEST_RESULT_PASSED 0 58 | #define TEST_RESULT_FAILED 1 59 | #define TEST_RESULT_NO_ASSERT 2 60 | #define TEST_RESULT_SKIPPED 3 61 | #define TEST_RESULT_SETUP_FAILURE 4 62 | 63 | /* !< Function pointer to a test case setup function (run before every test) */ 64 | typedef void (*SDLTest_TestCaseSetUpFp)(void *arg); 65 | 66 | /* !< Function pointer to a test case function */ 67 | typedef int (*SDLTest_TestCaseFp)(void *arg); 68 | 69 | /* !< Function pointer to a test case teardown function (run after every test) */ 70 | typedef void (*SDLTest_TestCaseTearDownFp)(void *arg); 71 | 72 | /** 73 | * Holds information about a single test case. 74 | */ 75 | typedef struct SDLTest_TestCaseReference { 76 | /* !< Func2Stress */ 77 | SDLTest_TestCaseFp testCase; 78 | /* !< Short name (or function name) "Func2Stress" */ 79 | char *name; 80 | /* !< Long name or full description "This test pushes func2() to the limit." */ 81 | char *description; 82 | /* !< Set to TEST_ENABLED or TEST_DISABLED (test won't be run) */ 83 | int enabled; 84 | } SDLTest_TestCaseReference; 85 | 86 | /** 87 | * Holds information about a test suite (multiple test cases). 88 | */ 89 | typedef struct SDLTest_TestSuiteReference { 90 | /* !< "PlatformSuite" */ 91 | char *name; 92 | /* !< The function that is run before each test. NULL skips. */ 93 | SDLTest_TestCaseSetUpFp testSetUp; 94 | /* !< The test cases that are run as part of the suite. Last item should be NULL. */ 95 | const SDLTest_TestCaseReference **testCases; 96 | /* !< The function that is run after each test. NULL skips. */ 97 | SDLTest_TestCaseTearDownFp testTearDown; 98 | } SDLTest_TestSuiteReference; 99 | 100 | 101 | /** 102 | * \brief Execute a test suite using the given run seed and execution key. 103 | * 104 | * \param testSuites Suites containing the test case. 105 | * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one. 106 | * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one. 107 | * \param filter Filter specification. NULL disables. Case sensitive. 108 | * \param testIterations Number of iterations to run each test case. 109 | * 110 | * \returns Test run result; 0 when all tests passed, 1 if any tests failed. 111 | */ 112 | int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *userRunSeed, Uint64 userExecKey, const char *filter, int testIterations); 113 | 114 | 115 | /* Ends C function definitions when using C++ */ 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | #include "close_code.h" 120 | 121 | #endif /* _SDL_test_harness_h */ 122 | 123 | /* vi: set ts=4 sw=4 expandtab: */ 124 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_images.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_images.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | Defines some images for tests. 33 | 34 | */ 35 | 36 | #ifndef _SDL_test_images_h 37 | #define _SDL_test_images_h 38 | 39 | #include "SDL.h" 40 | 41 | #include "begin_code.h" 42 | /* Set up for C function definitions, even when using C++ */ 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | /** 48 | *Type for test images. 49 | */ 50 | typedef struct SDLTest_SurfaceImage_s { 51 | int width; 52 | int height; 53 | unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ 54 | const char *pixel_data; 55 | } SDLTest_SurfaceImage_t; 56 | 57 | /* Test images */ 58 | SDL_Surface *SDLTest_ImageBlit(); 59 | SDL_Surface *SDLTest_ImageBlitColor(); 60 | SDL_Surface *SDLTest_ImageBlitAlpha(); 61 | SDL_Surface *SDLTest_ImageBlitBlendAdd(); 62 | SDL_Surface *SDLTest_ImageBlitBlend(); 63 | SDL_Surface *SDLTest_ImageBlitBlendMod(); 64 | SDL_Surface *SDLTest_ImageBlitBlendNone(); 65 | SDL_Surface *SDLTest_ImageBlitBlendAll(); 66 | SDL_Surface *SDLTest_ImageFace(); 67 | SDL_Surface *SDLTest_ImagePrimitives(); 68 | SDL_Surface *SDLTest_ImagePrimitivesBlend(); 69 | 70 | /* Ends C function definitions when using C++ */ 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | #include "close_code.h" 75 | 76 | #endif /* _SDL_test_images_h */ 77 | 78 | /* vi: set ts=4 sw=4 expandtab: */ 79 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_log.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | * 32 | * Wrapper to log in the TEST category 33 | * 34 | */ 35 | 36 | #ifndef _SDL_test_log_h 37 | #define _SDL_test_log_h 38 | 39 | #include "begin_code.h" 40 | /* Set up for C function definitions, even when using C++ */ 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /** 46 | * \brief Prints given message with a timestamp in the TEST category and INFO priority. 47 | * 48 | * \param fmt Message to be logged 49 | */ 50 | void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 51 | 52 | /** 53 | * \brief Prints given message with a timestamp in the TEST category and the ERROR priority. 54 | * 55 | * \param fmt Message to be logged 56 | */ 57 | void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); 58 | 59 | /* Ends C function definitions when using C++ */ 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | #include "close_code.h" 64 | 65 | #endif /* _SDL_test_log_h */ 66 | 67 | /* vi: set ts=4 sw=4 expandtab: */ 68 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_md5.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | *********************************************************************** 32 | ** Header file for implementation of MD5 ** 33 | ** RSA Data Security, Inc. MD5 Message-Digest Algorithm ** 34 | ** Created: 2/17/90 RLR ** 35 | ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version ** 36 | ** Revised (for MD5): RLR 4/27/91 ** 37 | ** -- G modified to have y&~z instead of y&z ** 38 | ** -- FF, GG, HH modified to add in last register done ** 39 | ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 ** 40 | ** -- distinct additive constant for each step ** 41 | ** -- round 4 added, working mod 7 ** 42 | *********************************************************************** 43 | */ 44 | 45 | /* 46 | *********************************************************************** 47 | ** Message-digest routines: ** 48 | ** To form the message digest for a message M ** 49 | ** (1) Initialize a context buffer mdContext using MD5Init ** 50 | ** (2) Call MD5Update on mdContext and M ** 51 | ** (3) Call MD5Final on mdContext ** 52 | ** The message digest is now in mdContext->digest[0...15] ** 53 | *********************************************************************** 54 | */ 55 | 56 | #ifndef _SDL_test_md5_h 57 | #define _SDL_test_md5_h 58 | 59 | #include "begin_code.h" 60 | /* Set up for C function definitions, even when using C++ */ 61 | #ifdef __cplusplus 62 | extern "C" { 63 | #endif 64 | 65 | /* ------------ Definitions --------- */ 66 | 67 | /* typedef a 32-bit type */ 68 | typedef unsigned long int MD5UINT4; 69 | 70 | /* Data structure for MD5 (Message-Digest) computation */ 71 | typedef struct { 72 | MD5UINT4 i[2]; /* number of _bits_ handled mod 2^64 */ 73 | MD5UINT4 buf[4]; /* scratch buffer */ 74 | unsigned char in[64]; /* input buffer */ 75 | unsigned char digest[16]; /* actual digest after Md5Final call */ 76 | } SDLTest_Md5Context; 77 | 78 | /* ---------- Function Prototypes ------------- */ 79 | 80 | /** 81 | * \brief initialize the context 82 | * 83 | * \param mdContext pointer to context variable 84 | * 85 | * Note: The function initializes the message-digest context 86 | * mdContext. Call before each new use of the context - 87 | * all fields are set to zero. 88 | */ 89 | void SDLTest_Md5Init(SDLTest_Md5Context * mdContext); 90 | 91 | 92 | /** 93 | * \brief update digest from variable length data 94 | * 95 | * \param mdContext pointer to context variable 96 | * \param inBuf pointer to data array/string 97 | * \param inLen length of data array/string 98 | * 99 | * Note: The function updates the message-digest context to account 100 | * for the presence of each of the characters inBuf[0..inLen-1] 101 | * in the message whose digest is being computed. 102 | */ 103 | 104 | void SDLTest_Md5Update(SDLTest_Md5Context * mdContext, unsigned char *inBuf, 105 | unsigned int inLen); 106 | 107 | 108 | /** 109 | * \brief complete digest computation 110 | * 111 | * \param mdContext pointer to context variable 112 | * 113 | * Note: The function terminates the message-digest computation and 114 | * ends with the desired message digest in mdContext.digest[0..15]. 115 | * Always call before using the digest[] variable. 116 | */ 117 | 118 | void SDLTest_Md5Final(SDLTest_Md5Context * mdContext); 119 | 120 | 121 | /* Ends C function definitions when using C++ */ 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | #include "close_code.h" 126 | 127 | #endif /* _SDL_test_md5_h */ 128 | 129 | /* vi: set ts=4 sw=4 expandtab: */ 130 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_test_random.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_test_random.h 24 | * 25 | * Include file for SDL test framework. 26 | * 27 | * This code is a part of the SDL2_test library, not the main SDL library. 28 | */ 29 | 30 | /* 31 | 32 | A "32-bit Multiply with carry random number generator. Very fast. 33 | Includes a list of recommended multipliers. 34 | 35 | multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32. 36 | period: (a*2^31)-1 37 | 38 | */ 39 | 40 | #ifndef _SDL_test_random_h 41 | #define _SDL_test_random_h 42 | 43 | #include "begin_code.h" 44 | /* Set up for C function definitions, even when using C++ */ 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | /* --- Definitions */ 50 | 51 | /* 52 | * Macros that return a random number in a specific format. 53 | */ 54 | #define SDLTest_RandomInt(c) ((int)SDLTest_Random(c)) 55 | 56 | /* 57 | * Context structure for the random number generator state. 58 | */ 59 | typedef struct { 60 | unsigned int a; 61 | unsigned int x; 62 | unsigned int c; 63 | unsigned int ah; 64 | unsigned int al; 65 | } SDLTest_RandomContext; 66 | 67 | 68 | /* --- Function prototypes */ 69 | 70 | /** 71 | * \brief Initialize random number generator with two integers. 72 | * 73 | * Note: The random sequence of numbers returned by ...Random() is the 74 | * same for the same two integers and has a period of 2^31. 75 | * 76 | * \param rndContext pointer to context structure 77 | * \param xi integer that defines the random sequence 78 | * \param ci integer that defines the random sequence 79 | * 80 | */ 81 | void SDLTest_RandomInit(SDLTest_RandomContext * rndContext, unsigned int xi, 82 | unsigned int ci); 83 | 84 | /** 85 | * \brief Initialize random number generator based on current system time. 86 | * 87 | * \param rndContext pointer to context structure 88 | * 89 | */ 90 | void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext); 91 | 92 | 93 | /** 94 | * \brief Initialize random number generator based on current system time. 95 | * 96 | * Note: ...RandomInit() or ...RandomInitTime() must have been called 97 | * before using this function. 98 | * 99 | * \param rndContext pointer to context structure 100 | * 101 | * \returns A random number (32bit unsigned integer) 102 | * 103 | */ 104 | unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext); 105 | 106 | 107 | /* Ends C function definitions when using C++ */ 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | #include "close_code.h" 112 | 113 | #endif /* _SDL_test_random_h */ 114 | 115 | /* vi: set ts=4 sw=4 expandtab: */ 116 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | #ifndef _SDL_timer_h 23 | #define _SDL_timer_h 24 | 25 | /** 26 | * \file SDL_timer.h 27 | * 28 | * Header for the SDL time management routines. 29 | */ 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | 34 | #include "begin_code.h" 35 | /* Set up for C function definitions, even when using C++ */ 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * \brief Get the number of milliseconds since the SDL library initialization. 42 | * 43 | * \note This value wraps if the program runs for more than ~49 days. 44 | */ 45 | extern DECLSPEC Uint32 SDLCALL SDL_GetTicks(void); 46 | 47 | /** 48 | * \brief Compare SDL ticks values, and return true if A has passed B 49 | * 50 | * e.g. if you want to wait 100 ms, you could do this: 51 | * Uint32 timeout = SDL_GetTicks() + 100; 52 | * while (!SDL_TICKS_PASSED(SDL_GetTicks(), timeout)) { 53 | * ... do work until timeout has elapsed 54 | * } 55 | */ 56 | #define SDL_TICKS_PASSED(A, B) ((Sint32)((B) - (A)) <= 0) 57 | 58 | /** 59 | * \brief Get the current value of the high resolution counter 60 | */ 61 | extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceCounter(void); 62 | 63 | /** 64 | * \brief Get the count per second of the high resolution counter 65 | */ 66 | extern DECLSPEC Uint64 SDLCALL SDL_GetPerformanceFrequency(void); 67 | 68 | /** 69 | * \brief Wait a specified number of milliseconds before returning. 70 | */ 71 | extern DECLSPEC void SDLCALL SDL_Delay(Uint32 ms); 72 | 73 | /** 74 | * Function prototype for the timer callback function. 75 | * 76 | * The callback function is passed the current timer interval and returns 77 | * the next timer interval. If the returned value is the same as the one 78 | * passed in, the periodic alarm continues, otherwise a new alarm is 79 | * scheduled. If the callback returns 0, the periodic alarm is cancelled. 80 | */ 81 | typedef Uint32 (SDLCALL * SDL_TimerCallback) (Uint32 interval, void *param); 82 | 83 | /** 84 | * Definition of the timer ID type. 85 | */ 86 | typedef int SDL_TimerID; 87 | 88 | /** 89 | * \brief Add a new timer to the pool of timers already running. 90 | * 91 | * \return A timer ID, or 0 when an error occurs. 92 | */ 93 | extern DECLSPEC SDL_TimerID SDLCALL SDL_AddTimer(Uint32 interval, 94 | SDL_TimerCallback callback, 95 | void *param); 96 | 97 | /** 98 | * \brief Remove a timer knowing its ID. 99 | * 100 | * \return A boolean value indicating success or failure. 101 | * 102 | * \warning It is not safe to remove a timer multiple times. 103 | */ 104 | extern DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id); 105 | 106 | 107 | /* Ends C function definitions when using C++ */ 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | #include "close_code.h" 112 | 113 | #endif /* _SDL_timer_h */ 114 | 115 | /* vi: set ts=4 sw=4 expandtab: */ 116 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_touch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_touch.h 24 | * 25 | * Include file for SDL touch event handling. 26 | */ 27 | 28 | #ifndef _SDL_touch_h 29 | #define _SDL_touch_h 30 | 31 | #include "SDL_stdinc.h" 32 | #include "SDL_error.h" 33 | #include "SDL_video.h" 34 | 35 | #include "begin_code.h" 36 | /* Set up for C function definitions, even when using C++ */ 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | typedef Sint64 SDL_TouchID; 42 | typedef Sint64 SDL_FingerID; 43 | 44 | typedef struct SDL_Finger 45 | { 46 | SDL_FingerID id; 47 | float x; 48 | float y; 49 | float pressure; 50 | } SDL_Finger; 51 | 52 | /* Used as the device ID for mouse events simulated with touch input */ 53 | #define SDL_TOUCH_MOUSEID ((Uint32)-1) 54 | 55 | 56 | /* Function prototypes */ 57 | 58 | /** 59 | * \brief Get the number of registered touch devices. 60 | */ 61 | extern DECLSPEC int SDLCALL SDL_GetNumTouchDevices(void); 62 | 63 | /** 64 | * \brief Get the touch ID with the given index, or 0 if the index is invalid. 65 | */ 66 | extern DECLSPEC SDL_TouchID SDLCALL SDL_GetTouchDevice(int index); 67 | 68 | /** 69 | * \brief Get the number of active fingers for a given touch device. 70 | */ 71 | extern DECLSPEC int SDLCALL SDL_GetNumTouchFingers(SDL_TouchID touchID); 72 | 73 | /** 74 | * \brief Get the finger object of the given touch, with the given index. 75 | */ 76 | extern DECLSPEC SDL_Finger * SDLCALL SDL_GetTouchFinger(SDL_TouchID touchID, int index); 77 | 78 | /* Ends C function definitions when using C++ */ 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | #include "close_code.h" 83 | 84 | #endif /* _SDL_touch_h */ 85 | 86 | /* vi: set ts=4 sw=4 expandtab: */ 87 | -------------------------------------------------------------------------------- /contrib/SDL/include/SDL_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file SDL_types.h 24 | * 25 | * \deprecated 26 | */ 27 | 28 | /* DEPRECATED */ 29 | #include "SDL_stdinc.h" 30 | -------------------------------------------------------------------------------- /contrib/SDL/include/begin_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file begin_code.h 24 | * 25 | * This file sets things up for C dynamic library function definitions, 26 | * static inlined functions, and structures aligned at 4-byte alignment. 27 | * If you don't like ugly C preprocessor code, don't look at this file. :) 28 | */ 29 | 30 | /* This shouldn't be nested -- included it around code only. */ 31 | #ifdef _begin_code_h 32 | #error Nested inclusion of begin_code.h 33 | #endif 34 | #define _begin_code_h 35 | 36 | #ifndef SDL_DEPRECATED 37 | # if (__GNUC__ >= 4) /* technically, this arrived in gcc 3.1, but oh well. */ 38 | # define SDL_DEPRECATED __attribute__((deprecated)) 39 | # else 40 | # define SDL_DEPRECATED 41 | # endif 42 | #endif 43 | 44 | #ifndef SDL_UNUSED 45 | # ifdef __GNUC__ 46 | # define SDL_UNUSED __attribute__((unused)) 47 | # else 48 | # define SDL_UNUSED 49 | # endif 50 | #endif 51 | 52 | /* Some compilers use a special export keyword */ 53 | #ifndef DECLSPEC 54 | # if defined(__WIN32__) || defined(__WINRT__) 55 | # ifdef __BORLANDC__ 56 | # ifdef BUILD_SDL 57 | # define DECLSPEC 58 | # else 59 | # define DECLSPEC __declspec(dllimport) 60 | # endif 61 | # else 62 | # define DECLSPEC __declspec(dllexport) 63 | # endif 64 | # else 65 | # if defined(__GNUC__) && __GNUC__ >= 4 66 | # define DECLSPEC __attribute__ ((visibility("default"))) 67 | # else 68 | # define DECLSPEC 69 | # endif 70 | # endif 71 | #endif 72 | 73 | /* By default SDL uses the C calling convention */ 74 | #ifndef SDLCALL 75 | #if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__) 76 | #define SDLCALL __cdecl 77 | #else 78 | #define SDLCALL 79 | #endif 80 | #endif /* SDLCALL */ 81 | 82 | /* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ 83 | #ifdef __SYMBIAN32__ 84 | #undef DECLSPEC 85 | #define DECLSPEC 86 | #endif /* __SYMBIAN32__ */ 87 | 88 | /* Force structure packing at 4 byte alignment. 89 | This is necessary if the header is included in code which has structure 90 | packing set to an alternate value, say for loading structures from disk. 91 | The packing is reset to the previous value in close_code.h 92 | */ 93 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__BORLANDC__) 94 | #ifdef _MSC_VER 95 | #pragma warning(disable: 4103) 96 | #endif 97 | #ifdef __BORLANDC__ 98 | #pragma nopackwarning 99 | #endif 100 | #ifdef _M_X64 101 | /* Use 8-byte alignment on 64-bit architectures, so pointers are aligned */ 102 | #pragma pack(push,8) 103 | #else 104 | #pragma pack(push,4) 105 | #endif 106 | #endif /* Compiler needs structure packing set */ 107 | 108 | #ifndef SDL_INLINE 109 | #if defined(__GNUC__) 110 | #define SDL_INLINE __inline__ 111 | #elif defined(_MSC_VER) || defined(__BORLANDC__) || \ 112 | defined(__DMC__) || defined(__SC__) || \ 113 | defined(__WATCOMC__) || defined(__LCC__) || \ 114 | defined(__DECC) 115 | #define SDL_INLINE __inline 116 | #ifndef __inline__ 117 | #define __inline__ __inline 118 | #endif 119 | #else 120 | #define SDL_INLINE inline 121 | #ifndef __inline__ 122 | #define __inline__ inline 123 | #endif 124 | #endif 125 | #endif /* SDL_INLINE not defined */ 126 | 127 | #ifndef SDL_FORCE_INLINE 128 | #if defined(_MSC_VER) 129 | #define SDL_FORCE_INLINE __forceinline 130 | #elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) ) 131 | #define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__ 132 | #else 133 | #define SDL_FORCE_INLINE static SDL_INLINE 134 | #endif 135 | #endif /* SDL_FORCE_INLINE not defined */ 136 | 137 | /* Apparently this is needed by several Windows compilers */ 138 | #if !defined(__MACH__) 139 | #ifndef NULL 140 | #ifdef __cplusplus 141 | #define NULL 0 142 | #else 143 | #define NULL ((void *)0) 144 | #endif 145 | #endif /* NULL */ 146 | #endif /* ! Mac OS X - breaks precompiled headers */ 147 | -------------------------------------------------------------------------------- /contrib/SDL/include/close_code.h: -------------------------------------------------------------------------------- 1 | /* 2 | Simple DirectMedia Layer 3 | Copyright (C) 1997-2016 Sam Lantinga 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | /** 23 | * \file close_code.h 24 | * 25 | * This file reverses the effects of begin_code.h and should be included 26 | * after you finish any function and structure declarations in your headers 27 | */ 28 | 29 | #undef _begin_code_h 30 | 31 | /* Reset structure packing at previous byte alignment */ 32 | #if defined(_MSC_VER) || defined(__MWERKS__) || defined(__WATCOMC__) || defined(__BORLANDC__) 33 | #ifdef __BORLANDC__ 34 | #pragma nopackwarning 35 | #endif 36 | #pragma pack(pop) 37 | #endif /* Compiler needs structure packing set */ 38 | -------------------------------------------------------------------------------- /contrib/SDL/lib/x64/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x64/SDL2.dll -------------------------------------------------------------------------------- /contrib/SDL/lib/x64/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x64/SDL2.lib -------------------------------------------------------------------------------- /contrib/SDL/lib/x64/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x64/SDL2main.lib -------------------------------------------------------------------------------- /contrib/SDL/lib/x64/SDL2test.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x64/SDL2test.lib -------------------------------------------------------------------------------- /contrib/SDL/lib/x86/SDL2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x86/SDL2.dll -------------------------------------------------------------------------------- /contrib/SDL/lib/x86/SDL2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x86/SDL2.lib -------------------------------------------------------------------------------- /contrib/SDL/lib/x86/SDL2main.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x86/SDL2main.lib -------------------------------------------------------------------------------- /contrib/SDL/lib/x86/SDL2test.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/SDL/lib/x86/SDL2test.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2007, Milan Ikits 3 | Copyright (C) 2002-2007, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | Mesa 3-D graphics library 32 | Version: 7.0 33 | 34 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a 37 | copy of this software and associated documentation files (the "Software"), 38 | to deal in the Software without restriction, including without limitation 39 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 40 | and/or sell copies of the Software, and to permit persons to whom the 41 | Software is furnished to do so, subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included 44 | in all copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 47 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 50 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 51 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 52 | 53 | 54 | Copyright (c) 2007 The Khronos Group Inc. 55 | 56 | Permission is hereby granted, free of charge, to any person obtaining a 57 | copy of this software and/or associated documentation files (the 58 | "Materials"), to deal in the Materials without restriction, including 59 | without limitation the rights to use, copy, modify, merge, publish, 60 | distribute, sublicense, and/or sell copies of the Materials, and to 61 | permit persons to whom the Materials are furnished to do so, subject to 62 | the following conditions: 63 | 64 | The above copyright notice and this permission notice shall be included 65 | in all copies or substantial portions of the Materials. 66 | 67 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 68 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 69 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 70 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 71 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 72 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 73 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 74 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/README.txt: -------------------------------------------------------------------------------- 1 | See doc/index.html for more information. 2 | 3 | If you downloaded the tarball from the GLEW website, you just need to: 4 | 5 | Unix: 6 | 7 | make 8 | 9 | sudo -s 10 | 11 | make install 12 | 13 | make clean 14 | 15 | Windows: 16 | 17 | use the project file in build/vc6/ 18 | 19 | If you wish to build GLEW from scratch (update the extension data from 20 | the net or add your own extension information), you need a Unix 21 | environment (including wget, perl, and GNU make). The extension data 22 | is regenerated from the top level source directory with: 23 | 24 | make extensions 25 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/TODO.txt: -------------------------------------------------------------------------------- 1 | Major: 2 | - add support for windows mini-client drivers 3 | - add windows installer (msi) 4 | - separate build of static and shared object files (for mingw and 5 | cygwin) 6 | - start designing GLEW 2.0 7 | 8 | Minor: 9 | - make auto scripts work with text mode cygwin mounts 10 | - add support for all SUN, MTX, and OML extensions 11 | - make auto/Makefile more robust against auto/core/*~ mistakes 12 | - web poll on separating glew, glxew and wglew 13 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release MX/Win32/glew32mx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release MX/Win32/glew32mx.dll -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release MX/x64/glew32mx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release MX/x64/glew32mx.dll -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/Win32/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/Win32/glew32.dll -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/Win32/glewinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/Win32/glewinfo.exe -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/Win32/visualinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/Win32/visualinfo.exe -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/x64/glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/x64/glew32.dll -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/x64/glewinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/x64/glewinfo.exe -------------------------------------------------------------------------------- /contrib/glew-1.11.0/bin/Release/x64/visualinfo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/bin/Release/x64/visualinfo.exe -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/glew.css: -------------------------------------------------------------------------------- 1 | h1 2 | { 3 | color: black; 4 | font: 23px "Verdana", "Arial", "Helvetica", sans-serif; 5 | font-weight: bold; 6 | text-align: center; 7 | margin-top: 12px; 8 | margin-bottom: 18px; 9 | } 10 | 11 | h2 12 | { 13 | color: black; 14 | font: 18px "Verdana", "Arial", "Helvetica", sans-serif; 15 | font-weight: bold; 16 | text-align: left; 17 | padding-top: 0px; 18 | padding-bottom: 0px; 19 | margin-top: 18px; 20 | margin-bottom: 12px; 21 | } 22 | 23 | h3 24 | { 25 | color: black; 26 | font: 17px "Verdana", "Arial", "Helvetica", sans-serif; 27 | text-align: left; 28 | padding-top: 0px; 29 | padding-bottom: 0px; 30 | margin-top: 12px; 31 | margin-bottom: 12px; 32 | } 33 | 34 | small 35 | { 36 | font: 8pt "Verdana", "Arial", "Helvetica", sans-serif; 37 | } 38 | 39 | body 40 | { 41 | color: black; 42 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 43 | text-align: left; 44 | } 45 | 46 | td 47 | { 48 | color: black; 49 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 50 | } 51 | 52 | tt 53 | { 54 | color: rgb(0,120,0); 55 | } 56 | /* color: maroon; */ 57 | 58 | td.num 59 | { 60 | color: lightgrey; 61 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 62 | text-align: right; 63 | } 64 | 65 | blockquote 66 | { 67 | color: rgb(0,120,0); 68 | background: #f0f0f0; 69 | text-align: left; 70 | margin-left: 40px; 71 | margin-right: 40px; 72 | margin-bottom: 6px; 73 | padding-bottom: 0px; 74 | margin-top: 0px; 75 | padding-top: 0px; 76 | border-top: 0px; 77 | border-width: 0px; 78 | } 79 | 80 | pre 81 | { 82 | color: rgb(0,120,0); 83 | background: #f0f0f0; 84 | text-align: left; 85 | margin-left: 40px; 86 | margin-right: 40px; 87 | margin-bottom: 6px; 88 | padding-bottom: 0px; 89 | margin-top: 0px; 90 | padding-top: 0px; 91 | border-top: 0px; 92 | border-width: 0px; 93 | } 94 | 95 | p 96 | { 97 | color: black; 98 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 99 | text-align: left; 100 | margin-bottom: 0px; 101 | padding-bottom: 6px; 102 | margin-top: 0px; 103 | padding-top: 0px; 104 | } 105 | 106 | p.right 107 | { 108 | color: black; 109 | font: 10pt "Verdana", "Arial", "Helvetica", sans-serif; 110 | text-align: right; 111 | margin-bottom: 0px; 112 | padding-bottom: 6px; 113 | margin-top: 0px; 114 | padding-top: 0px; 115 | } 116 | 117 | p.pre 118 | { 119 | color: rgb(0,120,0); 120 | font: 10pt "Courier New", "Courier", monospace; 121 | background: #f0f0f0; 122 | text-align: left; 123 | margin-top: 0px; 124 | margin-bottom: 6px; 125 | margin-left: 40px; 126 | margin-right: 40px; 127 | padding-top: 0px; 128 | padding-bottom: 6px; 129 | padding-left: 6px; 130 | padding-right: 6px; 131 | border-top: 0px; 132 | border-width: 0px; 133 | } 134 | 135 | a:link 136 | { 137 | color: rgb(0,0,139); 138 | text-decoration: none; 139 | } 140 | 141 | a:visited 142 | { 143 | color: rgb(220,20,60); 144 | text-decoration: none; 145 | } 146 | 147 | a:hover 148 | { 149 | color: rgb(220,20,60); 150 | text-decoration: underline; 151 | background: "#e8e8e8"; 152 | } 153 | 154 | ul 155 | { 156 | list-style-type: disc; 157 | text-align: left; 158 | margin-left: 40px; 159 | margin-top: 0px; 160 | padding-top: 0px; 161 | margin-bottom: 0px; 162 | padding-bottom: 3px; 163 | } 164 | 165 | ul.none 166 | { 167 | list-style-type: none; 168 | } 169 | 170 | ol 171 | { 172 | text-align: left; 173 | margin-left: 40px; 174 | margin-top: 0px; 175 | padding-top: 0px; 176 | margin-bottom: 0px; 177 | padding-bottom: 12px; 178 | } 179 | 180 | hr 181 | { 182 | color: maroon; 183 | background-color: maroon; 184 | height: 1px; 185 | border: 0px; 186 | width: 80%; 187 | } 188 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/glew.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/doc/glew.png -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/glew.txt: -------------------------------------------------------------------------------- 1 | The OpenGL Extension Wrangler Library 2 | Copyright (C) 2002-2008, Milan Ikits 3 | Copyright (C) 2002-2008, Marcelo E. Magallon 4 | Copyright (C) 2002, Lev Povalahev 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * The name of the author may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28 | THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/khronos.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 The Khronos Group Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and/or associated documentation files (the 5 | "Materials"), to deal in the Materials without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Materials, and to 8 | permit persons to whom the Materials are furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Materials. 13 | 14 | THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 21 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/mesa.txt: -------------------------------------------------------------------------------- 1 | Mesa 3-D graphics library 2 | Version: 7.0 3 | 4 | Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a 7 | copy of this software and associated documentation files (the "Software"), 8 | to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | and/or sell copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/doc/new.png -------------------------------------------------------------------------------- /contrib/glew-1.11.0/doc/ogl_sm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/doc/ogl_sm.jpg -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release MX/Win32/glew32mx.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release MX/Win32/glew32mx.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release MX/Win32/glew32mxs.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release MX/Win32/glew32mxs.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release MX/x64/glew32mx.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release MX/x64/glew32mx.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release MX/x64/glew32mxs.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release MX/x64/glew32mxs.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release/Win32/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release/Win32/glew32.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release/Win32/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release/Win32/glew32s.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release/x64/glew32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release/x64/glew32.lib -------------------------------------------------------------------------------- /contrib/glew-1.11.0/lib/Release/x64/glew32s.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/contrib/glew-1.11.0/lib/Release/x64/glew32s.lib -------------------------------------------------------------------------------- /glew32.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/glew32.dll -------------------------------------------------------------------------------- /images/q3vr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/images/q3vr1.png -------------------------------------------------------------------------------- /images/q3vr2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/images/q3vr2.png -------------------------------------------------------------------------------- /images/q3vr_youtube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/images/q3vr_youtube.png -------------------------------------------------------------------------------- /images/qbsp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/images/qbsp1.png -------------------------------------------------------------------------------- /images/qbsp3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/images/qbsp3.png -------------------------------------------------------------------------------- /maps/ntkjidm2.bsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/maps/ntkjidm2.bsp -------------------------------------------------------------------------------- /res/Basic.fsh: -------------------------------------------------------------------------------- 1 | #version 410 2 | 3 | uniform sampler2D sTexture; 4 | uniform sampler2D sLightmap; 5 | 6 | uniform int renderLightmaps = 0; 7 | uniform int useLightmaps = 1; 8 | uniform int useAlphaTest = 0; 9 | 10 | layout(location = 3) in vec2 TexCoord; 11 | layout(location = 4) in vec2 TexCoordLightmap; 12 | 13 | out vec4 fragmentColor; 14 | 15 | void main() 16 | { 17 | vec4 baseTex = texture(sTexture, TexCoord); 18 | vec4 lightMap = texture(sLightmap, TexCoordLightmap); 19 | 20 | if(renderLightmaps == 1) 21 | { 22 | fragmentColor = lightMap * 1.2; 23 | } 24 | else 25 | { 26 | if(useLightmaps == 0) 27 | { 28 | lightMap = vec4(1.0, 1.0, 1.0, 1.0); 29 | } 30 | 31 | if(useAlphaTest == 1) 32 | { 33 | if(baseTex.a >= 0.05) 34 | fragmentColor = baseTex * lightMap * 2.0; // make the output more vivid 35 | else 36 | discard; 37 | } 38 | else 39 | { 40 | fragmentColor = baseTex * lightMap * 2.0; // make the output more vivid 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /res/Basic.vsh: -------------------------------------------------------------------------------- 1 | #version 410 2 | 3 | uniform mat4 ModelViewProjectionMatrix; 4 | uniform float worldScaleFactor; 5 | 6 | layout(location = 0) in vec3 inVertex; 7 | layout(location = 1) in vec2 inTexCoord; 8 | layout(location = 2) in vec2 inTexCoordLightmap; 9 | 10 | layout(location = 3) out vec2 TexCoord; 11 | layout(location = 4) out vec2 TexCoordLightmap; 12 | 13 | void main() 14 | { 15 | gl_Position = ModelViewProjectionMatrix * vec4(inVertex * worldScaleFactor, 1.0); 16 | TexCoord = inTexCoord; 17 | TexCoordLightmap = inTexCoordLightmap; 18 | } 19 | -------------------------------------------------------------------------------- /res/Font.fsh: -------------------------------------------------------------------------------- 1 | #version 410 2 | uniform sampler2D sTexture; 3 | uniform vec4 vertexColor; 4 | 5 | layout(location = 6) in vec2 TexCoord; 6 | 7 | out vec4 fragmentColor; 8 | 9 | void main() 10 | { 11 | fragmentColor = texture2D(sTexture, TexCoord) * vertexColor; 12 | } 13 | -------------------------------------------------------------------------------- /res/Font.vsh: -------------------------------------------------------------------------------- 1 | #version 410 2 | 3 | layout(location = 5) in vec3 inVertex; 4 | 5 | uniform mat4 ModelViewProjectionMatrix; 6 | uniform mat4 TextureMatrix; 7 | 8 | layout(location = 6) out vec2 TexCoord; 9 | 10 | void main() 11 | { 12 | gl_Position = ModelViewProjectionMatrix * vec4(inVertex, 1.0); 13 | TexCoord = (TextureMatrix * vec4(inVertex, 1.0)).xy; 14 | } 15 | -------------------------------------------------------------------------------- /res/OVRFrustum.fsh: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform vec4 vertexColor; 4 | 5 | out vec4 fragmentColor; 6 | 7 | void main() 8 | { 9 | fragmentColor = vec4(vertexColor); 10 | } 11 | -------------------------------------------------------------------------------- /res/OVRFrustum.vsh: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform mat4 ModelViewProjectionMatrix; 4 | 5 | in vec3 inVertex; 6 | 7 | void main() 8 | { 9 | gl_Position = ModelViewProjectionMatrix * vec4(inVertex, 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /res/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/res/font.png -------------------------------------------------------------------------------- /res/missing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kondrak/quake_bsp_viewer_vr/d04590571f3959f40706a58a6ef21b34f82119a0/res/missing.png -------------------------------------------------------------------------------- /run.bat: -------------------------------------------------------------------------------- 1 | QuakeBspViewerVR maps/ntkjidm2.bsp -vr -------------------------------------------------------------------------------- /src/Application.hpp: -------------------------------------------------------------------------------- 1 | #ifndef APPLICATION_INCLUDED 2 | #define APPLICATION_INCLUDED 3 | 4 | #include 5 | #include "InputHandlers.hpp" 6 | #include "Math.hpp" 7 | 8 | class BspMap; 9 | class StatsUI; 10 | 11 | /* 12 | * main application 13 | */ 14 | 15 | class Application 16 | { 17 | public: 18 | // Oculus VR mirror modes 19 | enum VRMirrorMode 20 | { 21 | Mirror_Regular, 22 | Mirror_RegularLeftEye, 23 | Mirror_RegularRightEye, 24 | Mirror_NonDistort, 25 | Mirror_NonDistortLeftEye, 26 | Mirror_NonDistortRightEye, 27 | MM_Count 28 | }; 29 | 30 | Application() : m_running(true), m_mirrorMode(Mirror_Regular), m_VREnabled(false), m_q3map(NULL), m_q3stats(NULL), m_debugRenderState(RenderMapStats) 31 | { 32 | } 33 | 34 | void OnWindowResize(int newWidth, int newHeight); 35 | 36 | void OnStart(int argc, char **argv, bool vrMode); 37 | void OnRender(); 38 | void OnUpdate(float dt); 39 | 40 | inline bool Running() const { return m_running; } 41 | inline void Terminate() { m_running = false; } 42 | 43 | void OnTerminate(); 44 | bool KeyPressed(KeyCode key); 45 | void OnKeyPress(KeyCode key); 46 | void OnKeyRelease(KeyCode key); 47 | void OnMouseMove(int x, int y); 48 | bool VREnabled() const { return m_VREnabled; } 49 | const VRMirrorMode CurrMirrorMode() const { return (VRMirrorMode)m_mirrorMode; } 50 | private: 51 | void UpdateCamera( float dt ); 52 | inline void SetKeyPressed(KeyCode key, bool pressed) { m_keyStates[key] = pressed; } 53 | 54 | // helper functions for parsing Quake entities 55 | Math::Vector3f FindPlayerStart(const char *entities); 56 | bool FindEntityAttribute(const std::string &entity, const char *entityName, const char *attribName, std::string &output); 57 | 58 | 59 | bool m_running; 60 | bool m_VREnabled; 61 | int m_mirrorMode; 62 | 63 | std::map< KeyCode, bool > m_keyStates; 64 | 65 | BspMap *m_q3map; // loaded map 66 | StatsUI *m_q3stats; // map stats UI 67 | 68 | enum DebugRender 69 | { 70 | None = 0, 71 | RenderMapStats, 72 | RenderVRData, 73 | RenderVRTrackingCamera, 74 | RenderOVRLatencyTiming, // added in SDK 0.6.0.1 75 | RenderOVRAppRenderTiming, // added in SDK 0.6.0.1 76 | RenderOVRCompRenderTiming, // added in SDK 1.3.0 77 | RenderOVRPerf, 78 | RenderOVRVersion, 79 | DebugRenderMax 80 | }; 81 | 82 | unsigned int m_debugRenderState; 83 | }; 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/Frustum.cpp: -------------------------------------------------------------------------------- 1 | #include "Frustum.hpp" 2 | #include "renderer/RenderContext.hpp" 3 | 4 | extern RenderContext g_renderContext; 5 | 6 | void Frustum::OnRender() 7 | { 8 | // extract each plane from MVP matrix 9 | ExtractPlane(m_planes[0], g_renderContext.ModelViewProjectionMatrix, 1); 10 | ExtractPlane(m_planes[1], g_renderContext.ModelViewProjectionMatrix, -1); 11 | ExtractPlane(m_planes[2], g_renderContext.ModelViewProjectionMatrix, 2); 12 | ExtractPlane(m_planes[3], g_renderContext.ModelViewProjectionMatrix, -2); 13 | ExtractPlane(m_planes[4], g_renderContext.ModelViewProjectionMatrix, 3); 14 | ExtractPlane(m_planes[5], g_renderContext.ModelViewProjectionMatrix, -3); 15 | } 16 | 17 | bool Frustum::BoxInFrustum(const Math::Vector3f *vertices) 18 | { 19 | for (int i = 0; i < 6; ++i) 20 | { 21 | if((m_planes[i].A * vertices[0].m_x + m_planes[i].B * vertices[0].m_y + m_planes[i].C * vertices[0].m_z + m_planes[i].D) > 0) 22 | continue; 23 | if((m_planes[i].A * vertices[1].m_x + m_planes[i].B * vertices[1].m_y + m_planes[i].C * vertices[1].m_z + m_planes[i].D) > 0) 24 | continue; 25 | if((m_planes[i].A * vertices[2].m_x + m_planes[i].B * vertices[2].m_y + m_planes[i].C * vertices[2].m_z + m_planes[i].D) > 0) 26 | continue; 27 | if((m_planes[i].A * vertices[3].m_x + m_planes[i].B * vertices[3].m_y + m_planes[i].C * vertices[3].m_z + m_planes[i].D) > 0) 28 | continue; 29 | if((m_planes[i].A * vertices[4].m_x + m_planes[i].B * vertices[4].m_y + m_planes[i].C * vertices[4].m_z + m_planes[i].D) > 0) 30 | continue; 31 | if((m_planes[i].A * vertices[5].m_x + m_planes[i].B * vertices[5].m_y + m_planes[i].C * vertices[5].m_z + m_planes[i].D) > 0) 32 | continue; 33 | if((m_planes[i].A * vertices[6].m_x + m_planes[i].B * vertices[6].m_y + m_planes[i].C * vertices[6].m_z + m_planes[i].D) > 0) 34 | continue; 35 | if((m_planes[i].A * vertices[7].m_x + m_planes[i].B * vertices[7].m_y + m_planes[i].C * vertices[7].m_z + m_planes[i].D) > 0) 36 | continue; 37 | 38 | return false; 39 | } 40 | 41 | return true; 42 | } 43 | 44 | // extract a plane from a given matrix and row id 45 | void Frustum::ExtractPlane(Plane &plane, const Math::Matrix4f &mvpMatrix, int row) 46 | { 47 | int scale = (row < 0) ? -1 : 1; 48 | row = abs(row) - 1; 49 | 50 | // calculate plane coefficients from the matrix 51 | plane.A = mvpMatrix.m_m[3] + scale * mvpMatrix.m_m[row + 0]; 52 | plane.B = mvpMatrix.m_m[7] + scale * mvpMatrix.m_m[row + 4]; 53 | plane.C = mvpMatrix.m_m[11] + scale * mvpMatrix.m_m[row + 8]; 54 | plane.D = mvpMatrix.m_m[15] + scale * mvpMatrix.m_m[row + 12]; 55 | 56 | // normalize the plane 57 | float length = Math::QuickInverseSqrt( plane.A * plane.A + plane.B * plane.B + plane.C * plane.C ); 58 | 59 | plane.A *= length; 60 | plane.B *= length; 61 | plane.C *= length; 62 | plane.D *= length; 63 | } -------------------------------------------------------------------------------- /src/Frustum.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FRUSTUM_INCLUDED 2 | #define FRUSTUM_INCLUDED 3 | 4 | #include "renderer/OpenGL.hpp" 5 | #include "Math.hpp" 6 | 7 | /* 8 | * View frustum 9 | */ 10 | 11 | struct Plane 12 | { 13 | float A, B, C, D; 14 | }; 15 | 16 | class Frustum 17 | { 18 | public: 19 | void OnRender(); 20 | bool BoxInFrustum(const Math::Vector3f *vertices); 21 | 22 | private: 23 | void ExtractPlane(Plane &plane, const Math::Matrix4f &mvpMatrix, int row); 24 | Plane m_planes[6]; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/InputHandlers.cpp: -------------------------------------------------------------------------------- 1 | #include "InputHandlers.hpp" 2 | #include "Application.hpp" 3 | 4 | extern Application g_application; 5 | 6 | KeyCode SDLKeyToKeyCode(SDL_Keycode key) 7 | { 8 | switch (key) 9 | { 10 | case SDLK_1: 11 | return KEY_1; 12 | case SDLK_2: 13 | return KEY_2; 14 | case SDLK_3: 15 | return KEY_3; 16 | case SDLK_4: 17 | return KEY_4; 18 | case SDLK_5: 19 | return KEY_5; 20 | case SDLK_6: 21 | return KEY_6; 22 | case SDLK_7: 23 | return KEY_7; 24 | case SDLK_8: 25 | return KEY_8; 26 | case SDLK_9: 27 | return KEY_9; 28 | case SDLK_0: 29 | return KEY_0; 30 | case SDLK_a: 31 | return KEY_A; 32 | case SDLK_b: 33 | return KEY_B; 34 | case SDLK_c: 35 | return KEY_C; 36 | case SDLK_d: 37 | return KEY_D; 38 | case SDLK_e: 39 | return KEY_E; 40 | case SDLK_f: 41 | return KEY_F; 42 | case SDLK_g: 43 | return KEY_G; 44 | case SDLK_h: 45 | return KEY_H; 46 | case SDLK_i: 47 | return KEY_I; 48 | case SDLK_j: 49 | return KEY_J; 50 | case SDLK_k: 51 | return KEY_K; 52 | case SDLK_l: 53 | return KEY_L; 54 | case SDLK_m: 55 | return KEY_M; 56 | case SDLK_n: 57 | return KEY_N; 58 | case SDLK_o: 59 | return KEY_O; 60 | case SDLK_p: 61 | return KEY_P; 62 | case SDLK_q: 63 | return KEY_Q; 64 | case SDLK_r: 65 | return KEY_R; 66 | case SDLK_s: 67 | return KEY_S; 68 | case SDLK_t: 69 | return KEY_T; 70 | case SDLK_u: 71 | return KEY_U; 72 | case SDLK_v: 73 | return KEY_V; 74 | case SDLK_w: 75 | return KEY_W; 76 | case SDLK_x: 77 | return KEY_X; 78 | case SDLK_y: 79 | return KEY_Y; 80 | case SDLK_z: 81 | return KEY_Z; 82 | case SDLK_ESCAPE: 83 | return KEY_ESC; 84 | case SDLK_F1: 85 | return KEY_F1; 86 | case SDLK_F2: 87 | return KEY_F2; 88 | case SDLK_F3: 89 | return KEY_F3; 90 | case SDLK_F4: 91 | return KEY_F4; 92 | case SDLK_F5: 93 | return KEY_F5; 94 | case SDLK_F6: 95 | return KEY_F6; 96 | case SDLK_F7: 97 | return KEY_F7; 98 | case SDLK_F8: 99 | return KEY_F8; 100 | case SDLK_F9: 101 | return KEY_F9; 102 | case SDLK_F10: 103 | return KEY_F10; 104 | case SDLK_F11: 105 | return KEY_F11; 106 | case SDLK_F12: 107 | return KEY_F12; 108 | case SDLK_SPACE: 109 | return KEY_SPACE; 110 | case SDLK_BACKQUOTE: 111 | return KEY_TILDE; 112 | } 113 | 114 | return KEY_NULL; 115 | } 116 | 117 | 118 | void processEvents() 119 | { 120 | SDL_Event event; 121 | 122 | while (SDL_PollEvent(&event)) 123 | { 124 | switch (event.type) 125 | { 126 | case SDL_KEYDOWN: 127 | // alt + f4 handling 128 | if (event.key.keysym.sym == SDLK_F4 && (event.key.keysym.mod == KMOD_LALT || event.key.keysym.mod == KMOD_RALT)) 129 | { 130 | g_application.Terminate(); 131 | break; 132 | } 133 | g_application.OnKeyPress( SDLKeyToKeyCode( event.key.keysym.sym ) ); 134 | break; 135 | case SDL_KEYUP: 136 | g_application.OnKeyRelease(SDLKeyToKeyCode(event.key.keysym.sym)); 137 | break; 138 | case SDL_MOUSEMOTION: 139 | g_application.OnMouseMove(event.motion.x, event.motion.y); 140 | break; 141 | case SDL_QUIT: 142 | g_application.Terminate(); 143 | break; 144 | // window events 145 | case SDL_WINDOWEVENT: 146 | switch (event.window.event) 147 | { 148 | case SDL_WINDOWEVENT_RESIZED: 149 | g_application.OnWindowResize(event.window.data1, event.window.data2); 150 | break; 151 | } 152 | break; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/InputHandlers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INPUTHANDLERS_INCLUDED 2 | #define INPUTHANDLERS_INCLUDED 3 | 4 | #include 5 | 6 | /* 7 | * application input/event handlers 8 | */ 9 | 10 | enum KeyCode 11 | { 12 | KEY_NULL, 13 | KEY_1, 14 | KEY_2, 15 | KEY_3, 16 | KEY_4, 17 | KEY_5, 18 | KEY_6, 19 | KEY_7, 20 | KEY_8, 21 | KEY_9, 22 | KEY_0, 23 | KEY_A, 24 | KEY_B, 25 | KEY_C, 26 | KEY_D, 27 | KEY_E, 28 | KEY_F, 29 | KEY_G, 30 | KEY_H, 31 | KEY_I, 32 | KEY_J, 33 | KEY_K, 34 | KEY_L, 35 | KEY_M, 36 | KEY_N, 37 | KEY_O, 38 | KEY_P, 39 | KEY_Q, 40 | KEY_R, 41 | KEY_S, 42 | KEY_T, 43 | KEY_U, 44 | KEY_V, 45 | KEY_W, 46 | KEY_X, 47 | KEY_Y, 48 | KEY_Z, 49 | KEY_ESC, 50 | KEY_F1, 51 | KEY_F2, 52 | KEY_F3, 53 | KEY_F4, 54 | KEY_F5, 55 | KEY_F6, 56 | KEY_F7, 57 | KEY_F8, 58 | KEY_F9, 59 | KEY_F10, 60 | KEY_F11, 61 | KEY_F12, 62 | KEY_SPACE, 63 | KEY_TILDE 64 | }; 65 | 66 | // handler functions 67 | KeyCode SDLKeyToKeyCode( SDL_Keycode key ); 68 | void processEvents(); 69 | 70 | #endif -------------------------------------------------------------------------------- /src/StringHelpers.cpp: -------------------------------------------------------------------------------- 1 | #include "StringHelpers.hpp" 2 | 3 | namespace StringHelpers 4 | { 5 | std::vector tokenizeString(const char *str, char c, int tokenLimit) 6 | { 7 | std::vector result; 8 | int currCount = 0; 9 | 10 | do 11 | { 12 | // stop further tokenization if we reached token number limit 13 | if (++currCount == tokenLimit) 14 | { 15 | result.push_back(std::string(str)); 16 | break; 17 | } 18 | 19 | const char *begin = str; 20 | 21 | while (*str != c && *str) 22 | str++; 23 | 24 | result.push_back(std::string(begin, str)); 25 | 26 | } while (*str++); 27 | 28 | return result; 29 | } 30 | 31 | 32 | std::string trim(const std::string &str, char c) 33 | { 34 | size_t firstPos = str.find_first_not_of(c); 35 | size_t lastPos = str.find_last_not_of(c); 36 | 37 | if (firstPos == std::string::npos) 38 | return str; 39 | 40 | return str.substr(firstPos, lastPos - firstPos + 1); 41 | } 42 | } -------------------------------------------------------------------------------- /src/StringHelpers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STRINGHELPERS_HPP 2 | #define STRINGHELPERS_HPP 3 | 4 | #include 5 | #include 6 | 7 | namespace StringHelpers 8 | { 9 | // tokenize tokenLimit elements using c as delimeter 10 | std::vector tokenizeString(const char *str, char c, int tokenLimit = 0); 11 | 12 | // trim 'c' character from start and end of a string 13 | std::string trim(const std::string &str, char c); 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /src/Utils.cpp: -------------------------------------------------------------------------------- 1 | #include "Utils.hpp" 2 | #ifdef _WIN32 3 | #include 4 | #endif 5 | 6 | #include "renderer/OpenGL.hpp" 7 | 8 | void LogError(const char *msg) 9 | { 10 | // basic error logging for VS debugger 11 | #ifdef _WIN32 12 | OutputDebugStringA(msg); 13 | #else 14 | printf("%s\n", msg); 15 | #endif 16 | } 17 | 18 | void ClearWindow(float r, float g, float b) 19 | { 20 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); 21 | glClearColor(r, g, b, 1.0f); 22 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 23 | } 24 | 25 | void DrawRectangle(float x, float y, float w, float h, float r, float g, float b) 26 | { 27 | GLboolean texOn = glIsEnabled(GL_TEXTURE_2D); 28 | GLboolean depthOn = glIsEnabled(GL_DEPTH_TEST); 29 | GLboolean blendOn = glIsEnabled(GL_BLEND); 30 | 31 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 32 | glActiveTexture(GL_TEXTURE0); 33 | glDisable(GL_TEXTURE_2D); 34 | glDisable(GL_DEPTH_TEST); 35 | glDisable(GL_BLEND); 36 | glMatrixMode(GL_PROJECTION); 37 | glLoadIdentity(); 38 | glOrtho(-1.f, 1.f, 1.f, -1.0f, 0.1f, 10.0f); 39 | 40 | glMatrixMode(GL_MODELVIEW); 41 | glLoadIdentity(); 42 | 43 | glBegin(GL_QUADS); 44 | glColor3f(r, g, b); 45 | glVertex3f(x - w / 2.f, y - w / 2.f, -1.f); 46 | glVertex3f(x + w / 2.f, y - w / 2.f, -1.f); 47 | glVertex3f(x + w / 2.f, y + w / 2.f, -1.f); 48 | glVertex3f(x - w / 2.f, y + w / 2.f, -1.f); 49 | glEnd(); 50 | 51 | if (texOn) 52 | glEnable(GL_TEXTURE_2D); 53 | 54 | if (depthOn) 55 | glEnable(GL_DEPTH_TEST); 56 | 57 | if (blendOn) 58 | glEnable(GL_BLEND); 59 | } -------------------------------------------------------------------------------- /src/Utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_HPP 2 | #define UTILS_HPP 3 | 4 | #ifdef _DEBUG 5 | #include 6 | #define LOG_MESSAGE(msg) { \ 7 | std::stringstream msgStr; \ 8 | msgStr << "[LOG]: " << msg << "\n"; \ 9 | LogError(msgStr.str().c_str()); \ 10 | } 11 | 12 | #define LOG_MESSAGE_ASSERT(x, msg) \ 13 | if(!x) { \ 14 | std::stringstream msgStr; \ 15 | msgStr << "[!ASSERT!]: " << msg << "\n"; \ 16 | LogError(msgStr.str().c_str()); \ 17 | __debugbreak(); \ 18 | } 19 | #else 20 | #define LOG_MESSAGE(msg) 21 | #define LOG_MESSAGE_ASSERT(x, msg) 22 | #endif 23 | 24 | 25 | void LogError(const char *msg); 26 | void ClearWindow(float r, float g, float b); 27 | void DrawRectangle(float x, float y, float w, float h, float r, float g, float b); 28 | #endif 29 | -------------------------------------------------------------------------------- /src/common/BspMap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BSPMAP_INCLUDED 2 | #define BSPMAP_INCLUDED 3 | 4 | #include "q3bsp/Q3BspRenderHelpers.hpp" 5 | 6 | /* 7 | * Base class for renderable bsp map. Future reference for other BSP format support. 8 | */ 9 | 10 | class BspMap 11 | { 12 | public: 13 | BspMap() : m_renderFlags(0) 14 | { 15 | } 16 | 17 | virtual ~BspMap() 18 | { 19 | } 20 | 21 | virtual void Init() = 0; 22 | virtual void OnRenderStart() = 0; // prepare for render 23 | virtual void Render() = 0; // perform rendering 24 | virtual void OnRenderFinish() = 0; // finish render 25 | 26 | virtual bool ClusterVisible(int cameraCluster, int testCluster) const = 0; // determine bsp cluster visibility 27 | virtual int FindCameraLeaf(const Math::Vector3f &cameraPosition) const = 0; // return bsp leaf index containing the camera 28 | virtual void CalculateVisibleFaces(const Math::Vector3f &cameraPosition) = 0; // determine which bsp faces are visible 29 | 30 | // render helpers - extra flags + map statistics 31 | inline void ToggleRenderFlag(int flag) { m_renderFlags ^= flag; } 32 | inline bool HasRenderFlag(int flag) const { return (m_renderFlags & flag) == flag; } 33 | inline const BspStats &GetMapStats() const { return m_mapStats; } 34 | 35 | protected: 36 | int m_renderFlags; 37 | BspStats m_mapStats; 38 | }; 39 | 40 | 41 | #endif -------------------------------------------------------------------------------- /src/common/StatsUI.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STATSUI_INCLUDED 2 | #define STATSUI_INCLUDED 3 | 4 | /* 5 | * Map stats display UI base class. Future reference for other BSP format support. 6 | */ 7 | 8 | class BspMap; 9 | 10 | class StatsUI 11 | { 12 | public: 13 | StatsUI(BspMap *map) : m_map(map) 14 | { 15 | } 16 | 17 | virtual ~StatsUI() 18 | { 19 | } 20 | 21 | virtual void Render() = 0; // perform rendering 22 | 23 | protected: 24 | BspMap *m_map; 25 | }; 26 | 27 | 28 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3Bsp.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSP_INCLUDED 2 | #define Q3BSP_INCLUDED 3 | 4 | /* 5 | * Data structures for Quake III BSP (according to http://www.mralligator.com/q3/) 6 | */ 7 | 8 | 9 | // math types 10 | struct vec2i 11 | { 12 | int x, y; 13 | }; 14 | 15 | struct vec3i 16 | { 17 | int x, y, z; 18 | }; 19 | 20 | struct vec2f 21 | { 22 | float x, y; 23 | }; 24 | 25 | struct vec3f 26 | { 27 | float x, y, z; 28 | }; 29 | 30 | 31 | //data types (lumps) 32 | enum LumpTypes 33 | { 34 | Entities = 0, 35 | Textures, 36 | Planes, 37 | Nodes, 38 | Leafs, 39 | LeafFaces, 40 | LeafBrushes, 41 | Models, 42 | Brushes, 43 | BrushSides, 44 | Vertices, 45 | MeshVerts, 46 | Effects, 47 | Faces, 48 | Lightmaps, 49 | LightVols, 50 | VisData 51 | }; 52 | 53 | 54 | enum FaceTypes 55 | { 56 | FaceTypePolygon = 1, 57 | FaceTypePatch = 2, 58 | FaceTypeMesh = 3, 59 | FaceTypeBillboard = 4 60 | }; 61 | 62 | 63 | struct Q3BspDirEntry 64 | { 65 | int offset; 66 | int length; 67 | }; 68 | 69 | 70 | struct Q3BspHeader 71 | { 72 | char magic[4]; 73 | int version; 74 | Q3BspDirEntry direntries[17]; 75 | }; 76 | 77 | 78 | struct Q3BspEntityLump 79 | { 80 | int size; 81 | char *ents; 82 | }; 83 | 84 | 85 | struct Q3BspTextureLump 86 | { 87 | char name[64]; 88 | int flags; 89 | int contents; 90 | }; 91 | 92 | 93 | struct Q3BspPlaneLump 94 | { 95 | vec3f normal; 96 | float dist; 97 | }; 98 | 99 | 100 | struct Q3BspNodeLump 101 | { 102 | int plane; 103 | vec2i children; 104 | vec3i mins; 105 | vec3i maxs; 106 | }; 107 | 108 | 109 | struct Q3BspLeafLump 110 | { 111 | int cluster; 112 | int area; 113 | vec3i mins; 114 | vec3i maxs; 115 | int leafFace; 116 | int n_leafFaces; 117 | int leafBrush; 118 | int n_leafBrushes; 119 | }; 120 | 121 | 122 | struct Q3BspLeafFaceLump 123 | { 124 | int face; 125 | }; 126 | 127 | 128 | struct Q3BspLeafBrushLump 129 | { 130 | int brush; 131 | }; 132 | 133 | 134 | struct Q3BspModelLump 135 | { 136 | vec3f mins; 137 | vec3f maxs; 138 | int face; 139 | int n_faces; 140 | int brush; 141 | int n_brushes; 142 | }; 143 | 144 | 145 | struct Q3BspBrushLump 146 | { 147 | int brushSide; 148 | int n_brushSides; 149 | int texture; 150 | }; 151 | 152 | 153 | struct Q3BspBrushSideLump 154 | { 155 | int plane; 156 | int texture; 157 | }; 158 | 159 | 160 | struct Q3BspVertexLump 161 | { 162 | vec3f position; 163 | vec2f texcoord[2]; 164 | vec3f normal; 165 | unsigned char color[4]; 166 | 167 | Q3BspVertexLump operator+(const Q3BspVertexLump & rhs) const 168 | { 169 | Q3BspVertexLump result; 170 | result.position.x = position.x + rhs.position.x; 171 | result.position.y = position.y + rhs.position.y; 172 | result.position.z = position.z + rhs.position.z; 173 | 174 | result.texcoord[0].x = texcoord[0].x + rhs.texcoord[0].x; 175 | result.texcoord[0].y = texcoord[0].y + rhs.texcoord[0].y; 176 | result.texcoord[1].x = texcoord[1].x + rhs.texcoord[1].x; 177 | result.texcoord[1].y = texcoord[1].y + rhs.texcoord[1].y; 178 | 179 | return result; 180 | } 181 | 182 | Q3BspVertexLump operator*(const float rhs) const 183 | { 184 | Q3BspVertexLump result; 185 | result.position.x = position.x * rhs; 186 | result.position.y = position.y * rhs; 187 | result.position.z = position.z * rhs; 188 | result.texcoord[0].x = texcoord[0].x * rhs; 189 | result.texcoord[0].y = texcoord[0].y * rhs; 190 | result.texcoord[1].x = texcoord[1].x * rhs; 191 | result.texcoord[1].y = texcoord[1].y * rhs; 192 | 193 | return result; 194 | } 195 | }; 196 | 197 | 198 | struct Q3BspMeshVertLump 199 | { 200 | int offset; 201 | }; 202 | 203 | 204 | struct Q3BspEffectLump 205 | { 206 | char name[64]; 207 | int brush; 208 | int unknown; 209 | }; 210 | 211 | 212 | struct Q3BspFaceLump 213 | { 214 | int texture; 215 | int effect; 216 | int type; 217 | int vertex; 218 | int n_vertexes; 219 | int meshvert; 220 | int n_meshverts; 221 | int lm_index; 222 | vec2i lm_start; 223 | vec2i lm_size; 224 | vec3f lm_origin; 225 | vec3f lm_vecs[2]; 226 | vec3f normal; 227 | vec2i size; 228 | }; 229 | 230 | 231 | struct Q3BspLightMapLump 232 | { 233 | unsigned char map[128 * 128 * 3]; 234 | }; 235 | 236 | 237 | struct Q3BspLightVolLump 238 | { 239 | unsigned char ambient[3]; 240 | unsigned char directional[3]; 241 | unsigned char dir[2]; 242 | }; 243 | 244 | 245 | struct Q3BspVisDataLump 246 | { 247 | int n_vecs; 248 | int sz_vecs; 249 | unsigned char* vecs; 250 | }; 251 | 252 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3BspLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "q3bsp/Q3BspLoader.hpp" 2 | #include 3 | 4 | Q3BspMap *Q3BspLoader::Load(const std::string &filename) 5 | { 6 | std::ifstream bspFile; 7 | bspFile.open(filename, std::ios::in | std::ios::binary ); 8 | 9 | if(!bspFile.is_open()) 10 | { 11 | return NULL; 12 | } 13 | 14 | // bsp header 15 | Q3BspHeader bspHeader; 16 | LoadBspHeader( bspHeader, bspFile ); 17 | 18 | //validate the header 19 | bool validQ3Bsp = !strncmp(bspHeader.magic, "IBSP", 4) && (bspHeader.version == 0x2e); 20 | 21 | if(!validQ3Bsp) 22 | { 23 | return NULL; 24 | } 25 | 26 | // header is valid - load the rest of the map 27 | Q3BspMap *q3map = new Q3BspMap; 28 | 29 | q3map->header = bspHeader; 30 | 31 | // entities lump 32 | LoadEntitiesLump( q3map, bspFile ); 33 | // generic lumps 34 | LoadLump( q3map, Textures, q3map->textures, bspFile ); 35 | LoadLump( q3map, Planes, q3map->planes, bspFile ); 36 | LoadLump( q3map, Nodes, q3map->nodes, bspFile ); 37 | LoadLump( q3map, Leafs, q3map->leaves, bspFile ); 38 | LoadLump( q3map, LeafFaces, q3map->leafFaces, bspFile ); 39 | LoadLump( q3map, LeafBrushes, q3map->leafBrushes, bspFile ); 40 | LoadLump( q3map, Models, q3map->models, bspFile ); 41 | LoadLump( q3map, Brushes, q3map->brushes, bspFile ); 42 | LoadLump( q3map, BrushSides, q3map->brushSides, bspFile ); 43 | LoadLump( q3map, Vertices, q3map->vertices, bspFile ); 44 | LoadLump( q3map, MeshVerts, q3map->meshVertices, bspFile ); 45 | LoadLump( q3map, Effects, q3map->effects, bspFile ); 46 | LoadLump( q3map, Faces, q3map->faces, bspFile ); 47 | LoadLump( q3map, Lightmaps, q3map->lightMaps, bspFile ); 48 | LoadLump( q3map, LightVols, q3map->lightVols, bspFile ); 49 | // vis data lump 50 | LoadVisDataLump( q3map, bspFile ); 51 | 52 | bspFile.close(); 53 | 54 | return q3map; 55 | } 56 | 57 | 58 | void Q3BspLoader::LoadBspHeader(Q3BspHeader &hdr, std::ifstream &fstream) 59 | { 60 | fstream.read( (char*)&(hdr), sizeof(Q3BspHeader) ); 61 | } 62 | 63 | 64 | void Q3BspLoader::LoadEntitiesLump(Q3BspMap *map, std::ifstream &fstream) 65 | { 66 | map->entities.size = map->header.direntries[Entities].length; 67 | map->entities.ents = new char[map->entities.size]; 68 | 69 | fstream.seekg( map->header.direntries[Entities].offset, std::ios_base::beg ); 70 | fstream.read( map->entities.ents, sizeof(char) * map->entities.size ); 71 | } 72 | 73 | 74 | void Q3BspLoader::LoadVisDataLump(Q3BspMap *map, std::ifstream &fstream) 75 | { 76 | fstream.seekg( map->header.direntries[VisData].offset, std::ios_base::beg ); 77 | 78 | fstream.read((char *)&(map->visData.n_vecs), sizeof(int) ); 79 | fstream.read((char *)&(map->visData.sz_vecs), sizeof(int) ); 80 | 81 | int vecSize = map->visData.n_vecs * map->visData.sz_vecs; 82 | map->visData.vecs = new unsigned char[vecSize]; 83 | 84 | fstream.read( (char *)(map->visData.vecs), vecSize * sizeof(unsigned char) ); 85 | } -------------------------------------------------------------------------------- /src/q3bsp/Q3BspLoader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSPLOADER_INCLUDED 2 | #define Q3BSPLOADER_INCLUDED 3 | 4 | #include "q3bsp/Q3BspMap.hpp" 5 | 6 | /* 7 | * Loading class for Q3 bsp 8 | */ 9 | 10 | class Q3BspLoader 11 | { 12 | public: 13 | Q3BspMap *Load(const std::string &filename); 14 | 15 | private: 16 | void LoadBspHeader(Q3BspHeader &hdr, std::ifstream &fstream); 17 | void LoadEntitiesLump(Q3BspMap *map, std::ifstream &fstream); 18 | void LoadVisDataLump(Q3BspMap *map, std::ifstream &fstream); 19 | 20 | template 21 | void LoadLump(Q3BspMap *map, LumpTypes lType, std::vector &container, std::ifstream &fstream); 22 | }; 23 | 24 | 25 | // common loader for generic bsp lumps 26 | template 27 | void Q3BspLoader::LoadLump(Q3BspMap *map, LumpTypes lType, std::vector &container, std::ifstream &fstream) 28 | { 29 | int numElements = map->header.direntries[lType].length / sizeof(T); 30 | fstream.seekg( map->header.direntries[lType].offset, std::ios_base::beg ); 31 | 32 | container.reserve(numElements); 33 | 34 | for(int i = 0; i < numElements; i++) 35 | { 36 | T element; 37 | fstream.read( (char*)&element, sizeof(T) ); 38 | 39 | container.push_back(element); 40 | } 41 | } 42 | 43 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3BspMap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSPMAP_INCLUDED 2 | #define Q3BSPMAP_INCLUDED 3 | 4 | #include "Frustum.hpp" 5 | #include "common/BspMap.hpp" 6 | #include "q3bsp/Q3Bsp.hpp" 7 | #include "renderer/OpenGL.hpp" 8 | #include 9 | #include 10 | 11 | class Texture; 12 | struct Q3BspPatch; 13 | 14 | /* 15 | * Quake III map 16 | */ 17 | 18 | class Q3BspMap : public BspMap 19 | { 20 | public: 21 | static const int s_tesselationLevel; // level of curved surface tesselation 22 | static const float s_worldScale; // scale down factor for the map 23 | 24 | Q3BspMap() : BspMap(), m_lightmapTextures(NULL) 25 | { 26 | } 27 | 28 | ~Q3BspMap(); 29 | 30 | void Init(); 31 | void OnRenderStart(); 32 | void Render(); 33 | void OnRenderFinish(); 34 | 35 | bool ClusterVisible(int cameraCluster, int testCluster) const; 36 | int FindCameraLeaf(const Math::Vector3f &cameraPosition) const; 37 | void CalculateVisibleFaces(const Math::Vector3f &cameraPosition); 38 | 39 | // bsp data 40 | Q3BspHeader header; 41 | Q3BspEntityLump entities; 42 | std::vector textures; 43 | std::vector planes; 44 | std::vector nodes; 45 | std::vector leaves; 46 | std::vector leafFaces; 47 | std::vector leafBrushes; 48 | std::vector models; 49 | std::vector brushes; 50 | std::vector brushSides; 51 | std::vector vertices; 52 | std::vector meshVertices; 53 | std::vector effects; 54 | std::vector faces; 55 | std::vector lightMaps; 56 | std::vector lightVols; 57 | Q3BspVisDataLump visData; 58 | 59 | private: 60 | void LoadTextures(); 61 | void LoadLightmaps(); 62 | void SetLightmapGamma(float gamma); 63 | void CreatePatch(const Q3BspFaceLump &f); 64 | void RenderFace(int idx); 65 | void RenderPatch(int idx); 66 | 67 | // VBO creation 68 | void CreateBuffersForFace(const Q3BspFaceLump &face, int idx); 69 | void CreateBuffersForPatch(int idx); 70 | 71 | // render data 72 | std::vector m_renderLeaves; // bsp leaves in "renderable format" 73 | std::vector m_renderFaces; // bsp faces in "renderable format" 74 | 75 | std::vector m_patches; // curved surfaces 76 | std::vector m_textures; // loaded in-game textures 77 | std::vector m_visibleFaces; // list of visible surfaces to render 78 | GLuint *m_lightmapTextures; // bsp lightmaps 79 | 80 | Frustum m_frustum; // view frustum 81 | 82 | // helper textures 83 | Texture *m_missingTex; // rendered if an in-game texture is missing 84 | GLuint m_whiteTex; // used if no lightmap specified for a face 85 | 86 | // rendering buffers (VAO + VBO) 87 | RenderBuffers m_renderBuffers; 88 | }; 89 | 90 | 91 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3BspPatch.cpp: -------------------------------------------------------------------------------- 1 | #include "q3bsp/Q3BspPatch.hpp" 2 | #include "renderer/OpenGL.hpp" 3 | 4 | 5 | void Q3BspBiquadPatch::Tesselate(int tessLevel) 6 | { 7 | m_tesselationLevel = tessLevel; 8 | m_vertices.resize( (m_tesselationLevel + 1) * (m_tesselationLevel + 1) ); 9 | 10 | for (int i = 0; i <= m_tesselationLevel; ++i) 11 | { 12 | float a = (float)i / m_tesselationLevel; 13 | float b = 1.f - a; 14 | 15 | m_vertices[i]= controlPoints[0] * (b * b) + 16 | controlPoints[3] * (2 * b * a) + 17 | controlPoints[6] * (a * a); 18 | } 19 | 20 | for (int i = 1; i <= m_tesselationLevel; ++i) 21 | { 22 | float a = (float)i / m_tesselationLevel; 23 | float b = 1.f - a; 24 | 25 | Q3BspVertexLump temp[3]; 26 | 27 | for (int j = 0, k = 0; j < 3; ++j, k = 3 * j) 28 | { 29 | temp[j] = controlPoints[k + 0] * ( b * b ) + 30 | controlPoints[k + 1] * ( 2 * b * a) + 31 | controlPoints[k + 2] * ( a * a ); 32 | } 33 | 34 | for (int j = 0; j <= m_tesselationLevel; ++j) 35 | { 36 | float a = (float)j / m_tesselationLevel; 37 | float b = 1.f - a; 38 | 39 | m_vertices[i * (m_tesselationLevel + 1) + j] = temp[0] * ( b * b ) + 40 | temp[1] * ( 2 * b * a ) + 41 | temp[2] * ( a * a ); 42 | } 43 | } 44 | 45 | m_indices.resize( m_tesselationLevel * ( m_tesselationLevel + 1 ) * 2 ); 46 | 47 | for (int row = 0; row < m_tesselationLevel; ++row) 48 | { 49 | for (int col = 0; col <= m_tesselationLevel; ++col) 50 | { 51 | m_indices[( row * (m_tesselationLevel + 1) + col ) * 2 + 1] = row * (m_tesselationLevel + 1) + col; 52 | m_indices[( row * (m_tesselationLevel + 1) + col ) * 2] = (row + 1) * (m_tesselationLevel + 1) + col; 53 | } 54 | } 55 | 56 | m_trianglesPerRow = new int[m_tesselationLevel]; 57 | m_rowIndexPointers = new unsigned int *[m_tesselationLevel]; 58 | 59 | for (int row = 0; row < m_tesselationLevel; ++row) 60 | { 61 | m_trianglesPerRow[row] = 2 * (m_tesselationLevel + 1); 62 | m_rowIndexPointers[row] = &m_indices[row * 2 * (m_tesselationLevel + 1)]; 63 | } 64 | } 65 | 66 | 67 | void Q3BspBiquadPatch::Render() 68 | { 69 | // render the patch 70 | if (!GL_EXT_multi_draw_arrays) 71 | { 72 | for (int row = 0; row < m_tesselationLevel; ++row) 73 | { 74 | glDrawElements(GL_TRIANGLE_STRIP, 2 * (m_tesselationLevel + 1), GL_UNSIGNED_INT, 75 | &m_indices[row * 2 * (m_tesselationLevel + 1)]); 76 | } 77 | } 78 | else 79 | { 80 | glMultiDrawElementsEXT(GL_TRIANGLE_STRIP, m_trianglesPerRow, 81 | GL_UNSIGNED_INT, (const void **)m_rowIndexPointers, 82 | m_tesselationLevel); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/q3bsp/Q3BspPatch.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSPPATCH_INCLUDED 2 | #define Q3BSPPATCH_INCLUDED 3 | 4 | #include "q3bsp/Q3BspMap.hpp" 5 | 6 | 7 | // Quake III BSP curved surface component ( biquadratic (3x3) patch ) 8 | class Q3BspBiquadPatch 9 | { 10 | public: 11 | Q3BspBiquadPatch() : m_tesselationLevel(0), 12 | m_trianglesPerRow(NULL), 13 | m_rowIndexPointers(NULL) 14 | { 15 | } 16 | 17 | ~Q3BspBiquadPatch() 18 | { 19 | delete [] m_trianglesPerRow; 20 | delete [] m_rowIndexPointers; 21 | } 22 | 23 | void Tesselate(int tessLevel); // perform tesselation 24 | void Render(); 25 | 26 | Q3BspVertexLump controlPoints[9]; 27 | std::vector m_vertices; 28 | private: 29 | int m_tesselationLevel; 30 | std::vector m_indices; 31 | int* m_trianglesPerRow; // store as pointer arrays for easier access by GL functions 32 | unsigned int** m_rowIndexPointers; // - " - 33 | }; 34 | 35 | 36 | // Quake III BSP curved surface (an array of biquadratic patches) 37 | struct Q3BspPatch 38 | { 39 | int textureIdx; // surface texture index 40 | int lightmapIdx; // surface lightmap index 41 | int width; 42 | int height; 43 | 44 | std::vector quadraticPatches; 45 | }; 46 | 47 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3BspRenderHelpers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSPRENDERHELPERS_INCLUDED 2 | #define Q3BSPRENDERHELPERS_INCLUDED 3 | 4 | #include "renderer/OpenGL.hpp" 5 | #include 6 | #include 7 | 8 | /* 9 | * Helper structs for Q3BspMap rendering 10 | */ 11 | 12 | enum Q3BspRenderFlags 13 | { 14 | Q3RenderShowWireframe = 1 << 0, 15 | Q3RenderShowLightmaps = 1 << 1, 16 | Q3RenderUseLightmaps = 1 << 2, 17 | Q3RenderAlphaTest = 1 << 3, 18 | Q3RenderSkipMissingTex = 1 << 4, 19 | Q3RenderSkipPVS = 1 << 5, 20 | Q3RenderSkipFC = 1 << 6 21 | }; 22 | 23 | 24 | // leaf structure used for occlusion culling (PVS/frustum) 25 | struct Q3LeafRenderable 26 | { 27 | int visCluster; 28 | int firstFace; 29 | int numFaces; 30 | Math::Vector3f boundingBoxVertices[8]; 31 | }; 32 | 33 | 34 | // face structure used for rendering 35 | struct Q3FaceRenderable 36 | { 37 | int type; 38 | int index; 39 | }; 40 | 41 | 42 | // VBO handles for a single face in the BSP 43 | struct FaceBuffers 44 | { 45 | GLuint m_vertexBuffer; 46 | GLuint m_texcoordBuffer; 47 | GLuint m_lightmapTexcoordBuffer; 48 | }; 49 | 50 | 51 | struct RenderBuffers 52 | { 53 | GLuint m_vertexArray; // single vertex vertex array for the entire map 54 | 55 | std::map< int, FaceBuffers > m_faceVBOs; 56 | std::map< int, std::vector > m_patchVBOs; 57 | }; 58 | 59 | 60 | // map statistics 61 | struct BspStats 62 | { 63 | BspStats() : totalVertices(0), 64 | totalFaces(0), 65 | visibleFaces(0), 66 | totalPatches(0), 67 | visiblePatches(0) 68 | { 69 | } 70 | 71 | int totalVertices; 72 | int totalFaces; 73 | int visibleFaces; 74 | int totalPatches; 75 | int visiblePatches; 76 | }; 77 | 78 | 79 | 80 | #endif -------------------------------------------------------------------------------- /src/q3bsp/Q3BspStatsUI.cpp: -------------------------------------------------------------------------------- 1 | #include "Application.hpp" 2 | #include "q3bsp/Q3BspMap.hpp" 3 | #include "q3bsp/Q3BspStatsUI.hpp" 4 | #include "renderer/OculusVR.hpp" 5 | #include "renderer/RenderContext.hpp" 6 | #include 7 | 8 | extern RenderContext g_renderContext; 9 | extern Application g_application; 10 | extern OculusVR g_oculusVR; 11 | 12 | Q3StatsUI::Q3StatsUI(BspMap *map) : StatsUI(map) 13 | { 14 | m_font = new Font("res/font.png"); 15 | 16 | // make the font slightly bigger in VR 17 | if (g_application.VREnabled()) 18 | m_font->SetScale(Math::Vector2f(3.f * (float)g_renderContext.height / 1080.f, 3.f * (float)g_renderContext.height / 1080.f)); 19 | else 20 | m_font->SetScale(Math::Vector2f(2.f, 2.f)); 21 | } 22 | 23 | 24 | void Q3StatsUI::Render() 25 | { 26 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 27 | glActiveTexture(GL_TEXTURE0); 28 | 29 | // no map loaded or no cmdline parameter specified - display error message 30 | if(!m_map) 31 | { 32 | m_font->SetColor(Math::Vector4f(1.f, 0.f, 0.f, 1.f)); 33 | m_font->drawText("Error loading BSP - missing/corrupted file or no file specified!", -0.7f, 0.0f, 0.f); 34 | return; 35 | } 36 | 37 | // check if we should rescale the font for non-VR mode here, since user can change window size dynamically (unlike VR mode) 38 | if (!g_application.VREnabled()) 39 | m_font->SetScale(Math::Vector2f(2.f * (float)g_renderContext.height / 768.f, 2.f * (float)g_renderContext.height / 768.f)); 40 | 41 | static const float statsX = g_application.VREnabled() ? -0.19f : -0.99f; 42 | static const float keysX = g_application.VREnabled() ? -0.19f : 0.35f; 43 | static const float statsY = g_application.VREnabled() ? 0.25f : 0.70f; 44 | static const float keysY = g_application.VREnabled() ? -0.02f : -0.25f; 45 | static const float ySpacing = 0.05f; 46 | 47 | const BspStats &stats = m_map->GetMapStats(); 48 | 49 | std::stringstream statsStream; 50 | 51 | statsStream << "Total vertices: " << stats.totalVertices; 52 | m_font->drawText(statsStream.str(), statsX, statsY, 0.f); 53 | 54 | statsStream.str(""); 55 | statsStream << "Total faces: " << stats.totalFaces; 56 | m_font->drawText(statsStream.str(), statsX, statsY - ySpacing, 0.f); 57 | 58 | statsStream.str(""); 59 | statsStream << "Total patches: " << stats.totalPatches; 60 | m_font->drawText(statsStream.str(), statsX, statsY - ySpacing * 2.f, 0.f); 61 | 62 | statsStream.str(""); 63 | statsStream << "Rendered faces: " << stats.visibleFaces; 64 | m_font->drawText(statsStream.str(), statsX, statsY - ySpacing * 3.f, 0.f); 65 | 66 | statsStream.str(""); 67 | statsStream << "Rendered patches: " << stats.visiblePatches; 68 | m_font->drawText(statsStream.str(), statsX, statsY - ySpacing * 4.f, 0.); 69 | 70 | m_font->SetColor(Math::Vector4f(1.f, 0.f, 0.f, 1.f)); 71 | m_font->drawText(" ~ - toggle stats view", keysX, keysY, 0.f); 72 | 73 | if (m_map->HasRenderFlag(Q3RenderShowWireframe)) 74 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 75 | else 76 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 77 | m_font->drawText("F1 - show wireframe", keysX, keysY - ySpacing, 0.f); 78 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 79 | 80 | if (m_map->HasRenderFlag(Q3RenderShowLightmaps)) 81 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 82 | m_font->drawText("F2 - show lightmaps", keysX, keysY - ySpacing * 2.f, 0.f); 83 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 84 | 85 | if (m_map->HasRenderFlag(Q3RenderUseLightmaps)) 86 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 87 | m_font->drawText("F3 - use lightmaps", keysX, keysY - ySpacing * 3.f, 0.f); 88 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 89 | 90 | if (m_map->HasRenderFlag(Q3RenderAlphaTest)) 91 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 92 | m_font->drawText("F4 - use alpha test", keysX, keysY - ySpacing * 4.f, 0.f); 93 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 94 | 95 | if (!m_map->HasRenderFlag(Q3RenderSkipMissingTex)) 96 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 97 | m_font->drawText("F5 - show missing textures", keysX, keysY - ySpacing * 5.f, 0.f); 98 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 99 | 100 | if (!m_map->HasRenderFlag(Q3RenderSkipPVS)) 101 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 102 | m_font->drawText("F6 - use PVS culling", keysX, keysY - ySpacing * 6.f, 0.f); 103 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 104 | 105 | if (!m_map->HasRenderFlag(Q3RenderSkipFC)) 106 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 107 | m_font->drawText("F7 - use frustum culling", keysX, keysY - ySpacing * 7.f, 0.f); 108 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 109 | 110 | if (g_application.VREnabled()) 111 | { 112 | if (g_oculusVR.MSAAEnabled()) 113 | m_font->SetColor(Math::Vector4f(0.f, 1.f, 0.f, 1.f)); 114 | m_font->drawText("F8 - multisampling (MSAA)", keysX, keysY - ySpacing * 8.f, 0.f); 115 | m_font->SetColor(Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/q3bsp/Q3BspStatsUI.hpp: -------------------------------------------------------------------------------- 1 | #ifndef Q3BSPSTATSUI_INCLUDED 2 | #define Q3BSPSTATSUI_INCLUDED 3 | 4 | #include "common/StatsUI.hpp" 5 | #include "renderer/OpenGL.hpp" 6 | #include "renderer/Font.hpp" 7 | 8 | /* 9 | * Quake III BSP stats display 10 | */ 11 | 12 | class Q3StatsUI : public StatsUI 13 | { 14 | public: 15 | Q3StatsUI(BspMap *map); 16 | ~Q3StatsUI() 17 | { 18 | delete m_font; 19 | } 20 | 21 | void Render(); 22 | 23 | private: 24 | Font *m_font; 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /src/renderer/Camera.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CAMERA_INCLUDED 2 | #define CAMERA_INCLUDED 3 | 4 | #include "Math.hpp" 5 | 6 | /* 7 | * DOF6/FPS camera 8 | */ 9 | 10 | class Camera 11 | { 12 | public: 13 | enum CameraMode 14 | { 15 | CAM_DOF6, 16 | CAM_FPS, 17 | CAM_ORTHO 18 | }; 19 | 20 | Camera(float x, float y, float z); 21 | 22 | Camera(const Math::Vector3f &position, 23 | const Math::Vector3f &up, 24 | const Math::Vector3f &right, 25 | const Math::Vector3f &view ); 26 | 27 | void OnRender(); 28 | void RotateCamera(float angle, float x, float y, float z); 29 | void RotateCamera(const Math::Quaternion &q); 30 | void Move( const Math::Vector3f &Direction ); 31 | void MoveForward( float Distance ); 32 | void MoveUpward( float Distance ); 33 | void Strafe( float Distance ); 34 | 35 | void SetMode(CameraMode cm); 36 | CameraMode GetMode() { return m_mode; } 37 | const Math::Vector3f &Position() const { return m_position; } 38 | 39 | // rotate in Euler-space - used mainly for some debugging 40 | void rotateX(float angle); 41 | void rotateY(float angle); 42 | void rotateZ(float angle); 43 | 44 | void OnMouseMove(int x, int y); 45 | 46 | const Math::Matrix4f &ProjectionMatrix() const { return m_projectionMatrix; } 47 | const Math::Matrix4f &ViewMatrix() const { return m_viewMatrix; } 48 | 49 | void UpdateProjectionMatrix(); // on window resize 50 | 51 | // manually specify vector values 52 | void SetRightVector(float x, float y, float z) 53 | { 54 | m_rightVector.m_x = x; 55 | m_rightVector.m_y = y; 56 | m_rightVector.m_z = z; 57 | } 58 | 59 | void SetUpVector(float x, float y, float z) 60 | { 61 | m_upVector.m_x = x; 62 | m_upVector.m_y = y; 63 | m_upVector.m_z = z; 64 | } 65 | 66 | void SetViewVector(float x, float y, float z) 67 | { 68 | m_viewVector.m_x = x; 69 | m_viewVector.m_y = y; 70 | m_viewVector.m_z = z; 71 | } 72 | private: 73 | CameraMode m_mode; 74 | Math::Vector3f m_position; 75 | float m_yLimit; 76 | Math::Matrix4f m_viewMatrix; 77 | Math::Matrix4f m_projectionMatrix; 78 | 79 | // camera orientation vectors 80 | Math::Vector3f m_viewVector; 81 | Math::Vector3f m_rightVector; 82 | Math::Vector3f m_upVector; 83 | 84 | // current rotation info (angles in radian) 85 | Math::Vector3f m_rotation; 86 | }; 87 | 88 | #endif -------------------------------------------------------------------------------- /src/renderer/CameraDirector.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/CameraDirector.hpp" 2 | 3 | 4 | CameraDirector::~CameraDirector() 5 | { 6 | for (auto &it : m_cameras) 7 | { 8 | delete it; 9 | } 10 | } 11 | 12 | 13 | int CameraDirector::AddCamera(float x, float y, float z) 14 | { 15 | m_cameras.push_back( new Camera(x, y, z) ); 16 | m_activeCamera = m_cameras.back(); 17 | 18 | return m_cameras.size(); 19 | } 20 | 21 | 22 | int CameraDirector::AddCamera(const Math::Vector3f &position, 23 | const Math::Vector3f &up, 24 | const Math::Vector3f &right, 25 | const Math::Vector3f &view ) 26 | { 27 | m_cameras.push_back( new Camera(position, up, right, view) ); 28 | m_activeCamera = m_cameras.back(); 29 | 30 | return m_cameras.size(); 31 | } 32 | 33 | 34 | void CameraDirector::OnMouseMove(int x, int y) 35 | { 36 | m_activeCamera->OnMouseMove(x, y); 37 | } -------------------------------------------------------------------------------- /src/renderer/CameraDirector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CAMERADIRECTOR_INCLUDED 2 | #define CAMERADIRECTOR_INCLUDED 3 | 4 | #include "renderer/Camera.hpp" 5 | #include 6 | 7 | /* 8 | * global manager for all game cameras 9 | */ 10 | 11 | class CameraDirector 12 | { 13 | public: 14 | CameraDirector::CameraDirector() : m_activeCamera(NULL) 15 | { 16 | } 17 | 18 | ~CameraDirector(); 19 | 20 | int AddCamera(float x, float y, float z); 21 | int AddCamera(const Math::Vector3f &position, 22 | const Math::Vector3f &up, 23 | const Math::Vector3f &right, 24 | const Math::Vector3f &view ); 25 | Camera *GetActiveCamera() { return m_activeCamera; } 26 | Camera *GetCamera(int camIdx) { return m_cameras[camIdx]; } 27 | void SetActiveCamera(int camIdx) { m_activeCamera = m_cameras[camIdx]; } 28 | 29 | void OnMouseMove(int x, int y); 30 | 31 | private: 32 | Camera *m_activeCamera; 33 | std::vector m_cameras; 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /src/renderer/Font.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/Font.hpp" 2 | #include "renderer/RenderContext.hpp" 3 | #include "renderer/ShaderManager.hpp" 4 | #include "renderer/CameraDirector.hpp" 5 | #include "renderer/Texture.hpp" 6 | #include "renderer/TextureManager.hpp" 7 | 8 | extern RenderContext g_renderContext; 9 | extern CameraDirector g_cameraDirector; 10 | 11 | static const int CHAR_WIDTH = 8; 12 | static const int CHAR_HEIGHT = 9; 13 | static const float CHAR_SPACING = 1.5f; 14 | 15 | 16 | Font::Font(const char *tex) : m_scale(1.f, 1.f), m_position(0.0f, 0.0f, 0.0f), m_color(1.f, 1.f, 1.f, 1.f) 17 | { 18 | glGenVertexArrays(1, &m_fontVertexArray); 19 | glBindVertexArray(m_fontVertexArray); 20 | 21 | const float verts[] = { 0.0f, 0.0f, -1.0f, 22 | 0.0f, -1.0f, -1.0f, 23 | 1.0f, 0.0f, -1.0f, 24 | 1.0f, -1.0f, -1.0f }; 25 | 26 | const int indices[] = { 0, 1, 2, 3 }; 27 | 28 | glGenBuffers(1, &m_vertexBuffer); 29 | glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer); 30 | glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW); 31 | 32 | const ShaderProgram &shader = ShaderManager::GetInstance()->UseShaderProgram(ShaderManager::FontShader); 33 | m_vertexPosAttr = glGetAttribLocation(shader.id, "inVertex"); 34 | 35 | glEnableVertexAttribArray(m_vertexPosAttr); 36 | glVertexAttribPointer(m_vertexPosAttr, 3, GL_FLOAT, GL_FALSE, 0, (void*)0); 37 | 38 | glGenBuffers(1, &m_indexBuffer); 39 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer); 40 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 41 | 42 | m_texture = TextureManager::GetInstance()->LoadTexture(tex); 43 | 44 | // disable l. filter for this texture (it's bound in Load()) 45 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 46 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 47 | } 48 | 49 | Font::~Font() 50 | { 51 | if (glIsBuffer(m_vertexBuffer)) 52 | glDeleteBuffers(1, &m_vertexBuffer); 53 | 54 | if (glIsBuffer(m_indexBuffer)) 55 | glDeleteBuffers(1, &m_indexBuffer); 56 | 57 | glDisableVertexAttribArray(m_vertexPosAttr); 58 | 59 | if (glIsVertexArray(m_fontVertexArray)) 60 | glDeleteVertexArrays(1, &m_fontVertexArray); 61 | } 62 | 63 | void Font::renderAt(const Math::Vector3f &pos, int w, int h, int uo, int vo, const Math::Vector4f &color) 64 | { 65 | LOG_MESSAGE_ASSERT(m_texture != NULL, "Trying to render with no texture?"); 66 | 67 | Math::Matrix4f texMatrix, mvMatrix; 68 | 69 | Math::Translate(mvMatrix, pos.m_x, pos.m_y); 70 | Math::Scale(mvMatrix, 2.f * w / g_renderContext.height, 2.f * h / g_renderContext.height); 71 | Math::Scale(mvMatrix, m_scale.m_x, m_scale.m_y); 72 | 73 | Math::Scale(texMatrix, 1.f / m_texture->Width(), -1.f / m_texture->Height()); 74 | Math::Translate(texMatrix, (float)uo, (float)-vo); 75 | Math::Scale(texMatrix, (float)w, (float)h); 76 | 77 | Math::Matrix4f MVP = g_cameraDirector.GetActiveCamera()->ProjectionMatrix() * mvMatrix; 78 | 79 | // update matrices 80 | const ShaderProgram &shader = ShaderManager::GetInstance()->GetActiveShader(); 81 | glUniformMatrix4fv(shader.uniforms[TextureMatrix], 1, GL_FALSE, &texMatrix[0]); 82 | glUniformMatrix4fv(shader.uniforms[ModelViewProjectionMatrix], 1, GL_FALSE, &MVP[0]); 83 | glUniform4fv(shader.uniforms[VertexColor], 1, &color.m_x); 84 | 85 | glBindVertexArray(m_fontVertexArray); 86 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffer); 87 | glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, 0); 88 | } 89 | 90 | void Font::drawText(const std::string &text, float x, float y, float z, float r, float g, float b, float a) 91 | { 92 | drawText(text, Math::Vector3f(x, y, z), Math::Vector4f(r, g, b, a)); 93 | } 94 | 95 | void Font::drawText(const std::string &text, float x, float y, float z) 96 | { 97 | drawText(text, Math::Vector3f(x, y, z), m_color); 98 | } 99 | 100 | void Font::drawText(const std::string &text) 101 | { 102 | drawText(text, m_position, m_color); 103 | } 104 | 105 | void Font::drawText(const std::string &text, const Math::Vector3f &position, const Math::Vector4f &color) 106 | { 107 | glDisable(GL_DEPTH_TEST); 108 | glEnable(GL_BLEND); 109 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 110 | 111 | Camera::CameraMode camMode = g_cameraDirector.GetActiveCamera()->GetMode(); 112 | g_cameraDirector.GetActiveCamera()->SetMode(Camera::CAM_ORTHO); 113 | 114 | TextureManager::GetInstance()->BindTexture(m_texture); 115 | ShaderManager::GetInstance()->UseShaderProgram(ShaderManager::FontShader); 116 | 117 | Math::Vector3f pos = position; 118 | 119 | for (size_t i = 0; i < text.length(); i++) 120 | { 121 | int cu = text[i] - 32; 122 | 123 | if (cu >= 0 && cu < 32 * 3) 124 | { 125 | renderAt(pos, CHAR_WIDTH, CHAR_HEIGHT, cu % 16 * CHAR_WIDTH, cu / 16 * (CHAR_HEIGHT + 1), color); 126 | } 127 | 128 | pos.m_x += m_scale.m_x * (CHAR_SPACING / g_renderContext.scrRatio) * CHAR_WIDTH / g_renderContext.height; 129 | } 130 | 131 | g_cameraDirector.GetActiveCamera()->SetMode(camMode); 132 | 133 | glDisable(GL_BLEND); 134 | glEnable(GL_DEPTH_TEST); 135 | } 136 | 137 | -------------------------------------------------------------------------------- /src/renderer/Font.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FONT_HPP 2 | #define FONT_HPP 3 | 4 | #include "renderer/OpenGL.hpp" 5 | #include 6 | 7 | class Texture; 8 | 9 | class Font 10 | { 11 | public: 12 | Font(const char *texture); 13 | ~Font(); 14 | void SetColor(const Math::Vector4f &color) { m_color = color; } 15 | void SetPosition(const Math::Vector3f &position) { m_position = position; } 16 | void SetScale(const Math::Vector2f &scale) { m_scale = scale; } 17 | void drawText(const std::string &text); 18 | void drawText(const std::string &text, float x, float y, float z, float r, float g, float b, float a); 19 | void drawText(const std::string &text, const Math::Vector3f &position, const Math::Vector4f &color=Math::Vector4f(1.f, 1.f, 1.f, 1.f)); 20 | void drawText(const std::string &text, float x, float y, float z=-1.0f); 21 | private: 22 | void renderAt(const Math::Vector3f &pos, int w, int h, int uo, int vo, const Math::Vector4f &color); 23 | Texture* m_texture; 24 | Math::Vector2f m_scale; 25 | Math::Vector3f m_position; 26 | Math::Vector4f m_color; 27 | 28 | // OpenGL thingamabobs 29 | GLuint m_fontVertexArray; // VAO 30 | 31 | GLuint m_vertexBuffer; // VBO 32 | GLuint m_indexBuffer; // IBO 33 | 34 | GLuint m_vertexPosAttr; // attribute location 35 | }; 36 | 37 | #endif -------------------------------------------------------------------------------- /src/renderer/OVRCameraFrustum.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OVRCAMERAFRUSTUM_HPP 2 | #define OVRCAMERAFRUSTUM_HPP 3 | #include "renderer/OpenGL.hpp" 4 | #include "OVR_CAPI.h" 5 | #include "OVR_CAPI_GL.h" 6 | 7 | /* 8 | * Rendering class for IR tracking camera bounds (frustum) 9 | */ 10 | class OVRCameraFrustum 11 | { 12 | public: 13 | ~OVRCameraFrustum(); 14 | void Recalculate(ovrSession session); 15 | void OnRender(); 16 | private: 17 | GLuint m_vertexArray; 18 | GLuint m_vertexBuffers[3]; 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /src/renderer/OVRTrackerChaperone.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OVRTRACKERCHAPERONE_HPP 2 | #define OVRTRACKERCHAPERONE_HPP 3 | #include "renderer/OpenGL.hpp" 4 | #include "OVR_CAPI.h" 5 | #include "OVR_CAPI_GL.h" 6 | #include "Extras/OVR_Math.h" 7 | 8 | /* 9 | * Rendering class for Vive-style tracker chaperone 10 | */ 11 | class OVRTrackerChaperone 12 | { 13 | public: 14 | ~OVRTrackerChaperone(); 15 | void Recalculate(ovrSession session, const OVR::Vector3f &headPos); 16 | void OnRender(); 17 | private: 18 | GLuint m_vertexArray; 19 | GLuint m_vertexBuffers[4]; 20 | float m_planeDistances[4]; 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /src/renderer/OculusVR.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OCULUSVR_INCLUDED 2 | #define OCULUSVR_INCLUDED 3 | 4 | #include "InputHandlers.hpp" 5 | #include "renderer/OpenGL.hpp" 6 | #include "renderer/OculusVRDebug.hpp" 7 | #include "renderer/OVRCameraFrustum.hpp" 8 | #include "renderer/OVRTrackerChaperone.hpp" 9 | #include "Extras/OVR_Math.h" 10 | #include "OVR_CAPI.h" 11 | 12 | /* 13 | * Oculus Rift setup class (as of SDK 1.3.0) 14 | */ 15 | class OculusVR 16 | { 17 | public: 18 | OculusVR() : m_hmdSession(nullptr), 19 | m_debugData(nullptr), 20 | m_cameraFrustum(nullptr), 21 | m_trackerChaperone(nullptr), 22 | m_msaaEnabled(true), 23 | m_frameIndex(0), 24 | m_sensorSampleTime(0) 25 | { 26 | } 27 | 28 | ~OculusVR(); 29 | bool InitVR(); 30 | bool InitVRBuffers(int windowWidth, int windowHeight); 31 | bool InitNonDistortMirror(int windowWidth, int windowHeight); // create non-distorted mirror if necessary (debug purposes) 32 | void DestroyVR(); 33 | const ovrSizei GetResolution() const; 34 | void OnRenderStart(); 35 | const OVR::Matrix4f OnEyeRender(int eyeIndex); 36 | void OnEyeRenderFinish(int eyeIndex); 37 | const OVR::Matrix4f GetEyeMVPMatrix(int eyeIdx) const; 38 | void SubmitFrame(); 39 | 40 | void BlitMirror(ovrEyeType numEyes=ovrEye_Count, int offset = 0); // regular OculusVR mirror view 41 | void OnNonDistortMirrorStart(); // non-distorted mirror rendering start (debug purposes) 42 | void BlitNonDistortMirror(int offset); // non-distorted mirror rendering (debug purposes) 43 | 44 | void OnKeyPress(KeyCode key); 45 | void CreateDebug(); 46 | void UpdateDebug(); 47 | void RenderDebug(); 48 | void RenderTrackerFrustum(); 49 | void RenderTrackerChaperone(); 50 | bool IsDebugHMD() const { return (m_hmdDesc.AvailableHmdCaps & ovrHmdCap_DebugDevice) != 0; } 51 | void ShowPerfStats(ovrPerfHudMode statsMode); 52 | void SetMSAA(bool val) { m_msaaEnabled = val; } 53 | bool MSAAEnabled() const { return m_msaaEnabled; } 54 | private: 55 | // A buffer struct used to store eye textures and framebuffers. 56 | // We create one instance for the left eye, one for the right eye. 57 | // Final rendering is done via blitting two separate frame buffers into one render target. 58 | struct OVRBuffer 59 | { 60 | OVRBuffer(const ovrSession &session, int eyeIdx); 61 | void OnRender(); 62 | void OnRenderFinish(); 63 | void SetupMSAA(); 64 | void OnRenderMSAA(); 65 | void OnRenderMSAAFinish(); 66 | void Destroy(const ovrSession &session); 67 | 68 | ovrSizei m_eyeTextureSize; 69 | GLuint m_eyeFbo = 0; 70 | GLuint m_eyeTexId = 0; 71 | GLuint m_depthBuffer = 0; 72 | 73 | GLuint m_msaaEyeFbo = 0; // framebuffer for MSAA texture 74 | GLuint m_eyeTexMSAA = 0; // color texture for MSAA 75 | GLuint m_depthTexMSAA = 0; // depth texture for MSAA 76 | 77 | ovrTextureSwapChain m_swapTextureChain = nullptr; 78 | }; 79 | 80 | // data and buffers used to render to HMD 81 | ovrSession m_hmdSession; 82 | ovrHmdDesc m_hmdDesc; 83 | ovrEyeRenderDesc m_eyeRenderDesc[ovrEye_Count]; 84 | ovrPosef m_eyeRenderPose[ovrEye_Count]; 85 | ovrVector3f m_hmdToEyeOffset[ovrEye_Count]; 86 | OVRBuffer *m_eyeBuffers[ovrEye_Count]; 87 | 88 | OVR::Matrix4f m_projectionMatrix[ovrEye_Count]; 89 | OVR::Matrix4f m_eyeOrientation[ovrEye_Count]; 90 | OVR::Matrix4f m_eyePose[ovrEye_Count]; 91 | 92 | // frame timing data and tracking info 93 | double m_frameTiming; 94 | ovrTrackingState m_trackingState; 95 | 96 | // mirror texture used to render HMD view to OpenGL window 97 | ovrMirrorTexture m_mirrorTexture; 98 | ovrMirrorTextureDesc m_mirrorDesc; 99 | 100 | // debug non-distorted mirror texture data 101 | GLuint m_nonDistortTexture; 102 | GLuint m_nonDistortDepthBuffer; 103 | GLuint m_mirrorFBO; 104 | GLuint m_nonDistortFBO; 105 | int m_nonDistortViewPortWidth; 106 | int m_nonDistortViewPortHeight; 107 | bool m_msaaEnabled; 108 | long long m_frameIndex; 109 | double m_sensorSampleTime; 110 | 111 | // debug hardware output data 112 | OculusVRDebug *m_debugData; 113 | 114 | // debug camera frustum renderer 115 | OVRCameraFrustum *m_cameraFrustum; 116 | 117 | // debug tracker chaperone 118 | OVRTrackerChaperone *m_trackerChaperone; 119 | }; 120 | 121 | 122 | #endif -------------------------------------------------------------------------------- /src/renderer/OculusVRDebug.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/OculusVRDebug.hpp" 2 | #include "renderer/CameraDirector.hpp" 3 | #include "renderer/Font.hpp" 4 | #include "renderer/OculusVR.hpp" 5 | #include "renderer/RenderContext.hpp" 6 | #include 7 | 8 | extern RenderContext g_renderContext; 9 | extern CameraDirector g_cameraDirector; 10 | 11 | OculusVRDebug::OculusVRDebug() : m_frameCounter(0), 12 | m_totalFrameCounter(0), 13 | m_secondsPerFrame(0.0f), 14 | m_fps(0.0f), 15 | m_lastFpsUpdate(0.0f) 16 | { 17 | m_font = new Font("res/font.png"); 18 | m_font->SetScale(Math::Vector2f(3.f * (float)g_renderContext.height / 1080.f, 3.f * (float)g_renderContext.height / 1080.f)); 19 | } 20 | 21 | OculusVRDebug::~OculusVRDebug() 22 | { 23 | delete m_font; 24 | } 25 | 26 | void OculusVRDebug::OnUpdate(const ovrTrackingState &trackingState) 27 | { 28 | UpdateFrameRateCounter(ovr_GetTimeInSeconds()); 29 | } 30 | 31 | void OculusVRDebug::OnRender(const ovrSession session, const ovrTrackingState &trackingState, const ovrEyeRenderDesc *eyeRenderDescs, const ovrSizei &eyeTextureSize) 32 | { 33 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 34 | glActiveTexture(GL_TEXTURE0); 35 | 36 | static const float xPos = -0.3f; 37 | static const float ySpacing = 0.05f; 38 | std::stringstream statsStream; 39 | 40 | char buf[128]; 41 | float hmdYaw, hmdPitch, hmdRoll; 42 | ovrHmdDesc hmdDesc = ovr_GetHmdDesc(session); 43 | OVR::Quatf headOrientation(trackingState.HeadPose.ThePose.Orientation); 44 | headOrientation.GetEulerAngles(&hmdYaw, &hmdPitch, &hmdRoll); 45 | 46 | sprintf(buf, "HMD YPR:%2.0f %2.0f %2.0f HMD: %s", hmdYaw * PIdiv180inv, hmdPitch * PIdiv180inv, hmdRoll * PIdiv180inv, hmdDesc.ProductName); 47 | m_font->drawText(buf, xPos, 0.1f, 0.f); 48 | 49 | sprintf(buf, "FPS: %.1f ms/frame: %.1f Frame: %03d %d", m_fps, m_secondsPerFrame * 1000.0f, m_frameCounter, m_totalFrameCounter % 2); 50 | m_font->drawText(buf, xPos, 0.1f - ySpacing, 0.f); 51 | 52 | sprintf(buf, "Pos: %2.2f %2.2f %2.2f Tracking: %s", g_cameraDirector.GetActiveCamera()->Position().m_x, 53 | g_cameraDirector.GetActiveCamera()->Position().m_y, 54 | g_cameraDirector.GetActiveCamera()->Position().m_z, 55 | trackingState.StatusFlags & ovrStatus_PositionTracked ? "YES" : "NO"); 56 | m_font->drawText(buf, xPos, 0.1f - ySpacing * 2.f, 0.f); 57 | 58 | float eyeNeckDist[2] = {}; 59 | ovr_GetFloatArray(session, OVR_KEY_EYE_TO_NOSE_DISTANCE, eyeNeckDist, 2); 60 | sprintf(buf, "EyeHeight: %2.2f IPD: %2.1fmm", ovr_GetFloat(session, OVR_KEY_EYE_HEIGHT, 0.f), (eyeNeckDist[0] + eyeNeckDist[1]) * 1000.f); 61 | m_font->drawText(buf, xPos, 0.1f - ySpacing * 3.f, 0.f); 62 | 63 | // Average FOVs 64 | OVR::FovPort leftFov = eyeRenderDescs[0].Fov; 65 | OVR::FovPort rightFov = eyeRenderDescs[1].Fov; 66 | 67 | // Rendered size changes based on selected options & dynamic rendering. 68 | sprintf(buf, "FOV %2.1fx%2.1f, Resolution: %ix%i", (leftFov.GetHorizontalFovDegrees() + rightFov.GetHorizontalFovDegrees()) * 0.5f, 69 | (leftFov.GetVerticalFovDegrees() + rightFov.GetVerticalFovDegrees()) * 0.5, 70 | eyeTextureSize.w, eyeTextureSize.h); 71 | m_font->drawText(buf, xPos, 0.1f - ySpacing * 4.f, 0.f); 72 | 73 | // latency readings 74 | float latencies[5] = {}; 75 | if (ovr_GetFloatArray(session, "DK2Latency", latencies, 5) == 5) 76 | { 77 | char text[5][32]; 78 | for (int i = 0; i < 5; ++i) 79 | { 80 | FormatLatencyReading(text[i], sizeof(text[i]), latencies[i]); 81 | } 82 | 83 | statsStream.str(""); 84 | statsStream << "M2P Latency Ren: " << text[0] << " TWrp: " << text[1]; 85 | m_font->drawText(statsStream.str(), xPos, 0.1f - ySpacing * 5.f, 0.f); 86 | 87 | statsStream.str(""); 88 | statsStream << "PostPresent: " << text[2] << " Err: " << text[3] << " " << text[4]; 89 | m_font->drawText(statsStream.str(), xPos, 0.1f - ySpacing * 6.f, 0.f); 90 | } 91 | } 92 | 93 | 94 | void OculusVRDebug::UpdateFrameRateCounter(double curtime) 95 | { 96 | m_frameCounter++; 97 | m_totalFrameCounter++; 98 | float secondsSinceLastMeasurement = (float)(curtime - m_lastFpsUpdate); 99 | 100 | if (secondsSinceLastMeasurement >= 1.f) 101 | { 102 | m_secondsPerFrame = (float)(curtime - m_lastFpsUpdate) / (float)m_frameCounter; 103 | m_fps = 1.0f / m_secondsPerFrame; 104 | m_lastFpsUpdate = curtime; 105 | m_frameCounter = 0; 106 | } 107 | } 108 | 109 | void OculusVRDebug::FormatLatencyReading(char* buff, size_t size, float val) 110 | { 111 | if (val < 0.000001f) 112 | strcpy(buff, "N/A "); 113 | else 114 | sprintf(buff, "%4.2fms", val * 1000.0f); 115 | } -------------------------------------------------------------------------------- /src/renderer/OculusVRDebug.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OCULUSVRDEBUG_HPP 2 | #define OCULUSVRDEBUG_HPP 3 | #include "OVR_CAPI.h" 4 | 5 | class Font; 6 | 7 | class OculusVRDebug 8 | { 9 | public: 10 | OculusVRDebug(); 11 | ~OculusVRDebug(); 12 | 13 | void OnUpdate(const ovrTrackingState &trackingState); 14 | void OnRender(const ovrSession session, const ovrTrackingState &trackingState, const ovrEyeRenderDesc *eyeRenderDescs, const ovrSizei &eyeTextureSize); 15 | 16 | private: 17 | void UpdateFrameRateCounter(double curtime); 18 | void FormatLatencyReading(char* buff, size_t size, float val); 19 | 20 | // Frame timing logic. 21 | int m_frameCounter; 22 | int m_totalFrameCounter; 23 | float m_secondsPerFrame; 24 | float m_fps; 25 | double m_lastFpsUpdate; 26 | 27 | Font *m_font; 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /src/renderer/OpenGL.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/OpenGL.hpp" 2 | 3 | namespace Renderer 4 | { 5 | // create perspective projection matrix 6 | void MakePerspective(Math::Matrix4f &matrix, float fov, float scrRatio, float nearPlane, float farPlane) 7 | { 8 | matrix.Zero(); 9 | 10 | float tanFov = tanf(0.5f * fov); // fov is in radians! 11 | 12 | matrix[0] = 1.f / (scrRatio * tanFov); 13 | matrix[5] = 1.f / tanFov; 14 | matrix[10] = -(farPlane + nearPlane) / (farPlane - nearPlane); 15 | matrix[11] = -1.f; 16 | matrix[14] = -2.f * farPlane * nearPlane / (farPlane - nearPlane); 17 | } 18 | 19 | 20 | // create orthographic projection matrix 21 | void MakeOrthogonal(Math::Matrix4f &matrix, float left, float right, float bottom, float top, float nearPlane, float farPlane) 22 | { 23 | matrix.Identity(); 24 | 25 | matrix[0] = 2.f / (right - left); 26 | matrix[5] = 2.f / (top - bottom); 27 | matrix[10] = -2.f / (farPlane - nearPlane); 28 | matrix[12] = -(right + left) / (right - left); 29 | matrix[13] = -(top + bottom) / (top - bottom); 30 | matrix[14] = -(farPlane + nearPlane) / (farPlane - nearPlane); 31 | } 32 | 33 | // create view matrix 34 | void MakeView(Math::Matrix4f &matrix, const Math::Vector3f &eye, const Math::Vector3f &target, const Math::Vector3f &up) 35 | { 36 | Math::Vector3f z = target; 37 | z.Normalize(); 38 | Math::Vector3f x = z.CrossProduct(up); 39 | x.Normalize(); 40 | Math::Vector3f y = x.CrossProduct(z); 41 | 42 | matrix.Identity(); 43 | 44 | matrix[0] = x.m_x; 45 | matrix[4] = x.m_y; 46 | matrix[8] = x.m_z; 47 | 48 | matrix[1] = y.m_x; 49 | matrix[5] = y.m_y; 50 | matrix[9] = y.m_z; 51 | 52 | matrix[2] = -z.m_x; 53 | matrix[6] = -z.m_y; 54 | matrix[10] = -z.m_z; 55 | 56 | matrix[12] = -x.DotProduct(eye); 57 | matrix[13] = -y.DotProduct(eye); 58 | matrix[14] = z.DotProduct(eye); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/renderer/OpenGL.hpp: -------------------------------------------------------------------------------- 1 | #ifndef OPENGL_INCLUDED 2 | #define OPENGL_INCLUDED 3 | 4 | #ifdef _WIN32 5 | #include 6 | #include "glew-1.11.0/include/GL/glew.h" 7 | #else 8 | #error "Only Windows platform supported for now." 9 | #endif 10 | 11 | #include "Math.hpp" 12 | #include "Utils.hpp" 13 | 14 | namespace Renderer 15 | { 16 | void MakePerspective(Math::Matrix4f &matrix, float fov, float scrRatio, float nearPlane, float farPlane); 17 | void MakeOrthogonal(Math::Matrix4f &matrix, float left, float right, float bottom, float top, float nearPlane, float farPlane); 18 | void MakeView(Math::Matrix4f &matrix, const Math::Vector3f &eye, const Math::Vector3f &target, const Math::Vector3f &up); 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /src/renderer/RenderContext.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/RenderContext.hpp" 2 | 3 | void RenderContext::Init(const char *title, int x, int y, int w, int h) 4 | { 5 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 6 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 7 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); 8 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); 9 | SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); 10 | 11 | window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); 12 | 13 | context = SDL_GL_CreateContext(window); 14 | 15 | SDL_GetWindowSize(window, &width, &height); 16 | 17 | // VSync control 18 | SDL_GL_SetSwapInterval(0); 19 | 20 | halfWidth = width >> 1; 21 | halfHeight = height >> 1; 22 | 23 | scrRatio = (float)width / (float)height; 24 | 25 | /* 26 | * ----(1.0)--- 27 | * | | 28 | * -ratio ratio 29 | * | | 30 | * ---(-1.0)--- 31 | */ 32 | left = -scrRatio; 33 | right = scrRatio; 34 | bottom = -1.0f; 35 | top = 1.0f; 36 | } 37 | 38 | void RenderContext::Destroy() 39 | { 40 | if (window) 41 | { 42 | SDL_GL_DeleteContext(context); 43 | SDL_DestroyWindow(window); 44 | window = NULL; 45 | } 46 | } -------------------------------------------------------------------------------- /src/renderer/RenderContext.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RENDERCONTEXT_INCLUDED 2 | #define RENDERCONTEXT_INCLUDED 3 | 4 | #include "Math.hpp" 5 | #include "renderer/OpenGL.hpp" 6 | #include 7 | #include 8 | 9 | /* 10 | * SDL-based OpenGL render context 11 | */ 12 | 13 | class RenderContext 14 | { 15 | public: 16 | RenderContext() : window(NULL), 17 | fov(75.f * PIdiv180), 18 | nearPlane(0.1f), 19 | farPlane(1000.f), 20 | scrRatio(0.0f), 21 | width(0), 22 | height(0), 23 | halfWidth(0), 24 | halfHeight(0), 25 | left(0.0f), 26 | right(0.0f), 27 | bottom(0.0f), 28 | top(0.0f) 29 | { 30 | } 31 | 32 | void Init(const char *title, int x, int y, int w, int h); 33 | void Destroy(); 34 | 35 | SDL_Window *window; 36 | SDL_GLContext context; 37 | 38 | float fov; 39 | float nearPlane; 40 | float farPlane; 41 | float scrRatio; 42 | int width; 43 | int height; 44 | int halfWidth; 45 | int halfHeight; 46 | 47 | // ortho parameters 48 | float left; 49 | float right; 50 | float bottom; 51 | float top; 52 | 53 | Math::Matrix4f ModelViewProjectionMatrix; // global MVP used to orient the entire world 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /src/renderer/Shader.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_HPP 2 | #define SHADER_HPP 3 | 4 | #include "renderer/OpenGL.hpp" 5 | 6 | // Group shader programs and their uniform locations together 7 | enum UniformId 8 | { 9 | ModelViewProjectionMatrix, 10 | TextureMatrix, 11 | VertexColor, 12 | RenderLightmaps, 13 | UseLightmaps, 14 | UseAlphaTest, 15 | WorldScaleFactor, 16 | NUM_UNIFORMS 17 | }; 18 | 19 | struct ShaderProgram 20 | { 21 | GLuint id; 22 | GLuint vertShader; 23 | GLuint fragShader; 24 | 25 | GLint uniforms[NUM_UNIFORMS]; 26 | 27 | ShaderProgram() : id(0), vertShader(0), fragShader(0) 28 | { 29 | for (int i = 0; i < NUM_UNIFORMS; i++) 30 | { 31 | uniforms[i] = -1; 32 | } 33 | } 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /src/renderer/ShaderManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SHADERMANAGER_HPP 2 | #define SHADERMANAGER_HPP 3 | 4 | #include "renderer/OpenGL.hpp" 5 | #include "renderer/Shader.hpp" 6 | #include 7 | 8 | class ShaderManager 9 | { 10 | public: 11 | // specific shaders 12 | enum ShaderName 13 | { 14 | BasicShader, 15 | FontShader, 16 | OVRFrustumShader, 17 | NUM_SHADERS 18 | }; 19 | 20 | static ShaderManager* GetInstance(); 21 | 22 | void LoadShaders(); 23 | void DestroyShaders(); 24 | 25 | const ShaderProgram& GetShaderProgram(ShaderName type) const { return m_shaderProgram[type]; } 26 | const ShaderProgram& GetActiveShader() const { return m_shaderProgram[m_activeShader]; } 27 | const ShaderProgram& UseShaderProgram(ShaderName type); 28 | void DisableShader(); 29 | private: 30 | ShaderManager() : m_activeShader(NUM_SHADERS) 31 | { 32 | } 33 | 34 | ~ShaderManager(); 35 | 36 | std::string ReadShaderFromFile(const char *filename); 37 | void CompileShader(GLuint *newShader, GLenum shaderType, const char *shaderSrc); 38 | void LoadShader(ShaderName shaderName, const char* vshFilename, const char *fshFilename); 39 | bool LinkShader(GLuint* const pProgramObject, const GLuint VertexShader, const GLuint FragmentShader); 40 | ShaderName m_activeShader; 41 | 42 | ShaderProgram m_shaderProgram[NUM_SHADERS]; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/renderer/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/Texture.hpp" 2 | #include "stb_image/stb_image.h" 3 | 4 | 5 | Texture::Texture( const char *filename ) : m_texId(0) 6 | { 7 | m_textureData = stbi_load(filename, &m_width, &m_height, &m_components, 0); 8 | } 9 | 10 | 11 | Texture::~Texture() 12 | { 13 | if(m_textureData != NULL) 14 | stbi_image_free( m_textureData ); 15 | 16 | if (glIsTexture(m_texId)) 17 | { 18 | glDeleteTextures(1, &m_texId); 19 | } 20 | } 21 | 22 | GLuint Texture::Load() 23 | { 24 | // texture was already bound or could not be loaded - return texId/0 25 | if(m_textureData == NULL) 26 | return m_texId; 27 | 28 | glGenTextures(1, &m_texId); 29 | glBindTexture(GL_TEXTURE_2D, m_texId); 30 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 32 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 33 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 34 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 35 | 36 | glTexImage2D(GL_TEXTURE_2D, 0, m_components, m_width, m_height, 0, m_components == 3 ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, m_textureData); 37 | 38 | stbi_image_free( m_textureData ); 39 | 40 | m_textureData = NULL; 41 | 42 | return m_texId; 43 | } -------------------------------------------------------------------------------- /src/renderer/Texture.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTURE_INCLUDED 2 | #define TEXTURE_INCLUDED 3 | 4 | #include "renderer/OpenGL.hpp" 5 | 6 | /* 7 | * Basic texture 8 | */ 9 | 10 | class Texture 11 | { 12 | public: 13 | friend class TextureManager; 14 | 15 | const int Width() const { return m_width; } 16 | const int Height() const { return m_height; } 17 | const int Components() const { return m_components; } 18 | const GLuint Id() const { return m_texId; } 19 | 20 | private: 21 | Texture(const char *filename); 22 | ~Texture(); 23 | 24 | GLuint Load(); 25 | 26 | int m_width; 27 | int m_height; 28 | int m_components; 29 | GLuint m_texId; 30 | unsigned char *m_textureData; 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /src/renderer/TextureManager.cpp: -------------------------------------------------------------------------------- 1 | #include "renderer/TextureManager.hpp" 2 | 3 | 4 | TextureManager* TextureManager::GetInstance() 5 | { 6 | static TextureManager instance; 7 | 8 | return &instance; 9 | } 10 | 11 | TextureManager::~TextureManager() 12 | { 13 | ReleaseTextures(); 14 | } 15 | 16 | 17 | void TextureManager::ReleaseTextures() 18 | { 19 | for (std::map::iterator it = m_textures.begin(); it != m_textures.end(); ++it) 20 | { 21 | delete it->second; 22 | } 23 | 24 | m_currentTexture = 0; 25 | } 26 | 27 | Texture *TextureManager::LoadTexture(const char *textureName) 28 | { 29 | if (m_textures.count(textureName) == 0) 30 | { 31 | LOG_MESSAGE("[TextureManager] Loading texture: " << textureName); 32 | Texture *newTex = new Texture(textureName); 33 | 34 | // failed to load texture/file doesn't exist 35 | if (newTex->Load() == 0) 36 | { 37 | delete newTex; 38 | return NULL; 39 | } 40 | 41 | m_textures[textureName] = newTex; 42 | } 43 | 44 | return m_textures[textureName]; 45 | } 46 | 47 | void TextureManager::BindTexture(Texture *t) 48 | { 49 | if (m_currentTexture != t->Id()) 50 | { 51 | m_currentTexture = t->Id(); 52 | glBindTexture(GL_TEXTURE_2D, t->Id()); 53 | } 54 | } 55 | 56 | void TextureManager::UnBindTexture() 57 | { 58 | if (m_currentTexture != 0) 59 | { 60 | glBindTexture(GL_TEXTURE_2D, 0); 61 | m_currentTexture = 0; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/renderer/TextureManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TEXTUREMANAGER_HPP 2 | #define TEXTUREMANAGER_HPP 3 | 4 | #include "renderer/OpenGL.hpp" 5 | #include "renderer/Texture.hpp" 6 | #include 7 | 8 | class TextureManager 9 | { 10 | public: 11 | static TextureManager* GetInstance(); 12 | 13 | Texture *LoadTexture(const char *textureName); 14 | void BindTexture(Texture *t); 15 | void UnBindTexture(); // set current texture to 0; 16 | void ReleaseTextures(); 17 | private: 18 | TextureManager() : m_currentTexture(0) 19 | { 20 | } 21 | 22 | ~TextureManager(); 23 | 24 | std::map m_textures; 25 | GLuint m_currentTexture; 26 | }; 27 | 28 | #endif 29 | --------------------------------------------------------------------------------