├── CMakeLists.txt ├── COPYING ├── Doxyfile ├── FindAssimp.cmake ├── FindGLEW.cmake ├── FindOggVorbis.cmake ├── FindOpenAL.cmake ├── FindOpenVR.cmake ├── FindTinyXML.cmake ├── README.md ├── build_win32 ├── Rpg │ ├── Rpg.vcxproj │ ├── Rpg.vcxproj.filters │ └── Rpg.vcxproj.user ├── Tanks │ ├── Tanks.vcxproj │ ├── Tanks.vcxproj.filters │ └── Tanks.vcxproj.user ├── TestTerrainFancy │ ├── TestTerrainFancy.vcxproj │ ├── TestTerrainFancy.vcxproj.filters │ └── TestTerrainFancy.vcxproj.user ├── TestTerrainFancyOpenVR │ ├── TestTerrainFancyOpenVR.vcxproj │ └── TestTerrainFancyOpenVR.vcxproj.filters ├── TinyGameEngine.sln ├── TinyGameEngine.vcxproj ├── TinyGameEngine.vcxproj.filters ├── TinyGameEngine.vcxproj.user ├── TinyGameEngineOpenVR.vcxproj ├── TinyGameEngineOpenVR.vcxproj.filters └── TinyGameEngineOpenVR.vcxproj.user ├── config.h.cmake ├── data ├── SOURCES ├── font │ ├── OpenBaskerville-0.0.75.ttf │ └── mensch.ttf ├── img │ ├── 512hills.png │ ├── bullet │ │ └── plasma.png │ ├── cm_clay_top.png │ ├── cm_cliff.png │ ├── cm_cliff2.png │ ├── cm_cliff_desert.png │ ├── cm_cliff_desert2.png │ ├── cm_cliff_snow.png │ ├── cm_desert_plants.png │ ├── cm_desert_tile.png │ ├── cm_dirt.png │ ├── cm_dirt_cracked.png │ ├── cm_dirt_desert.png │ ├── cm_dirt_desert2.png │ ├── cm_forest_floor.png │ ├── cm_forest_leaves.png │ ├── cm_forest_pine.png │ ├── cm_grass.png │ ├── cm_grass2.png │ ├── cm_grass3.png │ ├── cm_lakebed_desert.png │ ├── cm_lava.png │ ├── cm_mosaic.png │ ├── cm_moss.png │ ├── cm_mud.png │ ├── cm_pavement.png │ ├── cm_pavement2.png │ ├── cm_pavement3.png │ ├── cm_pavement4.png │ ├── cm_pavement5.png │ ├── cm_planks.png │ ├── cm_planks2.png │ ├── cm_planks3.png │ ├── cm_planks4.png │ ├── cm_planks5.png │ ├── cm_poplar_side.png │ ├── cm_roof.png │ ├── cm_sand.png │ ├── cm_snow.png │ ├── cm_stones.png │ ├── cm_tile_red.png │ ├── cm_tile_white.png │ ├── cm_wall.png │ ├── cm_wall2.png │ ├── cm_wall3.png │ ├── cm_wall4.png │ ├── cm_water.png │ ├── flat.png │ ├── quadbody.png │ ├── quadwheel.png │ ├── sky.png │ ├── tank1.png │ ├── tasmania.png │ ├── terrain │ │ ├── desert_cliff_egypt_2.png │ │ ├── desert_cliff_egypt_2_norm.png │ │ ├── desert_cliff_egypt_2_spec.png │ │ ├── desert_lakebed_dry_b.png │ │ ├── desert_lakebed_dry_b_norm.png │ │ ├── desert_lakebed_dry_b_spec.png │ │ ├── desert_sand_smooth_b.png │ │ ├── desert_sand_smooth_b_norm.png │ │ ├── desert_sand_smooth_b_spec.png │ │ ├── desert_sand_stones.png │ │ ├── desert_sand_stones_norm.png │ │ ├── desert_sand_stones_spec.png │ │ ├── dirt.jpg │ │ ├── dirt_normal.jpg │ │ ├── forest.jpg │ │ ├── forest_normal.jpg │ │ ├── grass.jpg │ │ ├── grass_normal.jpg │ │ ├── rocks.jpg │ │ └── rocks_normal.jpg │ ├── testb.png │ ├── testc.png │ ├── testg.png │ ├── testp.png │ ├── testr.png │ ├── testw.png │ ├── testy.png │ ├── tree0_leaves.png │ ├── tree0_sprite.png │ ├── tree0_trunk.png │ └── tree0_trunk_normal.png ├── mesh │ ├── cubes.dae │ ├── quadbody.dae │ ├── quadwheel.dae │ ├── tank1.dae │ ├── tree0_leaves.obj │ └── tree0_trunk.obj ├── moba │ ├── League_of_Sints_logo.png │ ├── cliff_diffuse.png │ ├── cliff_norm.png │ ├── dire_nexus.dae │ ├── dire_tower.dae │ ├── dire_tower_diffuse.png │ ├── dire_tower_norm.png │ ├── dirt_diffuse.png │ ├── forest_diffuse.png │ ├── forest_norm.png │ ├── gift.png │ ├── grass_diffuse.png │ ├── grass_norm.png │ ├── map.png │ ├── map_attr_dirt.png │ ├── map_attr_forest.png │ ├── map_attr_tile.png │ ├── map_attributes.glsl │ ├── moba.xml │ ├── pine.dae │ ├── pine_diffuse.png │ ├── pine_sprite.png │ ├── radiant_nexus.dae │ ├── radiant_tower.dae │ ├── radiant_tower_diffuse.png │ ├── radiant_tower_norm.png │ ├── sky.png │ ├── tile_diffuse.png │ ├── tile_norm.png │ ├── wolf_diffuse.png │ └── wolf_run.dae ├── rpg.xml ├── rpg │ ├── Achaeus.dae │ ├── Acolyte.dae │ ├── Adult_Red_Dragon.dae │ ├── Arch_Mage.dae │ ├── Boar_Updated.dae │ ├── Cultist.dae │ ├── CyclopsGeneric.dae │ ├── DwarfPaladinFigure.dae │ ├── Dwarf_Bard.dae │ ├── ElfRangerFigure.dae │ ├── ElfRanger_28mm.dae │ ├── ElvenSorcererFigure.dae │ ├── EpicDwarfFigure.dae │ ├── FirbolgDruidFigure.dae │ ├── Giant_Elk.dae │ ├── GrumpRangerFigure.dae │ ├── Hoplite45deg.dae │ ├── Julias_boar200.dae │ ├── Kraken_Tentacle.dae │ ├── Kraken_for_Print3.dae │ ├── Large_Shell.dae │ ├── Merfolk_DandD_character.dae │ ├── Merrow_updated_sculpted.dae │ ├── Pegasus_Updated.dae │ ├── SeaElfPriest.dae │ ├── Simple_Pine_Tree.dae │ ├── Spider_Thin.dae │ ├── VictorianGentleman.dae │ ├── Viking.dae │ ├── Weasel.dae │ ├── assassin_crossbow_ready.dae │ ├── bear_optimize.dae │ ├── buffalo.dae │ ├── dwarven_warrior_by_kevin_mic.dae │ ├── dwarven_warrior_heft_axe.dae │ ├── elf_mage_by_nicoledelancret.dae │ ├── great_white_2.dae │ ├── gryphonflying.dae │ ├── gryphonstanding.dae │ ├── horse.dae │ ├── old_man_staff_out.dae │ ├── old_man_standing_ready.dae │ ├── paladin_drinking_sword_out.dae │ ├── paladin_sword_down.dae │ ├── roman_legionary_spear.dae │ ├── roman_legionary_sword.dae │ ├── spartan.dae │ ├── tiefling_swashbuckler_crouching.dae │ ├── wererat.dae │ └── winged_guardian_defensive.dae ├── shader │ ├── desert.glsl │ └── temperate.glsl └── tanks.xml ├── doc ├── manual.bib └── manual.tex ├── moba ├── CMakeLists.txt └── src │ ├── faction.cpp │ ├── faction.h │ ├── forest.cpp │ ├── forest.h │ ├── game.cpp │ ├── game.h │ ├── minion_type.cpp │ ├── minion_type.h │ ├── moba.cpp │ ├── terrain.cpp │ └── terrain.h ├── rpg ├── CMakeLists.txt └── src │ ├── character.cpp │ ├── character.h │ ├── game.cpp │ ├── game.h │ ├── game_msg.cpp │ ├── messages.cpp │ ├── messages.h │ ├── network.cpp │ ├── network.h │ ├── rpg.cpp │ ├── terrain.cpp │ ├── terrain.h │ ├── voxel.cpp │ └── voxel.h ├── src ├── test_AddRemove.cpp ├── test_AnimatedMeshHorde.cpp ├── test_ComputeTexture.cpp ├── test_Console.cpp ├── test_Font.cpp ├── test_Forest.cpp ├── test_Network.cpp ├── test_Quadtree.cpp ├── test_ReadAnimatedMesh.cpp ├── test_ReadSample.cpp ├── test_ReadStaticMesh.cpp ├── test_RigidBodyCollision.cpp ├── test_RigidBodyPendulum.cpp ├── test_RigidBodySystem.cpp ├── test_SDLApplication.cpp ├── test_ShaderHashing.cpp ├── test_SoundSource.cpp ├── test_StaticMesh.cpp ├── test_StaticMeshHorde.cpp ├── test_Terrain.cpp ├── test_TerrainFancy.cpp ├── test_TerrainFancyEGA.cpp ├── test_TerrainFar.cpp └── test_WorldIconHorde.cpp ├── tanks ├── CMakeLists.txt └── src │ ├── game.cpp │ ├── game.h │ ├── game_msg.cpp │ ├── messages.cpp │ ├── messages.h │ ├── network.cpp │ ├── network.h │ ├── soldier.cpp │ ├── soldier.h │ ├── tank.cpp │ ├── tank.h │ ├── tanks.cpp │ ├── terrain.cpp │ └── terrain.h └── tiny ├── CMakeLists.txt ├── algo ├── gridmap.h └── typecluster.h ├── draw ├── animatedmesh.cpp ├── animatedmesh.h ├── animatedmeshhorde.cpp ├── animatedmeshhorde.h ├── buffer.cpp ├── buffer.h ├── colour.h ├── computetexture.cpp ├── computetexture.h ├── detail │ ├── formats.h │ ├── worldrenderer.cpp │ └── worldrenderer.h ├── effects │ ├── diffuse.cpp │ ├── diffuse.h │ ├── lambert.cpp │ ├── lambert.h │ ├── normals.cpp │ ├── normals.h │ ├── showimage.cpp │ ├── showimage.h │ ├── solid.cpp │ ├── solid.h │ ├── sunsky.cpp │ ├── sunsky.h │ ├── sunskyega.cpp │ ├── sunskyega.h │ ├── sunskyvoxelmap.cpp │ └── sunskyvoxelmap.h ├── glcheck.cpp ├── glcheck.h ├── heightmap │ ├── diamondsquare.h │ ├── heighttocolour.h │ ├── normalmap.h │ ├── resize.h │ ├── scale.h │ └── tangentmap.h ├── iconhorde.cpp ├── iconhorde.h ├── icontexture2d.cpp ├── icontexture2d.h ├── indexbuffer.h ├── lighthorde.cpp ├── lighthorde.h ├── renderable.cpp ├── renderable.h ├── renderer.cpp ├── renderer.h ├── rendererwithcamera.cpp ├── rendererwithcamera.h ├── screensquare.cpp ├── screensquare.h ├── shader.cpp ├── shader.h ├── shaderprogram.cpp ├── shaderprogram.h ├── staticmesh.cpp ├── staticmesh.h ├── staticmeshhorde.cpp ├── staticmeshhorde.h ├── staticmeshhordetexturearray.cpp ├── staticmeshhordetexturearray.h ├── terrain.cpp ├── terrain.h ├── textbox.cpp ├── textbox.h ├── texture.cpp ├── texture.h ├── texture1d.h ├── texture2d.h ├── texture2darray.h ├── texture2dcubearray.h ├── texture3d.h ├── texturebuffer.h ├── tiledhorde.h ├── uniformmap.cpp ├── uniformmap.h ├── vertexbuffer.h ├── vertexbufferinterpreter.h ├── voxelmap.cpp ├── voxelmap.h ├── worldrenderer.cpp └── worldrenderer.h ├── hash ├── md5.cpp └── md5.h ├── img ├── image.cpp ├── image.h └── io │ ├── image.cpp │ └── image.h ├── lod ├── quadtree.cpp └── quadtree.h ├── math ├── genmat.h ├── vec.cpp └── vec.h ├── mesh ├── animatedmesh.cpp ├── animatedmesh.h ├── io │ ├── animatedmesh.cpp │ ├── animatedmesh.h │ ├── detail │ │ └── aimesh.h │ ├── staticmesh.cpp │ └── staticmesh.h ├── staticmesh.cpp └── staticmesh.h ├── net ├── client.cpp ├── client.h ├── console.cpp ├── console.h ├── host.cpp ├── host.h ├── message.cpp └── message.h ├── os ├── application.cpp ├── application.h ├── sdlapplication.cpp └── sdlapplication.h ├── rigid ├── aabbtree.cpp ├── aabbtree.h ├── rigidbody.cpp ├── rigidbody.h ├── triangle.cpp └── triangle.h ├── smp ├── io │ ├── sample.cpp │ └── sample.h ├── sample.cpp └── sample.h └── snd ├── alcheck.cpp ├── alcheck.h ├── buffer.cpp ├── buffer.h ├── detail └── formats.h ├── source.cpp ├── source.h ├── worldsounderer.cpp └── worldsounderer.h /FindAssimp.cmake: -------------------------------------------------------------------------------- 1 | # Based on http://www.openengine.dk/code/extensions/Assimp/FindAssimp.cmake. 2 | # - Try to find Assimp 3 | # Once done this will define 4 | # 5 | # ASSIMP_FOUND - system has Assimp 6 | # ASSIMP_INCLUDE_DIR - the Assimp include directory 7 | # ASSIMP_LIBRARIES - Link these to use Assimp 8 | # 9 | 10 | SET(ASSIMP "assimp") 11 | 12 | FIND_PATH(ASSIMP_INCLUDE_DIR NAMES assimp/scene.h 13 | PATHS 14 | ${ASSIMP_DEPS_INCLUDE_DIR} 15 | ${PROJECT_BINARY_DIR}/include 16 | ${PROJECT_SOURCE_DIR}/include 17 | ${PROJECT_SOURCE_DIR}/libraries/assimp/include 18 | ENV CPATH 19 | /usr/include 20 | /usr/local/include 21 | /opt/local/include 22 | NO_DEFAULT_PATH 23 | ) 24 | 25 | 26 | FIND_LIBRARY(LIBASSIMP 27 | NAMES 28 | ${ASSIMP} 29 | PATHS 30 | ${ASSIMP_DEPS_LIB_DIR} 31 | ${PROJECT_SOURCE_DIR}/libraries/assimp/lib 32 | ENV LD_LIBRARY_PATH 33 | ENV LIBRARY_PATH 34 | /usr/lib 35 | /usr/lib/x86_64-linux-gnu 36 | /usr/local/lib 37 | /opt/local/lib 38 | NO_DEFAULT_PATH 39 | ) 40 | 41 | SET (ASSIMP_LIBRARIES 42 | ${LIBASSIMP} 43 | ) 44 | 45 | IF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARIES) 46 | SET(ASSIMP_FOUND TRUE) 47 | ENDIF(ASSIMP_INCLUDE_DIR AND ASSIMP_LIBRARIES) 48 | 49 | # show the COLLADA_DOM_INCLUDE_DIR and COLLADA_DOM_LIBRARIES variables only in the advanced view 50 | IF(ASSIMP_FOUND) 51 | MARK_AS_ADVANCED(ASSIMP_INCLUDE_DIR ASSIMP_LIBRARIES ) 52 | ENDIF(ASSIMP_FOUND) 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /FindGLEW.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Try to find GLEW library and include path. 3 | # Once done this will define 4 | # 5 | # GLEW_FOUND 6 | # GLEW_INCLUDE_PATH 7 | # GLEW_LIBRARY 8 | # 9 | 10 | IF (WIN32) 11 | FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h 12 | PATHS 13 | $ENV{PROGRAMFILES}/GLEW/include 14 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/include 15 | DOC "The directory where GL/glew.h resides") 16 | FIND_LIBRARY( GLEW_LIBRARY 17 | NAMES glew GLEW glew32 glew32s 18 | PATHS 19 | $ENV{PROGRAMFILES}/GLEW/lib 20 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin 21 | ${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib 22 | DOC "The GLEW library") 23 | ELSE (WIN32) 24 | FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h 25 | /usr/include 26 | /usr/local/include 27 | /sw/include 28 | /opt/local/include 29 | DOC "The directory where GL/glew.h resides") 30 | FIND_LIBRARY( GLEW_LIBRARY 31 | NAMES GLEW glew 32 | PATHS 33 | /usr/lib64 34 | /usr/lib 35 | /usr/local/lib64 36 | /usr/local/lib 37 | /sw/lib 38 | /opt/local/lib 39 | DOC "The GLEW library") 40 | ENDIF (WIN32) 41 | 42 | IF (GLEW_INCLUDE_PATH) 43 | SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") 44 | ELSE (GLEW_INCLUDE_PATH) 45 | SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise") 46 | ENDIF (GLEW_INCLUDE_PATH) 47 | 48 | MARK_AS_ADVANCED( GLEW_FOUND ) -------------------------------------------------------------------------------- /FindTinyXML.cmake: -------------------------------------------------------------------------------- 1 | # - Find TinyXML 2 | # Find the native TinyXML includes and library 3 | # 4 | # TINYXML_FOUND - True if TinyXML found. 5 | # TINYXML_INCLUDE_DIR - where to find tinyxml.h, etc. 6 | # TINYXML_LIBRARIES - List of libraries when using TinyXML. 7 | # 8 | 9 | IF( TINYXML_INCLUDE_DIR ) 10 | # Already in cache, be silent 11 | SET( TinyXML_FIND_QUIETLY TRUE ) 12 | ENDIF( TINYXML_INCLUDE_DIR ) 13 | 14 | FIND_PATH( TINYXML_INCLUDE_DIR "tinyxml.h" 15 | PATH_SUFFIXES "tinyxml" ) 16 | 17 | FIND_LIBRARY( TINYXML_LIBRARIES 18 | NAMES "tinyxml" 19 | PATH_SUFFIXES "tinyxml" ) 20 | 21 | # handle the QUIETLY and REQUIRED arguments and set TINYXML_FOUND to TRUE if 22 | # all listed variables are TRUE 23 | INCLUDE( "FindPackageHandleStandardArgs" ) 24 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( "TinyXML" DEFAULT_MSG TINYXML_INCLUDE_DIR TINYXML_LIBRARIES ) 25 | 26 | MARK_AS_ADVANCED( TINYXML_INCLUDE_DIR TINYXML_LIBRARIES ) 27 | -------------------------------------------------------------------------------- /build_win32/Rpg/Rpg.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /build_win32/Rpg/Rpg.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /build_win32/Tanks/Tanks.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | -------------------------------------------------------------------------------- /build_win32/Tanks/Tanks.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /build_win32/TestTerrainFancy/TestTerrainFancy.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /build_win32/TestTerrainFancy/TestTerrainFancy.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /build_win32/TestTerrainFancyOpenVR/TestTerrainFancyOpenVR.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /build_win32/TinyGameEngine.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /build_win32/TinyGameEngineOpenVR.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /config.h.cmake: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define SCREEN_WIDTH 1920 6 | #define SCREEN_HEIGHT 980 7 | #define DATA_DIRECTORY std::string("${TINY_SOURCE_DIR}/data/") 8 | 9 | #ifndef NDEBUG 10 | #cmakedefine DEBUG 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /data/font/OpenBaskerville-0.0.75.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/font/OpenBaskerville-0.0.75.ttf -------------------------------------------------------------------------------- /data/font/mensch.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/font/mensch.ttf -------------------------------------------------------------------------------- /data/img/512hills.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/512hills.png -------------------------------------------------------------------------------- /data/img/bullet/plasma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/bullet/plasma.png -------------------------------------------------------------------------------- /data/img/cm_clay_top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_clay_top.png -------------------------------------------------------------------------------- /data/img/cm_cliff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_cliff.png -------------------------------------------------------------------------------- /data/img/cm_cliff2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_cliff2.png -------------------------------------------------------------------------------- /data/img/cm_cliff_desert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_cliff_desert.png -------------------------------------------------------------------------------- /data/img/cm_cliff_desert2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_cliff_desert2.png -------------------------------------------------------------------------------- /data/img/cm_cliff_snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_cliff_snow.png -------------------------------------------------------------------------------- /data/img/cm_desert_plants.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_desert_plants.png -------------------------------------------------------------------------------- /data/img/cm_desert_tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_desert_tile.png -------------------------------------------------------------------------------- /data/img/cm_dirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_dirt.png -------------------------------------------------------------------------------- /data/img/cm_dirt_cracked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_dirt_cracked.png -------------------------------------------------------------------------------- /data/img/cm_dirt_desert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_dirt_desert.png -------------------------------------------------------------------------------- /data/img/cm_dirt_desert2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_dirt_desert2.png -------------------------------------------------------------------------------- /data/img/cm_forest_floor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_forest_floor.png -------------------------------------------------------------------------------- /data/img/cm_forest_leaves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_forest_leaves.png -------------------------------------------------------------------------------- /data/img/cm_forest_pine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_forest_pine.png -------------------------------------------------------------------------------- /data/img/cm_grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_grass.png -------------------------------------------------------------------------------- /data/img/cm_grass2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_grass2.png -------------------------------------------------------------------------------- /data/img/cm_grass3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_grass3.png -------------------------------------------------------------------------------- /data/img/cm_lakebed_desert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_lakebed_desert.png -------------------------------------------------------------------------------- /data/img/cm_lava.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_lava.png -------------------------------------------------------------------------------- /data/img/cm_mosaic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_mosaic.png -------------------------------------------------------------------------------- /data/img/cm_moss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_moss.png -------------------------------------------------------------------------------- /data/img/cm_mud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_mud.png -------------------------------------------------------------------------------- /data/img/cm_pavement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_pavement.png -------------------------------------------------------------------------------- /data/img/cm_pavement2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_pavement2.png -------------------------------------------------------------------------------- /data/img/cm_pavement3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_pavement3.png -------------------------------------------------------------------------------- /data/img/cm_pavement4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_pavement4.png -------------------------------------------------------------------------------- /data/img/cm_pavement5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_pavement5.png -------------------------------------------------------------------------------- /data/img/cm_planks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_planks.png -------------------------------------------------------------------------------- /data/img/cm_planks2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_planks2.png -------------------------------------------------------------------------------- /data/img/cm_planks3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_planks3.png -------------------------------------------------------------------------------- /data/img/cm_planks4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_planks4.png -------------------------------------------------------------------------------- /data/img/cm_planks5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_planks5.png -------------------------------------------------------------------------------- /data/img/cm_poplar_side.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_poplar_side.png -------------------------------------------------------------------------------- /data/img/cm_roof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_roof.png -------------------------------------------------------------------------------- /data/img/cm_sand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_sand.png -------------------------------------------------------------------------------- /data/img/cm_snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_snow.png -------------------------------------------------------------------------------- /data/img/cm_stones.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_stones.png -------------------------------------------------------------------------------- /data/img/cm_tile_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_tile_red.png -------------------------------------------------------------------------------- /data/img/cm_tile_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_tile_white.png -------------------------------------------------------------------------------- /data/img/cm_wall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_wall.png -------------------------------------------------------------------------------- /data/img/cm_wall2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_wall2.png -------------------------------------------------------------------------------- /data/img/cm_wall3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_wall3.png -------------------------------------------------------------------------------- /data/img/cm_wall4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_wall4.png -------------------------------------------------------------------------------- /data/img/cm_water.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/cm_water.png -------------------------------------------------------------------------------- /data/img/flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/flat.png -------------------------------------------------------------------------------- /data/img/quadbody.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/quadbody.png -------------------------------------------------------------------------------- /data/img/quadwheel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/quadwheel.png -------------------------------------------------------------------------------- /data/img/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/sky.png -------------------------------------------------------------------------------- /data/img/tank1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tank1.png -------------------------------------------------------------------------------- /data/img/tasmania.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tasmania.png -------------------------------------------------------------------------------- /data/img/terrain/desert_cliff_egypt_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_cliff_egypt_2.png -------------------------------------------------------------------------------- /data/img/terrain/desert_cliff_egypt_2_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_cliff_egypt_2_norm.png -------------------------------------------------------------------------------- /data/img/terrain/desert_cliff_egypt_2_spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_cliff_egypt_2_spec.png -------------------------------------------------------------------------------- /data/img/terrain/desert_lakebed_dry_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_lakebed_dry_b.png -------------------------------------------------------------------------------- /data/img/terrain/desert_lakebed_dry_b_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_lakebed_dry_b_norm.png -------------------------------------------------------------------------------- /data/img/terrain/desert_lakebed_dry_b_spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_lakebed_dry_b_spec.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_smooth_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_smooth_b.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_smooth_b_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_smooth_b_norm.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_smooth_b_spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_smooth_b_spec.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_stones.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_stones.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_stones_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_stones_norm.png -------------------------------------------------------------------------------- /data/img/terrain/desert_sand_stones_spec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/desert_sand_stones_spec.png -------------------------------------------------------------------------------- /data/img/terrain/dirt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/dirt.jpg -------------------------------------------------------------------------------- /data/img/terrain/dirt_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/dirt_normal.jpg -------------------------------------------------------------------------------- /data/img/terrain/forest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/forest.jpg -------------------------------------------------------------------------------- /data/img/terrain/forest_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/forest_normal.jpg -------------------------------------------------------------------------------- /data/img/terrain/grass.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/grass.jpg -------------------------------------------------------------------------------- /data/img/terrain/grass_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/grass_normal.jpg -------------------------------------------------------------------------------- /data/img/terrain/rocks.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/rocks.jpg -------------------------------------------------------------------------------- /data/img/terrain/rocks_normal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/terrain/rocks_normal.jpg -------------------------------------------------------------------------------- /data/img/testb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testb.png -------------------------------------------------------------------------------- /data/img/testc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testc.png -------------------------------------------------------------------------------- /data/img/testg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testg.png -------------------------------------------------------------------------------- /data/img/testp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testp.png -------------------------------------------------------------------------------- /data/img/testr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testr.png -------------------------------------------------------------------------------- /data/img/testw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testw.png -------------------------------------------------------------------------------- /data/img/testy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/testy.png -------------------------------------------------------------------------------- /data/img/tree0_leaves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tree0_leaves.png -------------------------------------------------------------------------------- /data/img/tree0_sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tree0_sprite.png -------------------------------------------------------------------------------- /data/img/tree0_trunk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tree0_trunk.png -------------------------------------------------------------------------------- /data/img/tree0_trunk_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/img/tree0_trunk_normal.png -------------------------------------------------------------------------------- /data/moba/League_of_Sints_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/League_of_Sints_logo.png -------------------------------------------------------------------------------- /data/moba/cliff_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/cliff_diffuse.png -------------------------------------------------------------------------------- /data/moba/cliff_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/cliff_norm.png -------------------------------------------------------------------------------- /data/moba/dire_tower_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/dire_tower_diffuse.png -------------------------------------------------------------------------------- /data/moba/dire_tower_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/dire_tower_norm.png -------------------------------------------------------------------------------- /data/moba/dirt_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/dirt_diffuse.png -------------------------------------------------------------------------------- /data/moba/forest_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/forest_diffuse.png -------------------------------------------------------------------------------- /data/moba/forest_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/forest_norm.png -------------------------------------------------------------------------------- /data/moba/gift.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/gift.png -------------------------------------------------------------------------------- /data/moba/grass_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/grass_diffuse.png -------------------------------------------------------------------------------- /data/moba/grass_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/grass_norm.png -------------------------------------------------------------------------------- /data/moba/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/map.png -------------------------------------------------------------------------------- /data/moba/map_attr_dirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/map_attr_dirt.png -------------------------------------------------------------------------------- /data/moba/map_attr_forest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/map_attr_forest.png -------------------------------------------------------------------------------- /data/moba/map_attr_tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/map_attr_tile.png -------------------------------------------------------------------------------- /data/moba/map_attributes.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | precision highp float; 4 | 5 | uniform sampler2D source; 6 | uniform vec2 sourceInverseSize; 7 | uniform float mapScale; 8 | 9 | in vec2 tex; 10 | out vec4 colour; 11 | 12 | void main(void) 13 | { 14 | float height = texture(source, tex).x; 15 | float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x; 16 | float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x; 17 | float north = texture(source, tex + vec2(0.0f, sourceInverseSize.y)).x; 18 | float south = texture(source, tex - vec2(0.0f, sourceInverseSize.y)).x; 19 | 20 | vec3 normal = normalize(vec3(west - east, mapScale, south - north)); 21 | 22 | float slope = 1.0f - normal.y; 23 | float type = 0.0f; 24 | 25 | if (slope > 0.1f) 26 | { 27 | type = 0.0f; 28 | } 29 | else 30 | { 31 | type = 2.0f; 32 | } 33 | 34 | colour = vec4(type/255.0f, 0.0f, 0.0f, 0.0f); 35 | } 36 | -------------------------------------------------------------------------------- /data/moba/pine_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/pine_diffuse.png -------------------------------------------------------------------------------- /data/moba/pine_sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/pine_sprite.png -------------------------------------------------------------------------------- /data/moba/radiant_tower_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/radiant_tower_diffuse.png -------------------------------------------------------------------------------- /data/moba/radiant_tower_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/radiant_tower_norm.png -------------------------------------------------------------------------------- /data/moba/sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/sky.png -------------------------------------------------------------------------------- /data/moba/tile_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/tile_diffuse.png -------------------------------------------------------------------------------- /data/moba/tile_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/tile_norm.png -------------------------------------------------------------------------------- /data/moba/wolf_diffuse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BasFaggingerAuer/tiny-game-engine/922f407f065e9e691f0b71f35355118330f6180a/data/moba/wolf_diffuse.png -------------------------------------------------------------------------------- /data/shader/desert.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | precision highp float; 4 | 5 | uniform sampler2D source; 6 | uniform vec2 sourceInverseSize; 7 | uniform float mapScale; 8 | 9 | in vec2 tex; 10 | out vec4 colour; 11 | 12 | void main(void) 13 | { 14 | float height = texture(source, tex).x; 15 | float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x; 16 | float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x; 17 | float north = texture(source, tex + vec2(0.0f, sourceInverseSize.y)).x; 18 | float south = texture(source, tex - vec2(0.0f, sourceInverseSize.y)).x; 19 | 20 | vec3 normal = normalize(vec3(west - east, mapScale, south - north)); 21 | 22 | float slope = 1.0f - normal.y; 23 | float type = 0.0f; 24 | 25 | if (slope > 0.5f) 26 | { 27 | type = 3.0f; 28 | } 29 | else if (slope > 0.1f) 30 | { 31 | type = 2.0f; 32 | } 33 | else if (slope > 0.05f || height > 10.0f) 34 | { 35 | type = 1.0f; 36 | } 37 | else 38 | { 39 | type = 0.0f; 40 | } 41 | 42 | colour = vec4(type/255.0f, 0.0f, 0.0f, 0.0f); 43 | } 44 | -------------------------------------------------------------------------------- /data/shader/temperate.glsl: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | precision highp float; 4 | 5 | uniform sampler2D source; 6 | uniform vec2 sourceInverseSize; 7 | uniform float mapScale; 8 | 9 | in vec2 tex; 10 | out vec4 colour; 11 | 12 | void main(void) 13 | { 14 | float height = texture(source, tex).x; 15 | float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x; 16 | float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x; 17 | float north = texture(source, tex + vec2(0.0f, sourceInverseSize.y)).x; 18 | float south = texture(source, tex - vec2(0.0f, sourceInverseSize.y)).x; 19 | 20 | vec3 normal = normalize(vec3(west - east, mapScale, south - north)); 21 | 22 | float slope = 1.0f - normal.y; 23 | float forestFrac = clamp(max(0.0f, 1.0f - 9.0f*slope)*max(0.0f, 1.0f - 0.1f*(height - 450.0f)), 0.0f, 1.0f); 24 | float grassFrac = (1.0f - forestFrac)*clamp(max(0.0f, 1.0f - 7.0f*slope)*max(0.0f, 1.0f - 0.1f*(height - 1200.0f)), 0.0f, 1.0f); 25 | float mudFrac = (1.0f - grassFrac - forestFrac)*clamp(max(0.0f, 1.0f - 1.0f*slope), 0.0f, 1.0f); 26 | float rockFrac = 1.0f - forestFrac - grassFrac - mudFrac; 27 | 28 | colour = vec4(0.0f); 29 | colour.x = (0.0f*forestFrac + 1.0f*grassFrac + 2.0f*mudFrac + 3.0f*rockFrac)/255.0f; 30 | } 31 | -------------------------------------------------------------------------------- /data/tanks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/manual.bib: -------------------------------------------------------------------------------- 1 | @InProceedings{Oren1994, 2 | author = {M. Oren and S.K. Nayar}, 3 | title = {{G}eneralization of {L}ambert's {R}eflectance {M}odel}, 4 | booktitle = {ACM 21st Annual Conference on Computer Graphics and Interactive Techniques (SIGGRAPH)}, 5 | pages = {239--246}, 6 | month = {Jul}, 7 | year = {1994} 8 | } 9 | 10 | -------------------------------------------------------------------------------- /moba/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(TinyXML REQUIRED) 2 | 3 | include_directories(${OPENGL_INCLUDE_DIR}) 4 | link_directories(${OPENGL_LIBRARY_DIR}) 5 | include_directories(${GLEW_INCLUDE_DIR}) 6 | link_directories(${GLEW_LIBRARY_DIR}) 7 | include_directories(${OPENAL_INCLUDE_DIR}) 8 | include_directories(${OGGVORBIS_INCLUDE_DIR}) 9 | include_directories(${ASSIMP_INCLUDE_DIR}) 10 | link_directories(${ASSIMP_LIBRARY_DIR}) 11 | include_directories(${SDL2_INCLUDE_DIRS}) 12 | link_directories(${SDL2_LIBRARY_DIRS}) 13 | include_directories(${SDL2_IMAGE_INCLUDE_DIRS}) 14 | link_directories(${SDL2_IMAGE_LIBRARY_DIRS}) 15 | include_directories(${SDL2_TTF_INCLUDE_DIRS}) 16 | link_directories(${SDL2_TTF_LIBRARY_DIRS}) 17 | include_directories(${SDL2_NET_INCLUDE_DIRS}) 18 | link_directories(${SDL2_NET_LIBRARY_DIRS}) 19 | include_directories(${TINYXML_INCLUDE_DIR}) 20 | link_directories(${TINYXML_LIBRARY_DIR}) 21 | include_directories(${TINY_SOURCE_DIR}) 22 | include_directories(${TINY_BINARY_DIR}) 23 | 24 | set(MOBA_LIBS 25 | tinygame 26 | ${ASSIMP_LIBRARIES} 27 | ${OPENGL_LIBRARY} 28 | ${GLEW_LIBRARY} 29 | ${OPENAL_LIBRARY} 30 | ${OGGVORBIS_LIBRARIES} 31 | ${SDL2_LIBRARIES} 32 | ${SDL2IMAGE_LIBRARIES} 33 | ${SDL2TTF_LIBRARIES} 34 | ${SDL2NET_LIBRARIES} 35 | ${TINYXML_LIBRARIES}) 36 | 37 | add_executable(moba src/moba.cpp 38 | src/terrain.cpp 39 | src/forest.cpp 40 | src/minion_type.cpp 41 | src/faction.cpp 42 | src/game.cpp) 43 | 44 | target_link_libraries(moba ${MOBA_LIBS}) 45 | 46 | -------------------------------------------------------------------------------- /moba/src/faction.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "terrain.h" 31 | 32 | namespace moba 33 | { 34 | 35 | class MinionSpawner 36 | { 37 | public: 38 | MinionSpawner(const std::string &, TiXmlElement *); 39 | ~MinionSpawner(); 40 | 41 | std::string minionType; 42 | std::string pathName; 43 | int nrSpawn; 44 | float radius; 45 | float cooldownTime; 46 | float currentTime; 47 | }; 48 | 49 | class Faction 50 | { 51 | public: 52 | Faction(const std::string &, TiXmlElement *); 53 | ~Faction(); 54 | 55 | std::list plantBuildings(const GameTerrain *terrain); 56 | 57 | std::string name; 58 | 59 | float nexusScale; 60 | float nexusRadius; 61 | tiny::vec4 nexusPosition; 62 | tiny::draw::StaticMeshHorde *nexusMesh; 63 | tiny::draw::RGBATexture2D *nexusDiffuseTexture; 64 | tiny::draw::RGBATexture2D *nexusNormalTexture; 65 | 66 | float towerScale; 67 | float towerRadius; 68 | std::list towerPositions; 69 | tiny::draw::StaticMeshHorde *towerMeshes; 70 | tiny::draw::RGBATexture2D *towerDiffuseTexture; 71 | tiny::draw::RGBATexture2D *towerNormalTexture; 72 | 73 | std::list minionSpawners; 74 | }; 75 | 76 | } //namespace moba 77 | 78 | -------------------------------------------------------------------------------- /moba/src/forest.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include "terrain.h" 33 | 34 | namespace moba 35 | { 36 | 37 | class GameForest 38 | { 39 | public: 40 | GameForest(const std::string &, TiXmlElement *); 41 | ~GameForest(); 42 | 43 | std::list plantTrees(const GameTerrain *terrain); 44 | void setCameraPosition(const tiny::vec3 &); 45 | 46 | tiny::draw::StaticMeshHorde *treeMeshes; 47 | tiny::draw::WorldIconHorde *treeSprites; 48 | 49 | private: 50 | int nrPlantedTrees; 51 | int maxNrHighDetailTrees; 52 | int maxNrLowDetailTrees; 53 | int biomeIndex; 54 | float collisionRadius; 55 | float treeHighDetailRadius; 56 | float treeLowDetailRadius; 57 | 58 | tiny::lod::Quadtree *quadtree; 59 | 60 | tiny::draw::RGBATexture2D *treeDiffuseTexture; 61 | tiny::draw::RGBATexture2D *treeSpriteTexture; 62 | tiny::vec2 treeSpriteSize; 63 | 64 | std::vector allTreeHighDetailInstances; 65 | std::vector allTreeLowDetailInstances; 66 | 67 | std::vector visibleTreeInstanceIndices; 68 | std::vector visibleTreeHighDetailInstances; 69 | std::vector visibleTreeLowDetailInstances; 70 | 71 | std::vector treePositions; 72 | }; 73 | 74 | } //namespace moba 75 | 76 | -------------------------------------------------------------------------------- /moba/src/minion_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "terrain.h" 29 | 30 | namespace moba 31 | { 32 | 33 | class MinionType 34 | { 35 | public: 36 | MinionType(const std::string &, TiXmlElement *); 37 | ~MinionType(); 38 | 39 | void updateInstances(); 40 | 41 | std::string name; 42 | 43 | float maxSpeed; 44 | float radius; 45 | 46 | int maxNrInstances; 47 | tiny::mesh::AnimatedMesh mesh; 48 | tiny::draw::RGBTexture2D *diffuseTexture; 49 | tiny::draw::RGBTexture2D *normalTexture; 50 | tiny::draw::AnimationTextureBuffer *animationTexture; 51 | tiny::draw::AnimatedMeshHorde *horde; 52 | 53 | std::list instances; 54 | }; 55 | 56 | class MinionPath 57 | { 58 | public: 59 | MinionPath(const std::string &, TiXmlElement *); 60 | ~MinionPath(); 61 | 62 | void plantNodes(const GameTerrain *); 63 | 64 | std::string name; 65 | std::vector nodes; 66 | }; 67 | 68 | class Minion 69 | { 70 | public: 71 | Minion(const std::string &, const std::string &, const tiny::vec2 &); 72 | ~Minion(); 73 | 74 | std::string name; 75 | std::string type; 76 | 77 | std::string path; 78 | unsigned int pathIndex; 79 | 80 | tiny::vec2 pos; 81 | float angle; 82 | 83 | std::string action; 84 | float actionTime; 85 | }; 86 | 87 | } //namespace moba 88 | 89 | -------------------------------------------------------------------------------- /moba/src/moba.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "game.h" 27 | 28 | int main(int argc, char **argv) 29 | { 30 | tiny::os::Application *application = 0; 31 | moba::Game *game = 0; 32 | 33 | try 34 | { 35 | int screenWidth = 1280; 36 | int screenHeight = 960; 37 | 38 | if (argc != 2 && argc != 4) 39 | { 40 | std::cerr << "Usage: " << argv[0] << " path/to/resources [screenwidth screenheight]" << std::endl; 41 | throw std::exception(); 42 | } 43 | 44 | if (argc == 4) 45 | { 46 | screenWidth = atoi(argv[2]); 47 | screenHeight = atoi(argv[3]); 48 | } 49 | 50 | application = new tiny::os::SDLApplication(screenWidth, screenHeight); 51 | } 52 | catch (std::exception &e) 53 | { 54 | std::cerr << "Unable to initialize SDL!" << std::endl; 55 | return -1; 56 | } 57 | 58 | try 59 | { 60 | game = new moba::Game(application, argv[1]); 61 | } 62 | catch (std::exception &e) 63 | { 64 | delete application; 65 | std::cerr << "Unable to initialize game!" << std::endl; 66 | return -1; 67 | } 68 | 69 | while (application->isRunning()) 70 | { 71 | game->update(application, application->pollEvents()); 72 | game->render(); 73 | application->paint(); 74 | } 75 | 76 | delete game; 77 | delete application; 78 | 79 | std::cerr << "Goodbye." << std::endl; 80 | 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /rpg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(TinyXML REQUIRED) 2 | 3 | include_directories(${OPENGL_INCLUDE_DIR}) 4 | link_directories(${OPENGL_LIBRARY_DIR}) 5 | include_directories(${GLEW_INCLUDE_DIR}) 6 | link_directories(${GLEW_LIBRARY_DIR}) 7 | include_directories(${OPENAL_INCLUDE_DIR}) 8 | include_directories(${OGGVORBIS_INCLUDE_DIR}) 9 | include_directories(${ASSIMP_INCLUDE_DIR}) 10 | link_directories(${ASSIMP_LIBRARY_DIR}) 11 | include_directories(${SDL2_INCLUDE_DIRS}) 12 | link_directories(${SDL2_LIBRARY_DIRS}) 13 | include_directories(${SDL2_IMAGE_INCLUDE_DIRS}) 14 | link_directories(${SDL2_IMAGE_LIBRARY_DIRS}) 15 | include_directories(${SDL2_TTF_INCLUDE_DIRS}) 16 | link_directories(${SDL2_TTF_LIBRARY_DIRS}) 17 | include_directories(${SDL2_NET_INCLUDE_DIRS}) 18 | link_directories(${SDL2_NET_LIBRARY_DIRS}) 19 | include_directories(${TINYXML_INCLUDE_DIR}) 20 | link_directories(${TINYXML_LIBRARY_DIR}) 21 | include_directories(${TINY_SOURCE_DIR}) 22 | include_directories(${TINY_BINARY_DIR}) 23 | 24 | set(RPG_LIBS 25 | tinygame 26 | ${ASSIMP_LIBRARIES} 27 | ${OPENGL_LIBRARY} 28 | ${GLEW_LIBRARY} 29 | ${OPENAL_LIBRARY} 30 | ${OGGVORBIS_LIBRARIES} 31 | ${SDL2_LIBRARIES} 32 | ${SDL2IMAGE_LIBRARIES} 33 | ${SDL2TTF_LIBRARIES} 34 | ${SDL2NET_LIBRARIES} 35 | ${TINYXML_LIBRARIES}) 36 | 37 | add_executable(rpg src/rpg.cpp 38 | src/messages.cpp 39 | src/network.cpp 40 | src/terrain.cpp 41 | src/voxel.cpp 42 | src/character.cpp 43 | src/game.cpp 44 | src/game_msg.cpp) 45 | 46 | target_link_libraries(rpg ${RPG_LIBS}) 47 | 48 | -------------------------------------------------------------------------------- /rpg/src/messages.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace rpg 22 | { 23 | 24 | namespace msg 25 | { 26 | 27 | namespace mt 28 | { 29 | 30 | enum mt_t 31 | { 32 | none = 0, 33 | help, 34 | host, 35 | join, 36 | disconnect, 37 | addPlayer, 38 | removePlayer, 39 | welcomePlayer, 40 | terrainOffset, 41 | sunDirection, 42 | listCharacterTypes, 43 | listCharacters, 44 | addCharacter, 45 | removeCharacter, 46 | updateCharacter, 47 | setPlayerCharacter, 48 | updateVoxel, 49 | startVoxelMap, 50 | chunkVoxelMap, 51 | updateVoxelBasePlane, 52 | playerSpawnRequest 53 | }; 54 | 55 | } //namespace mt 56 | 57 | } //namespace msg 58 | 59 | class GameMessageTranslator : public tiny::net::MessageTranslator 60 | { 61 | public: 62 | GameMessageTranslator(); 63 | ~GameMessageTranslator(); 64 | }; 65 | 66 | } //namespace rpg 67 | 68 | -------------------------------------------------------------------------------- /rpg/src/network.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "messages.h" 24 | #include "network.h" 25 | #include "game.h" 26 | 27 | using namespace rpg; 28 | 29 | GameClient::GameClient(const std::string &hostName, const unsigned int &hostPort, Game *a_game) : 30 | tiny::net::Client(hostName, hostPort, a_game->getTranslator()), 31 | game(a_game) 32 | { 33 | 34 | } 35 | 36 | GameClient::~GameClient() 37 | { 38 | 39 | } 40 | 41 | void GameClient::receiveMessage(const Message &message) 42 | { 43 | game->applyMessage(0, message); 44 | } 45 | 46 | void GameClient::disconnectedFromHost() 47 | { 48 | game->clear(); 49 | } 50 | 51 | GameHost::GameHost(const unsigned int &hostPort, Game *a_game) : 52 | tiny::net::Host(hostPort, a_game->getTranslator()), 53 | game(a_game) 54 | { 55 | 56 | } 57 | 58 | GameHost::~GameHost() 59 | { 60 | 61 | } 62 | 63 | void GameHost::addClient(const unsigned int &clientIndex) 64 | { 65 | Message msg(msg::mt::addPlayer); 66 | 67 | msg << clientIndex; 68 | 69 | game->applyMessage(0, msg); 70 | } 71 | 72 | void GameHost::receiveMessage(const unsigned int &clientIndex, const Message &message) 73 | { 74 | game->applyMessage(clientIndex, message); 75 | } 76 | 77 | void GameHost::removeClient(const unsigned int &clientIndex) 78 | { 79 | Message msg(msg::mt::removePlayer); 80 | 81 | msg << clientIndex; 82 | 83 | game->applyMessage(0, msg); 84 | } 85 | 86 | GameConsole::GameConsole(Game *a_game) : 87 | game(a_game) 88 | { 89 | 90 | } 91 | 92 | GameConsole::~GameConsole() 93 | { 94 | 95 | } 96 | 97 | void GameConsole::execute(const std::string &command) 98 | { 99 | Message message; 100 | 101 | if (command.empty()) 102 | { 103 | return; 104 | } 105 | 106 | if (!game->getTranslator()->textToMessage(command, message)) 107 | { 108 | addLine("Unknown command or parameters!"); 109 | return; 110 | } 111 | 112 | if (!game->userMessage(message)) 113 | { 114 | addLine("Invalid command!"); 115 | } 116 | } 117 | 118 | void GameConsole::update() 119 | { 120 | game->updateConsole(); 121 | } 122 | 123 | 124 | -------------------------------------------------------------------------------- /rpg/src/network.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace rpg 24 | { 25 | 26 | typedef tiny::net::Message Message; 27 | 28 | class Game; 29 | 30 | class GameConsole : public tiny::net::Console 31 | { 32 | public: 33 | GameConsole(Game *); 34 | ~GameConsole(); 35 | 36 | protected: 37 | void execute(const std::string &); 38 | void update(); 39 | 40 | private: 41 | Game * const game; 42 | }; 43 | 44 | class GameHost : public tiny::net::Host 45 | { 46 | public: 47 | GameHost(const unsigned int &, Game *); 48 | ~GameHost(); 49 | 50 | protected: 51 | void addClient(const unsigned int &); 52 | void receiveMessage(const unsigned int &, const tiny::net::Message &); 53 | void removeClient(const unsigned int &); 54 | 55 | private: 56 | Game * const game; 57 | }; 58 | 59 | class GameClient : public tiny::net::Client 60 | { 61 | public: 62 | GameClient(const std::string &, const unsigned int &, Game *); 63 | ~GameClient(); 64 | 65 | protected: 66 | void receiveMessage(const tiny::net::Message &); 67 | void disconnectedFromHost(); 68 | 69 | private: 70 | Game * const game; 71 | }; 72 | 73 | } //namespace rpg 74 | 75 | -------------------------------------------------------------------------------- /rpg/src/rpg.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "messages.h" 27 | #include "network.h" 28 | #include "game.h" 29 | 30 | int main(int argc, char **argv) 31 | { 32 | tiny::os::Application *application = 0; 33 | rpg::Game *game = 0; 34 | 35 | try 36 | { 37 | int screenWidth = 1600; 38 | int screenHeight = 900; 39 | std::string basePath = ""; 40 | 41 | if (argc != 1 && argc != 2 && argc != 4) 42 | { 43 | std::cerr << "Usage: " << argv[0] << " [path/to/resources/] [screenwidth screenheight]" << std::endl; 44 | throw std::exception(); 45 | } 46 | 47 | if (argc >= 2) 48 | { 49 | basePath = std::string(argv[1]); 50 | } 51 | 52 | if (argc >= 4) 53 | { 54 | screenWidth = atoi(argv[2]); 55 | screenHeight = atoi(argv[3]); 56 | } 57 | 58 | application = new tiny::os::SDLApplication(screenWidth, screenHeight); 59 | 60 | game = new rpg::Game(application, basePath); 61 | } 62 | catch (std::exception &) 63 | { 64 | std::cerr << "Unable to start application!" << std::endl; 65 | return -1; 66 | } 67 | 68 | while (application->isRunning()) 69 | { 70 | game->update(application, static_cast(application->pollEvents())); 71 | game->render(); 72 | application->paint(); 73 | } 74 | 75 | delete game; 76 | delete application; 77 | 78 | std::cerr << "Goodbye." << std::endl; 79 | 80 | return 0; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /rpg/src/voxel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace rpg 29 | { 30 | 31 | class GameVoxelMap 32 | { 33 | public: 34 | GameVoxelMap(const std::string &, TiXmlElement *); 35 | ~GameVoxelMap(); 36 | 37 | void createVoxelPalette(); 38 | bool createFromCompressedVoxels(const std::string &, const float &); 39 | void setVoxelBasePlane(const int &); 40 | void createCheckerboard(); 41 | void lightCheckerboardSphere(const tiny::ivec3 &, const int &); 42 | void setVoxel(const tiny::ivec3 &, const int &); 43 | int getVoxel(const tiny::ivec3 &) const; 44 | float getScale() const; 45 | float getScaledWidth() const; 46 | float getScaledHeight() const; 47 | float getScaledDepth() const; 48 | tiny::draw::VoxelIntersection getIntersection(const tiny::vec3 &, const tiny::vec3 &) const; 49 | int getBaseHeight(const int &, const int &) const; 50 | std::string getCompressedVoxels() const; 51 | 52 | tiny::draw::VoxelMap *voxelMap; 53 | tiny::draw::RGBATexture3D *voxelTexture; 54 | 55 | private: 56 | tiny::draw::RGBTexture2DCubeArray *voxelCubeArrayTexture; 57 | }; 58 | 59 | } //namespace rpg 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/test_ComputeTexture.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | tiny::os::Application *application = 0; 32 | tiny::draw::RGBATexture2D *testTexture = 0; 33 | tiny::draw::ComputeTexture *computeTexture = 0; 34 | 35 | using namespace std; 36 | 37 | void setup() 38 | { 39 | vector inputTextures; 40 | vector outputTextures; 41 | const string fragmentShader = 42 | "#version 150\n" 43 | "\n" 44 | "precision highp float;\n" 45 | "\n" 46 | "uniform sampler2D source;\n" 47 | "uniform vec2 sourceInverseSize;\n" 48 | "\n" 49 | "in vec2 tex;\n" 50 | "out vec4 colour;\n" 51 | "\n" 52 | "void main(void)\n" 53 | "{\n" 54 | " colour = vec4(texture(source, tex).xyz, 1.0f);\n" 55 | "}\n"; 56 | 57 | inputTextures.push_back("source"); 58 | outputTextures.push_back("colour"); 59 | 60 | computeTexture = new tiny::draw::ComputeTexture(inputTextures, SCREEN_WIDTH, SCREEN_HEIGHT, outputTextures, fragmentShader); 61 | testTexture = new tiny::draw::RGBATexture2D(tiny::img::Image::createTestImage(256)); 62 | computeTexture->setInput(*testTexture, "source"); 63 | } 64 | 65 | void cleanup() 66 | { 67 | delete computeTexture; 68 | delete testTexture; 69 | } 70 | 71 | void render() 72 | { 73 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 74 | 75 | computeTexture->compute(); 76 | } 77 | 78 | int main(int, char **) 79 | { 80 | try 81 | { 82 | application = new tiny::os::SDLApplication(SCREEN_WIDTH, SCREEN_HEIGHT); 83 | setup(); 84 | } 85 | catch (std::exception &e) 86 | { 87 | cerr << "Unable to start application!" << endl; 88 | return -1; 89 | } 90 | 91 | while (application->isRunning()) 92 | { 93 | application->pollEvents(); 94 | render(); 95 | application->paint(); 96 | } 97 | 98 | cleanup(); 99 | delete application; 100 | 101 | cerr << "Goodbye." << endl; 102 | 103 | return 0; 104 | } 105 | 106 | -------------------------------------------------------------------------------- /src/test_SDLApplication.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | tiny::os::Application *application = 0; 28 | 29 | using namespace std; 30 | 31 | void setup() 32 | { 33 | 34 | } 35 | 36 | void cleanup() 37 | { 38 | 39 | } 40 | 41 | void render() 42 | { 43 | 44 | } 45 | 46 | int main(int, char **) 47 | { 48 | try 49 | { 50 | application = new tiny::os::SDLApplication(SCREEN_WIDTH, SCREEN_HEIGHT); 51 | setup(); 52 | } 53 | catch (std::exception &e) 54 | { 55 | cerr << "Unable to start application!" << endl; 56 | return -1; 57 | } 58 | 59 | while (application->isRunning()) 60 | { 61 | application->pollEvents(); 62 | render(); 63 | application->paint(); 64 | } 65 | 66 | cleanup(); 67 | delete application; 68 | 69 | cerr << "Goodbye." << endl; 70 | 71 | return 0; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /tanks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(TinyXML REQUIRED) 2 | 3 | include_directories(${OPENGL_INCLUDE_DIR}) 4 | link_directories(${OPENGL_LIBRARY_DIR}) 5 | include_directories(${GLEW_INCLUDE_DIR}) 6 | link_directories(${GLEW_LIBRARY_DIR}) 7 | include_directories(${OPENAL_INCLUDE_DIR}) 8 | include_directories(${OGGVORBIS_INCLUDE_DIR}) 9 | include_directories(${ASSIMP_INCLUDE_DIR}) 10 | link_directories(${ASSIMP_LIBRARY_DIR}) 11 | include_directories(${SDL2_INCLUDE_DIRS}) 12 | link_directories(${SDL2_LIBRARY_DIRS}) 13 | include_directories(${SDL2_IMAGE_INCLUDE_DIRS}) 14 | link_directories(${SDL2_IMAGE_LIBRARY_DIRS}) 15 | include_directories(${SDL2_TTF_INCLUDE_DIRS}) 16 | link_directories(${SDL2_TTF_LIBRARY_DIRS}) 17 | include_directories(${SDL2_NET_INCLUDE_DIRS}) 18 | link_directories(${SDL2_NET_LIBRARY_DIRS}) 19 | include_directories(${TINYXML_INCLUDE_DIR}) 20 | link_directories(${TINYXML_LIBRARY_DIR}) 21 | include_directories(${TINY_SOURCE_DIR}) 22 | include_directories(${TINY_BINARY_DIR}) 23 | 24 | set(TANKS_LIBS 25 | tinygame 26 | ${ASSIMP_LIBRARIES} 27 | ${OPENGL_LIBRARY} 28 | ${GLEW_LIBRARY} 29 | ${OPENAL_LIBRARY} 30 | ${OGGVORBIS_LIBRARIES} 31 | ${SDL2_LIBRARIES} 32 | ${SDL2IMAGE_LIBRARIES} 33 | ${SDL2TTF_LIBRARIES} 34 | ${SDL2NET_LIBRARIES} 35 | ${TINYXML_LIBRARIES}) 36 | 37 | add_executable(tanks src/tanks.cpp 38 | src/messages.cpp 39 | src/network.cpp 40 | src/terrain.cpp 41 | src/soldier.cpp 42 | src/game.cpp 43 | src/game_msg.cpp) 44 | 45 | target_link_libraries(tanks ${TANKS_LIBS}) 46 | 47 | -------------------------------------------------------------------------------- /tanks/src/messages.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace tanks 22 | { 23 | 24 | namespace msg 25 | { 26 | 27 | namespace mt 28 | { 29 | 30 | enum mt_t 31 | { 32 | none = 0, 33 | help, 34 | host, 35 | join, 36 | disconnect, 37 | addPlayer, 38 | removePlayer, 39 | welcomePlayer, 40 | terrainOffset, 41 | addSoldier, 42 | removeSoldier, 43 | updateSoldier, 44 | setPlayerSoldier, 45 | playerSpawnRequest, 46 | playerShootRequest, 47 | addBullet, 48 | addExplosion 49 | }; 50 | 51 | } //namespace mt 52 | 53 | } //namespace msg 54 | 55 | class GameMessageTranslator : public tiny::net::MessageTranslator 56 | { 57 | public: 58 | GameMessageTranslator(); 59 | ~GameMessageTranslator(); 60 | }; 61 | 62 | } //namespace tanks 63 | 64 | -------------------------------------------------------------------------------- /tanks/src/network.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "messages.h" 24 | #include "network.h" 25 | #include "game.h" 26 | 27 | using namespace tanks; 28 | 29 | GameClient::GameClient(const std::string &hostName, const unsigned int &hostPort, Game *a_game) : 30 | tiny::net::Client(hostName, hostPort, a_game->getTranslator()), 31 | game(a_game) 32 | { 33 | 34 | } 35 | 36 | GameClient::~GameClient() 37 | { 38 | 39 | } 40 | 41 | void GameClient::receiveMessage(const Message &message) 42 | { 43 | game->applyMessage(0, message); 44 | } 45 | 46 | void GameClient::disconnectedFromHost() 47 | { 48 | game->clear(); 49 | } 50 | 51 | GameHost::GameHost(const unsigned int &hostPort, Game *a_game) : 52 | tiny::net::Host(hostPort, a_game->getTranslator()), 53 | game(a_game) 54 | { 55 | 56 | } 57 | 58 | GameHost::~GameHost() 59 | { 60 | 61 | } 62 | 63 | void GameHost::addClient(const unsigned int &clientIndex) 64 | { 65 | Message msg(msg::mt::addPlayer); 66 | 67 | msg << clientIndex; 68 | 69 | game->applyMessage(0, msg); 70 | } 71 | 72 | void GameHost::receiveMessage(const unsigned int &clientIndex, const Message &message) 73 | { 74 | game->applyMessage(clientIndex, message); 75 | } 76 | 77 | void GameHost::removeClient(const unsigned int &clientIndex) 78 | { 79 | Message msg(msg::mt::removePlayer); 80 | 81 | msg << clientIndex; 82 | 83 | game->applyMessage(0, msg); 84 | } 85 | 86 | GameConsole::GameConsole(Game *a_game) : 87 | game(a_game) 88 | { 89 | 90 | } 91 | 92 | GameConsole::~GameConsole() 93 | { 94 | 95 | } 96 | 97 | void GameConsole::execute(const std::string &command) 98 | { 99 | Message message; 100 | 101 | if (command.empty()) 102 | { 103 | return; 104 | } 105 | 106 | if (!game->getTranslator()->textToMessage(command, message)) 107 | { 108 | addLine("Unknown command or parameters!"); 109 | return; 110 | } 111 | 112 | if (!game->userMessage(message)) 113 | { 114 | addLine("Invalid command!"); 115 | } 116 | } 117 | 118 | void GameConsole::update() 119 | { 120 | game->updateConsole(); 121 | } 122 | 123 | 124 | -------------------------------------------------------------------------------- /tanks/src/network.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace tanks 24 | { 25 | 26 | typedef tiny::net::Message Message; 27 | 28 | class Game; 29 | 30 | class GameConsole : public tiny::net::Console 31 | { 32 | public: 33 | GameConsole(Game *); 34 | ~GameConsole(); 35 | 36 | protected: 37 | void execute(const std::string &); 38 | void update(); 39 | 40 | private: 41 | Game * const game; 42 | }; 43 | 44 | class GameHost : public tiny::net::Host 45 | { 46 | public: 47 | GameHost(const unsigned int &, Game *); 48 | ~GameHost(); 49 | 50 | protected: 51 | void addClient(const unsigned int &); 52 | void receiveMessage(const unsigned int &, const tiny::net::Message &); 53 | void removeClient(const unsigned int &); 54 | 55 | private: 56 | Game * const game; 57 | }; 58 | 59 | class GameClient : public tiny::net::Client 60 | { 61 | public: 62 | GameClient(const std::string &, const unsigned int &, Game *); 63 | ~GameClient(); 64 | 65 | protected: 66 | void receiveMessage(const tiny::net::Message &); 67 | void disconnectedFromHost(); 68 | 69 | private: 70 | Game * const game; 71 | }; 72 | 73 | } //namespace tanks 74 | 75 | -------------------------------------------------------------------------------- /tanks/src/tank.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace tanks 28 | { 29 | 30 | struct TankInstance 31 | { 32 | TankInstance(const unsigned int &a_type = 0) : 33 | type(a_type), 34 | controls(0), 35 | x(0.0f), 36 | q(0.0f, 0.0f, 0.0f, 1.0f), 37 | P(0.0f), 38 | L(0.0f) 39 | { 40 | 41 | } 42 | 43 | unsigned int type; 44 | unsigned int controls; 45 | tiny::vec3 x; //position 46 | tiny::vec4 q; //orientation 47 | tiny::vec3 P; //linear momentum 48 | tiny::vec3 L; //angular momentum 49 | }; 50 | 51 | class TankType 52 | { 53 | public: 54 | TankType(const std::string &, TiXmlElement *); 55 | ~TankType(); 56 | 57 | void clearInstances(); 58 | void addInstance(const TankInstance &); 59 | void updateInstances(); 60 | 61 | std::string name; 62 | float mass; 63 | float inertia; 64 | float radius1; 65 | float radius2; 66 | tiny::vec3 thrust_pos[4]; 67 | tiny::vec3 thrust_force[4]; 68 | 69 | tiny::draw::StaticMeshHorde *horde; 70 | tiny::draw::RGBTexture2D *diffuseTexture; 71 | tiny::draw::RGBTexture2D *normalTexture; 72 | int nrInstances; 73 | int maxNrInstances; 74 | std::vector instances; 75 | }; 76 | 77 | } //namespace tanks 78 | 79 | -------------------------------------------------------------------------------- /tanks/src/tanks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "messages.h" 27 | #include "network.h" 28 | #include "game.h" 29 | 30 | int main(int argc, char **argv) 31 | { 32 | tiny::os::Application *application = 0; 33 | tanks::Game *game = 0; 34 | 35 | try 36 | { 37 | int screenWidth = 800; 38 | int screenHeight = 600; 39 | 40 | if (argc != 2 && argc != 4) 41 | { 42 | std::cerr << "Usage: " << argv[0] << " path/to/resources [screenwidth screenheight]" << std::endl; 43 | throw std::exception(); 44 | } 45 | 46 | if (argc == 4) 47 | { 48 | screenWidth = atoi(argv[2]); 49 | screenHeight = atoi(argv[3]); 50 | } 51 | 52 | application = new tiny::os::SDLApplication(screenWidth, screenHeight); 53 | game = new tanks::Game(application, argv[1]); 54 | } 55 | catch (std::exception &) 56 | { 57 | std::cerr << "Unable to start application!" << std::endl; 58 | return -1; 59 | } 60 | 61 | while (application->isRunning()) 62 | { 63 | game->update(application, static_cast(application->pollEvents())); 64 | game->render(); 65 | application->paint(); 66 | } 67 | 68 | delete game; 69 | delete application; 70 | 71 | std::cerr << "Goodbye." << std::endl; 72 | 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /tiny/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${OPENGL_INCLUDE_DIR}) 2 | include_directories(${GLEW_INCLUDE_DIR}) 3 | include_directories(${OPENAL_INCLUDE_DIR}) 4 | include_directories(${OGGVORBIS_INCLUDE_DIR}) 5 | include_directories(${ASSIMP_INCLUDE_DIR}) 6 | include_directories(${SDL2_INCLUDE_DIRS}) 7 | include_directories(${SDL2_IMAGE_INCLUDE_DIRS}) 8 | include_directories(${SDL2_TTF_INCLUDE_DIRS}) 9 | include_directories(${SDL2_NET_INCLUDE_DIRS}) 10 | include_directories(${CMAKE_SOURCE_DIR}) 11 | 12 | if(ENABLE_OPENVR) 13 | include_directories(${OPENVR_INCLUDE_DIRS}) 14 | endif() 15 | 16 | add_library(tinygame 17 | math/vec.cpp 18 | hash/md5.cpp 19 | net/message.cpp 20 | net/host.cpp 21 | net/client.cpp 22 | net/console.cpp 23 | img/image.cpp 24 | img/io/image.cpp 25 | smp/sample.cpp 26 | smp/io/sample.cpp 27 | snd/alcheck.cpp 28 | snd/buffer.cpp 29 | snd/source.cpp 30 | snd/worldsounderer.cpp 31 | lod/quadtree.cpp 32 | mesh/staticmesh.cpp 33 | mesh/animatedmesh.cpp 34 | mesh/io/staticmesh.cpp 35 | mesh/io/animatedmesh.cpp 36 | rigid/aabbtree.cpp 37 | rigid/triangle.cpp 38 | rigid/rigidbody.cpp 39 | draw/glcheck.cpp 40 | draw/buffer.cpp 41 | draw/uniformmap.cpp 42 | draw/renderable.cpp 43 | draw/renderer.cpp 44 | draw/shader.cpp 45 | draw/shaderprogram.cpp 46 | draw/texture.cpp 47 | draw/computetexture.cpp 48 | draw/screensquare.cpp 49 | draw/rendererwithcamera.cpp 50 | draw/worldrenderer.cpp 51 | draw/detail/worldrenderer.cpp 52 | draw/staticmesh.cpp 53 | draw/staticmeshhorde.cpp 54 | draw/staticmeshhordetexturearray.cpp 55 | draw/animatedmesh.cpp 56 | draw/animatedmeshhorde.cpp 57 | draw/icontexture2d.cpp 58 | draw/iconhorde.cpp 59 | draw/textbox.cpp 60 | draw/lighthorde.cpp 61 | draw/terrain.cpp 62 | draw/voxelmap.cpp 63 | draw/effects/diffuse.cpp 64 | draw/effects/normals.cpp 65 | draw/effects/lambert.cpp 66 | draw/effects/sunsky.cpp 67 | draw/effects/sunskyega.cpp 68 | draw/effects/sunskyvoxelmap.cpp 69 | draw/effects/solid.cpp 70 | draw/effects/showimage.cpp 71 | os/application.cpp 72 | os/sdlapplication.cpp) 73 | 74 | -------------------------------------------------------------------------------- /tiny/draw/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::draw; 20 | 21 | BufferInterface::BufferInterface(const size_t &a_sizeInBytes, const GLenum &a_target, const GLenum &a_usage) : 22 | sizeInBytes(0), 23 | target(a_target), 24 | usage(a_usage), 25 | bufferIndex(0) 26 | { 27 | resizeDeviceBuffer(a_sizeInBytes); 28 | } 29 | 30 | BufferInterface::BufferInterface(const BufferInterface &a_buffer) : 31 | sizeInBytes(0), 32 | target(a_buffer.target), 33 | usage(a_buffer.usage), 34 | bufferIndex(0) 35 | { 36 | resizeDeviceBuffer(a_buffer.sizeInBytes); 37 | } 38 | 39 | BufferInterface::~BufferInterface() 40 | { 41 | destroyDeviceBuffer(); 42 | } 43 | 44 | GLuint BufferInterface::getIndex() const 45 | { 46 | return bufferIndex; 47 | } 48 | 49 | void BufferInterface::bind() const 50 | { 51 | GL_CHECK(glBindBuffer(target, bufferIndex)); 52 | } 53 | 54 | void BufferInterface::unbind() const 55 | { 56 | GL_CHECK(glBindBuffer(target, 0)); 57 | } 58 | 59 | void BufferInterface::createDeviceBuffer() 60 | { 61 | GL_CHECK(glGenBuffers(1, &bufferIndex)); 62 | 63 | if (bufferIndex == 0) 64 | throw std::bad_alloc(); 65 | } 66 | 67 | void BufferInterface::destroyDeviceBuffer() 68 | { 69 | //Frees all data bound to this class on the device. 70 | if (bufferIndex != 0) GL_CHECK(glDeleteBuffers(1, &bufferIndex)); 71 | 72 | sizeInBytes = 0; 73 | bufferIndex = 0; 74 | } 75 | 76 | void BufferInterface::resizeDeviceBuffer(const size_t &a_sizeInBytes) 77 | { 78 | //Do not perform needless re-allocation. 79 | if (sizeInBytes == a_sizeInBytes) return; 80 | 81 | //Create new device array. 82 | sizeInBytes = a_sizeInBytes; 83 | 84 | if (sizeInBytes == 0) 85 | { 86 | destroyDeviceBuffer(); 87 | return; 88 | } 89 | 90 | //Allocate new buffer if necessary. 91 | if (bufferIndex == 0) createDeviceBuffer(); 92 | 93 | //Resize buffer. 94 | GL_CHECK(glBindBuffer(target, bufferIndex)); 95 | GL_CHECK(glBufferData(target, sizeInBytes, 0, usage)); 96 | GL_CHECK(glBindBuffer(target, 0)); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /tiny/draw/colour.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015, Matthijs van Dorp. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | class Colour 30 | { 31 | private: 32 | unsigned char r; /**< Red shade from 0 to 255. */ 33 | unsigned char g; /**< Green shade from 0 to 255. */ 34 | unsigned char b; /**< Blue shade from 0 to 255. */ 35 | unsigned char a; /**< Alpha shade from 0 to 255. */ 36 | public: 37 | Colour(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a = 255) : 38 | r(_r), g(_g), b(_b), a(_a) {} 39 | 40 | vec4 toVector(void) const { return vec4( (1.0f/255.0f)*r, (1.0f/255.0f)*g, (1.0f/255.0f)*b, (1.0f/255.0f)*a); } 41 | }; 42 | } // end namespace tiny 43 | 44 | } // end namespace draw 45 | -------------------------------------------------------------------------------- /tiny/draw/detail/formats.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace tiny 28 | { 29 | 30 | namespace draw 31 | { 32 | 33 | namespace detail 34 | { 35 | 36 | template 37 | inline GLenum getOpenGLDataType() {return GL_UNSIGNED_BYTE;} 38 | 39 | template<> 40 | inline GLenum getOpenGLDataType() {return GL_FLOAT;} 41 | template<> 42 | inline GLenum getOpenGLDataType() {return GL_UNSIGNED_BYTE;} 43 | template<> 44 | inline GLenum getOpenGLDataType() {return GL_INT;} 45 | template<> 46 | inline GLenum getOpenGLDataType() {return GL_UNSIGNED_INT;} 47 | 48 | template 49 | inline GLenum getOpenGLChannelType() {return GL_RED;} 50 | 51 | template<> 52 | inline GLenum getOpenGLChannelType<1>() {return GL_RED;} 53 | template<> 54 | inline GLenum getOpenGLChannelType<2>() {return GL_RG;} 55 | template<> 56 | inline GLenum getOpenGLChannelType<3>() {return GL_RGB;} 57 | template<> 58 | inline GLenum getOpenGLChannelType<4>() {return GL_RGBA;} 59 | 60 | template 61 | inline GLint getOpenGLTextureFormat() {return GL_R8;} 62 | 63 | template<> 64 | inline GLint getOpenGLTextureFormat<1, unsigned char>() {return GL_R8;} 65 | template<> 66 | inline GLint getOpenGLTextureFormat<2, unsigned char>() {return GL_RG8;} 67 | template<> 68 | inline GLint getOpenGLTextureFormat<3, unsigned char>() {return GL_RGB8;} 69 | template<> 70 | inline GLint getOpenGLTextureFormat<4, unsigned char>() {return GL_RGBA8;} 71 | 72 | template<> 73 | inline GLint getOpenGLTextureFormat<1, float>() {return GL_R32F;} 74 | template<> 75 | inline GLint getOpenGLTextureFormat<2, float>() {return GL_RG32F;} 76 | template<> 77 | inline GLint getOpenGLTextureFormat<3, float>() {return GL_RGB32F;} 78 | template<> 79 | inline GLint getOpenGLTextureFormat<4, float>() {return GL_RGBA32F;} 80 | 81 | } 82 | 83 | } 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /tiny/draw/detail/worldrenderer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | using namespace tiny::draw::detail; 22 | 23 | WorldRendererStageOne::WorldRendererStageOne(const float &aspectRatio, const int &screenWidth, const int &screenHeight) : 24 | RendererWithCamera(aspectRatio, false, screenWidth, screenHeight) 25 | { 26 | addRenderTarget("diffuse"); 27 | addRenderTarget("worldNormal"); 28 | addRenderTarget("worldPosition"); 29 | } 30 | 31 | WorldRendererStageOne::~WorldRendererStageOne() 32 | { 33 | 34 | } 35 | 36 | WorldRendererStageTwo::WorldRendererStageTwo(const float &aspectRatio, const int &screenWidth, const int &screenHeight) : 37 | RendererWithCamera(aspectRatio, true, screenWidth, screenHeight) 38 | { 39 | addRenderTarget("colour"); 40 | uniformMap.addTexture("diffuseTexture"); 41 | uniformMap.addTexture("worldNormalTexture"); 42 | uniformMap.addTexture("worldPositionTexture"); 43 | } 44 | 45 | WorldRendererStageTwo::~WorldRendererStageTwo() 46 | { 47 | 48 | } 49 | 50 | void WorldRendererStageTwo::setScreenSize(const int &screenWidth, const int &screenHeight) 51 | { 52 | uniformMap.setVec2Uniform(vec2(1.0f/static_cast(screenWidth), 53 | 1.0f/static_cast(screenHeight)), 54 | "inverseScreenSize"); 55 | 56 | this->setViewportSize(screenWidth, screenHeight); 57 | } -------------------------------------------------------------------------------- /tiny/draw/effects/diffuse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::draw::effects; 20 | 21 | Diffuse::Diffuse() 22 | { 23 | 24 | } 25 | 26 | Diffuse::~Diffuse() 27 | { 28 | 29 | } 30 | 31 | std::string Diffuse::getFragmentShaderCode() const 32 | { 33 | return std::string( 34 | "#version 150\n" 35 | "\n" 36 | "precision highp float;\n" 37 | "\n" 38 | "uniform sampler2D diffuseTexture;\n" 39 | "uniform vec2 inverseScreenSize;\n" 40 | "\n" 41 | "out vec4 colour;\n" 42 | "\n" 43 | "void main(void)\n" 44 | "{\n" 45 | " vec2 tex = gl_FragCoord.xy*inverseScreenSize;\n" 46 | " vec4 diffuse = texture(diffuseTexture, tex);\n" 47 | " \n" 48 | " colour = vec4(diffuse.xyz, 1.0f);\n" 49 | "}\n"); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tiny/draw/effects/diffuse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class Diffuse : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | Diffuse(); 41 | ~Diffuse(); 42 | 43 | std::string getFragmentShaderCode() const; 44 | }; 45 | 46 | } 47 | 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tiny/draw/effects/lambert.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny; 20 | using namespace tiny::draw::effects; 21 | 22 | Lambert::Lambert() 23 | { 24 | setLight(normalize(vec3(1.0f, 1.0f, 1.0f))); 25 | } 26 | 27 | Lambert::~Lambert() 28 | { 29 | 30 | } 31 | 32 | std::string Lambert::getFragmentShaderCode() const 33 | { 34 | return std::string( 35 | "#version 150\n" 36 | "\n" 37 | "precision highp float;\n" 38 | "\n" 39 | "uniform sampler2D diffuseTexture;\n" 40 | "uniform sampler2D worldNormalTexture;\n" 41 | "\n" 42 | "uniform vec2 inverseScreenSize;\n" 43 | "uniform vec3 lightDirection;\n" 44 | "\n" 45 | "out vec4 colour;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " vec2 tex = gl_FragCoord.xy*inverseScreenSize;\n" 50 | " vec4 diffuse = texture(diffuseTexture, tex);\n" 51 | " vec4 worldNormal = texture(worldNormalTexture, tex);\n" 52 | " \n" 53 | " colour = vec4(max(0.0f, dot(worldNormal.xyz, lightDirection))*diffuse.xyz, 1.0f);\n" 54 | "}\n"); 55 | } 56 | 57 | void Lambert::setLight(const vec3 &a_light) 58 | { 59 | light = normalize(a_light); 60 | uniformMap.setVec3Uniform(light, "lightDirection"); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /tiny/draw/effects/lambert.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class Lambert : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | Lambert(); 41 | ~Lambert(); 42 | 43 | std::string getFragmentShaderCode() const; 44 | 45 | void setLight(const vec3 &); 46 | 47 | private: 48 | vec3 light; 49 | }; 50 | 51 | } 52 | 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /tiny/draw/effects/normals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::draw::effects; 20 | 21 | Normals::Normals() 22 | { 23 | 24 | } 25 | 26 | Normals::~Normals() 27 | { 28 | 29 | } 30 | 31 | std::string Normals::getFragmentShaderCode() const 32 | { 33 | return std::string( 34 | "#version 150\n" 35 | "\n" 36 | "precision highp float;\n" 37 | "\n" 38 | "uniform sampler2D worldNormalTexture;\n" 39 | "uniform vec2 inverseScreenSize;\n" 40 | "\n" 41 | "out vec4 colour;\n" 42 | "\n" 43 | "void main(void)\n" 44 | "{\n" 45 | " vec2 tex = gl_FragCoord.xy*inverseScreenSize;\n" 46 | " vec3 normal = texture(worldNormalTexture, tex).xyz;\n" 47 | " \n" 48 | " colour = vec4(0.5f*(vec3(1.0f) + normalize(normal)), 1.0f);\n" 49 | "}\n"); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tiny/draw/effects/normals.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class Normals : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | Normals(); 41 | ~Normals(); 42 | 43 | std::string getFragmentShaderCode() const; 44 | }; 45 | 46 | } 47 | 48 | } 49 | 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tiny/draw/effects/showimage.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::draw::effects; 20 | 21 | ShowImage::ShowImage() 22 | { 23 | uniformMap.addTexture("imageTexture"); 24 | setAspectRatio(1.0f); 25 | setAlpha(1.0f); 26 | } 27 | 28 | ShowImage::~ShowImage() 29 | { 30 | 31 | } 32 | 33 | void ShowImage::setAspectRatio(const float &aspectRatio) 34 | { 35 | uniformMap.setFloatUniform(aspectRatio, "aspectRatio"); 36 | } 37 | 38 | void ShowImage::setAlpha(const float &alphaMul) 39 | { 40 | uniformMap.setFloatUniform(alphaMul, "alphaMul"); 41 | } 42 | 43 | std::string ShowImage::getFragmentShaderCode() const 44 | { 45 | return std::string( 46 | "#version 150\n" 47 | "\n" 48 | "precision highp float;\n" 49 | "\n" 50 | "uniform sampler2D imageTexture;\n" 51 | "uniform vec2 inverseScreenSize;\n" 52 | "uniform float aspectRatio;\n" 53 | "uniform float alphaMul;\n" 54 | "\n" 55 | "out vec4 colour;\n" 56 | "\n" 57 | "void main(void)\n" 58 | "{\n" 59 | " vec2 tex = gl_FragCoord.xy*inverseScreenSize;\n" 60 | " \n" 61 | " tex.y = 1.0f - tex.y;\n" 62 | " tex.x = 0.5f + (tex.x - 0.5f)*aspectRatio;\n" 63 | " \n" 64 | " vec4 diffuse = texture(imageTexture, tex);\n" 65 | " \n" 66 | " colour = vec4(diffuse.xyz, alphaMul*diffuse.w);\n" 67 | "}\n"); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tiny/draw/effects/showimage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class ShowImage : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | ShowImage(); 41 | ~ShowImage(); 42 | 43 | template 44 | void setImageTexture(const TextureType &texture) 45 | { 46 | uniformMap.setTexture(texture, "imageTexture"); 47 | } 48 | 49 | void setAspectRatio(const float &); 50 | void setAlpha(const float &); 51 | std::string getFragmentShaderCode() const; 52 | }; 53 | 54 | } 55 | 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /tiny/draw/effects/solid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny; 20 | using namespace tiny::draw::effects; 21 | 22 | Solid::Solid() 23 | { 24 | setColour(vec4(1.0f, 1.0f, 1.0f, 0.0f)); 25 | } 26 | 27 | Solid::~Solid() 28 | { 29 | 30 | } 31 | 32 | std::string Solid::getTypeName() const { 33 | return "Solid"; 34 | } 35 | 36 | std::string Solid::getFragmentShaderCode() const 37 | { 38 | return std::string( 39 | "#version 150\n" 40 | "\n" 41 | "precision highp float;\n" 42 | "\n" 43 | "uniform vec4 mulColour;\n" 44 | "\n" 45 | "out vec4 colour;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " colour = mulColour;\n" 50 | "}\n"); 51 | } 52 | 53 | void Solid::setColour(const vec4 &a_colour) 54 | { 55 | colour = a_colour; 56 | uniformMap.setVec4Uniform(colour, "mulColour"); 57 | } 58 | 59 | -------------------------------------------------------------------------------- /tiny/draw/effects/solid.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class Solid : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | Solid(); 41 | ~Solid(); 42 | std::string getTypeName() const; 43 | 44 | std::string getFragmentShaderCode() const; 45 | 46 | void setColour(const vec4 &); 47 | 48 | private: 49 | vec4 colour; 50 | }; 51 | 52 | } 53 | 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /tiny/draw/effects/sunsky.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class SunSky : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | SunSky(); 41 | ~SunSky(); 42 | std::string getTypeName() const; 43 | 44 | std::string getFragmentShaderCode() const; 45 | 46 | template 47 | void setSkyTexture(const TextureType &texture) 48 | { 49 | const size_t width = texture.getWidth(); 50 | const size_t height = texture.getHeight(); 51 | 52 | if (width > 0) 53 | { 54 | skyColours.resize(width); 55 | 56 | for (size_t i = 0; i < width; ++i) 57 | { 58 | const vec4 colour = texture(i, height - 1); 59 | 60 | skyColours[i] = vec3(colour.x, colour.y, colour.z); 61 | } 62 | } 63 | 64 | setSun(sun); 65 | uniformMap.setTexture(texture, "skyTexture"); 66 | } 67 | 68 | void setSun(const vec3 &); 69 | void setFog(const float &); 70 | 71 | private: 72 | vec3 sun; 73 | std::vector skyColours; 74 | }; 75 | 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /tiny/draw/effects/sunskyega.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class SunSkyEGA : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | SunSkyEGA(); 41 | ~SunSkyEGA(); 42 | std::string getTypeName() const; 43 | 44 | std::string getFragmentShaderCode() const; 45 | 46 | template 47 | void setSkyTexture(const TextureType &texture) 48 | { 49 | const size_t width = texture.getWidth(); 50 | const size_t height = texture.getHeight(); 51 | 52 | if (width > 0) 53 | { 54 | skyColours.resize(width); 55 | 56 | for (size_t i = 0; i < width; ++i) 57 | { 58 | const vec4 colour = texture(i, height - 1); 59 | 60 | skyColours[i] = vec3(colour.x, colour.y, colour.z); 61 | } 62 | } 63 | 64 | setSun(sun); 65 | uniformMap.setTexture(texture, "skyTexture"); 66 | } 67 | 68 | void setSun(const vec3 &); 69 | void setFog(const float &); 70 | 71 | private: 72 | vec3 sun; 73 | std::vector skyColours; 74 | }; 75 | 76 | } 77 | 78 | } 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /tiny/draw/effects/sunskyvoxelmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | namespace effects 35 | { 36 | 37 | class SunSkyVoxelMap : public tiny::draw::ScreenFillingSquare 38 | { 39 | public: 40 | SunSkyVoxelMap(const int &, const float & = 1.0e-3f); 41 | ~SunSkyVoxelMap(); 42 | std::string getTypeName() const; 43 | 44 | std::string getFragmentShaderCode() const; 45 | 46 | template 47 | void setSkyTexture(const TextureType &texture) 48 | { 49 | const size_t width = texture.getWidth(); 50 | const size_t height = texture.getHeight(); 51 | 52 | if (width > 0) 53 | { 54 | skyColours.resize(width); 55 | 56 | for (size_t i = 0; i < width; ++i) 57 | { 58 | const vec4 colour = texture(i, height - 1); 59 | 60 | skyColours[i] = vec3(colour.x, colour.y, colour.z); 61 | } 62 | } 63 | 64 | setSun(sun); 65 | uniformMap.setTexture(texture, "skyTexture"); 66 | } 67 | 68 | template 69 | void setVoxelMap(const TextureType &voxelTexture, const float &scale_) 70 | { 71 | uniformMap.setTexture(voxelTexture, "voxelTexture"); 72 | uniformMap.setFloatUniform(scale_, "voxelScale"); 73 | uniformMap.setVec3Uniform(static_cast(voxelTexture.getWidth()), static_cast(voxelTexture.getHeight()), static_cast(voxelTexture.getDepth()), "voxelTextureSize"); 74 | } 75 | 76 | void setSun(const vec3 &); 77 | void setFog(const float &); 78 | 79 | private: 80 | const int nrSteps; 81 | const float epsilon; 82 | vec3 sun; 83 | std::vector skyColours; 84 | }; 85 | 86 | } 87 | 88 | } 89 | 90 | } 91 | 92 | -------------------------------------------------------------------------------- /tiny/draw/glcheck.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | void tiny::draw::CheckOpenGLError(const char *statement, const char *fileName, const int line) 22 | { 23 | const GLenum error = glGetError(); 24 | 25 | if (error != GL_NO_ERROR) 26 | { 27 | std::cerr << "OpenGL error " << error << " (" << gluErrorString(error) << ") at " << fileName << ":" << line << " for '" << statement << "'!" << std::endl; 28 | abort(); 29 | } 30 | else 31 | { 32 | //std::cerr << statement << " OK." << std::endl; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tiny/draw/glcheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | //From http://stackoverflow.com/questions/11256470/define-a-macro-to-facilitate-opengl-command-debugging. 26 | namespace tiny 27 | { 28 | 29 | namespace draw 30 | { 31 | 32 | void CheckOpenGLError(const char *, const char *, const int); 33 | 34 | } 35 | 36 | } 37 | 38 | #ifndef NDEBUG 39 | #define GL_CHECK(statement) do { \ 40 | statement; \ 41 | tiny::draw::CheckOpenGLError(#statement, __FILE__, __LINE__); \ 42 | } while (0) 43 | #else 44 | #define GL_CHECK(stmt) stmt 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /tiny/draw/heightmap/heighttocolour.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | 30 | template 31 | void computeColourFromHeight(const TextureType1 &heightMap, TextureType2 &colourMap, const float &mapScale) 32 | { 33 | std::vector inputTextures; 34 | std::vector outputTextures; 35 | const std::string fragmentShader = 36 | "#version 150\n" 37 | "\n" 38 | "precision highp float;\n" 39 | "\n" 40 | "uniform sampler2D source;\n" 41 | "uniform vec2 sourceInverseSize;\n" 42 | "uniform float mapScale;\n" 43 | "\n" 44 | "in vec2 tex;\n" 45 | "out vec4 dest;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x;\n" 50 | " float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x;\n" 51 | " float north = texture(source, tex + vec2(0.0f, sourceInverseSize.y)).x;\n" 52 | " float south = texture(source, tex - vec2(0.0f, sourceInverseSize.y)).x;\n" 53 | " \n" 54 | " vec3 n = normalize(vec3(west - east, mapScale, south - north));\n" 55 | " \n" 56 | " float rock = (n.y < 0.5f ? 1.0f : 0.0f);\n" 57 | " float mud = (1.0f - rock)*(n.y < 0.9f ? 1.0f : 0.0f);\n" 58 | " float grass = 1.0f - rock - mud;\n" 59 | " \n" 60 | " dest = rock*vec4(0.6f, 0.6f, 0.6f, 1.0f) + mud*vec4(0.4f, 0.2f, 0.1f, 1.0f) + grass*vec4(0.2f, 0.5f, 0.1f, 1.0f);\n" 61 | "}\n"; 62 | 63 | inputTextures.push_back("source"); 64 | outputTextures.push_back("dest"); 65 | 66 | ComputeTexture *computeTexture = new ComputeTexture(inputTextures, colourMap.getWidth(), colourMap.getHeight(), outputTextures, fragmentShader); 67 | 68 | computeTexture->uniformMap().setFloatUniform(2.0f*mapScale, "mapScale"); 69 | computeTexture->setInput(heightMap, "source"); 70 | computeTexture->setOutput(colourMap, "dest"); 71 | computeTexture->compute(); 72 | colourMap.getFromDevice(); 73 | 74 | delete computeTexture; 75 | } 76 | 77 | } 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /tiny/draw/heightmap/normalmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | 30 | template 31 | void computeNormalMap(const TextureType1 &heightMap, TextureType2 &normalMap, const float &mapScale) 32 | { 33 | std::vector inputTextures; 34 | std::vector outputTextures; 35 | const std::string fragmentShader = 36 | "#version 150\n" 37 | "\n" 38 | "precision highp float;\n" 39 | "\n" 40 | "uniform sampler2D source;\n" 41 | "uniform vec2 sourceInverseSize;\n" 42 | "uniform float mapScale;\n" 43 | "\n" 44 | "in vec2 tex;\n" 45 | "out vec4 normal;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x;\n" 50 | " float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x;\n" 51 | " float north = texture(source, tex + vec2(0.0f, sourceInverseSize.y)).x;\n" 52 | " float south = texture(source, tex - vec2(0.0f, sourceInverseSize.y)).x;\n" 53 | " \n" 54 | " vec3 n = normalize(vec3(west - east, mapScale, south - north));\n" 55 | " \n" 56 | " normal = vec4(0.5f*(n + 1.0f), 1.0f);\n" 57 | "}\n"; 58 | 59 | inputTextures.push_back("source"); 60 | outputTextures.push_back("normal"); 61 | 62 | ComputeTexture *computeTexture = new ComputeTexture(inputTextures, normalMap.getWidth(), normalMap.getHeight(), outputTextures, fragmentShader); 63 | 64 | computeTexture->uniformMap().setFloatUniform(2.0f*mapScale, "mapScale"); 65 | computeTexture->setInput(heightMap, "source"); 66 | computeTexture->setOutput(normalMap, "normal"); 67 | computeTexture->compute(); 68 | normalMap.getFromDevice(); 69 | 70 | delete computeTexture; 71 | } 72 | 73 | } 74 | 75 | } 76 | 77 | -------------------------------------------------------------------------------- /tiny/draw/heightmap/resize.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | 30 | template 31 | void computeResizedTexture(const TextureType1 &source, TextureType2 &dest, const vec2 &scale, const vec2 &add) 32 | { 33 | std::vector inputTextures; 34 | std::vector outputTextures; 35 | const std::string fragmentShader = 36 | "#version 150\n" 37 | "\n" 38 | "precision highp float;\n" 39 | "\n" 40 | "uniform sampler2D source;\n" 41 | "uniform vec2 scaleVec;\n" 42 | "uniform vec2 addVec;\n" 43 | "\n" 44 | "in vec2 tex;\n" 45 | "out vec4 dest;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " dest = texture(source, tex*scaleVec + addVec);\n" 50 | "}\n"; 51 | 52 | inputTextures.push_back("source"); 53 | outputTextures.push_back("dest"); 54 | 55 | ComputeTexture *computeTexture = new ComputeTexture(inputTextures, dest.getWidth(), dest.getHeight(), outputTextures, fragmentShader); 56 | 57 | computeTexture->uniformMap().setVec2Uniform(scale, "scaleVec"); 58 | computeTexture->uniformMap().setVec2Uniform(add, "addVec"); 59 | computeTexture->setInput(source, "source"); 60 | computeTexture->setOutput(dest, "dest"); 61 | computeTexture->compute(); 62 | dest.getFromDevice(); 63 | 64 | delete computeTexture; 65 | } 66 | 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /tiny/draw/heightmap/scale.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | 30 | template 31 | void computeScaledTexture(const TextureType1 &source, TextureType2 &dest, const vec4 &scale, const vec4 &add) 32 | { 33 | std::vector inputTextures; 34 | std::vector outputTextures; 35 | const std::string fragmentShader = 36 | "#version 150\n" 37 | "\n" 38 | "precision highp float;\n" 39 | "\n" 40 | "uniform sampler2D source;\n" 41 | "uniform vec4 scaleVec;\n" 42 | "uniform vec4 addVec;\n" 43 | "\n" 44 | "in vec2 tex;\n" 45 | "out vec4 dest;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " dest = texture(source, tex)*scaleVec + addVec;\n" 50 | "}\n"; 51 | 52 | inputTextures.push_back("source"); 53 | outputTextures.push_back("dest"); 54 | 55 | ComputeTexture *computeTexture = new ComputeTexture(inputTextures, dest.getWidth(), dest.getHeight(), outputTextures, fragmentShader); 56 | 57 | computeTexture->uniformMap().setVec4Uniform(scale, "scaleVec"); 58 | computeTexture->uniformMap().setVec4Uniform(add, "addVec"); 59 | computeTexture->setInput(source, "source"); 60 | computeTexture->setOutput(dest, "dest"); 61 | computeTexture->compute(); 62 | dest.getFromDevice(); 63 | 64 | delete computeTexture; 65 | } 66 | 67 | } 68 | 69 | } 70 | 71 | -------------------------------------------------------------------------------- /tiny/draw/heightmap/tangentmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace draw 28 | { 29 | 30 | template 31 | void computeTangentMap(const TextureType1 &heightMap, TextureType2 &tangentMap, const float &mapScale) 32 | { 33 | std::vector inputTextures; 34 | std::vector outputTextures; 35 | const std::string fragmentShader = 36 | "#version 150\n" 37 | "\n" 38 | "precision highp float;\n" 39 | "\n" 40 | "uniform sampler2D source;\n" 41 | "uniform vec2 sourceInverseSize;\n" 42 | "uniform float mapScale;\n" 43 | "\n" 44 | "in vec2 tex;\n" 45 | "out vec4 tangent;\n" 46 | "\n" 47 | "void main(void)\n" 48 | "{\n" 49 | " float east = texture(source, tex + vec2(sourceInverseSize.x, 0.0f)).x;\n" 50 | " float west = texture(source, tex - vec2(sourceInverseSize.x, 0.0f)).x;\n" 51 | " \n" 52 | " vec3 n = normalize(vec3(mapScale, east - west, 0.0f));\n" 53 | " \n" 54 | " tangent = vec4(0.5f*(n + 1.0f), 1.0f);\n" 55 | "}\n"; 56 | 57 | inputTextures.push_back("source"); 58 | outputTextures.push_back("tangent"); 59 | 60 | ComputeTexture *computeTexture = new ComputeTexture(inputTextures, tangentMap.getWidth(), tangentMap.getHeight(), outputTextures, fragmentShader); 61 | 62 | computeTexture->uniformMap().setFloatUniform(2.0f*mapScale, "mapScale"); 63 | computeTexture->setInput(heightMap, "source"); 64 | computeTexture->setOutput(tangentMap, "tangent"); 65 | computeTexture->compute(); 66 | tangentMap.getFromDevice(); 67 | 68 | delete computeTexture; 69 | } 70 | 71 | } 72 | 73 | } 74 | 75 | -------------------------------------------------------------------------------- /tiny/draw/icontexture2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace tiny 28 | { 29 | 30 | namespace draw 31 | { 32 | 33 | class IconTexture2D : public Texture2D 34 | { 35 | public: 36 | IconTexture2D(const size_t &, const size_t &); 37 | ~IconTexture2D(); 38 | 39 | void clearIcons(); 40 | vec4 packIcon(const img::Image &); 41 | void packIcons(const std::vector &); 42 | vec4 getIcon(const int &) const; 43 | vec2 getMaxIconDimensions() const; 44 | 45 | private: 46 | vec4 addSingleIcon(const img::Image &); 47 | 48 | std::map occupied; 49 | std::list xBounds, yBounds; 50 | std::vector subImages; 51 | ivec2 maxSubImageDimensions; 52 | }; 53 | 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /tiny/draw/indexbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace tiny 22 | { 23 | 24 | namespace draw 25 | { 26 | 27 | /*! \p IndexBuffer : data buffer on an OpenGL device designed for holding vertex data. 28 | * 29 | * \tparam T type of object stored in this buffer 30 | */ 31 | template 32 | class IndexBuffer : public Buffer 33 | { 34 | public: 35 | IndexBuffer(const size_t &a_size) : 36 | Buffer(a_size, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) 37 | { 38 | 39 | } 40 | 41 | IndexBuffer(const IndexBuffer &a_buffer) : 42 | Buffer(a_buffer) 43 | { 44 | 45 | } 46 | 47 | template 48 | IndexBuffer(Iterator first, Iterator last) : 49 | Buffer(first, last, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW) 50 | { 51 | 52 | } 53 | 54 | virtual ~IndexBuffer() 55 | { 56 | 57 | } 58 | }; 59 | 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tiny/draw/lighthorde.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace tiny 26 | { 27 | 28 | namespace draw 29 | { 30 | 31 | struct PointLightInstance 32 | { 33 | PointLightInstance() 34 | { 35 | 36 | } 37 | 38 | PointLightInstance(const vec4 &a_position, 39 | const vec4 &a_colour) : 40 | position(a_position), 41 | colour(a_colour) 42 | { 43 | 44 | } 45 | 46 | vec4 position; 47 | vec4 colour; 48 | }; 49 | 50 | class PointLightVertexBufferInterpreter : public VertexBufferInterpreter 51 | { 52 | public: 53 | PointLightVertexBufferInterpreter(const size_t &); 54 | ~PointLightVertexBufferInterpreter(); 55 | }; 56 | 57 | class PointLightHorde : public Renderable 58 | { 59 | public: 60 | PointLightHorde(const size_t &); 61 | ~PointLightHorde(); 62 | 63 | std::string getVertexShaderCode() const; 64 | std::string getGeometryShaderCode() const; 65 | std::string getFragmentShaderCode() const; 66 | 67 | template 68 | void setLights(Iterator first, Iterator last) 69 | { 70 | nrLights = 0; 71 | 72 | for (Iterator i = first; i != last && nrLights < maxNrLights; ++i) 73 | { 74 | lights[nrLights++] = *i; 75 | } 76 | 77 | lights.sendToDevice(); 78 | } 79 | 80 | protected: 81 | void render(const ShaderProgram &) const; 82 | 83 | private: 84 | const size_t maxNrLights; 85 | size_t nrLights; 86 | PointLightVertexBufferInterpreter lights; 87 | }; 88 | 89 | } 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /tiny/draw/renderable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | using namespace tiny::draw; 23 | 24 | Renderable::Renderable() 25 | { 26 | createVertexArray(); 27 | } 28 | 29 | Renderable::Renderable(const Renderable &) 30 | { 31 | //TODO. 32 | createVertexArray(); 33 | } 34 | 35 | Renderable::~Renderable() 36 | { 37 | GL_CHECK(glDeleteVertexArrays(1, &vertexArrayIndex)); 38 | } 39 | 40 | std::string Renderable::getTypeName() const { 41 | return "Renderable"; 42 | } 43 | 44 | std::string Renderable::getGeometryShaderCode() const 45 | { 46 | return ""; 47 | } 48 | 49 | void Renderable::bind() 50 | { 51 | GL_CHECK(glBindVertexArray(vertexArrayIndex)); 52 | } 53 | 54 | void Renderable::unbind() 55 | { 56 | GL_CHECK(glBindVertexArray(0)); 57 | } 58 | 59 | void Renderable::createVertexArray() 60 | { 61 | GL_CHECK(glGenVertexArrays(1, &vertexArrayIndex)); 62 | 63 | if (vertexArrayIndex == 0) 64 | throw std::bad_alloc(); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /tiny/draw/rendererwithcamera.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | using namespace tiny; 22 | using namespace tiny::draw; 23 | 24 | const float RendererWithCamera::nearClippingPlane = 1.0e-1f; 25 | const float RendererWithCamera::farClippingPlane = 1.0e8f; 26 | 27 | RendererWithCamera::RendererWithCamera(const float &aspectRatio, const bool &a_renderToDefaultFrameBuffer, const int &a_viewportWidth, const int &a_viewportHeight) : 28 | Renderer(a_renderToDefaultFrameBuffer, a_viewportWidth, a_viewportHeight), 29 | cameraToScreen(mat4::frustumMatrix(vec3(-0.07f*aspectRatio, -0.07f, nearClippingPlane), vec3(0.07f*aspectRatio, 0.07f, farClippingPlane))), 30 | cameraToWorld(mat4::identityMatrix()), 31 | worldToCamera(mat4::identityMatrix()), 32 | worldToScreen(mat4::identityMatrix()), 33 | screenToWorld(mat4::identityMatrix()), 34 | cameraPosition(0.0f, 0.0f, 0.0f) 35 | { 36 | updateCameraUniforms(); 37 | } 38 | 39 | RendererWithCamera::~RendererWithCamera() 40 | { 41 | 42 | } 43 | 44 | void RendererWithCamera::setProjectionMatrix(const mat4 &matrix) 45 | { 46 | cameraToScreen = matrix; 47 | updateCameraUniforms(); 48 | } 49 | 50 | void RendererWithCamera::setCamera(const vec3 &position, const vec4 &orientation) 51 | { 52 | cameraToWorld = mat4::rotationTranslationMatrix(orientation, position); 53 | worldToCamera = cameraToWorld.inverted(); 54 | cameraPosition = position; 55 | updateCameraUniforms(); 56 | } 57 | 58 | vec3 RendererWithCamera::getWorldDirection(const vec2 &screenCoordinates) const 59 | { 60 | //Calculate ray direction in 3D corresponding to screen coordinates normalized to [0, 1] x [0, 1] with the latest updated camera values. 61 | vec4 tmp = screenToWorld*vec4(2.0f*screenCoordinates - 1.0f, -1.0f, 1.0f); 62 | 63 | return normalize(((tmp/tmp.w) - vec4(cameraPosition, 0.0f)).xyz()); 64 | } 65 | 66 | void RendererWithCamera::updateCameraUniforms() 67 | { 68 | worldToScreen = cameraToScreen*worldToCamera; 69 | screenToWorld = worldToScreen.invertedFull(); 70 | 71 | uniformMap.setVec3Uniform(cameraPosition, "cameraPosition"); 72 | uniformMap.setMat4Uniform(cameraToWorld, "cameraToWorld"); 73 | uniformMap.setMat4Uniform(worldToScreen, "worldToScreen"); 74 | uniformMap.setMat4Uniform(screenToWorld, "screenToWorld"); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /tiny/draw/rendererwithcamera.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace draw 32 | { 33 | 34 | class RendererWithCamera : public Renderer 35 | { 36 | public: 37 | RendererWithCamera(const float &, const bool &, const int &, const int &); 38 | virtual ~RendererWithCamera(); 39 | 40 | void setProjectionMatrix(const mat4 &); 41 | void setCamera(const vec3 &, const vec4 &); 42 | vec3 getWorldDirection(const vec2 &) const; 43 | 44 | static const float nearClippingPlane; 45 | static const float farClippingPlane; 46 | 47 | private: 48 | void updateCameraUniforms(); 49 | 50 | mat4 cameraToScreen; 51 | mat4 cameraToWorld; 52 | mat4 worldToCamera; 53 | mat4 worldToScreen; 54 | mat4 screenToWorld; 55 | vec3 cameraPosition; 56 | }; 57 | 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /tiny/draw/screensquare.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | using namespace tiny::draw; 24 | 25 | ScreenFillingSquareVertexBufferInterpreter::ScreenFillingSquareVertexBufferInterpreter() : 26 | VertexBufferInterpreter(4) 27 | { 28 | hostData[0] = vec2(-1.0f, 1.0f); 29 | hostData[1] = vec2(-1.0f,-1.0f); 30 | hostData[2] = vec2( 1.0f, 1.0f); 31 | hostData[3] = vec2( 1.0f,-1.0f); 32 | 33 | sendToDevice(); 34 | 35 | addVec2Attribute(0*sizeof(float), "vertex"); 36 | } 37 | 38 | ScreenFillingSquareVertexBufferInterpreter::~ScreenFillingSquareVertexBufferInterpreter() 39 | { 40 | 41 | } 42 | 43 | std::string ScreenFillingSquare::getTypeName() const { 44 | return "ScreenFillingSquare"; 45 | } 46 | 47 | void ScreenFillingSquareVertexBufferInterpreter::setSquareDimensions( 48 | float left, float top, float right, float bottom) 49 | { 50 | left = std::max(std::min(left, 1.0f), -1.0f); 51 | right = std::min(std::max(right, -1.0f), 1.0f); 52 | top = std::max(std::min(top, 1.0f), -1.0f); 53 | bottom = std::min(std::max(bottom, -1.0f), 1.0f); 54 | hostData[0] = tiny::vec2(left, top); 55 | hostData[1] = tiny::vec2(left, bottom); 56 | hostData[2] = tiny::vec2(right, top); 57 | hostData[3] = tiny::vec2(right, bottom); 58 | 59 | sendToDevice(); 60 | } 61 | 62 | ScreenFillingSquare::ScreenFillingSquare() : 63 | Renderable() 64 | { 65 | 66 | } 67 | 68 | ScreenFillingSquare::~ScreenFillingSquare() 69 | { 70 | 71 | } 72 | 73 | void ScreenFillingSquare::setSquareDimensions(float left, float top, float right, float bottom) 74 | { 75 | square.setSquareDimensions(left, top, right, bottom); 76 | } 77 | 78 | std::string ScreenFillingSquare::getVertexShaderCode() const 79 | { 80 | return 81 | "#version 150\n" 82 | "\n" 83 | "in vec2 vertex;\n" 84 | "\n" 85 | "void main(void)\n" 86 | "{\n" 87 | " gl_Position = vec4(vertex.x, vertex.y, 0.0f, 1.0f);\n" 88 | "}\n\0"; 89 | } 90 | 91 | void ScreenFillingSquare::render(const ShaderProgram &program) const 92 | { 93 | //Draw screen-filling quad. 94 | square.bind(program); 95 | renderRangeAsTriangleStrip(0, 4); 96 | square.unbind(program); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /tiny/draw/screensquare.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace tiny 34 | { 35 | 36 | namespace draw 37 | { 38 | 39 | class ScreenFillingSquareVertexBufferInterpreter : public VertexBufferInterpreter 40 | { 41 | public: 42 | ScreenFillingSquareVertexBufferInterpreter(); 43 | ~ScreenFillingSquareVertexBufferInterpreter(); 44 | 45 | void setSquareDimensions(float left, float top, float right, float bottom); 46 | }; 47 | 48 | class ScreenFillingSquare : public Renderable 49 | { 50 | public: 51 | ScreenFillingSquare(); 52 | ~ScreenFillingSquare(); 53 | std::string getTypeName() const; 54 | 55 | std::string getVertexShaderCode() const; 56 | 57 | void setSquareDimensions(float left, float top, float right, float bottom); 58 | 59 | protected: 60 | void render(const ShaderProgram &) const; 61 | 62 | private: 63 | ScreenFillingSquareVertexBufferInterpreter square; 64 | }; 65 | 66 | } 67 | 68 | } 69 | 70 | -------------------------------------------------------------------------------- /tiny/draw/shader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::draw; 20 | 21 | VertexShader::VertexShader() : 22 | Shader() 23 | { 24 | 25 | } 26 | 27 | VertexShader::~VertexShader() 28 | { 29 | 30 | } 31 | 32 | GeometryShader::GeometryShader() : 33 | Shader() 34 | { 35 | 36 | } 37 | 38 | GeometryShader::~GeometryShader() 39 | { 40 | 41 | } 42 | 43 | FragmentShader::FragmentShader() : 44 | Shader() 45 | { 46 | 47 | } 48 | 49 | FragmentShader::~FragmentShader() 50 | { 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tiny/draw/shaderprogram.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | 26 | namespace tiny 27 | { 28 | 29 | namespace draw 30 | { 31 | 32 | /*! \p ShaderProgram : GLSL program describing the transformation of vertices and pixel data. 33 | */ 34 | class ShaderProgram 35 | { 36 | public: 37 | ShaderProgram(); 38 | ~ShaderProgram(); 39 | 40 | template 41 | void attach(const Shader &shader) 42 | { 43 | glAttachShader(programIndex, shader.getIndex()); 44 | } 45 | 46 | template 47 | void detach(const Shader &shader) 48 | { 49 | glDetachShader(programIndex, shader.getIndex()); 50 | } 51 | 52 | void link(); 53 | bool validate() const; 54 | GLuint getIndex() const; 55 | void bind() const; 56 | void unbind() const; 57 | 58 | private: 59 | ShaderProgram(const ShaderProgram &); 60 | 61 | GLuint programIndex; 62 | }; 63 | 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /tiny/draw/staticmesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace tiny 32 | { 33 | 34 | namespace draw 35 | { 36 | 37 | class StaticMeshVertexBufferInterpreter : public VertexBufferInterpreter 38 | { 39 | public: 40 | StaticMeshVertexBufferInterpreter(const tiny::mesh::StaticMesh &); 41 | ~StaticMeshVertexBufferInterpreter(); 42 | }; 43 | 44 | class StaticMeshIndexBuffer : public IndexBuffer 45 | { 46 | public: 47 | StaticMeshIndexBuffer(const tiny::mesh::StaticMesh &); 48 | ~StaticMeshIndexBuffer(); 49 | }; 50 | 51 | class StaticMesh : public Renderable 52 | { 53 | public: 54 | StaticMesh(const tiny::mesh::StaticMesh &); 55 | ~StaticMesh(); 56 | std::string getTypeName() const; 57 | 58 | template 59 | void setDiffuseTexture(const TextureType &texture) 60 | { 61 | uniformMap.setTexture(texture, "diffuseTexture"); 62 | } 63 | 64 | template 65 | void setNormalTexture(const TextureType &texture) 66 | { 67 | uniformMap.setTexture(texture, "normalTexture"); 68 | } 69 | 70 | std::string getVertexShaderCode() const; 71 | std::string getFragmentShaderCode() const; 72 | 73 | size_t bufferSize(void) const; 74 | 75 | protected: 76 | void render(const ShaderProgram &) const; 77 | 78 | private: 79 | StaticMeshIndexBuffer indices; 80 | StaticMeshVertexBufferInterpreter vertices; 81 | }; 82 | 83 | } 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /tiny/draw/texture1d.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace tiny 22 | { 23 | 24 | namespace draw 25 | { 26 | 27 | template 28 | class Texture1D : public Texture 29 | { 30 | public: 31 | Texture1D(const size_t &width, const size_t &height) : 32 | Texture(GL_TEXTURE_1D, width, height) 33 | { 34 | 35 | } 36 | 37 | Texture1D(const Texture1D &texture) 38 | Texture(texture) 39 | { 40 | 41 | } 42 | 43 | ~Texture1D() 44 | { 45 | 46 | } 47 | 48 | T & operator () (const size_t &a_x) 49 | { 50 | return this->hostData[a_x]; 51 | } 52 | 53 | const T & operator () (const size_t &a_x) const 54 | { 55 | return this->hostData[a_x]; 56 | } 57 | }; 58 | 59 | typedef Texture1D Vec4Texture1D; 60 | 61 | } 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tiny/draw/texturebuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace tiny 23 | { 24 | 25 | namespace draw 26 | { 27 | 28 | template 29 | class TextureBuffer : public Texture 30 | { 31 | public: 32 | TextureBuffer() : 33 | Texture(GL_TEXTURE_BUFFER, 1, 1, 1) 34 | { 35 | unbindBuffer(); 36 | } 37 | 38 | ~TextureBuffer() 39 | { 40 | 41 | } 42 | 43 | void bindBuffer(const BufferInterface &buffer) const 44 | { 45 | this->bind(); 46 | GL_CHECK(glTexBuffer(GL_TEXTURE_BUFFER, this->textureFormat, buffer.getIndex())); 47 | this->unbind(); 48 | } 49 | 50 | void unbindBuffer() const 51 | { 52 | this->bind(); 53 | GL_CHECK(glTexBuffer(GL_TEXTURE_BUFFER, this->textureFormat, 0)); 54 | this->unbind(); 55 | } 56 | }; 57 | 58 | typedef TextureBuffer Vec4TextureBuffer; 59 | 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tiny/draw/vertexbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace tiny 22 | { 23 | 24 | namespace draw 25 | { 26 | 27 | /*! \p VertexBuffer : data buffer on an OpenGL device designed for holding vertex data. 28 | * 29 | * \tparam T type of object stored in this buffer 30 | */ 31 | template 32 | class VertexBuffer : public Buffer 33 | { 34 | public: 35 | VertexBuffer(const size_t &a_size) : 36 | Buffer(a_size, GL_ARRAY_BUFFER, GL_STATIC_DRAW) 37 | { 38 | 39 | } 40 | 41 | VertexBuffer(const VertexBuffer &a_buffer) : 42 | Buffer(a_buffer) 43 | { 44 | 45 | } 46 | 47 | template 48 | VertexBuffer(Iterator first, Iterator last) : 49 | Buffer(first, last, GL_ARRAY_BUFFER, GL_STATIC_DRAW) 50 | { 51 | 52 | } 53 | 54 | virtual ~VertexBuffer() 55 | { 56 | 57 | } 58 | }; 59 | 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tiny/img/image.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace tiny 23 | { 24 | 25 | namespace img 26 | { 27 | 28 | class Image 29 | { 30 | public: 31 | Image(); 32 | Image(const size_t &, const size_t &); 33 | ~Image(); 34 | 35 | static Image createSolidImage(const size_t & = 4, const unsigned char & = 255, const unsigned char & = 255, const unsigned char & = 255, const unsigned char & = 255); 36 | static Image createTestImage(const size_t & = 64); 37 | static Image createUpNormalImage(const size_t & = 4); 38 | 39 | Image flipUpDown() const; 40 | 41 | size_t width, height; 42 | std::vector data; 43 | }; 44 | 45 | } 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /tiny/img/io/image.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace img 28 | { 29 | 30 | namespace io 31 | { 32 | 33 | tiny::img::Image readImage(const std::string &); 34 | std::vector readFont(const std::string &, const int &); 35 | 36 | } 37 | 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /tiny/math/vec.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | using namespace tiny; 23 | 24 | vec2 tiny::randomVec2(const float &s) 25 | { 26 | return vec2(2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 27 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s); 28 | } 29 | 30 | vec3 tiny::randomVec3(const float &s) 31 | { 32 | return vec3(2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 33 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 34 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s); 35 | } 36 | 37 | vec4 tiny::randomVec4(const float &s) 38 | { 39 | return vec4(2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 40 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 41 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s, 42 | 2.0f*s*static_cast(rand())/static_cast(RAND_MAX) - s); 43 | } 44 | 45 | std::tuple mat3::eigenDecompositionSym() const 46 | { 47 | const auto [e, E] = tiny::eigenDecompositionSym(fromFixedSizeMatrix(*this)); 48 | 49 | return {toFixedSizeVector(e), toFixedSizeMatrix(E)}; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /tiny/mesh/animatedmesh.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::mesh; 20 | 21 | Animation::Animation() : 22 | name(""), 23 | frames() 24 | { 25 | 26 | } 27 | 28 | Animation::~Animation() 29 | { 30 | 31 | } 32 | 33 | Skeleton::Skeleton() : 34 | bones(), 35 | animations() 36 | { 37 | 38 | } 39 | 40 | Skeleton::~Skeleton() 41 | { 42 | 43 | } 44 | 45 | AnimatedMesh::AnimatedMesh() : 46 | skeleton(), 47 | vertices(), 48 | indices() 49 | { 50 | 51 | } 52 | 53 | AnimatedMesh::~AnimatedMesh() 54 | { 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /tiny/mesh/io/animatedmesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace mesh 28 | { 29 | 30 | namespace io 31 | { 32 | 33 | tiny::mesh::AnimatedMesh readAnimatedMesh(const std::string &, const std::string & = ""); 34 | 35 | } 36 | 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tiny/mesh/io/staticmesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace mesh 28 | { 29 | 30 | namespace io 31 | { 32 | 33 | tiny::mesh::StaticMesh readStaticMesh(const std::string &, const std::string & = ""); 34 | 35 | } 36 | 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tiny/mesh/staticmesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace mesh 28 | { 29 | 30 | struct StaticMeshVertex 31 | { 32 | StaticMeshVertex() : 33 | textureCoordinate(0.0f, 0.0f), 34 | tangent(1.0f, 0.0f, 0.0f), 35 | normal(0.0f, 0.0f, 1.0f), 36 | position(0.0f, 0.0f, 0.0f) 37 | { 38 | 39 | } 40 | 41 | StaticMeshVertex(const vec2 &a_textureCoordinate, 42 | const vec3 &a_tangent, 43 | const vec3 &a_normal, 44 | const vec3 &a_position) : 45 | textureCoordinate(a_textureCoordinate), 46 | tangent(a_tangent), 47 | normal(a_normal), 48 | position(a_position) 49 | { 50 | 51 | } 52 | 53 | vec2 textureCoordinate; 54 | vec3 tangent; 55 | vec3 normal; 56 | vec3 position; 57 | }; 58 | 59 | class StaticMesh 60 | { 61 | public: 62 | StaticMesh(); 63 | ~StaticMesh(); 64 | 65 | static StaticMesh createPlaneMesh(const float & = 1.0f); 66 | static StaticMesh createCubeMesh(const float & = 1.0f); 67 | static StaticMesh createBoxMesh(const float & = 1.0f, const float & = 1.0f, const float & = 1.0f); 68 | static StaticMesh createCylinderMesh(const float & = 1.0f, const float & = 1.0f, const int & = 12); 69 | static StaticMesh createIcosahedronMesh(const float & = 1.0f); 70 | float getRadius(const vec3 & = vec3(1.0f, 1.0f, 1.0f)) const; 71 | std::pair getBoundingBox(const vec3 & = vec3(1.0f, 1.0f, 1.0f)) const; 72 | 73 | std::vector vertices; 74 | std::vector indices; 75 | }; 76 | 77 | } 78 | 79 | } 80 | 81 | -------------------------------------------------------------------------------- /tiny/net/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace net 32 | { 33 | 34 | class Client 35 | { 36 | public: 37 | Client(const std::string &, const unsigned int &, MessageTranslator *); 38 | virtual ~Client(); 39 | 40 | bool listen(const double &); 41 | void sendMessage(const Message &); 42 | 43 | protected: 44 | virtual void receiveMessage(const Message &); 45 | virtual void disconnectedFromHost(); 46 | 47 | private: 48 | MessageTranslator * const translator; 49 | IPaddress hostAddress; 50 | TCPsocket socket; 51 | }; 52 | 53 | } 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /tiny/net/console.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | using namespace tiny::net; 22 | 23 | Console::Console() : 24 | lines(), 25 | lineScroll(0) 26 | { 27 | 28 | } 29 | 30 | Console::~Console() 31 | { 32 | 33 | } 34 | 35 | void Console::scrollUp() 36 | { 37 | lineScroll += 10; 38 | 39 | if (lineScroll >= (int)lines.size()) lineScroll = lines.size() - 1; 40 | 41 | update(); 42 | } 43 | 44 | void Console::scrollDown() 45 | { 46 | lineScroll -= 10; 47 | 48 | if (lineScroll < 0) lineScroll = 0; 49 | 50 | update(); 51 | } 52 | 53 | void Console::scrollDownFull() 54 | { 55 | lineScroll = 0; 56 | 57 | update(); 58 | } 59 | 60 | void Console::keyDown(const int &key) 61 | { 62 | if (key == '\n' || key == '\r') 63 | { 64 | addLine(curLine); 65 | 66 | const std::string command = curLine; 67 | 68 | curLine = ""; 69 | execute(command); 70 | } 71 | else if (key == '\b') 72 | { 73 | if (curLine.size() > 0) curLine.erase(curLine.size() - 1, curLine.size()); 74 | } 75 | else if (key == ' ') 76 | { 77 | curLine += ' '; 78 | } 79 | else if (key >= 32 && key < 255) 80 | { 81 | curLine += key; 82 | } 83 | 84 | update(); 85 | } 86 | 87 | void Console::addLine(const std::string &message) 88 | { 89 | std::cerr << "Console: " << message << std::endl; 90 | 91 | std::istringstream stream(message); 92 | 93 | while (stream.good()) 94 | { 95 | std::string messageLine; 96 | 97 | std::getline(stream, messageLine); 98 | lines.push_back(messageLine); 99 | } 100 | 101 | update(); 102 | } 103 | 104 | void Console::execute(const std::string &) 105 | { 106 | 107 | } 108 | 109 | std::string Console::getText(const int &nrLines) const 110 | { 111 | std::ostringstream stream; 112 | std::vector::const_reverse_iterator ptr = lines.rbegin() + lineScroll; 113 | 114 | stream << " $ " << curLine; 115 | 116 | for (int i = 0; i < nrLines && ptr != lines.rend(); ++i) 117 | { 118 | stream << std::endl; 119 | stream << "\\w\\3" << *ptr++; 120 | } 121 | 122 | return stream.str(); 123 | } 124 | 125 | void Console::update() 126 | { 127 | 128 | } 129 | 130 | -------------------------------------------------------------------------------- /tiny/net/console.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace tiny 24 | { 25 | 26 | namespace net 27 | { 28 | 29 | class Console 30 | { 31 | public: 32 | Console(); 33 | virtual ~Console(); 34 | 35 | void scrollUp(); 36 | void scrollDown(); 37 | void scrollDownFull(); 38 | void keyDown(const int &); 39 | void addLine(const std::string &); 40 | std::string getText(const int &) const; 41 | 42 | protected: 43 | virtual void execute(const std::string &); 44 | virtual void update(); 45 | 46 | private: 47 | std::vector lines; 48 | std::string curLine; 49 | int lineScroll; 50 | }; 51 | 52 | } 53 | 54 | } 55 | 56 | -------------------------------------------------------------------------------- /tiny/net/host.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | namespace tiny 29 | { 30 | 31 | namespace net 32 | { 33 | 34 | class Host 35 | { 36 | public: 37 | Host(const unsigned int &, MessageTranslator *); 38 | virtual ~Host(); 39 | 40 | bool listen(const double &); 41 | void sendMessage(const Message &); 42 | void sendPrivateMessage(const Message &, const unsigned int &); 43 | 44 | protected: 45 | virtual void addClient(const unsigned int &); 46 | virtual void receiveMessage(const unsigned int &, const Message &); 47 | virtual void removeClient(const unsigned int &); 48 | 49 | void kickClient(const unsigned int &); 50 | 51 | private: 52 | unsigned int lastClientIndex; 53 | IPaddress hostAddress; 54 | TCPsocket hostSocket; 55 | std::map clients; 56 | MessageTranslator * const translator; 57 | }; 58 | 59 | } 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /tiny/os/application.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | #include 22 | 23 | namespace tiny 24 | { 25 | 26 | namespace os 27 | { 28 | 29 | struct MouseState 30 | { 31 | MouseState() : 32 | x(0.0f), 33 | y(0.0f), 34 | buttons(0) 35 | { 36 | 37 | } 38 | 39 | MouseState(const float &a_x, 40 | const float &a_y, 41 | const unsigned int &a_buttons) : 42 | x(a_x), 43 | y(a_y), 44 | buttons(a_buttons) 45 | { 46 | 47 | } 48 | 49 | float x; 50 | float y; 51 | unsigned int buttons; 52 | }; 53 | 54 | class Application 55 | { 56 | public: 57 | Application(); 58 | virtual ~Application(); 59 | 60 | virtual double pollEvents() = 0; 61 | virtual void paint() = 0; 62 | virtual int getScreenWidth() const = 0; 63 | virtual int getScreenHeight() const = 0; 64 | 65 | #ifdef ENABLE_OPENVR 66 | virtual int getScreenWidthVR() const = 0; 67 | virtual int getScreenHeightVR() const = 0; 68 | virtual vr::IVRSystem *getHMDVR() const = 0; 69 | #endif 70 | 71 | virtual MouseState getMouseState(const bool &) = 0; 72 | 73 | void stopRunning(); 74 | bool isRunning() const; 75 | bool isKeyPressed(const int &) const; 76 | bool isKeyPressedOnce(const int &); 77 | std::string getTextInput(); 78 | 79 | virtual void keyDownCallback(const int &); 80 | virtual void keyUpCallback(const int &); 81 | 82 | void updateSimpleCamera(const float &, vec3 &, vec4 &) const; 83 | 84 | protected: 85 | bool pressedKeys[256]; 86 | std::string collectedText; 87 | 88 | private: 89 | bool running; 90 | }; 91 | 92 | } 93 | 94 | } 95 | 96 | -------------------------------------------------------------------------------- /tiny/os/sdlapplication.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #ifdef ENABLE_OPENVR 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | namespace tiny 31 | { 32 | 33 | namespace os 34 | { 35 | 36 | class SDLApplication : public Application 37 | { 38 | public: 39 | SDLApplication(const int &, const int &, const bool & = false, const int & = 0, const int & = 24); 40 | virtual ~SDLApplication(); 41 | 42 | double pollEvents(); 43 | void paint(); 44 | int getScreenWidth() const; 45 | int getScreenHeight() const; 46 | #ifdef ENABLE_OPENVR 47 | int getScreenWidthVR() const; 48 | int getScreenHeightVR() const; 49 | vr::IVRSystem *getHMDVR() const; 50 | #endif 51 | MouseState getMouseState(const bool &); 52 | 53 | virtual void keyDownCallback(const int &); 54 | virtual void keyUpCallback(const int &); 55 | 56 | private: 57 | void initOpenGL(); 58 | void initOpenAL(); 59 | void exitOpenAL(); 60 | 61 | int screenWidth; 62 | int screenHeight; 63 | int screenBPP; 64 | int screenDepthBPP; 65 | Uint32 screenFlags; 66 | SDL_Window *screen; 67 | SDL_GLContext glContext; 68 | Uint32 lastCount, curCount; 69 | bool wireframe; 70 | 71 | ALCdevice *alDevice; 72 | ALCcontext *alContext; 73 | 74 | int audioRate; 75 | int audioFormat; 76 | int audioChannels; 77 | int audioMixChannels; 78 | int audioBuffer; 79 | 80 | #ifdef ENABLE_OPENVR 81 | vr::IVRSystem *vrHMD; 82 | uint32_t screenWidthVR; 83 | uint32_t screenHeightVR; 84 | #endif 85 | }; 86 | 87 | } 88 | 89 | } 90 | 91 | -------------------------------------------------------------------------------- /tiny/rigid/triangle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny; 20 | 21 | vec3 tiny::getClosestPointOnTriangle(const vec3 &p, const std::array &t) noexcept 22 | { 23 | //Determine closest point on a triangle a-b-c w.r.t. a given point p. 24 | //From Fast Distance Queries for Triangles, Lines, and Points using SSE Instructions by E. Shellshear, 2014. 25 | const vec3 ab = t[1] - t[0]; 26 | const vec3 ac = t[2] - t[0]; 27 | const vec3 ap = p - t[0]; 28 | const float d1 = dot(ab, ap); 29 | const float d2 = dot(ac, ap); 30 | 31 | //Are we closest to point a? 32 | if (d1 <= 0.0f && d2 <= 0.0f) return t[0]; 33 | 34 | const vec3 bp = p - t[1]; 35 | const float d3 = dot(ab, bp); 36 | const float d4 = dot(ac, bp); 37 | 38 | //Are we closest to point b? 39 | if (d3 >= 0.0f && d4 <= d3) return t[1]; 40 | 41 | const vec3 cp = p - t[2]; 42 | const float d5 = dot(ab, cp); 43 | const float d6 = dot(ac, cp); 44 | 45 | //Are we closest to point c? 46 | if (d6 >= 0.0f && d5 <= d6) return t[2]; 47 | 48 | const float vc = d1*d4 - d3*d2; 49 | const float v1 = d1/(d1 - d3); 50 | 51 | //Are we closest to line ab? 52 | if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f) return t[0] + v1*ab; 53 | 54 | const float vb = d5*d2 - d1*d6; 55 | const float w1 = d2/(d2 - d6); 56 | 57 | //Are we closest to line ac? 58 | if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f) return t[0] + w1*ac; 59 | 60 | const float va = d3*d6 - d5*d4; 61 | const float w2 = (d4 - d3)/((d4 - d3) + (d5 - d6)); 62 | 63 | //Are we closest to line bc? 64 | if (va <= 0.0f && d4 - d3 >= 0.0f && d5 - d6 >= 0.0f) return t[1] + w2*(t[2] - t[1]); 65 | 66 | const float denom = 1.0f/(va + vb + vc); 67 | const float v2 = vb*denom; 68 | const float w3 = vc*denom; 69 | 70 | //We are closest to an interior point. 71 | return t[0] + v2*ab + w3*ac; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /tiny/rigid/triangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace tiny 23 | { 24 | 25 | vec3 getClosestPointOnTriangle(const vec3 &, const std::array &) noexcept; 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /tiny/smp/io/sample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include 27 | 28 | using namespace tiny::smp; 29 | 30 | Sample tiny::smp::io::readSample(const std::string &fileName) 31 | { 32 | //Read sample from disk. 33 | OggVorbis_File file; 34 | 35 | const int fopenStatus = ov_fopen(fileName.c_str(), &file); 36 | 37 | if (fopenStatus != 0) 38 | { 39 | std::cerr << "Unable to open '" << fileName << "' for reading: " << fopenStatus << "!" << std::endl; 40 | throw std::exception(); 41 | } 42 | 43 | //Retrieve file information. 44 | const vorbis_info *fileInfo = ov_info(&file, -1); 45 | Sample sample(fileInfo->rate, fileInfo->channels); 46 | 47 | //Read file in chunks. 48 | const size_t bufferSize = 65536; 49 | std::vector buffer(bufferSize/sizeof(short), 0); 50 | long nrBytesRead = 0; 51 | int bitStream = 0; 52 | 53 | do 54 | { 55 | nrBytesRead = ov_read(&file, reinterpret_cast(&buffer[0]), bufferSize, (SDL_BYTEORDER == SDL_BIG_ENDIAN ? 1 : 0), sizeof(short), 1, &bitStream); 56 | sample.data.insert(sample.data.end(), buffer.begin(), buffer.begin() + (nrBytesRead/sizeof(short))); 57 | } while(nrBytesRead > 0); 58 | 59 | ov_clear(&file); 60 | 61 | std::cerr << "Read a " << sample.channels << " channel file at " << sample.frequency << "Hz from '" << fileName << "'." << std::endl; 62 | return sample; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /tiny/smp/io/sample.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace tiny 25 | { 26 | 27 | namespace smp 28 | { 29 | 30 | namespace io 31 | { 32 | 33 | tiny::smp::Sample readSample(const std::string &); 34 | 35 | } 36 | 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tiny/smp/sample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #define _USE_MATH_DEFINES 18 | #include 19 | 20 | #include 21 | 22 | using namespace tiny::smp; 23 | 24 | Sample::Sample() : 25 | frequency(0), 26 | channels(0), 27 | data() 28 | { 29 | 30 | } 31 | 32 | Sample::Sample(const size_t &a_frequency, const size_t &a_channels) : 33 | frequency(a_frequency), 34 | channels(a_channels), 35 | data() 36 | { 37 | 38 | } 39 | 40 | Sample::~Sample() 41 | { 42 | 43 | } 44 | 45 | Sample Sample::createTone(const float &toneFrequency, const float &sampleFrequency) 46 | { 47 | //Create a sine wave of the desired frequency. 48 | Sample sample(static_cast(sampleFrequency), 1); 49 | 50 | //Sample one entire period. 51 | const size_t nrSamples = static_cast(ceil(sampleFrequency/toneFrequency)); 52 | 53 | sample.data.assign(nrSamples, 0); 54 | 55 | for (size_t i = 0; i < nrSamples; ++i) 56 | { 57 | sample.data[i] = static_cast(0.5f*32767.5f*(1.0f + sin(2.0f*M_PI*static_cast(i)/static_cast(nrSamples)))); 58 | } 59 | 60 | return sample; 61 | } 62 | 63 | Sample Sample::createBlockTone(const float &toneFrequency, const float &sampleFrequency) 64 | { 65 | //Create a sine wave of the desired frequency. 66 | Sample sample(static_cast(sampleFrequency), 1); 67 | 68 | //Sample one entire period. 69 | const size_t nrSamples = static_cast(ceil(sampleFrequency/toneFrequency)); 70 | 71 | sample.data.assign(nrSamples, 0); 72 | 73 | for (size_t i = 0; i < nrSamples/2; ++i) sample.data[i] = 32767; 74 | for (size_t i = nrSamples/2; i < nrSamples; ++i) sample.data[i] = -32767; 75 | 76 | return sample; 77 | } 78 | -------------------------------------------------------------------------------- /tiny/smp/sample.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace tiny 23 | { 24 | 25 | namespace smp 26 | { 27 | 28 | class Sample 29 | { 30 | public: 31 | Sample(); 32 | Sample(const size_t &, const size_t &); 33 | ~Sample(); 34 | 35 | static Sample createTone(const float & = 440.0, const float & = 44100.0f); 36 | static Sample createBlockTone(const float & = 440.0, const float & = 44100.0f); 37 | 38 | size_t frequency; 39 | size_t channels; 40 | std::vector data; 41 | }; 42 | 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /tiny/snd/alcheck.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | void tiny::snd::CheckOpenALError(const char *statement, const char *fileName, const int line) 22 | { 23 | const ALCenum error = alGetError(); 24 | 25 | if (error != AL_NO_ERROR) 26 | { 27 | std::cerr << "OpenAL error " << error << " (" << alGetString(error) << ") at " << fileName << ":" << line << " for '" << statement << "'!" << std::endl; 28 | abort(); 29 | } 30 | else 31 | { 32 | //std::cerr << statement << " OK." << std::endl; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tiny/snd/alcheck.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | //From http://stackoverflow.com/questions/11256470/define-a-macro-to-facilitate-opengl-command-debugging. 26 | namespace tiny 27 | { 28 | 29 | namespace snd 30 | { 31 | 32 | void CheckOpenALError(const char *, const char *, const int); 33 | 34 | } 35 | 36 | } 37 | 38 | #ifndef NDEBUG 39 | #define AL_CHECK(statement) do { \ 40 | statement; \ 41 | tiny::snd::CheckOpenALError(#statement, __FILE__, __LINE__); \ 42 | } while (0) 43 | #else 44 | #define AL_CHECK(stmt) stmt 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /tiny/snd/buffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | using namespace tiny::snd; 20 | 21 | BufferInterface::BufferInterface(const size_t &a_sizeInBytes, const ALenum &a_format, const ALsizei &a_frequency) : 22 | sizeInBytes(0), 23 | format(a_format), 24 | frequency(a_frequency), 25 | bufferIndex(0) 26 | { 27 | resizeDeviceBuffer(a_sizeInBytes); 28 | } 29 | 30 | BufferInterface::BufferInterface(const BufferInterface &a_buffer) : 31 | sizeInBytes(0), 32 | format(a_buffer.format), 33 | frequency(a_buffer.frequency), 34 | bufferIndex(0) 35 | { 36 | resizeDeviceBuffer(a_buffer.sizeInBytes); 37 | } 38 | 39 | BufferInterface::~BufferInterface() 40 | { 41 | destroyDeviceBuffer(); 42 | } 43 | 44 | ALuint BufferInterface::getIndex() const 45 | { 46 | return bufferIndex; 47 | } 48 | 49 | void BufferInterface::createDeviceBuffer() 50 | { 51 | AL_CHECK(alGenBuffers(1, &bufferIndex)); 52 | 53 | if (bufferIndex == 0) 54 | throw std::bad_alloc(); 55 | } 56 | 57 | void BufferInterface::destroyDeviceBuffer() 58 | { 59 | //Frees all data bound to this class on the device. 60 | if (bufferIndex != 0) AL_CHECK(alDeleteBuffers(1, &bufferIndex)); 61 | 62 | sizeInBytes = 0; 63 | bufferIndex = 0; 64 | } 65 | 66 | void BufferInterface::resizeDeviceBuffer(const size_t &a_sizeInBytes) 67 | { 68 | //Do not perform needless re-allocation. 69 | if (sizeInBytes == a_sizeInBytes) return; 70 | 71 | //Create new device array. 72 | sizeInBytes = a_sizeInBytes; 73 | 74 | if (sizeInBytes == 0) 75 | { 76 | destroyDeviceBuffer(); 77 | return; 78 | } 79 | 80 | //Allocate new buffer if necessary. 81 | if (bufferIndex == 0) createDeviceBuffer(); 82 | 83 | //Older versions of OpenAL require a non-null buffer to be supplied. 84 | std::vector tmp(sizeInBytes, 0); 85 | 86 | //Resize buffer. 87 | AL_CHECK(alBufferData(bufferIndex, format, static_cast(&tmp[0]), sizeInBytes, frequency)); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /tiny/snd/detail/formats.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | namespace tiny 28 | { 29 | 30 | namespace snd 31 | { 32 | 33 | namespace detail 34 | { 35 | 36 | template 37 | inline ALenum getOpenALBufferFormat() {return AL_FORMAT_MONO8;} 38 | 39 | template<> 40 | inline ALenum getOpenALBufferFormat<1, char>() {return AL_FORMAT_MONO8;} 41 | template<> 42 | inline ALenum getOpenALBufferFormat<2, char>() {return AL_FORMAT_STEREO8;} 43 | template<> 44 | inline ALenum getOpenALBufferFormat<1, short>() {return AL_FORMAT_MONO16;} 45 | template<> 46 | inline ALenum getOpenALBufferFormat<2, short>() {return AL_FORMAT_STEREO16;} 47 | 48 | } 49 | 50 | } 51 | 52 | } 53 | 54 | -------------------------------------------------------------------------------- /tiny/snd/source.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | 21 | using namespace tiny; 22 | using namespace tiny::snd; 23 | 24 | Source::Source(const vec3 &a_position, const vec3 &a_velocity) 25 | { 26 | AL_CHECK(alGenSources(1, &sourceIndex)); 27 | 28 | if (!sourceIndex) 29 | { 30 | throw std::bad_alloc(); 31 | } 32 | 33 | AL_CHECK(alSourcei(sourceIndex, AL_SOURCE_RELATIVE, AL_FALSE)); 34 | setPosition(a_position, a_velocity); 35 | 36 | AL_CHECK(alSourcef(sourceIndex, AL_ROLLOFF_FACTOR, 0.1f)); 37 | //AL_CHECK(alSourcef(sourceIndex, AL_REFERENCE_DISTANCE, 4.0f)); 38 | //AL_CHECK(alSourcef(sourceIndex, AL_MAX_DISTANCE, 128.0f)); 39 | } 40 | 41 | Source::~Source() 42 | { 43 | stopPlaying(); 44 | AL_CHECK(alDeleteSources(1, &sourceIndex)); 45 | } 46 | 47 | Source::Source(const Source &) 48 | { 49 | //Private copy constructor: do not permit source reassignment. 50 | } 51 | 52 | void Source::setPosition(const vec3 &a_position, const vec3 &a_velocity) 53 | { 54 | AL_CHECK(alSource3f(sourceIndex, AL_POSITION, a_position.x, a_position.y, a_position.z)); 55 | AL_CHECK(alSource3f(sourceIndex, AL_VELOCITY, a_velocity.x, a_velocity.y, a_velocity.z)); 56 | } 57 | 58 | void Source::setPitch(const float &a_pitch) 59 | { 60 | AL_CHECK(alSourcef(sourceIndex, AL_PITCH, a_pitch)); 61 | } 62 | 63 | void Source::setGain(const float &a_gain) 64 | { 65 | AL_CHECK(alSourcef(sourceIndex, AL_GAIN, a_gain)); 66 | } 67 | 68 | void Source::stopPlaying() 69 | { 70 | //std::cout << "Stopped playing on source index " << sourceIndex << "." << std::endl; 71 | AL_CHECK(alSourceStop(sourceIndex)); 72 | AL_CHECK(alSourcei(sourceIndex, AL_BUFFER, 0)); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /tiny/snd/source.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace tiny 34 | { 35 | 36 | namespace snd 37 | { 38 | 39 | class Source 40 | { 41 | public: 42 | Source(const vec3 &a_position = vec3(0.0f, 0.0f, 0.0f), const vec3 &a_velocity = vec3(0.0f, 0.0f, 0.0f)); 43 | ~Source(); 44 | 45 | void setPosition(const vec3 &a_position, const vec3 &a_velocity = vec3(0.0f, 0.0f, 0.0f)); 46 | void setPitch(const float &a_pitch); 47 | void setGain(const float &a_gain); 48 | 49 | template 50 | void playBuffer(const Buffer &a_buffer, const bool &a_looping, const float &a_offset = 0.0f) 51 | { 52 | //Play the given buffer with this source. 53 | AL_CHECK(alSourcei(sourceIndex, AL_LOOPING, a_looping ? AL_TRUE : AL_FALSE)); 54 | AL_CHECK(alSourcef(sourceIndex, AL_SEC_OFFSET, a_offset)); 55 | AL_CHECK(alSourcei(sourceIndex, AL_BUFFER, a_buffer.getIndex())); 56 | AL_CHECK(alSourcePlay(sourceIndex)); 57 | 58 | //std::cout << "Playing buffer with " << a_buffer.size() << " samples, looping " << a_looping << " on source " << sourceIndex << "." << std::endl; 59 | } 60 | 61 | void stopPlaying(); 62 | 63 | private: 64 | Source(const Source &); 65 | 66 | ALuint sourceIndex; 67 | }; 68 | 69 | } 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /tiny/snd/worldsounderer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | using namespace tiny; 26 | using namespace tiny::snd; 27 | 28 | WorldSounderer::WorldSounderer() 29 | { 30 | 31 | } 32 | 33 | WorldSounderer::~WorldSounderer() 34 | { 35 | 36 | } 37 | 38 | void WorldSounderer::setCamera(const vec3 &position, const vec4 &orientation, const vec3 &velocity) 39 | { 40 | const mat4 m = mat4::rotationMatrix(orientation); 41 | const vec3 at = m*vec3(0.0f, 0.0f,-1.0f); 42 | const vec3 up = m*vec3(0.0f, 1.0f, 0.0f); 43 | const ALfloat ori[] = {at.x, at.y, at.z, up.x, up.y, up.z}; 44 | 45 | AL_CHECK(alListener3f(AL_POSITION, position.x, position.y, position.z)); 46 | AL_CHECK(alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z)); 47 | AL_CHECK(alListenerfv(AL_ORIENTATION, ori)); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /tiny/snd/worldsounderer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2012, Bas Fagginger Auer. 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | #include 26 | 27 | namespace tiny 28 | { 29 | 30 | namespace snd 31 | { 32 | 33 | class WorldSounderer 34 | { 35 | public: 36 | WorldSounderer(); 37 | ~WorldSounderer(); 38 | 39 | static void setCamera(const vec3 &, const vec4 &, const vec3 & = vec3(0.0f, 0.0f, 0.0f)); 40 | }; 41 | 42 | } 43 | 44 | } 45 | 46 | --------------------------------------------------------------------------------