├── .gitignore ├── README.md ├── include └── .gitignore ├── makefile ├── res ├── models │ ├── dragon │ │ └── dragon.obj │ ├── fern │ │ └── fern.obj │ ├── grass │ │ └── grassModel.obj │ ├── lamp │ │ ├── lamp.mtl │ │ └── lamp.obj │ ├── low_poly_tree │ │ └── lowPolyTree.obj │ ├── pine │ │ └── pine.obj │ ├── stall │ │ └── stall.obj │ └── tree │ │ └── tree.obj ├── shaders │ ├── gui.f.glsl │ ├── gui.v.glsl │ ├── skybox.f.glsl │ ├── skybox.v.glsl │ ├── static.f.glsl │ ├── static.v.glsl │ ├── terrain.f.glsl │ ├── terrain.v.glsl │ ├── water.f.glsl │ └── water.v.glsl └── textures │ ├── dragon │ └── white.png │ ├── fern │ ├── fern.png │ └── fern_atlas.png │ ├── grass │ └── grassTexture.png │ ├── guis │ └── thinmatrix.png │ ├── lamp │ └── lamp.png │ ├── low_poly_tree │ └── lowPolyTree.png │ ├── pine │ └── pine.png │ ├── skybox │ ├── day │ │ ├── back.png │ │ ├── bottom.png │ │ ├── front.png │ │ ├── left.png │ │ ├── right.png │ │ └── top.png │ └── night │ │ ├── back.png │ │ ├── bottom.png │ │ ├── front.png │ │ ├── left.png │ │ ├── right.png │ │ └── top.png │ ├── stall │ └── stallTexture.png │ ├── terrain │ ├── blendMap.png │ ├── grass.png │ ├── grassFlowers.png │ ├── heightmap.png │ ├── mud.png │ └── path.png │ ├── tree │ └── tree.png │ └── water │ ├── normalMap.png │ └── waterDUDV.png ├── screenshot.png └── src ├── engine_tester ├── game_engine.cpp └── game_engine.hpp ├── entities ├── camera.cpp ├── camera.hpp ├── entity.cpp ├── entity.hpp ├── light.cpp └── light.hpp ├── guis ├── gui_renderer.cpp ├── gui_renderer.hpp ├── gui_shader.cpp ├── gui_shader.hpp ├── gui_texture.cpp └── gui_texture.hpp ├── main.cpp ├── models ├── raw_model.cpp ├── raw_model.hpp ├── textured_model.cpp └── textured_model.hpp ├── render_engine ├── display_manager.cpp ├── display_manager.hpp ├── entity_renderer.cpp ├── entity_renderer.hpp ├── glew.cpp ├── glew.hpp ├── loader.cpp ├── loader.hpp ├── master_renderer.cpp ├── master_renderer.hpp ├── obj_loader.cpp ├── obj_loader.hpp ├── terrain_renderer.cpp └── terrain_renderer.hpp ├── shaders ├── shader.cpp ├── shader.hpp ├── static_shader.cpp ├── static_shader.hpp ├── terrain_shader.cpp └── terrain_shader.hpp ├── skybox ├── skybox_renderer.cpp ├── skybox_renderer.hpp ├── skybox_shader.cpp └── skybox_shader.hpp ├── terrain ├── terrain.cpp └── terrain.hpp ├── textures ├── model_texture.cpp ├── model_texture.hpp ├── terrain_texture.cpp ├── terrain_texture.hpp ├── terrain_texture_pack.cpp └── terrain_texture_pack.hpp ├── toolbox ├── debug.cpp ├── debug.hpp ├── gl_handles.hpp ├── math.cpp ├── math.hpp ├── mouse_picker.cpp └── mouse_picker.hpp └── water ├── water_frame_buffers.cpp ├── water_frame_buffers.hpp ├── water_renderer.cpp ├── water_renderer.hpp ├── water_shader.cpp ├── water_shader.hpp ├── water_tile.cpp └── water_tile.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenGL 3D Game Engine 2 | 3 | This is a C++ implementation of the [ThinMatrix OpenGL 3D Game Engine tutorial series](https://www.youtube.com/playlist?list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP). The code requires [SFML](http://www.sfml-dev.org/index.php), [GLEW](http://glew.sourceforge.net/), and [GLM](http://glm.g-truc.net/). 4 | 5 | ![Current Screenshot](screenshot.png) 6 | 7 | Thanks for stopping by! Also, go check out [tcbrindle's implementation](https://github.com/tcbrindle/thinmatrix-gl-tutorials) if you have a chance; much of my implementation has been influenced by his (he deserves complete credit for the`gl_handles.hpp` file). 8 | -------------------------------------------------------------------------------- /include/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/include/.gitignore -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | ######################################## 2 | ## Path configurations 3 | ######################################## 4 | 5 | TARGET := GameEngine 6 | 7 | SRCDIR := src 8 | INCDIR := src 9 | BUILDDIR := obj 10 | TARGETDIR := bin 11 | SRCEXT := cpp 12 | DEPEXT := d 13 | OBJEXT := o 14 | 15 | ####################################### 16 | ## Compilation configurations 17 | ####################################### 18 | 19 | CC := g++ 20 | CFLAGS := -Wall -g -std=c++11 21 | 22 | LIB := -L$/usr/lib -lGL -lGLEW -lsfml-graphics -lsfml-window -lsfml-system 23 | INC := -I$(INCDIR) -I/usr/include 24 | INCDEP := -I$(INCDIR) 25 | 26 | SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) 27 | OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT))) 28 | 29 | ####################################### 30 | ## Compilation targets 31 | ####################################### 32 | 33 | all: $(TARGET) 34 | 35 | run: all 36 | ./$(TARGETDIR)/$(TARGET) 37 | 38 | remake: cleaner all 39 | 40 | clean: 41 | @$(RM) -rf $(BUILDDIR) 42 | 43 | cleaner: clean 44 | @$(RM) -rf $(TARGETDIR) 45 | 46 | -include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT)) 47 | 48 | $(TARGET): $(OBJECTS) 49 | @mkdir -p $(TARGETDIR) 50 | $(CC) -o $(TARGETDIR)/$(TARGET) $^ $(LIB) 51 | 52 | $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) 53 | @mkdir -p $(dir $@) 54 | $(CC) $(CFLAGS) $(INC) -c -o $@ $< 55 | @$(CC) $(CFLAGS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT) 56 | @cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp 57 | @sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT) 58 | @sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT) 59 | @rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp 60 | 61 | .PHONY: all run remake clean cleaner 62 | -------------------------------------------------------------------------------- /res/models/fern/fern.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.67 (sub 0) OBJ File: 'fern.blend' 2 | # www.blender.org 3 | o Plane 4 | v -1.668906 1.421207 -4.981303 5 | v 1.291248 1.274556 -4.874573 6 | v -1.681098 2.133895 -4.624559 7 | v 1.441855 2.133895 -4.624559 8 | v -1.716799 2.696792 -3.607163 9 | v 1.406155 2.587040 -3.607163 10 | v -1.561477 2.636679 -1.975693 11 | v 1.561477 2.470482 -1.975693 12 | v -1.347036 1.668626 -1.121537 13 | v 1.561477 1.857010 -0.942828 14 | v -1.561477 -0.004097 -0.036216 15 | v 1.561477 -0.004097 -0.036216 16 | v 4.922924 2.330723 -2.113493 17 | v 4.930951 2.184072 0.848574 18 | v 4.372616 2.743763 -2.092158 19 | v 4.493601 2.743764 1.028451 20 | v 3.455437 2.912039 -2.056599 21 | v 3.576422 2.802288 1.064010 22 | v 1.942091 2.636679 -1.997928 23 | v 2.063076 2.470482 1.122681 24 | v 1.096885 1.668625 -1.750557 25 | v 1.030987 1.857010 1.162695 26 | v 0.004071 -0.004097 -1.922791 27 | v 0.125055 -0.004097 1.197818 28 | v 5.066892 1.391006 0.895784 29 | v 3.068532 1.226996 3.537834 30 | v 4.896961 2.123907 0.870659 31 | v 2.891804 2.123907 3.730312 32 | v 4.156424 2.763720 0.489422 33 | v 2.151268 2.640977 3.349074 34 | v 2.614438 2.708673 -0.523145 35 | v 0.609281 2.522805 2.336507 36 | v 1.694611 1.626036 -0.875212 37 | v -0.336501 1.836719 1.673335 38 | v 0.838482 -0.244677 -1.768426 39 | v -1.166676 -0.244677 1.091226 40 | v 1.019397 2.313956 4.808662 41 | v -1.755515 2.175439 4.451704 42 | v 1.067131 2.704086 4.290682 43 | v -1.870153 2.704086 4.020000 44 | v 1.146687 2.863028 3.427385 45 | v -1.790596 2.759363 3.156702 46 | v 1.277956 2.602941 2.002943 47 | v -1.659327 2.445963 1.732260 48 | v 1.150299 1.688583 1.180983 49 | v -1.569803 1.866519 0.760803 50 | v 1.446060 0.108644 0.178775 51 | v -1.491222 0.108645 -0.091908 52 | v -2.841108 2.359943 5.062696 53 | v -4.854967 2.199116 2.513874 54 | v -2.381020 2.812909 4.671439 55 | v -4.599705 2.812910 2.062436 56 | v -1.614207 2.997452 4.019345 57 | v -3.832892 2.877091 1.410342 58 | v -0.348966 2.695474 2.943390 59 | v -2.567650 2.513212 0.334387 60 | v 0.212271 1.633845 2.157409 61 | v -1.704767 1.840439 -0.399406 62 | v 1.271327 -0.200569 1.565499 63 | v -0.947357 -0.200569 -1.043504 64 | v -6.274055 1.495219 2.121059 65 | v -6.142600 1.319109 -1.433610 66 | v -5.544260 2.263995 1.986592 67 | v -5.540795 2.263996 -1.763698 68 | v -4.359546 2.953154 1.726256 69 | v -4.356080 2.821356 -2.024032 70 | v -2.407223 2.758862 1.710761 71 | v -2.403757 2.559280 -2.039528 72 | v -1.381247 1.596347 1.454191 73 | v -1.163412 1.822574 -2.038382 74 | v -0.078146 -0.412391 1.712912 75 | v -0.074680 -0.412391 -2.037376 76 | v -5.393490 2.359763 -2.091071 77 | v -3.270963 2.199023 -4.547807 78 | v -4.922800 2.812483 -1.713156 79 | v -2.779778 2.812484 -4.382275 80 | v -4.138320 2.996925 -1.083301 81 | v -1.995298 2.876630 -3.752418 82 | v -2.843926 2.695112 -0.044037 83 | v -0.700904 2.512949 -2.713154 84 | v -1.966746 1.634059 0.358820 85 | v 0.181862 1.840542 -2.004385 86 | v -1.186299 -0.199359 1.286863 87 | v 0.956723 -0.199359 -1.382254 88 | v -3.411818 3.548868 0.997281 89 | v -2.987591 3.599077 -1.523562 90 | v -2.848599 3.707952 1.095761 91 | v -2.444523 3.919941 -1.557639 92 | v -2.065775 3.556531 1.202876 93 | v -1.694590 3.680621 -1.462553 94 | v -0.939843 2.863784 1.318995 95 | v -0.585573 2.942669 -1.352623 96 | v -0.520648 1.836716 1.113190 97 | v 0.054735 2.129301 -1.320096 98 | v -0.183668 0.144097 1.216864 99 | v 0.220408 0.356086 -1.436535 100 | v -2.752246 3.548868 -2.331894 101 | v -0.428357 3.599077 -3.396862 102 | v -2.517365 3.707952 -1.810603 103 | v -0.095124 3.919941 -2.966700 104 | v -2.166277 3.556531 -1.102773 105 | v 0.247442 3.680621 -2.292838 106 | v -1.629914 2.863784 -0.106017 107 | v 0.779423 2.942669 -1.313553 108 | v -1.224182 1.836715 0.125201 109 | v 1.112171 2.129301 -0.765528 110 | v -1.120676 0.144097 0.462233 111 | v 1.301564 0.356086 -0.693862 112 | v 1.179569 3.548868 -3.299581 113 | v 3.068619 3.599077 -1.577340 114 | v 0.791671 3.707952 -2.879523 115 | v 2.803056 3.919941 -1.102408 116 | v 0.345733 3.637383 -2.162762 117 | v 2.385048 3.761473 -0.406775 118 | v -0.430031 2.863784 -1.396071 119 | v 1.623650 2.942669 0.349049 120 | v -0.484141 1.836715 -0.932226 121 | v 1.249424 2.129301 0.869633 122 | v -0.753842 0.144098 -0.705146 123 | v 1.257542 0.356086 1.071969 124 | v 3.478751 3.063767 0.129736 125 | v 2.508179 3.113976 2.494606 126 | v 2.969543 3.472751 -0.191974 127 | v 1.989343 3.684741 2.306629 128 | v 2.194941 3.556531 -0.538472 129 | v 1.244161 3.680621 1.979129 130 | v 1.122468 2.863784 -0.900428 131 | v 0.186821 2.942669 1.626945 132 | v 0.668168 1.836715 -0.792301 133 | v -0.430486 2.129301 1.453785 134 | v 0.362412 0.144098 -0.967850 135 | v -0.617787 0.356086 1.530752 136 | v 1.723514 3.227772 2.919589 137 | v -0.813319 3.277982 3.234388 138 | v 1.606172 3.518214 2.393483 139 | v -1.051909 3.730203 2.765519 140 | v 1.425735 3.556531 1.529277 141 | v -1.234463 3.680621 1.936269 142 | v 1.214835 2.863784 0.417193 143 | v -1.446452 2.942669 0.842165 144 | v 0.897690 1.836715 0.074411 145 | v -1.598496 2.129301 0.219321 146 | v 0.900611 0.144098 -0.278144 147 | v -1.757470 0.356086 0.093891 148 | vt 0.261788 0.894097 149 | vt 0.741905 0.894097 150 | vt 0.261788 0.999931 151 | vt 0.261788 0.750634 152 | vt 0.741905 0.750634 153 | vt 0.261788 0.513983 154 | vt 0.741905 0.513983 155 | vt 0.261788 0.307545 156 | vt 0.741905 0.307545 157 | vt 0.261788 0.000069 158 | vt 0.741905 0.000069 159 | vt 0.741905 0.999931 160 | vn 0.012848 0.702567 -0.711478 161 | vn 0.020722 0.682089 -0.730949 162 | vn 0.008454 0.417798 -0.908475 163 | vn 0.034089 0.970763 -0.237495 164 | vn 0.028413 0.982147 -0.185919 165 | vn -0.002197 0.931425 0.363872 166 | vn 0.050600 0.950804 0.305551 167 | vn -0.060060 0.579974 0.812403 168 | vn -0.036378 0.647877 0.760857 169 | vn 0.000000 0.544298 0.838862 170 | vn -0.051668 0.478774 0.876400 171 | vn 0.409406 0.911954 0.025819 172 | vn 0.432630 0.901395 -0.016755 173 | vn 0.762535 0.646565 -0.021699 174 | vn -0.002838 0.999115 0.041627 175 | vn -0.064425 0.997650 0.023103 176 | vn -0.440352 0.897580 0.020173 177 | vn -0.361736 0.930509 0.057314 178 | vn -0.797571 0.600513 -0.056856 179 | vn -0.745903 0.665731 0.019196 180 | vn -0.861782 0.506851 -0.018891 181 | vn -0.898312 0.437910 0.034822 182 | vn 0.698874 0.494675 0.516556 183 | vn 0.674551 0.550340 0.491989 184 | vn 0.814081 0.058443 0.577746 185 | vn 0.238380 0.950316 0.200171 186 | vn 0.172155 0.971587 0.162389 187 | vn -0.299814 0.931639 -0.205206 188 | vn -0.266366 0.954711 -0.132359 189 | vn -0.600360 0.600513 -0.528123 190 | vn -0.605304 0.665731 -0.436293 191 | vn -0.674459 0.506851 -0.536790 192 | vn -0.736076 0.437910 -0.516129 193 | vn -0.036775 0.916135 0.399121 194 | vn -0.080782 0.901364 0.425428 195 | vn -0.066225 0.776391 0.626728 196 | vn -0.025605 0.999512 -0.017548 197 | vn -0.027863 0.996460 -0.078982 198 | vn -0.003967 0.883175 -0.468978 199 | vn 0.045595 0.915891 -0.398785 200 | vn 0.083438 0.617115 -0.782434 201 | vn 0.155522 0.675375 -0.720847 202 | vn 0.076968 0.544298 -0.835322 203 | vn 0.131870 0.478774 -0.867946 204 | vn -0.305338 0.916135 0.259651 205 | vn -0.355174 0.901364 0.247688 206 | vn -0.485519 0.776391 0.401807 207 | vn -0.005890 0.999725 -0.022248 208 | vn 0.027192 0.996612 -0.077395 209 | vn 0.333567 0.880856 -0.335856 210 | vn 0.311014 0.913816 -0.261086 211 | vn 0.606677 0.617115 -0.501083 212 | vn 0.615162 0.675375 -0.406659 213 | vn 0.639058 0.544298 -0.543443 214 | vn 0.701102 0.478774 -0.528367 215 | vn -0.626392 0.779382 -0.011170 216 | vn -0.616840 0.786798 -0.020203 217 | vn -0.752464 0.658498 -0.011689 218 | vn -0.232734 0.971923 -0.034364 219 | vn -0.149419 0.988311 -0.029939 220 | vn 0.432173 0.900845 -0.040376 221 | vn 0.368816 0.929472 0.002625 222 | vn 0.786767 0.617115 0.011994 223 | vn 0.731986 0.675375 0.089389 224 | vn 0.838862 0.544298 0.000763 225 | vn 0.876339 0.478774 0.052461 226 | vn -0.312540 0.916135 -0.250923 227 | vn -0.310190 0.901364 -0.302133 228 | vn -0.486099 0.776391 -0.401105 229 | vn 0.020722 0.999725 -0.009980 230 | vn 0.081118 0.996612 0.012116 231 | vn 0.392682 0.880856 0.264290 232 | vn 0.315012 0.913816 0.256233 233 | vn 0.606433 0.617115 0.501389 234 | vn 0.515305 0.675375 0.527512 235 | vn 0.654134 0.544298 0.525193 236 | vn 0.651021 0.478774 0.588977 237 | vn -0.039766 0.997467 0.058840 238 | vn -0.070223 0.996551 0.043672 239 | vn -0.312082 0.949828 0.019776 240 | vn 0.351970 0.931425 0.092380 241 | vn 0.406476 0.907346 0.107028 242 | vn 0.748741 0.650807 0.125645 243 | vn 0.693106 0.701834 0.164220 244 | vn 0.941008 0.287820 0.177740 245 | vn 0.899045 0.355663 0.255348 246 | vn 0.965636 0.202216 0.163182 247 | vn 0.969817 0.123722 0.209998 248 | vn -0.071017 0.997467 0.000122 249 | vn -0.075594 0.996551 -0.033570 250 | vn -0.191656 0.949828 -0.247078 251 | vn 0.121281 0.931425 0.343089 252 | vn 0.139744 0.907346 0.396405 253 | vn 0.316568 0.650807 0.690054 254 | vn 0.253426 0.701834 0.665700 255 | vn 0.381481 0.287820 0.878384 256 | vn 0.293710 0.355663 0.887234 257 | vn 0.407361 0.202216 0.890561 258 | vn 0.370983 0.123722 0.920347 259 | vn 0.044221 0.993347 -0.106052 260 | vn 0.014801 0.990722 -0.134922 261 | vn 0.269295 0.877132 -0.397565 262 | vn -0.255837 0.938749 0.230781 263 | vn -0.302591 0.912412 0.275491 264 | vn -0.551134 0.636799 0.539171 265 | vn -0.469649 0.713095 0.520463 266 | vn -0.716178 0.263527 0.646229 267 | vn -0.648152 0.347850 0.677389 268 | vn -0.701132 0.155553 0.695822 269 | vn -0.664724 0.081668 0.742607 270 | vn 0.327616 0.942656 0.063509 271 | vn 0.362804 0.927641 0.088351 272 | vn 0.580432 0.796350 0.169958 273 | vn -0.204443 0.971740 -0.117893 274 | vn -0.237220 0.959471 -0.151952 275 | vn -0.667226 0.674642 -0.315622 276 | vn -0.624378 0.736290 -0.260781 277 | vn -0.852535 0.263527 -0.451338 278 | vn -0.858486 0.347850 -0.376751 279 | vn -0.893948 0.155553 -0.420240 280 | vn -0.925413 0.081668 -0.369976 281 | vn 0.088076 0.954680 0.284280 282 | vn 0.097964 0.957030 0.272896 283 | vn 0.140873 0.767968 0.624775 284 | vn 0.011750 0.963805 -0.266305 285 | vn -0.005890 0.945097 -0.326640 286 | vn -0.052400 0.674642 -0.736229 287 | vn -0.079134 0.736290 -0.672018 288 | vn -0.025086 0.263527 -0.964324 289 | vn -0.092990 0.347850 -0.932920 290 | vn -0.072512 0.155553 -0.985137 291 | vn -0.131748 0.081668 -0.987884 292 | vn 0.048097 0.271249 -0.961303 293 | vn 0.600787 0.798486 0.037904 294 | vn 0.775353 0.200293 0.598895 295 | vn -0.130985 0.609851 0.781579 296 | vn -0.640095 0.609851 0.467238 297 | vn -0.851009 0.521989 -0.057314 298 | vn -0.579485 0.609851 -0.540574 299 | vn -0.510666 0.856990 -0.068850 300 | vn -0.229835 0.856990 -0.461165 301 | vn 0.166631 0.963195 -0.210852 302 | vn 0.670217 0.694968 0.260292 303 | vn 0.075594 0.879971 0.468917 304 | s 1 305 | f 3/1/1 4/2/2 1/3/3 306 | f 5/4/4 6/5/5 3/1/1 307 | f 7/6/6 8/7/7 6/5/5 308 | f 9/8/8 10/9/9 7/6/6 309 | f 11/10/10 12/11/11 9/8/8 310 | f 15/1/12 16/2/13 14/12/14 311 | f 17/4/15 18/5/16 15/1/12 312 | f 19/6/17 20/7/18 17/4/15 313 | f 21/8/19 22/9/20 19/6/17 314 | f 23/10/21 24/11/22 22/9/20 315 | f 27/1/23 28/2/24 26/12/25 316 | f 29/4/26 30/5/27 28/2/24 317 | f 31/6/28 32/7/29 29/4/26 318 | f 33/8/30 34/9/31 31/6/28 319 | f 35/10/32 36/11/33 34/9/31 320 | f 39/1/34 40/2/35 37/3/36 321 | f 41/4/37 42/5/38 40/2/35 322 | f 43/6/39 44/7/40 41/4/37 323 | f 45/8/41 46/9/42 44/7/40 324 | f 47/10/43 48/11/44 45/8/41 325 | f 51/1/45 52/2/46 49/3/47 326 | f 53/4/48 54/5/49 52/2/46 327 | f 55/6/50 56/7/51 54/5/49 328 | f 57/8/52 58/9/53 56/7/51 329 | f 59/10/54 60/11/55 57/8/52 330 | f 63/1/56 64/2/57 61/3/58 331 | f 65/4/59 66/5/60 63/1/56 332 | f 67/6/61 68/7/62 66/5/60 333 | f 69/8/63 70/9/64 68/7/62 334 | f 71/10/65 72/11/66 69/8/63 335 | f 75/1/67 76/2/68 73/3/69 336 | f 77/4/70 78/5/71 76/2/68 337 | f 79/6/72 80/7/73 78/5/71 338 | f 81/8/74 82/9/75 80/7/73 339 | f 83/10/76 84/11/77 81/8/74 340 | f 87/1/78 88/2/79 85/3/80 341 | f 89/4/81 90/5/82 87/1/78 342 | f 91/6/83 92/7/84 90/5/82 343 | f 93/8/85 94/9/86 92/7/84 344 | f 95/10/87 96/11/88 93/8/85 345 | f 99/1/89 100/2/90 97/3/91 346 | f 101/4/92 102/5/93 99/1/89 347 | f 103/6/94 104/7/95 102/5/93 348 | f 105/8/96 106/9/97 104/7/95 349 | f 107/10/98 108/11/99 105/8/96 350 | f 111/1/100 112/2/101 110/12/102 351 | f 113/4/103 114/5/104 111/1/100 352 | f 115/6/105 116/7/106 114/5/104 353 | f 117/8/107 118/9/108 115/6/105 354 | f 119/10/109 120/11/110 118/9/108 355 | f 123/1/111 124/2/112 121/3/113 356 | f 125/4/114 126/5/115 123/1/111 357 | f 127/6/116 128/7/117 125/4/114 358 | f 129/8/118 130/9/119 127/6/116 359 | f 131/10/120 132/11/121 130/9/119 360 | f 135/1/122 136/2/123 134/12/124 361 | f 137/4/125 138/5/126 136/2/123 362 | f 139/6/127 140/7/128 137/4/125 363 | f 141/8/129 142/9/130 139/6/127 364 | f 143/10/131 144/11/132 142/9/130 365 | f 4/2/2 2/12/133 1/3/3 366 | f 6/5/5 4/2/2 3/1/1 367 | f 5/4/4 7/6/6 6/5/5 368 | f 10/9/9 8/7/7 7/6/6 369 | f 12/11/11 10/9/9 9/8/8 370 | f 13/3/134 15/1/12 14/12/14 371 | f 18/5/16 16/2/13 15/1/12 372 | f 20/7/18 18/5/16 17/4/15 373 | f 22/9/20 20/7/18 19/6/17 374 | f 21/8/19 23/10/21 22/9/20 375 | f 25/3/135 27/1/23 26/12/25 376 | f 27/1/23 29/4/26 28/2/24 377 | f 32/7/29 30/5/27 29/4/26 378 | f 34/9/31 32/7/29 31/6/28 379 | f 33/8/30 35/10/32 34/9/31 380 | f 40/2/35 38/12/136 37/3/36 381 | f 39/1/34 41/4/37 40/2/35 382 | f 44/7/40 42/5/38 41/4/37 383 | f 43/6/39 45/8/41 44/7/40 384 | f 48/11/44 46/9/42 45/8/41 385 | f 52/2/46 50/12/137 49/3/47 386 | f 51/1/45 53/4/48 52/2/46 387 | f 53/4/48 55/6/50 54/5/49 388 | f 55/6/50 57/8/52 56/7/51 389 | f 60/11/55 58/9/53 57/8/52 390 | f 64/2/57 62/12/138 61/3/58 391 | f 66/5/60 64/2/57 63/1/56 392 | f 65/4/59 67/6/61 66/5/60 393 | f 67/6/61 69/8/63 68/7/62 394 | f 72/11/66 70/9/64 69/8/63 395 | f 76/2/68 74/12/139 73/3/69 396 | f 75/1/67 77/4/70 76/2/68 397 | f 77/4/70 79/6/72 78/5/71 398 | f 79/6/72 81/8/74 80/7/73 399 | f 84/11/77 82/9/75 81/8/74 400 | f 88/2/79 86/12/140 85/3/80 401 | f 90/5/82 88/2/79 87/1/78 402 | f 89/4/81 91/6/83 90/5/82 403 | f 91/6/83 93/8/85 92/7/84 404 | f 96/11/88 94/9/86 93/8/85 405 | f 100/2/90 98/12/141 97/3/91 406 | f 102/5/93 100/2/90 99/1/89 407 | f 101/4/92 103/6/94 102/5/93 408 | f 103/6/94 105/8/96 104/7/95 409 | f 108/11/99 106/9/97 105/8/96 410 | f 109/3/142 111/1/100 110/12/102 411 | f 114/5/104 112/2/101 111/1/100 412 | f 113/4/103 115/6/105 114/5/104 413 | f 118/9/108 116/7/106 115/6/105 414 | f 117/8/107 119/10/109 118/9/108 415 | f 124/2/112 122/12/143 121/3/113 416 | f 126/5/115 124/2/112 123/1/111 417 | f 128/7/117 126/5/115 125/4/114 418 | f 130/9/119 128/7/117 127/6/116 419 | f 129/8/118 131/10/120 130/9/119 420 | f 133/3/144 135/1/122 134/12/124 421 | f 135/1/122 137/4/125 136/2/123 422 | f 140/7/128 138/5/126 137/4/125 423 | f 142/9/130 140/7/128 139/6/127 424 | f 141/8/129 143/10/131 142/9/130 425 | -------------------------------------------------------------------------------- /res/models/grass/grassModel.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.67 (sub 0) OBJ File: 'lowPolyPlants.blend' 2 | # www.blender.org 3 | o Plane 4 | v 0.063088 0.003610 -4.997082 5 | v -1.136912 0.003610 -4.997082 6 | v 0.063088 1.203610 -4.997082 7 | v -1.136912 1.203610 -4.997082 8 | v -0.536911 0.003610 -5.597082 9 | v -0.536912 0.003610 -4.397082 10 | v -0.536912 1.203610 -5.597083 11 | v -0.536912 1.203610 -4.397082 12 | v -5.427285 0.003610 -0.769423 13 | v -6.627285 0.003610 -0.769423 14 | v -5.427285 1.203610 -0.769424 15 | v -6.627285 1.203610 -0.769424 16 | v -6.027285 0.003610 -1.369424 17 | v -6.027285 0.003610 -0.169423 18 | v -6.027285 1.203610 -1.369424 19 | v -6.027285 1.203610 -0.169424 20 | v 0.627331 0.003610 1.154491 21 | v 0.120805 0.003610 0.066634 22 | v 0.627331 1.203610 1.154491 23 | v 0.120805 1.203610 0.066634 24 | v 0.917996 0.003610 0.357300 25 | v -0.169860 0.003611 0.863825 26 | v 0.917996 1.203610 0.357300 27 | v -0.169860 1.203610 0.863825 28 | v 2.736700 0.003610 -2.973755 29 | v 1.939363 0.003610 -3.870557 30 | v 2.736700 1.203610 -2.973755 31 | v 1.939363 1.203610 -3.870557 32 | v 2.786432 0.003610 -3.820825 33 | v 1.889630 0.003610 -3.023487 34 | v 2.786432 1.203610 -3.820825 35 | v 1.889630 1.203610 -3.023487 36 | v -2.374338 0.003610 -1.890785 37 | v -3.247929 0.003610 -2.713487 38 | v -2.374338 1.203610 -1.890785 39 | v -3.247929 1.203610 -2.713487 40 | v -2.399782 0.003610 -2.738931 41 | v -3.222484 0.003611 -1.865341 42 | v -2.399782 1.203610 -2.738931 43 | v -3.222484 1.203610 -1.865341 44 | v 6.729870 0.003610 2.758007 45 | v 7.206303 0.003610 1.656639 46 | v 6.729870 1.203610 2.758007 47 | v 7.206303 1.203610 1.656640 48 | v 7.518770 0.003610 2.445540 49 | v 6.417403 0.003611 1.969108 50 | v 7.518770 1.203610 2.445540 51 | v 6.417403 1.203610 1.969108 52 | v -2.949056 0.003611 6.270791 53 | v -2.019891 0.003611 5.511415 54 | v -2.949056 1.203610 6.270791 55 | v -2.019891 1.203610 5.511416 56 | v -2.104786 0.003610 6.355686 57 | v -2.864161 0.003611 5.426521 58 | v -2.104786 1.203610 6.355686 59 | v -2.864161 1.203610 5.426521 60 | v -11.257655 0.003611 -0.649311 61 | v -12.123328 0.003610 0.181718 62 | v -11.257655 1.203610 -0.649312 63 | v -12.123328 1.203610 0.181718 64 | v -12.106008 0.003611 -0.666633 65 | v -11.274976 0.003610 0.199040 66 | v -12.106008 1.203610 -0.666633 67 | v -11.274976 1.203610 0.199040 68 | v -5.115887 0.003611 6.717537 69 | v -5.981559 0.003611 7.548567 70 | v -5.115886 1.203610 6.717537 71 | v -5.981559 1.203610 7.548567 72 | v -5.964238 0.003611 6.700215 73 | v -5.133207 0.003611 7.565888 74 | v -5.964237 1.203610 6.700215 75 | v -5.133207 1.203610 7.565887 76 | v -4.044483 0.003611 4.351145 77 | v -5.163255 0.003611 3.917153 78 | v -4.044483 1.203610 4.351144 79 | v -5.163255 1.203610 3.917153 80 | v -4.386873 0.003611 3.574763 81 | v -4.820865 0.003611 4.693535 82 | v -4.386873 1.203610 3.574763 83 | v -4.820865 1.203610 4.693534 84 | v -5.924183 0.003610 -3.071747 85 | v -6.925926 0.003611 -3.732436 86 | v -5.924183 1.203610 -3.071747 87 | v -6.925926 1.203610 -3.732436 88 | v -6.094710 0.003611 -3.902963 89 | v -6.755400 0.003611 -2.901220 90 | v -6.094710 1.203610 -3.902963 91 | v -6.755400 1.203610 -2.901221 92 | v -7.753965 0.003611 1.248239 93 | v -8.950217 0.003611 1.153468 94 | v -7.753965 1.203610 1.248238 95 | v -8.950217 1.203610 1.153467 96 | v -8.304706 0.003611 0.602727 97 | v -8.399476 0.003611 1.798979 98 | v -8.304706 1.203610 0.602727 99 | v -8.399476 1.203610 1.798979 100 | v -1.912768 0.003610 0.464466 101 | v -2.331797 0.003611 -0.659996 102 | v -1.912768 1.203610 0.464466 103 | v -2.331796 1.203610 -0.659996 104 | v -1.560051 0.003611 -0.307279 105 | v -2.684512 0.003611 0.111750 106 | v -1.560051 1.203610 -0.307280 107 | v -2.684513 1.203610 0.111750 108 | v -4.742368 0.003611 1.656384 109 | v -5.161397 0.003611 0.531922 110 | v -4.742368 1.203610 1.656384 111 | v -5.161397 1.203610 0.531922 112 | v -4.389652 0.003611 0.884638 113 | v -5.514113 0.003611 1.303667 114 | v -4.389652 1.203610 0.884638 115 | v -5.514114 1.203610 1.303667 116 | v 4.391148 1.203610 0.926363 117 | v 3.597642 1.203610 0.026169 118 | v 4.391148 0.003611 0.926362 119 | v 3.597642 0.003610 0.026169 120 | v 3.544298 1.203610 0.873019 121 | v 4.444492 1.203610 0.079513 122 | v 3.544298 0.003610 0.873018 123 | v 4.444492 0.003610 0.079513 124 | v 4.806449 1.203610 3.812527 125 | v 3.732761 1.203610 3.276623 126 | v 4.806449 0.003611 3.812527 127 | v 3.732761 0.003611 3.276624 128 | v 4.001654 1.203610 4.081419 129 | v 4.537557 1.203610 3.007731 130 | v 4.001654 0.003611 4.081419 131 | v 4.537557 0.003611 3.007731 132 | v 6.609623 1.203610 -3.161592 133 | v 7.186171 1.203610 -4.214014 134 | v 6.609624 0.003611 -3.161592 135 | v 7.186171 0.003610 -4.214014 136 | v 6.371686 1.203610 -3.976077 137 | v 7.424108 1.203610 -3.399530 138 | v 6.371686 0.003611 -3.976076 139 | v 7.424108 0.003610 -3.399530 140 | v -0.487433 1.203610 1.980146 141 | v -1.577091 1.203610 1.477509 142 | v -0.487433 0.003611 1.980146 143 | v -1.577091 0.003610 1.477509 144 | v -1.283581 1.203610 2.273656 145 | v -0.780943 1.203610 1.183998 146 | v -1.283581 0.003610 2.273657 147 | v -0.780943 0.003610 1.183998 148 | v 10.179677 1.203610 0.517455 149 | v 8.984852 1.203610 0.406136 150 | v 10.179677 0.003611 0.517455 151 | v 8.984852 0.003610 0.406136 152 | v 9.526605 1.203610 1.059208 153 | v 9.637924 1.203610 -0.135617 154 | v 9.526605 0.003610 1.059208 155 | v 9.637924 0.003610 -0.135617 156 | v 5.869500 1.203610 5.422760 157 | v 4.930470 1.203610 6.169901 158 | v 5.869502 0.003611 5.422760 159 | v 4.930470 0.003611 6.169903 160 | v 5.773557 1.203610 6.265846 161 | v 5.026414 1.203610 5.326817 162 | v 5.773557 0.003611 6.265847 163 | v 5.026415 0.003611 5.326817 164 | v 0.637121 1.203610 -1.805795 165 | v 1.213668 1.203610 -2.858217 166 | v 0.637121 0.003611 -1.805795 167 | v 1.213669 0.003611 -2.858217 168 | v 0.399184 1.203610 -2.620279 169 | v 1.451606 1.203610 -2.043732 170 | v 0.399184 0.003611 -2.620279 171 | v 1.451606 0.003611 -2.043732 172 | v 1.740329 1.203610 -0.516481 173 | v 1.336903 1.203610 -1.646635 174 | v 1.740329 0.003611 -0.516482 175 | v 1.336903 0.003610 -1.646635 176 | v 0.973539 1.203610 -0.879845 177 | v 2.103693 1.203610 -1.283271 178 | v 0.973540 0.003611 -0.879845 179 | v 2.103693 0.003611 -1.283271 180 | v 3.117721 1.203610 2.883694 181 | v 2.804810 1.203610 1.725209 182 | v 3.117721 0.003611 2.883693 183 | v 2.804810 0.003611 1.725209 184 | v 2.382023 1.203610 2.460907 185 | v 3.540508 1.203610 2.147995 186 | v 2.382023 0.003611 2.460907 187 | v 3.540508 0.003611 2.147995 188 | v 1.243791 1.203610 8.964542 189 | v 0.077800 1.203610 9.248203 190 | v 1.243791 0.003611 8.964540 191 | v 0.077800 0.003611 9.248203 192 | v 0.802626 1.203610 9.689367 193 | v 0.518964 1.203610 8.523376 194 | v 0.802626 0.003611 9.689367 195 | v 0.518964 0.003611 8.523376 196 | v 4.819168 1.203610 -1.187724 197 | v 4.506256 1.203610 -2.346208 198 | v 4.819168 0.003611 -1.187724 199 | v 4.506257 0.003611 -2.346208 200 | v 4.083470 1.203610 -1.610511 201 | v 5.241954 1.203610 -1.923421 202 | v 4.083470 0.003611 -1.610510 203 | v 5.241954 0.003611 -1.923421 204 | v 0.499905 1.203610 -8.019167 205 | v -0.210803 1.203610 -8.986067 206 | v 0.499905 0.003610 -8.019167 207 | v -0.210803 0.003610 -8.986066 208 | v -0.338899 1.203610 -8.147264 209 | v 0.628001 1.203610 -8.857970 210 | v -0.338898 0.003610 -8.147264 211 | v 0.628001 0.003610 -8.857970 212 | v -2.017782 1.203610 3.719780 213 | v -2.953916 1.203610 2.969012 214 | v -2.017782 0.003611 3.719780 215 | v -2.953915 0.003611 2.969012 216 | v -2.861232 1.203610 3.812463 217 | v -2.110465 1.203610 2.876329 218 | v -2.861232 0.003611 3.812463 219 | v -2.110465 0.003611 2.876329 220 | v 1.450961 1.203610 5.045464 221 | v 0.268659 1.203610 4.840132 222 | v 1.450961 0.003611 5.045464 223 | v 0.268660 0.003611 4.840132 224 | v 0.757144 1.203610 5.533949 225 | v 0.962477 1.203610 4.351647 226 | v 0.757144 0.003611 5.533949 227 | v 0.962477 0.003611 4.351646 228 | vt 0.000100 0.000100 229 | vt 0.999900 0.000100 230 | vt 0.999900 0.999900 231 | vt 0.000100 0.999900 232 | vn 0.000000 0.000000 1.000000 233 | vn 1.000000 0.000000 0.000000 234 | vn -0.906547 0.000000 0.422104 235 | vn 0.422104 0.000000 0.906547 236 | vn -0.747335 0.000000 0.664448 237 | vn 0.664448 0.000000 0.747335 238 | vn -0.685585 0.000000 0.727992 239 | vn 0.727992 0.000000 0.685585 240 | vn -0.917807 0.000001 -0.397027 241 | vn -0.397027 0.000000 0.917807 242 | vn -0.632813 0.000000 -0.774304 243 | vn -0.774305 0.000000 0.632813 244 | vn 0.692525 0.000000 0.721394 245 | vn 0.721393 -0.000000 -0.692526 246 | vn 0.721394 -0.000001 -0.692525 247 | vn -0.361660 0.000000 0.932310 248 | vn 0.932310 0.000000 0.361660 249 | vn -0.550575 0.000000 0.834786 250 | vn 0.834786 0.000000 0.550575 251 | vn -0.078976 0.000000 0.996877 252 | vn 0.996877 0.000000 0.078975 253 | vn -0.937052 0.000000 0.349191 254 | vn 0.349191 0.000001 0.937052 255 | vn 0.349191 -0.000000 0.937052 256 | vn 0.750161 0.000000 -0.661255 257 | vn 0.661255 -0.000000 0.750162 258 | vn 0.446586 -0.000000 -0.894741 259 | vn 0.894741 -0.000000 0.446586 260 | vn 0.877019 0.000000 0.480456 261 | vn -0.480456 0.000001 0.877019 262 | vn 0.418865 -0.000000 -0.908049 263 | vn 0.908049 0.000000 0.418865 264 | vn 0.092766 0.000000 -0.995688 265 | vn 0.995688 0.000000 0.092766 266 | vn -0.622618 -0.000001 -0.782526 267 | vn 0.782526 0.000001 -0.622618 268 | vn -0.480456 0.000000 0.877019 269 | vn 0.941795 -0.000000 -0.336188 270 | vn 0.336188 0.000000 0.941795 271 | vn 0.965404 -0.000000 -0.260759 272 | vn 0.260759 0.000000 0.965404 273 | vn -0.236386 0.000001 -0.971659 274 | vn 0.971659 -0.000000 -0.236386 275 | vn 0.965404 0.000001 -0.260759 276 | vn 0.260760 0.000000 0.965404 277 | vn 0.805749 -0.000000 -0.592257 278 | vn 0.592256 -0.000000 0.805750 279 | vn 0.625641 0.000001 -0.780111 280 | vn 0.780112 0.000000 0.625640 281 | vn 0.171110 0.000000 -0.985252 282 | vn 0.985252 0.000000 0.171111 283 | vn 0.664448 0.000000 0.747334 284 | vn -0.917807 -0.000000 -0.397028 285 | vn -0.632813 -0.000000 -0.774305 286 | vn -0.774304 0.000000 0.632813 287 | vn 0.721394 -0.000000 -0.692525 288 | vn -0.361659 0.000000 0.932310 289 | vn 0.661254 -0.000000 0.750162 290 | vn 0.877019 0.000001 0.480457 291 | vn 0.092765 -0.000000 -0.995688 292 | vn -0.622618 -0.000000 -0.782526 293 | vn 0.782525 -0.000000 -0.622619 294 | vn -0.236384 0.000000 -0.971660 295 | vn 0.971659 0.000000 -0.236385 296 | vn 0.965404 0.000000 -0.260760 297 | vn 0.260759 0.000001 0.965404 298 | vn 0.805750 0.000000 -0.592256 299 | vn 0.625640 -0.000000 -0.780112 300 | vn 0.780112 0.000000 0.625639 301 | s off 302 | f 2/1/1 1/2/1 3/3/1 303 | f 6/1/2 5/2/2 7/3/2 304 | f 10/1/1 9/2/1 11/3/1 305 | f 14/1/2 13/2/2 15/3/2 306 | f 18/1/3 17/2/3 20/4/3 307 | f 22/1/4 21/2/4 23/3/4 308 | f 26/1/5 25/2/5 28/4/5 309 | f 30/1/6 29/2/6 31/3/6 310 | f 34/1/7 33/2/7 36/4/7 311 | f 38/1/8 37/2/8 39/3/8 312 | f 42/1/9 41/2/9 44/4/9 313 | f 46/1/10 45/2/10 48/4/10 314 | f 50/1/11 49/2/11 52/4/11 315 | f 54/1/12 53/2/12 56/4/12 316 | f 58/1/13 57/2/13 59/3/13 317 | f 62/1/14 61/2/14 63/3/14 318 | f 66/1/13 65/2/13 67/3/13 319 | f 70/1/15 69/2/15 71/3/15 320 | f 74/1/16 73/2/16 76/4/16 321 | f 78/1/17 77/2/17 79/3/17 322 | f 82/1/18 81/2/18 84/4/18 323 | f 86/1/19 85/2/19 87/3/19 324 | f 90/1/20 89/2/20 92/4/20 325 | f 94/1/21 93/2/21 95/3/21 326 | f 98/1/22 97/2/22 100/4/22 327 | f 102/1/23 101/2/23 103/3/23 328 | f 106/1/22 105/2/22 108/4/22 329 | f 110/1/24 109/2/24 111/3/24 330 | f 115/1/25 116/2/25 114/3/25 331 | f 119/1/26 120/2/26 118/3/26 332 | f 123/1/27 124/2/27 122/3/27 333 | f 127/1/28 128/2/28 126/3/28 334 | f 131/1/29 132/2/29 130/3/29 335 | f 135/1/30 136/2/30 133/4/30 336 | f 139/1/31 140/2/31 138/3/31 337 | f 143/1/32 144/2/32 142/3/32 338 | f 147/1/33 148/2/33 146/3/33 339 | f 151/1/34 152/2/34 150/3/34 340 | f 155/1/35 156/2/35 153/4/35 341 | f 159/1/36 160/2/36 158/3/36 342 | f 163/1/29 164/2/29 162/3/29 343 | f 167/1/37 168/2/37 165/4/37 344 | f 171/1/38 172/2/38 170/3/38 345 | f 175/1/39 176/2/39 174/3/39 346 | f 179/1/40 180/2/40 178/3/40 347 | f 183/1/41 184/2/41 182/3/41 348 | f 187/1/42 188/2/42 185/4/42 349 | f 191/1/43 192/2/43 190/3/43 350 | f 195/1/44 196/2/44 194/3/44 351 | f 199/1/45 200/2/45 198/3/45 352 | f 203/1/46 204/2/46 202/3/46 353 | f 207/1/47 208/2/47 206/3/47 354 | f 211/1/48 212/2/48 210/3/48 355 | f 215/1/49 216/2/49 214/3/49 356 | f 219/1/50 220/2/50 218/3/50 357 | f 223/1/51 224/2/51 222/3/51 358 | f 4/4/1 2/1/1 3/3/1 359 | f 8/4/2 6/1/2 7/3/2 360 | f 12/4/1 10/1/1 11/3/1 361 | f 16/4/2 14/1/2 15/3/2 362 | f 17/2/3 19/3/3 20/4/3 363 | f 24/4/4 22/1/4 23/3/4 364 | f 25/2/5 27/3/5 28/4/5 365 | f 32/4/52 30/1/52 31/3/52 366 | f 33/2/7 35/3/7 36/4/7 367 | f 40/4/8 38/1/8 39/3/8 368 | f 41/2/53 43/3/53 44/4/53 369 | f 45/2/10 47/3/10 48/4/10 370 | f 49/2/54 51/3/54 52/4/54 371 | f 53/2/55 55/3/55 56/4/55 372 | f 60/4/13 58/1/13 59/3/13 373 | f 64/4/14 62/1/14 63/3/14 374 | f 68/4/13 66/1/13 67/3/13 375 | f 72/4/56 70/1/56 71/3/56 376 | f 73/2/57 75/3/57 76/4/57 377 | f 80/4/17 78/1/17 79/3/17 378 | f 81/2/18 83/3/18 84/4/18 379 | f 88/4/19 86/1/19 87/3/19 380 | f 89/2/20 91/3/20 92/4/20 381 | f 96/4/21 94/1/21 95/3/21 382 | f 97/2/22 99/3/22 100/4/22 383 | f 104/4/24 102/1/24 103/3/24 384 | f 105/2/22 107/3/22 108/4/22 385 | f 112/4/24 110/1/24 111/3/24 386 | f 113/4/25 115/1/25 114/3/25 387 | f 117/4/58 119/1/58 118/3/58 388 | f 121/4/27 123/1/27 122/3/27 389 | f 125/4/28 127/1/28 126/3/28 390 | f 129/4/59 131/1/59 130/3/59 391 | f 136/2/37 134/3/37 133/4/37 392 | f 137/4/31 139/1/31 138/3/31 393 | f 141/4/32 143/1/32 142/3/32 394 | f 145/4/60 147/1/60 146/3/60 395 | f 149/4/34 151/1/34 150/3/34 396 | f 156/2/61 154/3/61 153/4/61 397 | f 157/4/62 159/1/62 158/3/62 398 | f 161/4/29 163/1/29 162/3/29 399 | f 168/2/37 166/3/37 165/4/37 400 | f 169/4/38 171/1/38 170/3/38 401 | f 173/4/39 175/1/39 174/3/39 402 | f 177/4/40 179/1/40 178/3/40 403 | f 181/4/45 183/1/45 182/3/45 404 | f 188/2/63 186/3/63 185/4/63 405 | f 189/4/64 191/1/64 190/3/64 406 | f 193/4/65 195/1/65 194/3/65 407 | f 197/4/66 199/1/66 198/3/66 408 | f 201/4/67 203/1/67 202/3/67 409 | f 205/4/47 207/1/47 206/3/47 410 | f 209/4/68 211/1/68 210/3/68 411 | f 213/4/69 215/1/69 214/3/69 412 | f 217/4/50 219/1/50 218/3/50 413 | f 221/4/51 223/1/51 222/3/51 414 | -------------------------------------------------------------------------------- /res/models/lamp/lamp.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'newLamp.blend' 2 | # Material Count: 1 3 | 4 | newmtl None 5 | Ns 0 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.8 0.8 0.8 8 | Ks 0.8 0.8 0.8 9 | d 1 10 | illum 2 11 | map_Kd C:\Users\Karl\workspace\JGame\src\res\newLamp.png 12 | -------------------------------------------------------------------------------- /res/models/lamp/lamp.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.67 (sub 0) OBJ File: 'newLamp.blend' 2 | # www.blender.org 3 | o Circle 4 | v 0.000000 0.000000 -1.000000 5 | v -0.866025 0.000000 -0.500000 6 | v -0.866025 0.000000 0.500000 7 | v 0.000000 0.000000 1.000000 8 | v 0.866025 0.000000 0.500000 9 | v 0.866025 0.000000 -0.500000 10 | v 0.000000 0.203284 -1.000000 11 | v -0.866025 0.203284 -0.500000 12 | v -0.866025 0.203284 0.500000 13 | v 0.000000 0.203284 1.000000 14 | v 0.866025 0.203284 0.500000 15 | v 0.866025 0.203284 -0.500000 16 | v -0.000000 0.292193 -0.684327 17 | v -0.592644 0.292193 -0.342163 18 | v -0.592644 0.292193 0.342163 19 | v 0.000000 0.292193 0.684327 20 | v 0.592644 0.292193 0.342163 21 | v 0.592644 0.292193 -0.342163 22 | v 0.000000 0.704730 -0.526232 23 | v -0.455730 0.704730 -0.263116 24 | v -0.455730 0.704730 0.263116 25 | v 0.000000 0.704730 0.526232 26 | v 0.455731 0.704730 0.263116 27 | v 0.455731 0.704730 -0.263116 28 | v 0.000000 0.845468 -0.578269 29 | v -0.500795 0.845468 -0.289134 30 | v -0.500795 0.845468 0.289134 31 | v 0.000000 0.845468 0.578269 32 | v 0.500795 0.845468 0.289134 33 | v 0.500795 0.845468 -0.289134 34 | v 0.000000 1.003206 -0.445493 35 | v -0.385808 1.003206 -0.222746 36 | v -0.385808 1.003206 0.222747 37 | v 0.000000 1.003206 0.445493 38 | v 0.385808 1.003206 0.222746 39 | v 0.385808 1.003206 -0.222746 40 | v 0.000000 2.090684 -0.282920 41 | v -0.245015 2.090684 -0.141460 42 | v -0.245015 2.090684 0.141460 43 | v 0.000000 2.090684 0.282920 44 | v 0.245016 2.090684 0.141460 45 | v 0.245016 2.090684 -0.141460 46 | v 0.000000 2.326007 -0.427711 47 | v -0.370409 2.326007 -0.213856 48 | v -0.370409 2.326007 0.213856 49 | v 0.000000 2.326007 0.427711 50 | v 0.370409 2.326007 0.213856 51 | v 0.370409 2.326007 -0.213856 52 | v 0.000000 2.475571 -0.427711 53 | v -0.370409 2.475571 -0.213856 54 | v -0.370409 2.475571 0.213856 55 | v 0.000000 2.475571 0.427711 56 | v 0.370409 2.475571 0.213856 57 | v 0.370409 2.475571 -0.213856 58 | v 0.000000 2.729512 -0.272697 59 | v -0.236162 2.729512 -0.136348 60 | v -0.236162 2.729512 0.136348 61 | v 0.000000 2.729512 0.272697 62 | v 0.236162 2.729512 0.136348 63 | v 0.236162 2.729512 -0.136348 64 | v 0.000000 4.879075 -0.272697 65 | v -0.236162 4.879075 -0.136348 66 | v -0.236162 4.879075 0.136348 67 | v 0.000000 4.879075 0.272697 68 | v 0.236162 4.879075 0.136348 69 | v 0.236162 4.879075 -0.136348 70 | v 0.000000 5.243567 -0.375398 71 | v -0.325104 5.243567 -0.187699 72 | v -0.325104 5.243567 0.187699 73 | v 0.000000 5.243567 0.375398 74 | v 0.325104 5.243567 0.187699 75 | v 0.325104 5.243567 -0.187699 76 | v 0.000000 5.672225 -0.266302 77 | v -0.230625 5.672225 -0.133151 78 | v -0.230625 5.672225 0.133151 79 | v 0.000000 5.672225 0.266303 80 | v 0.230625 5.672225 0.133151 81 | v 0.230625 5.672225 -0.133151 82 | v 0.000000 9.141777 -0.266302 83 | v -0.230625 9.141777 -0.133151 84 | v -0.230625 9.141777 0.133151 85 | v 0.000000 9.141777 0.266303 86 | v 0.230625 9.141777 0.133151 87 | v 0.230625 9.141777 -0.133151 88 | v -0.000000 9.568781 -0.680494 89 | v -0.589325 9.568781 -0.340247 90 | v -0.589325 9.568781 0.340247 91 | v 0.000000 9.568781 0.680495 92 | v 0.589325 9.568781 0.340247 93 | v 0.589325 9.568781 -0.340247 94 | v -0.000000 10.843143 -1.192906 95 | v -1.033087 10.843143 -0.596453 96 | v -1.033087 10.843143 0.596453 97 | v 0.000000 10.843143 1.192906 98 | v 1.033087 10.843143 0.596453 99 | v 1.033087 10.843143 -0.596453 100 | v -0.000000 12.189035 -0.741928 101 | v -0.642529 12.189035 -0.370964 102 | v -0.642528 12.189035 0.370964 103 | v 0.000000 12.189035 0.741928 104 | v 0.642529 12.189035 0.370964 105 | v 0.642529 12.189035 -0.370964 106 | v -0.000000 12.280624 -0.974854 107 | v -0.844248 12.280624 -0.487427 108 | v -0.844248 12.280624 0.487427 109 | v 0.000000 12.280624 0.974854 110 | v 0.844248 12.280624 0.487427 111 | v 0.844248 12.280624 -0.487427 112 | v -0.000000 12.774069 -0.819319 113 | v -0.709551 12.774069 -0.409660 114 | v -0.709551 12.774069 0.409660 115 | v 0.000000 12.774069 0.819319 116 | v 0.709551 12.774069 0.409659 117 | v 0.709551 12.774069 -0.409659 118 | v -0.000000 13.182564 -0.377422 119 | v -0.326857 13.182564 -0.188711 120 | v -0.326857 13.182564 0.188711 121 | v 0.000000 13.182564 0.377422 122 | v 0.326857 13.182564 0.188711 123 | v 0.326857 13.182564 -0.188711 124 | v 0.000000 13.820358 0.000000 125 | v -0.589325 9.568781 -0.340247 126 | v -0.589325 9.568781 -0.340247 127 | v -0.000000 9.568781 -0.680494 128 | v -0.000000 9.568781 -0.680494 129 | v -0.589325 9.568781 0.340247 130 | v -0.589325 9.568781 0.340247 131 | v 0.000000 9.568781 0.680495 132 | v 0.000000 9.568781 0.680495 133 | v 0.589325 9.568781 0.340247 134 | v 0.589325 9.568781 0.340247 135 | v 0.589325 9.568781 -0.340247 136 | v 0.589325 9.568781 -0.340247 137 | v -1.033087 10.843143 -0.596453 138 | v -1.033087 10.843143 -0.596453 139 | v -1.033087 10.843143 -0.596453 140 | v -0.000000 10.843143 -1.192906 141 | v -0.000000 10.843143 -1.192906 142 | v -0.000000 10.843143 -1.192906 143 | v -1.033087 10.843143 0.596453 144 | v -1.033087 10.843143 0.596453 145 | v -1.033087 10.843143 0.596453 146 | v 0.000000 10.843143 1.192906 147 | v 0.000000 10.843143 1.192906 148 | v 0.000000 10.843143 1.192906 149 | v 1.033087 10.843143 0.596453 150 | v 1.033087 10.843143 0.596453 151 | v 1.033087 10.843143 0.596453 152 | v 1.033087 10.843143 -0.596453 153 | v 1.033087 10.843143 -0.596453 154 | v 1.033087 10.843143 -0.596453 155 | v -0.642529 12.189035 -0.370964 156 | v -0.642529 12.189035 -0.370964 157 | v -0.000000 12.189035 -0.741928 158 | v -0.000000 12.189035 -0.741928 159 | v -0.642528 12.189035 0.370964 160 | v -0.642528 12.189035 0.370964 161 | v 0.000000 12.189035 0.741928 162 | v 0.000000 12.189035 0.741928 163 | v 0.642529 12.189035 0.370964 164 | v 0.642529 12.189035 0.370964 165 | v 0.642529 12.189035 -0.370964 166 | v 0.642529 12.189035 -0.370964 167 | v -0.866025 0.203284 -0.500000 168 | v -0.866025 0.203284 -0.500000 169 | v -0.866025 0.203284 -0.500000 170 | v 0.000000 0.203284 -1.000000 171 | v 0.000000 0.203284 -1.000000 172 | v 0.000000 0.203284 -1.000000 173 | v -0.866025 0.203284 0.500000 174 | v -0.866025 0.203284 0.500000 175 | v -0.866025 0.203284 0.500000 176 | v 0.000000 0.203284 1.000000 177 | v 0.000000 0.203284 1.000000 178 | v 0.000000 0.203284 1.000000 179 | v 0.866025 0.203284 0.500000 180 | v 0.866025 0.203284 0.500000 181 | v 0.866025 0.203284 0.500000 182 | v 0.866025 0.203284 -0.500000 183 | v 0.866025 0.203284 -0.500000 184 | v 0.866025 0.203284 -0.500000 185 | v 0.866025 0.000000 -0.500000 186 | v 0.866025 0.000000 0.500000 187 | v -0.866025 0.000000 0.500000 188 | v -0.866025 0.000000 -0.500000 189 | v 0.000000 0.000000 1.000000 190 | v 0.000000 0.000000 -1.000000 191 | v -0.592644 0.292193 -0.342163 192 | v -0.592644 0.292193 -0.342163 193 | v -0.592644 0.292193 -0.342163 194 | v -0.000000 0.292193 -0.684327 195 | v -0.000000 0.292193 -0.684327 196 | v -0.000000 0.292193 -0.684327 197 | v -0.592644 0.292193 0.342163 198 | v -0.592644 0.292193 0.342163 199 | v -0.592644 0.292193 0.342163 200 | v 0.000000 0.292193 0.684327 201 | v 0.000000 0.292193 0.684327 202 | v 0.000000 0.292193 0.684327 203 | v 0.592644 0.292193 0.342163 204 | v 0.592644 0.292193 0.342163 205 | v 0.592644 0.292193 0.342163 206 | v 0.592644 0.292193 -0.342163 207 | v 0.592644 0.292193 -0.342163 208 | v 0.592644 0.292193 -0.342163 209 | v -0.455730 0.704730 -0.263116 210 | v -0.455730 0.704730 -0.263116 211 | v -0.455730 0.704730 -0.263116 212 | v 0.000000 0.704730 -0.526232 213 | v 0.000000 0.704730 -0.526232 214 | v 0.000000 0.704730 -0.526232 215 | v -0.455730 0.704730 0.263116 216 | v -0.455730 0.704730 0.263116 217 | v -0.455730 0.704730 0.263116 218 | v 0.000000 0.704730 0.526232 219 | v 0.000000 0.704730 0.526232 220 | v 0.000000 0.704730 0.526232 221 | v 0.455731 0.704730 0.263116 222 | v 0.455731 0.704730 0.263116 223 | v 0.455731 0.704730 0.263116 224 | v 0.455731 0.704730 -0.263116 225 | v 0.455731 0.704730 -0.263116 226 | v 0.455731 0.704730 -0.263116 227 | v -0.500795 0.845468 -0.289134 228 | v -0.500795 0.845468 -0.289134 229 | v -0.500795 0.845468 -0.289134 230 | v 0.000000 0.845468 -0.578269 231 | v 0.000000 0.845468 -0.578269 232 | v 0.000000 0.845468 -0.578269 233 | v -0.500795 0.845468 0.289134 234 | v -0.500795 0.845468 0.289134 235 | v -0.500795 0.845468 0.289134 236 | v 0.000000 0.845468 0.578269 237 | v 0.000000 0.845468 0.578269 238 | v 0.000000 0.845468 0.578269 239 | v 0.500795 0.845468 0.289134 240 | v 0.500795 0.845468 0.289134 241 | v 0.500795 0.845468 0.289134 242 | v 0.500795 0.845468 -0.289134 243 | v 0.500795 0.845468 -0.289134 244 | v 0.500795 0.845468 -0.289134 245 | v -0.385808 1.003206 -0.222746 246 | v -0.385808 1.003206 -0.222746 247 | v -0.385808 1.003206 -0.222746 248 | v 0.000000 1.003206 -0.445493 249 | v 0.000000 1.003206 -0.445493 250 | v 0.000000 1.003206 -0.445493 251 | v -0.385808 1.003206 0.222747 252 | v -0.385808 1.003206 0.222747 253 | v -0.385808 1.003206 0.222747 254 | v 0.000000 1.003206 0.445493 255 | v 0.000000 1.003206 0.445493 256 | v 0.000000 1.003206 0.445493 257 | v 0.385808 1.003206 0.222746 258 | v 0.385808 1.003206 0.222746 259 | v 0.385808 1.003206 0.222746 260 | v 0.385808 1.003206 -0.222746 261 | v 0.385808 1.003206 -0.222746 262 | v 0.385808 1.003206 -0.222746 263 | v -0.245015 2.090684 -0.141460 264 | v -0.245015 2.090684 -0.141460 265 | v 0.000000 2.090684 -0.282920 266 | v 0.000000 2.090684 -0.282920 267 | v -0.245015 2.090684 0.141460 268 | v -0.245015 2.090684 0.141460 269 | v 0.000000 2.090684 0.282920 270 | v 0.000000 2.090684 0.282920 271 | v 0.245016 2.090684 0.141460 272 | v 0.245016 2.090684 0.141460 273 | v 0.245016 2.090684 -0.141460 274 | v 0.245016 2.090684 -0.141460 275 | v -0.370409 2.326007 -0.213856 276 | v -0.370409 2.326007 -0.213856 277 | v -0.370409 2.326007 -0.213856 278 | v 0.000000 2.326007 -0.427711 279 | v 0.000000 2.326007 -0.427711 280 | v 0.000000 2.326007 -0.427711 281 | v -0.370409 2.326007 0.213856 282 | v -0.370409 2.326007 0.213856 283 | v -0.370409 2.326007 0.213856 284 | v 0.000000 2.326007 0.427711 285 | v 0.000000 2.326007 0.427711 286 | v 0.000000 2.326007 0.427711 287 | v 0.370409 2.326007 0.213856 288 | v 0.370409 2.326007 0.213856 289 | v 0.370409 2.326007 0.213856 290 | v 0.370409 2.326007 -0.213856 291 | v 0.370409 2.326007 -0.213856 292 | v 0.370409 2.326007 -0.213856 293 | v -0.245015 2.090684 0.141460 294 | v -0.245015 2.090684 -0.141460 295 | v 0.245016 2.090684 0.141460 296 | v 0.000000 2.090684 0.282920 297 | v 0.000000 2.090684 -0.282920 298 | v 0.245016 2.090684 -0.141460 299 | v -0.370409 2.475571 -0.213856 300 | v -0.370409 2.475571 -0.213856 301 | v -0.370409 2.475571 -0.213856 302 | v 0.000000 2.475571 -0.427711 303 | v 0.000000 2.475571 -0.427711 304 | v 0.000000 2.475571 -0.427711 305 | v -0.370409 2.475571 0.213856 306 | v -0.370409 2.475571 0.213856 307 | v -0.370409 2.475571 0.213856 308 | v 0.000000 2.475571 0.427711 309 | v 0.000000 2.475571 0.427711 310 | v 0.000000 2.475571 0.427711 311 | v 0.370409 2.475571 0.213856 312 | v 0.370409 2.475571 0.213856 313 | v 0.370409 2.475571 0.213856 314 | v 0.370409 2.475571 -0.213856 315 | v 0.370409 2.475571 -0.213856 316 | v 0.370409 2.475571 -0.213856 317 | v -0.236162 2.729512 -0.136348 318 | v -0.236162 2.729512 -0.136348 319 | v 0.000000 2.729512 -0.272697 320 | v 0.000000 2.729512 -0.272697 321 | v -0.236162 2.729512 0.136348 322 | v -0.236162 2.729512 0.136348 323 | v 0.000000 2.729512 0.272697 324 | v 0.000000 2.729512 0.272697 325 | v 0.236162 2.729512 0.136348 326 | v 0.236162 2.729512 0.136348 327 | v 0.236162 2.729512 -0.136348 328 | v 0.236162 2.729512 -0.136348 329 | vt 0.523785 0.851270 330 | vt 0.523638 0.940738 331 | vt 0.505451 0.940708 332 | vt 0.547941 0.940778 333 | vt 0.548088 0.851310 334 | vt 0.566129 0.940808 335 | vt 0.486356 0.851208 336 | vt 0.486210 0.940677 337 | vt 0.468022 0.940647 338 | vt 0.486736 0.940677 339 | vt 0.486883 0.851209 340 | vt 0.505071 0.851239 341 | vt 0.285078 0.899962 342 | vt 0.285224 0.810494 343 | vt 0.303265 0.899992 344 | vt 0.547561 0.851309 345 | vt 0.547414 0.940777 346 | vt 0.529374 0.851279 347 | vt 0.467642 0.851177 348 | vt 0.467495 0.940646 349 | vt 0.441798 0.926482 350 | vt 0.303792 0.899993 351 | vt 0.303939 0.810524 352 | vt 0.329636 0.824688 353 | vt 0.415528 0.940560 354 | vt 0.415675 0.851092 355 | vt 0.441272 0.926481 356 | vt 0.631938 0.851447 357 | vt 0.631791 0.940915 358 | vt 0.606195 0.865526 359 | vt 0.662375 0.851497 360 | vt 0.662228 0.940965 361 | vt 0.636532 0.926802 362 | vt 0.295640 0.798445 363 | vt 0.295787 0.708977 364 | vt 0.321383 0.784366 365 | vt 0.763543 0.851663 366 | vt 0.763443 0.912889 367 | vt 0.724566 0.905753 368 | vt 0.321933 0.770245 369 | vt 0.322033 0.709020 370 | vt 0.360910 0.716156 371 | vt 0.662902 0.851498 372 | vt 0.724128 0.851598 373 | vt 0.669911 0.890398 374 | vt 0.369074 0.810631 375 | vt 0.368974 0.871857 376 | vt 0.330174 0.817640 377 | vt 0.408424 0.851080 378 | vt 0.408323 0.912306 379 | vt 0.369446 0.905170 380 | vt 0.566702 0.912566 381 | vt 0.566803 0.851340 382 | vt 0.605602 0.905557 383 | vt 0.688469 0.932077 384 | vt 0.688392 0.979158 385 | vt 0.675167 0.981464 386 | vt 0.239519 0.797087 387 | vt 0.239596 0.750006 388 | vt 0.252822 0.747700 389 | vt 0.702667 0.979181 390 | vt 0.702744 0.932100 391 | vt 0.715884 0.981531 392 | vt 0.581203 0.915444 393 | vt 0.581125 0.962525 394 | vt 0.567985 0.913095 395 | vt 0.248712 0.812761 396 | vt 0.248634 0.859843 397 | vt 0.235409 0.862149 398 | vt 0.688919 0.979159 399 | vt 0.688996 0.932078 400 | vt 0.702136 0.981508 401 | vt 0.249157 0.862171 402 | vt 0.249242 0.810435 403 | vt 0.266631 0.856260 404 | vt 0.260890 0.900449 405 | vt 0.260805 0.952186 406 | vt 0.243351 0.946218 407 | vt 0.261332 0.952187 408 | vt 0.261417 0.900450 409 | vt 0.278871 0.906418 410 | vt 0.253264 0.799437 411 | vt 0.253348 0.747701 412 | vt 0.270738 0.793526 413 | vt 0.284698 0.810493 414 | vt 0.284613 0.862229 415 | vt 0.267224 0.816404 416 | vt 0.739058 0.913375 417 | vt 0.738974 0.965112 418 | vt 0.721519 0.959144 419 | vt 0.664976 0.811117 420 | vt 0.664910 0.850974 421 | vt 0.566857 0.818228 422 | vt 0.566342 0.810955 423 | vt 0.566277 0.850812 424 | vt 0.468182 0.843379 425 | vt 0.467708 0.810793 426 | vt 0.467643 0.850651 427 | vt 0.369548 0.843217 428 | vt 0.763610 0.811279 429 | vt 0.763544 0.851136 430 | vt 0.665491 0.818390 431 | vt 0.459455 0.770395 432 | vt 0.459390 0.810253 433 | vt 0.361337 0.777507 434 | vt 0.459556 0.709245 435 | vt 0.459490 0.749103 436 | vt 0.361395 0.741669 437 | vt 0.739533 0.945166 438 | vt 0.739575 0.919853 439 | vt 0.763379 0.951682 440 | vt 0.605579 0.919634 441 | vt 0.605538 0.944946 442 | vt 0.581671 0.951384 443 | vt 0.279356 0.932269 444 | vt 0.279397 0.906957 445 | vt 0.303264 0.900519 446 | vt 0.401806 0.936679 447 | vt 0.376494 0.936637 448 | vt 0.408322 0.912833 449 | vt 0.295165 0.766655 450 | vt 0.295123 0.791967 451 | vt 0.271319 0.760138 452 | vt 0.295249 0.715453 453 | vt 0.295207 0.740765 454 | vt 0.271340 0.747203 455 | vt 0.369953 0.975420 456 | vt 0.370016 0.937153 457 | vt 0.383334 0.975442 458 | vt 0.368866 0.937403 459 | vt 0.368804 0.975670 460 | vt 0.355422 0.975648 461 | vt 0.459467 0.763011 462 | vt 0.421201 0.762948 463 | vt 0.421223 0.749567 464 | vt 0.330537 0.975607 465 | vt 0.330600 0.937340 466 | vt 0.343918 0.975629 467 | vt 0.382429 0.749503 468 | vt 0.420696 0.749566 469 | vt 0.382407 0.762884 470 | vt 0.408282 0.937216 471 | vt 0.408220 0.975483 472 | vt 0.394838 0.975461 473 | vt 0.329511 0.900562 474 | vt 0.329448 0.938828 475 | vt 0.303761 0.931852 476 | vt 0.689001 0.929223 477 | vt 0.689063 0.890957 478 | vt 0.714711 0.922331 479 | vt 0.368973 0.872384 480 | vt 0.368910 0.910650 481 | vt 0.343223 0.903674 482 | vt 0.662775 0.929180 483 | vt 0.662838 0.890913 484 | vt 0.688525 0.897890 485 | vt 0.330643 0.911114 486 | vt 0.368910 0.911177 487 | vt 0.337535 0.936825 488 | vt 0.360821 0.770836 489 | vt 0.360758 0.809103 490 | vt 0.335110 0.777728 491 | vt 0.174870 0.175770 492 | vt 0.175155 0.175808 493 | vt 0.174734 0.175202 494 | vt 0.175277 0.175327 495 | vt 0.174993 0.175290 496 | vt 0.174955 0.176013 497 | vt 0.174793 0.175494 498 | vt 0.175192 0.175085 499 | vt 0.175355 0.175603 500 | vt 0.174613 0.175666 501 | vt 0.175413 0.175896 502 | vt 0.173786 0.174521 503 | vt 0.174832 0.177176 504 | vt 0.175534 0.175431 505 | vt 0.175316 0.173921 506 | vt 0.173543 0.176148 507 | vt 0.176361 0.176576 508 | vt 0.176604 0.174950 509 | vt 0.149535 0.159876 510 | vt 0.200612 0.191221 511 | vt 0.175881 0.145597 512 | vt 0.174267 0.205500 513 | vt 0.201420 0.161269 514 | vt 0.148728 0.189828 515 | vt 0.214195 0.177965 516 | vt 0.135952 0.173133 517 | vt 0.192546 0.210644 518 | vt 0.157601 0.140454 519 | vt 0.153422 0.208225 520 | vt 0.196726 0.142873 521 | vt 0.312656 0.175551 522 | vt 0.037491 0.175547 523 | vt 0.243869 0.294701 524 | vt 0.106278 0.056397 525 | vt 0.106280 0.294701 526 | vt 0.354599 0.075845 527 | vt 0.690483 0.075845 528 | vt 0.025014 0.722369 529 | vt 0.349566 0.071441 530 | vt 0.685450 0.071442 531 | vt 0.019981 0.717966 532 | vt 0.360197 0.073643 533 | vt 0.696081 0.073643 534 | vt 0.943635 0.731886 535 | vt 0.360197 0.075845 536 | vt 0.696081 0.075845 537 | vt 0.030612 0.722369 538 | vt 0.696082 0.073643 539 | vt 0.359633 0.065215 540 | vt 0.695517 0.065214 541 | vt 0.943071 0.723458 542 | vt 0.945027 0.728042 543 | vt 0.030214 0.716323 544 | vt 0.349310 0.068389 545 | vt 0.940313 0.728042 546 | vt 0.025499 0.716323 547 | vt 0.687622 0.068388 548 | vt 0.945027 0.730105 549 | vt 0.030214 0.718386 550 | vt 0.692337 0.070451 551 | vt 0.939784 0.730105 552 | vt 0.024971 0.718386 553 | vt 0.344068 0.070452 554 | vt 0.949742 0.728043 555 | vt 0.034929 0.716324 556 | vt 0.697051 0.068389 557 | vt 0.940312 0.730104 558 | vt 0.025499 0.718385 559 | vt 0.344595 0.070451 560 | vt 0.287215 0.775191 561 | vt 0.287215 0.893712 562 | vt 0.255394 0.875223 563 | vt 0.184573 0.952973 564 | vt 0.081931 0.893713 565 | vt 0.081931 0.775191 566 | vt 0.113854 0.875399 567 | vt 0.184573 0.715931 568 | vt 0.255292 0.793505 569 | vt 0.184675 0.916170 570 | vt 0.184471 0.752734 571 | vt 0.219147 0.857526 572 | vt 0.113752 0.793681 573 | vt 0.147304 0.852857 574 | vt 0.221843 0.816047 575 | vt 0.181878 0.875931 576 | vt 0.187268 0.792973 577 | vt 0.149999 0.811378 578 | vt 0.186531 0.819408 579 | vt 0.196622 0.843669 580 | vt 0.170566 0.840278 581 | vt 0.198580 0.828626 582 | vt 0.182615 0.849495 583 | vt 0.172524 0.825235 584 | vt 0.184573 0.834452 585 | vt 0.505598 0.851240 586 | vt 0.566276 0.851339 587 | vt 0.468169 0.851178 588 | vt 0.504924 0.940707 589 | vt 0.303412 0.810523 590 | vt 0.529227 0.940747 591 | vt 0.441899 0.865257 592 | vt 0.329535 0.885913 593 | vt 0.441372 0.865256 594 | vt 0.606094 0.926752 595 | vt 0.636632 0.865576 596 | vt 0.321483 0.723140 597 | vt 0.724643 0.858671 598 | vt 0.360833 0.763237 599 | vt 0.716992 0.890475 600 | vt 0.330097 0.864721 601 | vt 0.369523 0.858089 602 | vt 0.605680 0.858476 603 | vt 0.675251 0.929727 604 | vt 0.252737 0.799436 605 | vt 0.715969 0.929794 606 | vt 0.567900 0.964831 607 | vt 0.235494 0.810412 608 | vt 0.702221 0.929772 609 | vt 0.266697 0.816403 610 | vt 0.243416 0.906360 611 | vt 0.278806 0.946276 612 | vt 0.270803 0.753669 613 | vt 0.267158 0.856261 614 | vt 0.721585 0.919286 615 | vt 0.566815 0.843541 616 | vt 0.468223 0.818067 617 | vt 0.369589 0.817905 618 | vt 0.665449 0.843703 619 | vt 0.361295 0.802819 620 | vt 0.361437 0.716357 621 | vt 0.763442 0.913415 622 | vt 0.581733 0.913117 623 | vt 0.303202 0.938785 624 | vt 0.370056 0.912770 625 | vt 0.271256 0.798405 626 | vt 0.271403 0.708937 627 | vt 0.383397 0.937175 628 | vt 0.355485 0.937381 629 | vt 0.459489 0.749630 630 | vt 0.343981 0.937362 631 | vt 0.420674 0.762947 632 | vt 0.394901 0.937194 633 | vt 0.303801 0.907454 634 | vt 0.714751 0.897933 635 | vt 0.343263 0.879276 636 | vt 0.688485 0.922288 637 | vt 0.361933 0.936865 638 | vt 0.335070 0.802126 639 | vt 0.243868 0.056397 640 | vt 0.938037 0.734088 641 | vt 0.933004 0.729685 642 | vt 0.030612 0.720167 643 | vt 0.943635 0.734088 644 | vt 0.030048 0.711739 645 | vt 0.692336 0.068388 646 | vt 0.344596 0.068388 647 | vt 0.349311 0.070451 648 | vt 0.687093 0.070452 649 | vt 0.354026 0.068388 650 | vt 0.687621 0.070451 651 | vn 1.000000 0.000000 0.000000 652 | vn -1.000000 0.000000 0.000000 653 | vn 0.499985 0.000000 0.866024 654 | vn 0.499985 0.000000 -0.866024 655 | vn -0.499985 0.000000 -0.866024 656 | vn -0.499985 0.000000 0.866024 657 | vn 0.154607 0.950957 0.267830 658 | vn 0.154607 0.950957 -0.267830 659 | vn -0.154607 0.950957 -0.267830 660 | vn -0.154607 0.950957 0.267830 661 | vn 0.309244 0.950957 0.000000 662 | vn -0.309244 0.950957 0.000000 663 | vn 0.474532 0.314982 0.821925 664 | vn 0.474532 0.314982 -0.821925 665 | vn -0.474532 0.314982 -0.821925 666 | vn -0.474532 0.314982 0.821925 667 | vn 0.949095 0.314982 0.000000 668 | vn -0.949095 0.314982 0.000000 669 | vn 0.476180 -0.304941 0.824763 670 | vn 0.476180 -0.304941 -0.824763 671 | vn -0.476180 -0.304941 -0.824763 672 | vn -0.476180 -0.304941 0.824763 673 | vn 0.952361 -0.304941 0.000000 674 | vn -0.952361 -0.304941 0.000000 675 | vn -0.808069 0.589068 0.000000 676 | vn 0.404035 0.589068 0.699789 677 | vn 0.404035 0.589068 -0.699789 678 | vn -0.404035 0.589068 -0.699789 679 | vn -0.404035 0.589068 0.699789 680 | vn 0.808069 0.589068 0.000000 681 | vn -0.991699 0.128391 0.000000 682 | vn 0.495834 0.128391 0.858852 683 | vn 0.495834 0.128391 -0.858852 684 | vn -0.495834 0.128391 -0.858852 685 | vn -0.495834 0.128391 0.858852 686 | vn 0.991699 0.128391 0.000000 687 | vn -0.882504 -0.470260 0.000000 688 | vn 0.441237 -0.470260 0.764275 689 | vn 0.441237 -0.470260 -0.764275 690 | vn -0.441237 -0.470260 -0.764275 691 | vn -0.441237 -0.470260 0.764275 692 | vn 0.882504 -0.470260 0.000000 693 | vn 0.884060 0.467360 0.000000 694 | vn -0.884060 0.467360 0.000000 695 | vn 0.442030 0.467360 0.765618 696 | vn 0.442030 0.467360 -0.765618 697 | vn -0.442030 0.467360 -0.765618 698 | vn -0.442030 0.467360 0.765618 699 | vn 0.866024 0.000000 0.499985 700 | vn 0.866024 0.000000 -0.499985 701 | vn 0.857082 -0.143193 -0.494827 702 | vn -0.866024 0.000000 -0.499985 703 | vn -0.866024 0.000000 0.499985 704 | vn -0.857082 -0.143193 -0.494827 705 | vn 0.000000 0.000000 1.000000 706 | vn 0.857082 -0.143193 0.494827 707 | vn 0.000000 0.000000 -1.000000 708 | vn 0.000000 -0.143193 -0.989685 709 | vn -0.857082 -0.143193 0.494827 710 | vn 0.865963 -0.011750 -0.499954 711 | vn -0.865963 -0.011750 -0.499954 712 | vn 0.000000 -0.143193 0.989685 713 | vn 0.865963 -0.011750 0.499954 714 | vn 0.000000 -0.011750 -0.999908 715 | vn -0.865963 -0.011750 0.499954 716 | vn 0.000000 -0.011750 0.999908 717 | vn -0.858730 0.129460 0.495773 718 | vn 0.858730 0.129460 -0.495773 719 | vn -0.858730 0.129460 -0.495773 720 | vn 0.858730 0.129460 0.495773 721 | vn 0.000000 0.129460 -0.991577 722 | vn 0.000000 0.129460 0.991577 723 | vn -0.783837 -0.425153 0.452528 724 | vn 0.783837 -0.425153 -0.452528 725 | vn -0.783837 -0.425153 -0.452528 726 | vn 0.783837 -0.425153 0.452528 727 | vn 0.000000 -0.425153 -0.905087 728 | vn 0.000000 -0.425153 0.905087 729 | vn -0.621601 -0.696249 0.358867 730 | vn 0.621601 -0.696249 -0.358867 731 | vn -0.621601 -0.696249 -0.358867 732 | vn 0.621601 -0.696249 0.358867 733 | vn 0.000000 -0.696249 -0.717765 734 | vn -0.472182 -0.328837 -0.817835 735 | vn -0.472182 -0.328837 0.817835 736 | vn 0.944365 -0.328837 0.000000 737 | vn -0.944365 -0.328837 0.000000 738 | vn 0.472182 -0.328837 0.817835 739 | vn 0.472182 -0.328837 -0.817835 740 | vn 0.480178 0.278664 -0.831690 741 | vn -0.480178 0.278664 -0.831690 742 | vn -0.480178 0.278664 0.831690 743 | vn 0.960356 0.278664 0.000000 744 | vn -0.960356 0.278664 0.000000 745 | vn 0.480178 0.278664 0.831690 746 | vn 0.316904 -0.930631 -0.182958 747 | vn 0.000000 -0.930631 -0.365917 748 | vn 0.000000 -0.363964 -0.931394 749 | vn -0.316904 -0.930631 -0.182958 750 | vn -0.316904 -0.930631 0.182958 751 | vn 0.000000 -0.930631 0.365917 752 | vn -0.806604 -0.363964 0.465682 753 | vn 0.316904 -0.930631 0.182958 754 | vn 0.806604 -0.363964 -0.465682 755 | vn -0.806604 -0.363964 -0.465682 756 | vn 0.806604 -0.363964 0.465682 757 | vn 0.000000 0.501114 -0.865352 758 | vn 0.000000 -0.363964 0.931394 759 | vn -0.749413 0.501114 0.432661 760 | vn 0.749413 0.501114 -0.432661 761 | vn -0.749413 0.501114 -0.432661 762 | vn 0.749413 0.501114 0.432661 763 | vn 0.000000 0.501114 0.865352 764 | vn 0.656392 0.652272 0.378979 765 | vn 0.000000 0.652272 -0.757958 766 | vn -0.656392 0.652272 0.378979 767 | vn 0.656392 0.652272 -0.378979 768 | vn -0.656392 0.652272 -0.378979 769 | vn 0.000000 0.652272 0.757958 770 | vn 0.000000 1.000000 0.000000 771 | vn 0.000000 -0.696249 0.717765 772 | s 1 773 | f 183/1/1 6/2/1 12/3/1 774 | f 185/4/2 3/5/2 164/6/2 775 | f 186/7/3 5/8/3 11/9/3 776 | f 182/10/4 187/11/4 167/12/4 777 | f 1/13/5 2/14/5 7/15/5 778 | f 184/16/6 4/17/6 170/18/6 779 | f 174/19/7 177/20/7 17/21/7 780 | f 180/22/8 168/23/8 191/24/8 781 | f 169/25/9 165/26/9 13/27/9 782 | f 171/28/10 175/29/10 194/30/10 783 | f 178/31/11 181/32/11 18/33/11 784 | f 166/34/12 172/35/12 188/36/12 785 | f 198/37/13 201/38/13 23/39/13 786 | f 204/40/14 192/41/14 209/42/14 787 | f 193/43/15 189/44/15 19/45/15 788 | f 195/46/16 199/47/16 212/48/16 789 | f 202/49/17 205/50/17 24/51/17 790 | f 190/52/18 196/53/18 206/54/18 791 | f 216/55/19 219/56/19 29/57/19 792 | f 222/58/20 210/59/20 227/60/20 793 | f 211/61/21 207/62/21 25/63/21 794 | f 213/64/22 217/65/22 230/66/22 795 | f 220/67/23 223/68/23 30/69/23 796 | f 208/70/24 214/71/24 224/72/24 797 | f 225/73/25 231/74/25 242/75/25 798 | f 234/76/26 237/77/26 35/78/26 799 | f 240/79/27 228/80/27 245/81/27 800 | f 229/82/28 226/83/28 31/84/28 801 | f 232/85/29 235/86/29 248/87/29 802 | f 238/88/30 241/89/30 36/90/30 803 | f 243/91/31 249/92/31 260/93/31 804 | f 252/94/32 255/95/32 41/96/32 805 | f 258/97/33 246/98/33 262/99/33 806 | f 247/100/34 244/101/34 37/102/34 807 | f 250/103/35 253/104/35 264/105/35 808 | f 256/106/36 259/107/36 42/108/36 809 | f 261/109/37 265/110/37 272/111/37 810 | f 267/112/38 269/113/38 47/114/38 811 | f 271/115/39 263/116/39 275/117/39 812 | f 294/118/40 291/119/40 43/120/40 813 | f 290/121/41 293/122/41 278/123/41 814 | f 292/124/42 295/125/42 48/126/42 815 | f 273/127/2 279/128/2 296/129/2 816 | f 282/130/3 285/131/3 53/132/3 817 | f 288/133/4 276/134/4 299/135/4 818 | f 277/136/5 274/137/5 49/138/5 819 | f 280/139/6 283/140/6 302/141/6 820 | f 286/142/1 289/143/1 54/144/1 821 | f 309/145/43 312/146/43 60/147/43 822 | f 297/148/44 303/149/44 314/150/44 823 | f 306/151/45 310/152/45 59/153/45 824 | f 313/154/46 300/155/46 316/156/46 825 | f 301/157/47 298/158/47 55/159/47 826 | f 304/160/48 307/161/48 318/162/48 827 | f 323/163/49 325/164/50 66/165/51 828 | f 315/166/52 319/167/53 62/168/54 829 | f 321/169/55 323/163/49 65/170/56 830 | f 325/164/50 317/171/57 61/172/58 831 | f 317/171/57 315/166/52 61/172/58 832 | f 319/167/53 321/169/55 63/173/59 833 | f 65/170/56 66/165/51 72/174/60 834 | f 62/168/54 63/173/59 68/175/61 835 | f 64/176/62 65/170/56 71/177/63 836 | f 66/165/51 61/172/58 67/178/64 837 | f 61/172/58 62/168/54 67/178/64 838 | f 63/173/59 64/176/62 69/179/65 839 | f 69/179/65 70/180/66 75/181/67 840 | f 71/177/63 72/174/60 78/182/68 841 | f 68/175/61 69/179/65 74/183/69 842 | f 70/180/66 71/177/63 77/184/70 843 | f 72/174/60 67/178/64 73/185/71 844 | f 67/178/64 68/175/61 73/185/71 845 | f 75/181/67 76/186/72 81/187/73 846 | f 77/184/70 78/182/68 84/188/74 847 | f 74/183/69 75/181/67 80/189/75 848 | f 76/186/72 77/184/70 83/190/76 849 | f 78/182/68 73/185/71 79/191/77 850 | f 73/185/71 74/183/69 79/191/77 851 | f 81/187/73 82/192/78 87/193/79 852 | f 83/190/76 84/188/74 90/194/80 853 | f 80/189/75 81/187/73 86/195/81 854 | f 82/192/78 83/190/76 89/196/82 855 | f 84/188/74 79/191/77 85/197/83 856 | f 79/191/77 80/189/75 85/197/83 857 | f 124/198/84 122/199/84 91/200/84 858 | f 126/201/85 128/202/85 140/203/85 859 | f 130/204/86 132/205/86 96/206/86 860 | f 123/207/87 127/208/87 134/209/87 861 | f 129/204/88 131/210/88 95/206/88 862 | f 133/211/89 125/212/89 137/213/89 863 | f 150/214/90 138/215/90 154/216/90 864 | f 139/217/91 135/218/91 97/219/91 865 | f 141/220/92 144/221/92 156/222/92 866 | f 147/223/93 151/224/93 102/225/93 867 | f 136/226/94 142/227/94 152/228/94 868 | f 145/229/95 148/230/95 101/231/95 869 | f 163/232/96 155/233/97 103/234/98 870 | f 155/233/97 153/235/99 103/234/98 871 | f 157/236/100 159/237/101 105/238/102 872 | f 161/239/103 163/232/96 108/240/104 873 | f 153/235/99 157/236/100 104/241/105 874 | f 159/237/101 161/239/103 107/242/106 875 | f 108/240/104 103/234/98 109/243/107 876 | f 103/234/98 104/241/105 109/243/107 877 | f 105/238/102 106/244/108 111/245/109 878 | f 107/242/106 108/240/104 114/246/110 879 | f 104/241/105 105/238/102 110/247/111 880 | f 106/244/108 107/242/106 113/248/112 881 | f 112/249/113 113/248/112 119/250/114 882 | f 114/246/110 109/243/107 115/251/115 883 | f 109/243/107 110/247/111 115/251/115 884 | f 111/245/109 112/249/113 117/252/116 885 | f 113/248/112 114/246/110 120/253/117 886 | f 110/247/111 111/245/109 116/254/118 887 | f 118/255/119 119/250/114 121/256/120 888 | f 120/253/117 115/251/115 121/256/120 889 | f 115/251/115 116/254/118 121/256/120 890 | f 117/252/116 118/255/119 121/256/120 891 | f 119/250/114 120/253/117 121/256/120 892 | f 116/254/118 117/252/116 121/256/120 893 | f 176/257/1 183/1/1 12/3/1 894 | f 3/5/2 9/258/2 164/6/2 895 | f 173/259/3 186/7/3 11/9/3 896 | f 179/260/4 182/10/4 167/12/4 897 | f 2/14/5 8/261/5 7/15/5 898 | f 4/17/6 10/262/6 170/18/6 899 | f 197/263/7 174/19/7 17/21/7 900 | f 203/264/8 180/22/8 191/24/8 901 | f 165/26/9 14/265/9 13/27/9 902 | f 175/29/10 16/266/10 194/30/10 903 | f 200/267/11 178/31/11 18/33/11 904 | f 172/35/12 15/268/12 188/36/12 905 | f 215/269/13 198/37/13 23/39/13 906 | f 221/270/14 204/40/14 209/42/14 907 | f 189/44/15 20/271/15 19/45/15 908 | f 199/47/16 22/272/16 212/48/16 909 | f 218/273/17 202/49/17 24/51/17 910 | f 196/53/18 21/274/18 206/54/18 911 | f 233/275/19 216/55/19 29/57/19 912 | f 239/276/20 222/58/20 227/60/20 913 | f 207/62/21 26/277/21 25/63/21 914 | f 217/65/22 28/278/22 230/66/22 915 | f 236/279/23 220/67/23 30/69/23 916 | f 214/71/24 27/280/24 224/72/24 917 | f 231/74/25 33/281/25 242/75/25 918 | f 251/282/26 234/76/26 35/78/26 919 | f 257/283/27 240/79/27 245/81/27 920 | f 226/83/28 32/284/28 31/84/28 921 | f 235/86/29 34/285/29 248/87/29 922 | f 254/286/30 238/88/30 36/90/30 923 | f 249/92/31 39/287/31 260/93/31 924 | f 266/288/32 252/94/32 41/96/32 925 | f 270/289/33 258/97/33 262/99/33 926 | f 244/101/34 38/290/34 37/102/34 927 | f 253/104/35 40/291/35 264/105/35 928 | f 268/292/36 256/106/36 42/108/36 929 | f 265/110/37 45/293/37 272/111/37 930 | f 281/294/38 267/112/38 47/114/38 931 | f 287/295/39 271/115/39 275/117/39 932 | f 291/119/40 44/296/40 43/120/40 933 | f 293/122/41 46/297/41 278/123/41 934 | f 284/298/42 292/124/42 48/126/42 935 | f 279/128/2 51/299/2 296/129/2 936 | f 305/300/3 282/130/3 53/132/3 937 | f 311/301/4 288/133/4 299/135/4 938 | f 274/137/5 50/302/5 49/138/5 939 | f 283/140/6 52/303/6 302/141/6 940 | f 308/304/1 286/142/1 54/144/1 941 | f 322/305/43 309/145/43 60/147/43 942 | f 303/149/44 57/306/44 314/150/44 943 | f 320/307/45 306/151/45 59/153/45 944 | f 324/308/46 313/154/46 316/156/46 945 | f 298/158/47 56/309/47 55/159/47 946 | f 307/161/48 58/310/48 318/162/48 947 | f 65/170/56 323/163/49 66/165/51 948 | f 319/167/53 63/173/59 62/168/54 949 | f 64/176/62 321/169/55 65/170/56 950 | f 66/165/51 325/164/50 61/172/58 951 | f 315/166/52 62/168/54 61/172/58 952 | f 321/169/55 64/176/62 63/173/59 953 | f 71/177/63 65/170/56 72/174/60 954 | f 63/173/59 69/179/65 68/175/61 955 | f 70/180/66 64/176/62 71/177/63 956 | f 72/174/60 66/165/51 67/178/64 957 | f 62/168/54 68/175/61 67/178/64 958 | f 64/176/62 70/180/66 69/179/65 959 | f 70/180/66 76/186/72 75/181/67 960 | f 77/184/70 71/177/63 78/182/68 961 | f 69/179/65 75/181/67 74/183/69 962 | f 76/186/72 70/180/66 77/184/70 963 | f 78/182/68 72/174/60 73/185/71 964 | f 68/175/61 74/183/69 73/185/71 965 | f 76/186/72 82/192/78 81/187/73 966 | f 83/190/76 77/184/70 84/188/74 967 | f 75/181/67 81/187/73 80/189/75 968 | f 82/192/78 76/186/72 83/190/76 969 | f 84/188/74 78/182/68 79/191/77 970 | f 74/183/69 80/189/75 79/191/77 971 | f 82/192/78 88/311/121 87/193/79 972 | f 89/196/82 83/190/76 90/194/80 973 | f 81/187/73 87/193/79 86/195/81 974 | f 88/311/121 82/192/78 89/196/82 975 | f 90/194/80 84/188/74 85/197/83 976 | f 80/189/75 86/195/81 85/197/83 977 | f 122/199/84 92/312/84 91/200/84 978 | f 128/202/85 94/313/85 140/203/85 979 | f 146/314/86 130/204/86 96/206/86 980 | f 127/208/87 93/315/87 134/209/87 981 | f 143/314/88 129/204/88 95/206/88 982 | f 149/316/89 133/211/89 137/213/89 983 | f 162/317/90 150/214/90 154/216/90 984 | f 135/218/91 98/318/91 97/219/91 985 | f 144/221/92 100/319/92 156/222/92 986 | f 160/320/93 147/223/93 102/225/93 987 | f 142/227/94 99/321/94 152/228/94 988 | f 158/322/95 145/229/95 101/231/95 989 | f 108/240/104 163/232/96 103/234/98 990 | f 153/235/99 104/241/105 103/234/98 991 | f 159/237/101 106/244/108 105/238/102 992 | f 107/242/106 161/239/103 108/240/104 993 | f 157/236/100 105/238/102 104/241/105 994 | f 106/244/108 159/237/101 107/242/106 995 | f 114/246/110 108/240/104 109/243/107 996 | f 104/241/105 110/247/111 109/243/107 997 | f 106/244/108 112/249/113 111/245/109 998 | f 113/248/112 107/242/106 114/246/110 999 | f 105/238/102 111/245/109 110/247/111 1000 | f 112/249/113 106/244/108 113/248/112 1001 | f 118/255/119 112/249/113 119/250/114 1002 | f 120/253/117 114/246/110 115/251/115 1003 | f 110/247/111 116/254/118 115/251/115 1004 | f 112/249/113 118/255/119 117/252/116 1005 | f 119/250/114 113/248/112 120/253/117 1006 | f 111/245/109 117/252/116 116/254/118 1007 | -------------------------------------------------------------------------------- /res/shaders/gui.f.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec2 textureCoords; 4 | 5 | out vec4 out_Color; 6 | 7 | uniform sampler2D guiTexture; 8 | 9 | void main(void){ 10 | out_Color = texture(guiTexture,textureCoords); 11 | } 12 | -------------------------------------------------------------------------------- /res/shaders/gui.v.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec2 position; 4 | 5 | out vec2 textureCoords; 6 | 7 | uniform mat4 transformationMatrix; 8 | 9 | void main(void){ 10 | gl_Position = transformationMatrix * vec4(position, 0.0, 1.0); 11 | textureCoords = vec2((position.x+1.0)/2.0, 1 - (position.y+1.0)/2.0); 12 | } 13 | -------------------------------------------------------------------------------- /res/shaders/skybox.f.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec3 textureCoords; 4 | out vec4 out_Color; 5 | 6 | uniform samplerCube cubeMap; 7 | uniform samplerCube cubeMap2; 8 | uniform float blendFactor; 9 | uniform vec3 fogColor; 10 | 11 | const float lowerLimit = 0.0; 12 | const float upperLimit = 30.0; 13 | 14 | void main(void) { 15 | vec4 texture1 = texture(cubeMap, textureCoords); 16 | vec4 texture2 = texture(cubeMap2, textureCoords); 17 | vec4 finalColor = mix(texture1, texture2, blendFactor); 18 | 19 | float factor = (textureCoords.y - lowerLimit) / (upperLimit - lowerLimit); 20 | factor = clamp(factor, 0.0, 1.0); 21 | 22 | out_Color = mix(vec4(fogColor, 1.0), finalColor, factor); 23 | } 24 | -------------------------------------------------------------------------------- /res/shaders/skybox.v.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec3 position; 4 | out vec3 textureCoords; 5 | 6 | uniform mat4 projectionMatrix; 7 | uniform mat4 viewMatrix; 8 | 9 | void main(void) { 10 | gl_Position = projectionMatrix * viewMatrix * vec4(position, 1.0); 11 | textureCoords = position; 12 | } 13 | -------------------------------------------------------------------------------- /res/shaders/static.f.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec2 pass_textureCoords; 4 | in vec3 surfaceNormal; 5 | in vec3 toLightVector[4]; 6 | in vec3 toCameraVector; 7 | in float visibility; 8 | 9 | out vec4 out_color; 10 | 11 | uniform sampler2D modelTexture; 12 | uniform vec3 lightColor[4]; 13 | uniform vec3 attenuation[4]; 14 | uniform float shineDamper; 15 | uniform float reflectivity; 16 | uniform vec3 skyColor; 17 | 18 | void main(void) { 19 | vec3 unitNormal = normalize(surfaceNormal); 20 | vec3 unitToCameraVector = normalize(toCameraVector); 21 | 22 | vec3 totalDiffuse = vec3(0.0); 23 | vec3 totalSpecular = vec3(0.0); 24 | 25 | for (int i = 0; i < 4; i++) { 26 | float distance = length(toLightVector[i]); 27 | float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance); 28 | vec3 unitToLightVector = normalize(toLightVector[i]); 29 | float brightness = max(0.0, dot(unitNormal, unitToLightVector)); 30 | vec3 lightDirection = -unitToLightVector; 31 | vec3 reflectedLightDirection = reflect(lightDirection, unitNormal); 32 | float specularFactor = max(0.0, dot(reflectedLightDirection, unitToCameraVector)); 33 | float dampedFactor = pow(specularFactor, shineDamper); 34 | totalDiffuse = totalDiffuse + (brightness * lightColor[i]) / attFactor; 35 | totalSpecular = totalSpecular + (dampedFactor * reflectivity * lightColor[i]) / attFactor; 36 | } 37 | 38 | float ambient = 0.2; 39 | totalDiffuse = max(totalDiffuse, ambient); 40 | 41 | vec4 textureColor = texture(modelTexture, pass_textureCoords); 42 | if (textureColor.a < 0.5) { 43 | discard; 44 | } 45 | 46 | out_color = vec4(totalDiffuse, 1.0) * textureColor + vec4(totalSpecular, 1.0); 47 | out_color = mix(vec4(skyColor, 1.0), out_color, visibility); 48 | } 49 | -------------------------------------------------------------------------------- /res/shaders/static.v.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec3 position; 4 | in vec2 textureCoords; 5 | in vec3 normal; 6 | 7 | out vec2 pass_textureCoords; 8 | out vec3 surfaceNormal; 9 | out vec3 toLightVector[4]; 10 | out vec3 toCameraVector; 11 | out float visibility; 12 | 13 | uniform mat4 transformationMatrix; 14 | uniform mat4 projectionMatrix; 15 | uniform mat4 viewMatrix; 16 | uniform vec3 lightPosition[4]; 17 | 18 | uniform int useFakeLighting; 19 | 20 | uniform float numberOfRows; 21 | uniform vec2 offset; 22 | 23 | const float density = 0.0; //0.0035; 24 | const float gradient = 5.0; 25 | 26 | uniform vec4 plane; 27 | 28 | void main(void) { 29 | vec4 worldPosition = transformationMatrix * vec4(position, 1.0); 30 | 31 | gl_ClipDistance[0] = dot(worldPosition, plane); 32 | 33 | vec4 positionRelativeToCam = viewMatrix * worldPosition; 34 | gl_Position = projectionMatrix * positionRelativeToCam; 35 | pass_textureCoords = (textureCoords / numberOfRows) + offset; 36 | 37 | vec3 actualNormal = normal; 38 | if (useFakeLighting == 1) { 39 | actualNormal = vec3(0.0, 1.0, 0.0); 40 | } 41 | surfaceNormal = (transformationMatrix * vec4(actualNormal, 0.0)).xyz; 42 | toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz; 43 | for (int i = 0; i < 4; i++) { 44 | toLightVector[i] = lightPosition[i] - worldPosition.xyz; 45 | } 46 | 47 | float dist = length(positionRelativeToCam.xyz); 48 | visibility = exp(-pow((dist * density), gradient)); 49 | visibility = clamp(visibility, 0.0, 1.0); 50 | } 51 | -------------------------------------------------------------------------------- /res/shaders/terrain.f.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec2 pass_textureCoords; 4 | in vec3 surfaceNormal; 5 | in vec3 toLightVector[4]; 6 | in vec3 toCameraVector; 7 | in float visibility; 8 | 9 | out vec4 out_color; 10 | 11 | uniform sampler2D backgroundTexture; 12 | uniform sampler2D rTexture; 13 | uniform sampler2D gTexture; 14 | uniform sampler2D bTexture; 15 | uniform sampler2D blendMap; 16 | 17 | uniform vec3 lightColor[4]; 18 | uniform vec3 attenuation[4]; 19 | uniform float shineDamper; 20 | uniform float reflectivity; 21 | uniform vec3 skyColor; 22 | 23 | void main(void) { 24 | vec4 blendMapColor = texture(blendMap, pass_textureCoords); 25 | 26 | float backTextureAmount = 1 - (blendMapColor.r + blendMapColor.g + blendMapColor.b); 27 | vec2 tiledCoords = pass_textureCoords * 40.0; 28 | 29 | vec4 backgroundTextureColor = texture(backgroundTexture, tiledCoords) * backTextureAmount; 30 | vec4 rTextureColor = texture(rTexture, tiledCoords) * blendMapColor.r; 31 | vec4 gTextureColor = texture(gTexture, tiledCoords) * blendMapColor.g; 32 | vec4 bTextureColor = texture(bTexture, tiledCoords) * blendMapColor.b; 33 | 34 | vec4 totalColor = backgroundTextureColor + rTextureColor + gTextureColor + bTextureColor; 35 | 36 | vec3 unitNormal = normalize(surfaceNormal); 37 | vec3 unitToCameraVector = normalize(toCameraVector); 38 | 39 | vec3 totalDiffuse = vec3(0.0); 40 | vec3 totalSpecular = vec3(0.0); 41 | 42 | for (int i = 0; i < 4; i++) { 43 | float distance = length(toLightVector[i]); 44 | float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance); 45 | vec3 unitToLightVector = normalize(toLightVector[i]); 46 | float brightness = max(0.0, dot(unitNormal, unitToLightVector)); 47 | vec3 lightDirection = -unitToLightVector; 48 | vec3 reflectedLightDirection = reflect(lightDirection, unitNormal); 49 | float specularFactor = max(0.0, dot(reflectedLightDirection, unitToCameraVector)); 50 | float dampedFactor = pow(specularFactor, shineDamper); 51 | totalDiffuse = totalDiffuse + (brightness * lightColor[i]) / attFactor; 52 | totalSpecular = totalSpecular + (dampedFactor * reflectivity * lightColor[i]) / attFactor; 53 | } 54 | 55 | float ambient = 0.2; 56 | totalDiffuse = max(totalDiffuse, ambient); 57 | 58 | out_color = vec4(totalDiffuse, 1.0) * totalColor + vec4(totalSpecular, 1.0); 59 | out_color = mix(vec4(skyColor, 1.0), out_color, visibility); 60 | } 61 | -------------------------------------------------------------------------------- /res/shaders/terrain.v.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec3 position; 4 | in vec2 textureCoords; 5 | in vec3 normal; 6 | 7 | out vec2 pass_textureCoords; 8 | out vec3 surfaceNormal; 9 | out vec3 toLightVector[4]; 10 | out vec3 toCameraVector; 11 | out float visibility; 12 | 13 | uniform mat4 transformationMatrix; 14 | uniform mat4 projectionMatrix; 15 | uniform mat4 viewMatrix; 16 | uniform vec3 lightPosition[4]; 17 | 18 | const float density = 0.0; //0.0035; 19 | const float gradient = 5.0; 20 | 21 | uniform vec4 plane; 22 | 23 | void main(void) { 24 | vec4 worldPosition = transformationMatrix * vec4(position, 1.0); 25 | 26 | gl_ClipDistance[0] = dot(worldPosition, plane); 27 | 28 | vec4 positionRelativeToCam = viewMatrix * worldPosition; 29 | gl_Position = projectionMatrix * positionRelativeToCam; 30 | pass_textureCoords = textureCoords; 31 | 32 | surfaceNormal = (transformationMatrix * vec4(normal, 0.0)).xyz; 33 | toCameraVector = (inverse(viewMatrix) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz; 34 | for (int i = 0; i < 4; i++) { 35 | toLightVector[i] = lightPosition[i] - worldPosition.xyz; 36 | } 37 | 38 | float dist = length(positionRelativeToCam.xyz); 39 | visibility = exp(-pow((dist * density), gradient)); 40 | visibility = clamp(visibility, 0.0, 1.0); 41 | } 42 | -------------------------------------------------------------------------------- /res/shaders/water.f.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec4 clipSpace; 4 | in vec2 textureCoords; 5 | in vec3 toCameraVector; 6 | in vec3 fromLightVector; 7 | 8 | out vec4 out_Color; 9 | 10 | uniform sampler2D reflectionTexture; 11 | uniform sampler2D refractionTexture; 12 | uniform sampler2D dudvMap; 13 | uniform sampler2D normalMap; 14 | uniform sampler2D depthMap; 15 | 16 | uniform vec3 lightColor; 17 | uniform float moveFactor; 18 | 19 | const float waveStrength = 0.04; 20 | const float shineDamper = 20.0; 21 | const float reflectivity = 0.5; 22 | 23 | const float near = 0.1; 24 | const float far = 1000.0; 25 | 26 | 27 | void main(void) { 28 | vec2 ndc = (clipSpace.xy / clipSpace.w) / 2.0 + 0.5; 29 | vec2 reflectTexCoords = vec2(ndc.x, -ndc.y); 30 | vec2 refractTexCoords = vec2(ndc.x, ndc.y); 31 | 32 | float depth = texture(depthMap, refractTexCoords).r; 33 | float floorDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); 34 | 35 | depth = gl_FragCoord.z; 36 | float waterDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near)); 37 | float waterDepth = floorDistance - waterDistance; 38 | 39 | vec2 distortedTexCoords = texture(dudvMap, vec2(textureCoords.x + moveFactor, textureCoords.y)).rg * 0.1; 40 | distortedTexCoords = textureCoords + vec2(distortedTexCoords.x, distortedTexCoords.y + moveFactor); 41 | vec2 totalDistortion = (texture(dudvMap, distortedTexCoords).rg * 2.0 - 1.0) * waveStrength * clamp(waterDepth / 20.0, 0.0, 1.0); 42 | 43 | reflectTexCoords.x = clamp(reflectTexCoords.x + totalDistortion.x, 0.001, 0.999); 44 | reflectTexCoords.y = clamp(reflectTexCoords.y + totalDistortion.y, -0.999, -0.001); 45 | refractTexCoords = clamp(refractTexCoords + totalDistortion, 0.001, 0.999); 46 | 47 | vec4 reflectColor = texture(reflectionTexture, reflectTexCoords); 48 | vec4 refractColor = texture(refractionTexture, refractTexCoords); 49 | 50 | vec4 normalMapColor = texture(normalMap, distortedTexCoords); 51 | vec3 normal = normalize(vec3(normalMapColor.r * 2.0 - 1.0, normalMapColor.b * 3.0, normalMapColor.g * 2.0 - 1.0)); 52 | 53 | vec3 viewVector = normalize(toCameraVector); 54 | float refractiveFactor = dot(viewVector, normal); 55 | refractiveFactor = pow(refractiveFactor, 0.5); 56 | refractiveFactor = clamp(refractiveFactor, 0.0, 1.0); 57 | 58 | vec3 reflectedLight = reflect(normalize(fromLightVector), normal); 59 | float specular = max(dot(reflectedLight, viewVector), 0.0); 60 | specular = pow(specular, shineDamper); 61 | vec3 specularHighlights = lightColor * specular * reflectivity * clamp(waterDepth / 5.0, 0.0, 1.0); 62 | 63 | out_Color = mix(reflectColor, refractColor, refractiveFactor); 64 | out_Color = mix(out_Color, vec4(0.0, 0.3, 0.5, 1.0), 0.2) + vec4(specularHighlights, 0.0); 65 | out_Color.a = clamp(waterDepth / 5.0, 0.0, 1.0); 66 | } 67 | -------------------------------------------------------------------------------- /res/shaders/water.v.glsl: -------------------------------------------------------------------------------- 1 | #version 130 2 | 3 | in vec2 position; 4 | 5 | out vec4 clipSpace; 6 | out vec2 textureCoords; 7 | out vec3 toCameraVector; 8 | out vec3 fromLightVector; 9 | 10 | uniform mat4 projectionMatrix; 11 | uniform mat4 viewMatrix; 12 | uniform mat4 modelMatrix; 13 | uniform vec3 cameraPosition; 14 | uniform vec3 lightPosition; 15 | 16 | const float tiling = 4.0; 17 | 18 | 19 | void main(void) { 20 | vec4 worldPosition = modelMatrix * vec4(position.x, 0.0, position.y, 1.0); 21 | clipSpace = projectionMatrix * viewMatrix * worldPosition; 22 | gl_Position = clipSpace; 23 | textureCoords = (position.xy / 2.0 + 0.5) * tiling; 24 | toCameraVector = cameraPosition - worldPosition.xyz; 25 | fromLightVector = worldPosition.xyz - lightPosition; 26 | } 27 | -------------------------------------------------------------------------------- /res/textures/dragon/white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/dragon/white.png -------------------------------------------------------------------------------- /res/textures/fern/fern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/fern/fern.png -------------------------------------------------------------------------------- /res/textures/fern/fern_atlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/fern/fern_atlas.png -------------------------------------------------------------------------------- /res/textures/grass/grassTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/grass/grassTexture.png -------------------------------------------------------------------------------- /res/textures/guis/thinmatrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/guis/thinmatrix.png -------------------------------------------------------------------------------- /res/textures/lamp/lamp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/lamp/lamp.png -------------------------------------------------------------------------------- /res/textures/low_poly_tree/lowPolyTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/low_poly_tree/lowPolyTree.png -------------------------------------------------------------------------------- /res/textures/pine/pine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/pine/pine.png -------------------------------------------------------------------------------- /res/textures/skybox/day/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/back.png -------------------------------------------------------------------------------- /res/textures/skybox/day/bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/bottom.png -------------------------------------------------------------------------------- /res/textures/skybox/day/front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/front.png -------------------------------------------------------------------------------- /res/textures/skybox/day/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/left.png -------------------------------------------------------------------------------- /res/textures/skybox/day/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/right.png -------------------------------------------------------------------------------- /res/textures/skybox/day/top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/day/top.png -------------------------------------------------------------------------------- /res/textures/skybox/night/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/back.png -------------------------------------------------------------------------------- /res/textures/skybox/night/bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/bottom.png -------------------------------------------------------------------------------- /res/textures/skybox/night/front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/front.png -------------------------------------------------------------------------------- /res/textures/skybox/night/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/left.png -------------------------------------------------------------------------------- /res/textures/skybox/night/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/right.png -------------------------------------------------------------------------------- /res/textures/skybox/night/top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/skybox/night/top.png -------------------------------------------------------------------------------- /res/textures/stall/stallTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/stall/stallTexture.png -------------------------------------------------------------------------------- /res/textures/terrain/blendMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/blendMap.png -------------------------------------------------------------------------------- /res/textures/terrain/grass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/grass.png -------------------------------------------------------------------------------- /res/textures/terrain/grassFlowers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/grassFlowers.png -------------------------------------------------------------------------------- /res/textures/terrain/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/heightmap.png -------------------------------------------------------------------------------- /res/textures/terrain/mud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/mud.png -------------------------------------------------------------------------------- /res/textures/terrain/path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/terrain/path.png -------------------------------------------------------------------------------- /res/textures/tree/tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/tree/tree.png -------------------------------------------------------------------------------- /res/textures/water/normalMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/water/normalMap.png -------------------------------------------------------------------------------- /res/textures/water/waterDUDV.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/res/textures/water/waterDUDV.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michaelh800/thinmatrix-game-engine/e0e6173202943433f926c5a3699c007397b67272/screenshot.png -------------------------------------------------------------------------------- /src/engine_tester/game_engine.cpp: -------------------------------------------------------------------------------- 1 | #include "engine_tester/game_engine.hpp" 2 | #include "render_engine/obj_loader.hpp" 3 | 4 | 5 | GameEngine::~GameEngine() { 6 | display_.close(); 7 | } 8 | 9 | void GameEngine::doMainLoop() { 10 | 11 | /* *********************************************************** */ 12 | /* INITIALIZE */ 13 | /* *********************************************************** */ 14 | 15 | // create terrain 16 | TerrainTexture backgroundTexture(loader_.loadTexture("res/textures/terrain/grass.png")); 17 | TerrainTexture rTexture(loader_.loadTexture("res/textures/terrain/mud.png")); 18 | TerrainTexture gTexture(loader_.loadTexture("res/textures/terrain/grassFlowers.png")); 19 | TerrainTexture bTexture(loader_.loadTexture("res/textures/terrain/path.png")); 20 | TerrainTexturePack texturePack(backgroundTexture, rTexture, gTexture, bTexture); 21 | TerrainTexture blendMap(loader_.loadTexture("res/textures/terrain/blendMap.png")); 22 | terrains_.emplace_back(-0.5f, -0.5f, loader_, texturePack, blendMap, "res/textures/terrain/heightmap.png"); 23 | 24 | // set light positions 25 | // glm::vec3 lightHeight = glm::vec3(0, 17, 0); 26 | // glm::vec3 lightPos1 = glm::vec3(-80, terrains_.front().getHeightOfTerrain(-80, -90), -90); 27 | // glm::vec3 lightPos2 = glm::vec3(65, terrains_.front().getHeightOfTerrain(65, -10), -10); 28 | // glm::vec3 lightPos3 = glm::vec3(-20, terrains_.front().getHeightOfTerrain(-20, 150), 150); 29 | 30 | // add lights 31 | lights_.emplace_back(glm::vec3(0, 1000, -1000), glm::vec3(0.8f, 0.8f, 0.8f)); 32 | // lights_.emplace_back(lightPos1 + lightHeight, glm::vec3(2, 0, 0), glm::vec3(1.0f, 0.01f, 0.002f)); 33 | // lights_.emplace_back(lightPos2 + lightHeight, glm::vec3(0, 2, 2), glm::vec3(1.0f, 0.01f, 0.002f)); 34 | // lights_.emplace_back(lightPos3 + lightHeight, glm::vec3(2, 2, 0), glm::vec3(1.0f, 0.01f, 0.002f)); 35 | 36 | // create lamp model 37 | // ModelTexture lampTexture(loader_.loadTexture("res/textures/lamp/lamp.png")); 38 | // lampTexture.setFakeLighting(true); 39 | // lampTexture.setNumberOfRows(1); 40 | // auto lamp = TexturedModel(ObjLoader::loadObjModel("res/models/lamp/lamp.obj", loader_), lampTexture); 41 | 42 | // place lamp entities 43 | // entities_.emplace_back(&lamp, lightPos1, glm::vec3(0, 0, 0), glm::vec3(1, 1, 1)); 44 | // entities_.emplace_back(&lamp, lightPos2, glm::vec3(0, 0, 0), glm::vec3(1, 1, 1)); 45 | // entities_.emplace_back(&lamp, lightPos3, glm::vec3(0, 0, 0), glm::vec3(1, 1, 1)); 46 | 47 | // create tree model 48 | ModelTexture treeTexture(loader_.loadTexture("res/textures/pine/pine.png")); 49 | treeTexture.setNumberOfRows(1); 50 | auto tree = TexturedModel(ObjLoader::loadObjModel("res/models/pine/pine.obj", loader_), treeTexture); 51 | 52 | // create fern model 53 | ModelTexture fernTexture(loader_.loadTexture("res/textures/fern/fern_atlas.png")); 54 | fernTexture.setTransparency(true); 55 | fernTexture.setFakeLighting(true); 56 | fernTexture.setNumberOfRows(2); 57 | auto fern = TexturedModel(ObjLoader::loadObjModel("res/models/fern/fern.obj", loader_), fernTexture ); 58 | 59 | // randomly place tree and fern entities 60 | for (int x = -200; x <= 200; x += 20) { 61 | for (int z = -200; z <= 200; z += 20) { 62 | float random = (float)rand() / RAND_MAX; 63 | float y = terrains_.front().getHeightOfTerrain(x, z); 64 | if (y >= 0.0f && random < 0.1) { 65 | entities_.emplace_back(&fern, glm::vec3(x, y, z), glm::vec3(0), glm::vec3(1), rand()%4); 66 | } 67 | if (y >= 0.0f && random > 0.7) { 68 | entities_.emplace_back(&tree, glm::vec3(x, y, z), glm::vec3(0), glm::vec3(1)); 69 | } 70 | } 71 | } 72 | 73 | // create guis 74 | guis_.emplace_back(loader_.loadTexture("res/textures/guis/thinmatrix.png"), glm::vec2(-0.75f, 0.9f), glm::vec2(0.25f)); 75 | 76 | // create waters 77 | waters_.emplace_back(0.0f, 0.0f, 0.0f); 78 | 79 | 80 | /* *********************************************************** */ 81 | /* MAIN LOOP */ 82 | /* *********************************************************** */ 83 | 84 | bool running = true; 85 | 86 | while (running) { 87 | sf::Event event; 88 | while (display_.getWindow().pollEvent(event)) { 89 | if (event.type == sf::Event::Closed 90 | || sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) 91 | { 92 | running = false; 93 | } else if (event.type == sf::Event::Resized) { 94 | display_.resize(event.size.width, event.size.height); 95 | renderer_.resetProjectionMatrix(); 96 | } 97 | } 98 | 99 | camera_.update(terrains_.front()); 100 | // picker_.update(); 101 | // auto ray = picker_.getCurrentRay(); 102 | 103 | glEnable(GL_CLIP_DISTANCE0); 104 | float waterHeight = waters_.front().getHeight(); 105 | 106 | waterFbos_.bindReflectionFrameBuffer(); 107 | float distance = 2.0f * (camera_.getPosition().y - waterHeight); 108 | camera_.getPosition().y -= distance; 109 | camera_.invertPitch(); 110 | renderer_.renderScene(entities_, terrains_.front(), lights_, camera_, {0.0f, 1.0f, 0.0f, -waterHeight + 1.0f}); 111 | camera_.getPosition().y += distance; 112 | camera_.invertPitch(); 113 | 114 | waterFbos_.bindRefractionFrameBuffer(); 115 | renderer_.renderScene(entities_, terrains_.front(), lights_, camera_, {0.0f, -1.0f, 0.0f, waterHeight + 1.0f}); 116 | 117 | glDisable(GL_CLIP_DISTANCE0); 118 | 119 | waterFbos_.unbindCurrentFrameBuffer(); 120 | renderer_.renderScene(entities_, terrains_.front(), lights_, camera_, {0, 0, 0, 0}); 121 | waterRenderer_.render(waters_, camera_, lights_.front()); 122 | guiRenderer_.render(guis_); 123 | display_.update(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/engine_tester/game_engine.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "render_engine/display_manager.hpp" 3 | #include "render_engine/glew.hpp" 4 | #include "render_engine/loader.hpp" 5 | #include "entities/camera.hpp" 6 | #include "entities/light.hpp" 7 | #include "entities/entity.hpp" 8 | #include "terrain/terrain.hpp" 9 | #include "guis/gui_renderer.hpp" 10 | #include "render_engine/master_renderer.hpp" 11 | #include "toolbox/mouse_picker.hpp" 12 | #include "water/water_renderer.hpp" 13 | #include "water/water_tile.hpp" 14 | #include "water/water_frame_buffers.hpp" 15 | #include 16 | 17 | class GameEngine { 18 | public: 19 | GameEngine() = default; 20 | ~GameEngine(); 21 | 22 | void doMainLoop(); 23 | 24 | private: 25 | DisplayManager display_{}; 26 | Glew glew_{}; 27 | Loader loader_{}; 28 | Camera camera_{true}; 29 | std::vector lights_; 30 | std::vector entities_; 31 | std::vector terrains_; 32 | MasterRenderer renderer_{loader_}; 33 | MousePicker picker_{camera_, renderer_.getProjectionMatrix()}; 34 | GuiRenderer guiRenderer_{loader_}; 35 | std::vector guis_; 36 | WaterFrameBuffers waterFbos_{}; 37 | WaterRenderer waterRenderer_{loader_, renderer_.getProjectionMatrix(), waterFbos_}; 38 | std::vector waters_; 39 | }; 40 | -------------------------------------------------------------------------------- /src/entities/camera.cpp: -------------------------------------------------------------------------------- 1 | #include "entities/camera.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #include 4 | #define GLM_FORCE_RADIANS 5 | #include 6 | 7 | 8 | namespace { 9 | constexpr float EYE_LEVEL = 6.0f; 10 | constexpr float WALK_SPEED = 20.0f; 11 | constexpr float RUN_SPEED = 100.0f; 12 | constexpr float SENSITIVITY = 0.005f; 13 | } 14 | 15 | Camera::Camera(bool freeRoam) 16 | : freeRoam_(freeRoam) 17 | { 18 | position_ += glm::vec3(0.0f, EYE_LEVEL, 0.0f); 19 | } 20 | 21 | void Camera::update(Terrain const& terrain) { 22 | sf::Vector2i mousePositionDelta = DisplayManager::getMousePositionDelta(); 23 | updateDirection(glm::vec2(mousePositionDelta.x, mousePositionDelta.y)); 24 | updatePosition(terrain); 25 | } 26 | 27 | glm::mat4 Camera::getViewMatrix() const { 28 | return glm::lookAt(position_, position_ + viewDirection_, up_); 29 | } 30 | 31 | void Camera::invertPitch() { 32 | viewDirection_.y *= -1.0f; 33 | } 34 | 35 | glm::vec3& Camera::getPosition() { 36 | return position_; 37 | } 38 | 39 | void Camera::updateDirection(glm::vec2 const& mousePositionDelta) { 40 | if (glm::length(mousePositionDelta) > 100) return; 41 | 42 | glm::vec3 right = glm::cross(viewDirection_, up_); 43 | 44 | glm::mat4 matrix = glm::mat4(); 45 | matrix = glm::rotate(matrix, -mousePositionDelta.x * SENSITIVITY, up_); 46 | matrix = glm::rotate(matrix, -mousePositionDelta.y * SENSITIVITY, right); 47 | 48 | viewDirection_ = glm::normalize(glm::vec3(matrix * glm::vec4(viewDirection_, 0))); 49 | } 50 | 51 | void Camera::updatePosition(Terrain const& terrain) { 52 | float speed = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::LShift) ? RUN_SPEED : WALK_SPEED; 53 | float dt = DisplayManager::getFrameTime().asSeconds(); 54 | 55 | if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) { 56 | position_ += speed * dt * viewDirection_; 57 | } 58 | else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) { 59 | position_ -= speed * dt * viewDirection_; 60 | } 61 | else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { 62 | position_ -= speed * dt * glm::cross(viewDirection_, up_); 63 | } 64 | else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) { 65 | position_ += speed * dt * glm::cross(viewDirection_, up_); 66 | } 67 | 68 | if (!freeRoam_) { 69 | position_.y = terrain.getHeightOfTerrain(position_.x, position_.z) + EYE_LEVEL; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/entities/camera.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "terrain/terrain.hpp" 3 | #include 4 | #include 5 | 6 | class Camera { 7 | public: 8 | Camera(bool freeRoam=false); 9 | 10 | void update(Terrain const& terrain); 11 | void invertPitch(); 12 | 13 | glm::mat4 getViewMatrix() const; 14 | glm::vec3& getPosition(); 15 | 16 | private: 17 | bool freeRoam_; 18 | 19 | const glm::vec3 up_ {0, 1, 0}; 20 | glm::vec3 position_ {0, 0, 0}; 21 | glm::vec3 viewDirection_{0, 0, -1}; 22 | 23 | void updateDirection(glm::vec2 const& mousePositionDelta); 24 | void updatePosition(Terrain const& terrain); 25 | }; 26 | -------------------------------------------------------------------------------- /src/entities/entity.cpp: -------------------------------------------------------------------------------- 1 | #include "entities/entity.hpp" 2 | 3 | 4 | Entity::Entity(TexturedModel const* model, 5 | glm::vec3 const& position, 6 | glm::vec3 const& rotation, 7 | glm::vec3 const& scale, 8 | int textureIndex 9 | ) 10 | : model_(model) 11 | , position_(position) 12 | , rotation_(rotation) 13 | , scale_(scale) 14 | , textureIndex_(textureIndex) 15 | { } 16 | 17 | void Entity::move(glm::vec3 const& translation) { 18 | position_ += translation; 19 | } 20 | 21 | void Entity::rotate(glm::vec3 const& rotation) { 22 | rotation_ += rotation; 23 | } 24 | 25 | void Entity::scale(glm::vec3 const& scale) { 26 | scale_ *= scale; 27 | } 28 | 29 | float Entity::getTextureXOffset() const { 30 | int column = textureIndex_ % model_->getModelTexture().getNumberOfRows(); 31 | return (float) column / model_->getModelTexture().getNumberOfRows(); 32 | } 33 | 34 | float Entity::getTextureYOffset() const { 35 | int row = textureIndex_ / model_->getModelTexture().getNumberOfRows(); 36 | return (float) row / model_->getModelTexture().getNumberOfRows(); 37 | 38 | } 39 | 40 | TexturedModel const* Entity::getModel() const { return model_; } 41 | void Entity::setModel(TexturedModel const* model) { model_ = model; } 42 | 43 | glm::vec3 const& Entity::getPosition() const { return position_; } 44 | void Entity::setPosition(glm::vec3 const& position) { position_ = position; } 45 | 46 | glm::vec3 const& Entity::getRotation() const { return rotation_; } 47 | void Entity::setRotation(glm::vec3 const& rotation) { rotation_ = rotation; } 48 | 49 | glm::vec3 const& Entity::getScale() const { return scale_; } 50 | void Entity::setScale(glm::vec3 const& scale) { scale_ = scale; } -------------------------------------------------------------------------------- /src/entities/entity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "models/textured_model.hpp" 3 | #include 4 | 5 | class Entity { 6 | public: 7 | Entity(TexturedModel const* model, 8 | glm::vec3 const& position, 9 | glm::vec3 const& rotation, 10 | glm::vec3 const& scale, 11 | int textureIndex=0); 12 | 13 | void move(glm::vec3 const& translation); 14 | void rotate(glm::vec3 const& rotation); 15 | void scale(glm::vec3 const& scale); 16 | 17 | float getTextureXOffset() const; 18 | float getTextureYOffset() const; 19 | 20 | TexturedModel const* getModel() const; 21 | void setModel(TexturedModel const* model); 22 | glm::vec3 const& getPosition() const; 23 | void setPosition(glm::vec3 const& position); 24 | glm::vec3 const& getRotation() const; 25 | void setRotation(glm::vec3 const& rotation); 26 | glm::vec3 const& getScale() const; 27 | void setScale(glm::vec3 const& scale); 28 | 29 | private: 30 | TexturedModel const* model_; 31 | glm::vec3 position_; 32 | glm::vec3 rotation_; 33 | glm::vec3 scale_; 34 | int textureIndex_; 35 | }; 36 | -------------------------------------------------------------------------------- /src/entities/light.cpp: -------------------------------------------------------------------------------- 1 | #include "entities/light.hpp" 2 | 3 | 4 | Light::Light(glm::vec3 const& position, glm::vec3 const& color, glm::vec3 const& attenuation) 5 | : position_(position) 6 | , color_(color) 7 | , attenuation_(attenuation) 8 | { } 9 | 10 | glm::vec3 const& Light::getPosition() const { return position_; } 11 | void Light::setPosition(glm::vec3 const& position) { position_ = position; } 12 | 13 | glm::vec3 const& Light::getColor() const { return color_; } 14 | void Light::setColor(glm::vec3 const& color) { color_ = color; } 15 | 16 | glm::vec3 const& Light::getAttenuation() const { return attenuation_; } 17 | -------------------------------------------------------------------------------- /src/entities/light.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Light { 5 | public: 6 | Light(glm::vec3 const& position, 7 | glm::vec3 const& color, 8 | glm::vec3 const& attenuation=glm::vec3(1, 0, 0)); 9 | 10 | glm::vec3 const& getPosition() const; 11 | void setPosition(glm::vec3 const& position); 12 | 13 | glm::vec3 const& getColor() const; 14 | void setColor(glm::vec3 const& color); 15 | 16 | glm::vec3 const& getAttenuation() const; 17 | 18 | private: 19 | glm::vec3 position_; 20 | glm::vec3 color_; 21 | glm::vec3 attenuation_; 22 | }; 23 | -------------------------------------------------------------------------------- /src/guis/gui_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "guis/gui_renderer.hpp" 2 | #include "toolbox/math.hpp" 3 | 4 | 5 | GuiRenderer::GuiRenderer(Loader &loader) { 6 | std::vector positions = { -1, 1, -1, -1, 1, 1, 1, -1 }; 7 | quad_ = loader.loadToVao(positions, 2); 8 | } 9 | 10 | void GuiRenderer::render(std::vector const& guis) { 11 | shader_.start(); 12 | glBindVertexArray(quad_.getVaoId()); 13 | glEnableVertexAttribArray(0); 14 | glEnable(GL_BLEND); 15 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 16 | glDisable(GL_DEPTH_TEST); 17 | for (GuiTexture const& gui : guis) { 18 | glActiveTexture(GL_TEXTURE0); 19 | glBindTexture(GL_TEXTURE_2D, gui.getTextureId()); 20 | glm::mat4 transformationMatrix = 21 | Math::createTransformationMatrix(gui.getPosition(), gui.getScale()); 22 | shader_.loadTransformationMatrix(transformationMatrix); 23 | glDrawArrays(GL_TRIANGLE_STRIP, 0, quad_.getVertexCount()); 24 | } 25 | glEnable(GL_DEPTH_TEST); 26 | glDisable(GL_BLEND); 27 | glDisableVertexAttribArray(0); 28 | glBindVertexArray(0); 29 | shader_.stop(); 30 | } 31 | -------------------------------------------------------------------------------- /src/guis/gui_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "render_engine/loader.hpp" 3 | #include "models/raw_model.hpp" 4 | #include "guis/gui_texture.hpp" 5 | #include "guis/gui_shader.hpp" 6 | #include 7 | 8 | class GuiRenderer { 9 | public: 10 | GuiRenderer(Loader &loader); 11 | 12 | void render(std::vector const& guis); 13 | 14 | private: 15 | RawModel quad_; 16 | GuiShader shader_; 17 | }; 18 | -------------------------------------------------------------------------------- /src/guis/gui_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "guis/gui_shader.hpp" 2 | 3 | 4 | GuiShader::GuiShader() 5 | : Shader(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE) 6 | { 7 | initialize(); 8 | } 9 | 10 | void GuiShader::bindAttributes() { 11 | bindAttribute(0, "position"); 12 | } 13 | 14 | void GuiShader::getAllUniformLocations() { 15 | transformationMatrixLocation_ = getUniformLocation("transformationMatrix"); 16 | } 17 | 18 | void GuiShader::loadTransformationMatrix(glm::mat4 const& matrix) const { 19 | loadMatrix(transformationMatrixLocation_, matrix); 20 | } 21 | -------------------------------------------------------------------------------- /src/guis/gui_shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "shaders/shader.hpp" 3 | 4 | class GuiShader final : public Shader { 5 | public: 6 | GuiShader(); 7 | 8 | void loadTransformationMatrix(glm::mat4 const& matrix) const; 9 | 10 | protected: 11 | virtual void bindAttributes() override; 12 | virtual void getAllUniformLocations() override; 13 | 14 | private: 15 | static constexpr auto VERTEX_SHADER_FILE = "res/shaders/gui.v.glsl"; 16 | static constexpr auto FRAGMENT_SHADER_FILE = "res/shaders/gui.f.glsl"; 17 | 18 | GLint transformationMatrixLocation_; 19 | }; 20 | -------------------------------------------------------------------------------- /src/guis/gui_texture.cpp: -------------------------------------------------------------------------------- 1 | #include "guis/gui_texture.hpp" 2 | 3 | 4 | GuiTexture::GuiTexture(GLuint textureId, glm::vec2 position, glm::vec2 scale) 5 | : textureId_(textureId) 6 | , position_(position) 7 | , scale_(scale) 8 | { } 9 | 10 | GLuint GuiTexture::getTextureId() const { 11 | return textureId_; 12 | } 13 | 14 | glm::vec2 const& GuiTexture::getPosition() const { 15 | return position_; 16 | } 17 | 18 | glm::vec2 const& GuiTexture::getScale() const { 19 | return scale_; 20 | } 21 | -------------------------------------------------------------------------------- /src/guis/gui_texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | class GuiTexture { 6 | public: 7 | GuiTexture(GLuint textureId, glm::vec2 position, glm::vec2 scale); 8 | 9 | GLuint getTextureId() const; 10 | glm::vec2 const& getPosition() const; 11 | glm::vec2 const& getScale() const; 12 | 13 | private: 14 | GLuint textureId_; 15 | glm::vec2 position_; 16 | glm::vec2 scale_; 17 | }; 18 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "engine_tester/game_engine.hpp" 2 | 3 | 4 | int main(int argc, char **argv) { 5 | GameEngine engine; 6 | engine.doMainLoop(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/models/raw_model.cpp: -------------------------------------------------------------------------------- 1 | #include "models/raw_model.hpp" 2 | 3 | 4 | RawModel::RawModel(GLuint vaoId, GLsizei vertexCount) 5 | : vaoId_(vaoId) 6 | , vertexCount_(vertexCount) 7 | { } 8 | 9 | GLuint RawModel::getVaoId() const { return vaoId_; } 10 | 11 | GLsizei RawModel::getVertexCount() const { return vertexCount_; } 12 | -------------------------------------------------------------------------------- /src/models/raw_model.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class RawModel { 5 | public: 6 | RawModel() = default; 7 | RawModel(GLuint vaoId, GLsizei vertexCount); 8 | 9 | GLuint getVaoId() const; 10 | GLsizei getVertexCount() const; 11 | 12 | private: 13 | GLuint vaoId_; 14 | GLsizei vertexCount_; 15 | }; 16 | -------------------------------------------------------------------------------- /src/models/textured_model.cpp: -------------------------------------------------------------------------------- 1 | #include "models/textured_model.hpp" 2 | 3 | 4 | TexturedModel::TexturedModel(RawModel rawModel, ModelTexture modelTexture) 5 | : rawModel_(rawModel) 6 | , modelTexture_(modelTexture) 7 | { } 8 | 9 | RawModel const& TexturedModel::getRawModel() const { 10 | return rawModel_; 11 | } 12 | 13 | ModelTexture const& TexturedModel::getModelTexture() const { 14 | return modelTexture_; 15 | } 16 | -------------------------------------------------------------------------------- /src/models/textured_model.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "models/raw_model.hpp" 3 | #include "textures/model_texture.hpp" 4 | 5 | class TexturedModel { 6 | public: 7 | TexturedModel() = default; 8 | TexturedModel(RawModel rawModel, ModelTexture modelTexture); 9 | 10 | RawModel const& getRawModel() const; 11 | ModelTexture const& getModelTexture() const; 12 | 13 | private: 14 | RawModel rawModel_; 15 | ModelTexture modelTexture_; 16 | }; 17 | -------------------------------------------------------------------------------- /src/render_engine/display_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/display_manager.hpp" 2 | 3 | 4 | sf::Window DisplayManager::window_; 5 | sf::Clock DisplayManager::clock_; 6 | sf::Time DisplayManager::frameTime_; 7 | 8 | DisplayManager::DisplayManager(sf::String const& name) { 9 | window_.create(sf::VideoMode(900, 675), name, sf::Style::Default, sf::ContextSettings(32)); 10 | window_.setVerticalSyncEnabled(true); 11 | window_.setPosition(sf::Vector2i(50, 25)); 12 | window_.setMouseCursorVisible(false); 13 | } 14 | 15 | void DisplayManager::resize(int width, int height) { 16 | glViewport(0, 0, width, height); 17 | } 18 | 19 | void DisplayManager::update() { 20 | frameTime_ = clock_.restart(); 21 | window_.display(); 22 | } 23 | 24 | void DisplayManager::close() { 25 | window_.close(); 26 | } 27 | 28 | sf::Window& DisplayManager::getWindow() { 29 | return window_; 30 | } 31 | 32 | float DisplayManager::getAspectRatio() { 33 | sf::Vector2u dimensions = window_.getSize(); 34 | return (float) dimensions.x / dimensions.y; 35 | } 36 | 37 | sf::Time const& DisplayManager::getFrameTime() { 38 | return frameTime_; 39 | } 40 | 41 | sf::Vector2i DisplayManager::getMousePositionDelta() { 42 | sf::Vector2i center = static_cast(window_.getSize() / 2U); 43 | sf::Vector2i delta = sf::Mouse::getPosition(window_) - center; 44 | sf::Mouse::setPosition(center, window_); 45 | return delta; 46 | } 47 | -------------------------------------------------------------------------------- /src/render_engine/display_manager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | class DisplayManager { 6 | public: 7 | DisplayManager(sf::String const& name=""); 8 | 9 | void resize(int width, int height); 10 | void update(); 11 | void close(); 12 | 13 | static sf::Window& getWindow(); 14 | static float getAspectRatio(); 15 | static sf::Time const& getFrameTime(); 16 | static sf::Vector2i getMousePositionDelta(); 17 | 18 | private: 19 | static sf::Window window_; 20 | static sf::Clock clock_; 21 | static sf::Time frameTime_; 22 | }; 23 | -------------------------------------------------------------------------------- /src/render_engine/entity_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/entity_renderer.hpp" 2 | #include "render_engine/master_renderer.hpp" 3 | #include "toolbox/math.hpp" 4 | 5 | 6 | EntityRenderer::EntityRenderer(StaticShader const* shader) 7 | : shader_(shader) 8 | { } 9 | 10 | void EntityRenderer::render(EntityMap const& entities) const { 11 | for (auto const& batch : entities) { 12 | prepareTexturedModel(batch.first); 13 | for (auto const& entity : batch.second) { 14 | prepareInstance(entity); 15 | glDrawElements(GL_TRIANGLES, batch.first->getRawModel().getVertexCount(), GL_UNSIGNED_INT, 0); 16 | } 17 | unbindTexturedModel(); 18 | } 19 | } 20 | 21 | void EntityRenderer::loadProjectionMatrix(glm::mat4 const& projectionMatrix) const { 22 | shader_->start(); 23 | shader_->loadProjectionMatrix(projectionMatrix); 24 | shader_->stop(); 25 | } 26 | 27 | void EntityRenderer::prepareTexturedModel(TexturedModel const* texturedModel) const { 28 | glBindVertexArray(texturedModel->getRawModel().getVaoId()); 29 | glEnableVertexAttribArray(0); 30 | glEnableVertexAttribArray(1); 31 | glEnableVertexAttribArray(2); 32 | ModelTexture const& texture = texturedModel->getModelTexture(); 33 | if (texture.hasTransparency()) MasterRenderer::disableCulling(); 34 | shader_->loadNumberOfRows(texture.getNumberOfRows()); 35 | shader_->loadFakeLightingVariable(texture.usesFakeLighting()); 36 | shader_->loadShineVariables(texture.getShineDamper(), texture.getReflectivity()); 37 | glActiveTexture(GL_TEXTURE0); 38 | glBindTexture(GL_TEXTURE_2D, texture.getTextureId()); 39 | } 40 | 41 | void EntityRenderer::unbindTexturedModel() const { 42 | MasterRenderer::enableCulling(); 43 | glDisableVertexAttribArray(0); 44 | glDisableVertexAttribArray(1); 45 | glDisableVertexAttribArray(2); 46 | glBindVertexArray(0); 47 | } 48 | 49 | void EntityRenderer::prepareInstance(Entity const* entity) const { 50 | glm::mat4 transformationMatrix = Math::createTransformationMatrix( 51 | entity->getPosition(), entity->getRotation(), entity->getScale()); 52 | shader_->loadTransformationMatrix(transformationMatrix); 53 | shader_->loadOffset(glm::vec2(entity->getTextureXOffset(), entity->getTextureYOffset())); 54 | } 55 | -------------------------------------------------------------------------------- /src/render_engine/entity_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "entities/entity.hpp" 3 | #include "shaders/static_shader.hpp" 4 | #include 5 | #include 6 | 7 | class EntityRenderer { 8 | public: 9 | using EntityMap = std::unordered_map>; 10 | 11 | EntityRenderer(StaticShader const* shader); 12 | 13 | void render(EntityMap const& entities) const; 14 | void loadProjectionMatrix(glm::mat4 const& projectionMatrix) const; 15 | 16 | private: 17 | StaticShader const* shader_; 18 | 19 | void prepareTexturedModel(TexturedModel const* texturedModel) const; 20 | void unbindTexturedModel() const; 21 | void prepareInstance(Entity const* entity) const; 22 | }; 23 | -------------------------------------------------------------------------------- /src/render_engine/glew.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/glew.hpp" 2 | #include 3 | #include 4 | 5 | Glew::Glew() { 6 | glewExperimental = GL_TRUE; 7 | if (glewInit() != GLEW_OK) { 8 | printf("[ERROR]: Failed to initialize GLEW\n"); 9 | exit(EXIT_FAILURE); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/render_engine/glew.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Glew { 5 | public: 6 | Glew(); 7 | }; 8 | -------------------------------------------------------------------------------- /src/render_engine/loader.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/loader.hpp" 2 | #include 3 | #include 4 | 5 | 6 | RawModel Loader::loadToVao(std::vector const& positions, 7 | std::vector const& textureCoords, 8 | std::vector const& normals, 9 | std::vector const& indices) 10 | { 11 | GLuint vaoId = createVao(); 12 | bindIndexBuffer(indices); 13 | storeDataInAttributeList(0, 3, positions); 14 | storeDataInAttributeList(1, 2, textureCoords); 15 | storeDataInAttributeList(2, 3, normals); 16 | unbindVao(); 17 | return RawModel(vaoId, indices.size()); 18 | } 19 | 20 | RawModel Loader::loadToVao(std::vector const& positions, int dimensions) { 21 | GLuint vaoId = createVao(); 22 | storeDataInAttributeList(0, dimensions, positions); 23 | unbindVao(); 24 | return RawModel(vaoId, positions.size() / dimensions); 25 | } 26 | 27 | GLuint Loader::loadTexture(std::string const& textureFile) { 28 | sf::Image image; 29 | if (!image.loadFromFile(textureFile)) { 30 | std::cerr << "[ERROR]: Failed to load texture: " << textureFile << std::endl; 31 | } 32 | 33 | gl::TextureHandle texture; 34 | glGenTextures(1, &texture); 35 | GLuint textureId = texture.get(); 36 | glBindTexture(GL_TEXTURE_2D, textureId); 37 | 38 | glTexImage2D( 39 | GL_TEXTURE_2D, 0, GL_RGBA, image.getSize().x, image.getSize().y, 40 | 0, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr() 41 | ); 42 | 43 | glGenerateMipmap(GL_TEXTURE_2D); 44 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 45 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -0.4f ); 46 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 47 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); 48 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); 49 | textures_.push_back(std::move(texture)); 50 | return textureId; 51 | } 52 | 53 | GLuint Loader::loadCubeMap(std::vector const& textureFiles) { 54 | gl::TextureHandle texture; 55 | glGenTextures(1, &texture); 56 | GLuint textureId = texture.get(); 57 | glBindTexture(GL_TEXTURE_CUBE_MAP, textureId); 58 | 59 | for (GLuint i = 0; i < textureFiles.size(); i++) { 60 | sf::Image image; 61 | if (!image.loadFromFile(textureFiles[i])) { 62 | std::cerr << "[ERROR]: Failed to load texture: " << textureFiles[i] << std::endl; 63 | } 64 | 65 | glTexImage2D( 66 | GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, image.getSize().x, 67 | image.getSize().y, 0, GL_RGBA, GL_UNSIGNED_BYTE, image.getPixelsPtr() 68 | ); 69 | } 70 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); 71 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); 72 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 73 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 74 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 75 | textures_.push_back(std::move(texture)); 76 | return textureId; 77 | } 78 | 79 | GLuint Loader::createVao() { 80 | gl::VertexArrayHandle vao; 81 | glGenVertexArrays(1, &vao); 82 | GLuint vaoId = vao.get(); 83 | vaos_.push_back(std::move(vao)); 84 | glBindVertexArray(vaoId); 85 | return vaoId; 86 | } 87 | 88 | void Loader::bindIndexBuffer(std::vector const& indices) { 89 | gl::BufferHandle vbo; 90 | glGenBuffers(1, &vbo); 91 | GLuint vboId = vbo.get(); 92 | vbos_.push_back(std::move(vbo)); 93 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboId); 94 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(GLuint), indices.data(), GL_STATIC_DRAW); 95 | } 96 | 97 | void Loader::storeDataInAttributeList(int attributeNumber, int coordinateSize, std::vector const& data) { 98 | gl::BufferHandle vbo; 99 | glGenBuffers(1, &vbo); 100 | GLuint vboId = vbo.get(); 101 | vbos_.push_back(std::move(vbo)); 102 | glBindBuffer(GL_ARRAY_BUFFER, vboId); 103 | glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(GLfloat), data.data(), GL_STATIC_DRAW); 104 | glVertexAttribPointer(attributeNumber, coordinateSize, GL_FLOAT, GL_FALSE, 0, 0); 105 | glBindBuffer(GL_ARRAY_BUFFER, 0); 106 | } 107 | 108 | void Loader::unbindVao() { 109 | glBindVertexArray(0); 110 | } 111 | -------------------------------------------------------------------------------- /src/render_engine/loader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "models/raw_model.hpp" 3 | #include "toolbox/gl_handles.hpp" 4 | #include 5 | #include 6 | #include 7 | 8 | class Loader { 9 | public: 10 | RawModel loadToVao(std::vector const& positions, 11 | std::vector const& textureCoords, 12 | std::vector const& normals, 13 | std::vector const& indices); 14 | 15 | RawModel loadToVao(std::vector const& positions, int dimensions); 16 | 17 | GLuint loadTexture(std::string const& textureFile); 18 | GLuint loadCubeMap(std::vector const& textureFiles); 19 | 20 | private: 21 | GLuint createVao(); 22 | void bindIndexBuffer(std::vector const& indices); 23 | void storeDataInAttributeList(int attributeNumber, int coordinateSize, std::vector const& data); 24 | void unbindVao(); 25 | 26 | std::vector vaos_; 27 | std::vector vbos_; 28 | std::vector textures_; 29 | }; 30 | -------------------------------------------------------------------------------- /src/render_engine/master_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/master_renderer.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #define GLM_FORCE_RADIANS 4 | #include 5 | 6 | 7 | namespace { 8 | constexpr float FOV = 70.0f; 9 | constexpr float NEAR_PLANE = 0.1f; 10 | constexpr float FAR_PLANE = 1000.0f; 11 | constexpr float RED = 0.5444f; 12 | constexpr float GREEN = 0.62f; 13 | constexpr float BLUE = 0.69f; 14 | } 15 | 16 | MasterRenderer::MasterRenderer(Loader& loader) : skyboxRenderer_(loader) { 17 | resetProjectionMatrix(); 18 | enableCulling(); 19 | glEnable(GL_DEPTH_TEST); 20 | } 21 | 22 | void MasterRenderer::prepare() const { 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | glClearColor(RED, GREEN, BLUE, 1); 25 | } 26 | 27 | void MasterRenderer::render(std::vector const& lights, Camera const& camera, 28 | glm::vec4 const& clipPlane) 29 | { 30 | prepare(); 31 | entityShader_.start(); 32 | entityShader_.loadClipPlane(clipPlane); 33 | entityShader_.loadSkyColor(glm::vec3{RED, GREEN, BLUE}); 34 | entityShader_.loadLights(lights); 35 | entityShader_.loadViewMatrix(camera); 36 | entityRenderer_.render(entities_); 37 | entityShader_.stop(); 38 | terrainShader_.start(); 39 | terrainShader_.loadClipPlane(clipPlane); 40 | terrainShader_.loadSkyColor(glm::vec3{RED, GREEN, BLUE}); 41 | terrainShader_.loadLights(lights); 42 | terrainShader_.loadViewMatrix(camera); 43 | terrainRenderer_.render(terrains_); 44 | terrainShader_.stop(); 45 | skyboxRenderer_.render(camera, glm::vec3{RED, GREEN, BLUE}); 46 | entities_.clear(); 47 | terrains_.clear(); 48 | } 49 | 50 | void MasterRenderer::processEntity(Entity const* entity) { 51 | entities_[entity->getModel()].push_back(entity); 52 | } 53 | 54 | void MasterRenderer::processTerrain(Terrain const* terrain) { 55 | terrains_.push_back(terrain); 56 | } 57 | 58 | void MasterRenderer::enableCulling() { 59 | glEnable(GL_CULL_FACE); 60 | glCullFace(GL_BACK); 61 | } 62 | 63 | void MasterRenderer::disableCulling() { 64 | glDisable(GL_CULL_FACE); 65 | } 66 | 67 | void MasterRenderer::resetProjectionMatrix() { 68 | projectionMatrix_ = glm::perspective( 69 | FOV, DisplayManager::getAspectRatio(), NEAR_PLANE, FAR_PLANE); 70 | entityRenderer_.loadProjectionMatrix(projectionMatrix_); 71 | terrainRenderer_.loadProjectionMatrix(projectionMatrix_); 72 | skyboxRenderer_.loadProjectionMatrix(projectionMatrix_); 73 | } 74 | 75 | glm::mat4 const& MasterRenderer::getProjectionMatrix() const { 76 | return projectionMatrix_; 77 | } 78 | 79 | void MasterRenderer::renderScene(std::vector const& entities, Terrain const& terrain, 80 | std::vector const& lights, Camera const& camera, glm::vec4 const& clipPlane) 81 | { 82 | processTerrain(&terrain); 83 | for (Entity const& entity : entities) processEntity(&entity); 84 | render(lights, camera, clipPlane); 85 | } 86 | -------------------------------------------------------------------------------- /src/render_engine/master_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "render_engine/entity_renderer.hpp" 3 | #include "render_engine/terrain_renderer.hpp" 4 | #include "render_engine/loader.hpp" 5 | #include "entities/light.hpp" 6 | #include "entities/camera.hpp" 7 | #include "skybox/skybox_renderer.hpp" 8 | #include 9 | #include 10 | #include 11 | 12 | class MasterRenderer { 13 | public: 14 | MasterRenderer(Loader& loader); 15 | 16 | void renderScene( 17 | std::vector const& entities, 18 | Terrain const& terrain, 19 | std::vector const& lights, 20 | Camera const& camera, 21 | glm::vec4 const& cliPlane); 22 | 23 | void prepare() const; 24 | void render( 25 | std::vector const& lights, 26 | Camera const& camera, 27 | glm::vec4 const& cliPlane); 28 | 29 | void processEntity(Entity const* entity); 30 | void processTerrain(Terrain const* terrain); 31 | 32 | static void enableCulling(); 33 | static void disableCulling(); 34 | void resetProjectionMatrix(); 35 | glm::mat4 const& getProjectionMatrix() const; 36 | 37 | private: 38 | using EntityMap = std::unordered_map>; 39 | 40 | glm::mat4 projectionMatrix_; 41 | StaticShader entityShader_{}; 42 | TerrainShader terrainShader_{}; 43 | EntityRenderer entityRenderer_{&entityShader_}; 44 | TerrainRenderer terrainRenderer_{&terrainShader_}; 45 | EntityMap entities_; 46 | std::vector terrains_; 47 | SkyboxRenderer skyboxRenderer_; 48 | }; 49 | -------------------------------------------------------------------------------- /src/render_engine/obj_loader.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/obj_loader.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | RawModel ObjLoader::loadObjModel(std::string const& filename, Loader& loader) { 10 | std::ifstream fin(filename.c_str()); 11 | 12 | if (!fin.is_open()) { 13 | std::cerr << "[ERROR]: Failed to open file: " << filename << std::endl; 14 | exit(EXIT_FAILURE); 15 | } 16 | 17 | std::vector positions; 18 | std::vector texCoords; 19 | std::vector normals; 20 | 21 | std::vector _indices; 22 | std::vector _positions; 23 | std::vector _texCoords; 24 | std::vector _normals; 25 | 26 | std::string line; 27 | int last = 0; 28 | 29 | while (std::getline(fin, line)) { 30 | std::vector tokens = split(line, " "); 31 | if (tokens.empty()) { 32 | continue; 33 | } 34 | 35 | if (tokens[0] == "v") { 36 | positions.push_back(glm::vec3(stof(tokens[1]), stof(tokens[2]), stof(tokens[3]))); 37 | } 38 | else if (tokens[0] == "vt") { 39 | texCoords.push_back(glm::vec2(stof(tokens[1]), stof(tokens[2]))); 40 | } 41 | else if (tokens[0] == "vn") { 42 | normals.push_back(glm::vec3(stof(tokens[1]), stof(tokens[2]), stof(tokens[3]))); 43 | } 44 | else if (tokens[0] == "f") { 45 | 46 | fin.seekg(last); 47 | _positions = std::vector(3 * positions.size()); 48 | _texCoords = std::vector(2 * positions.size()); 49 | _normals = std::vector(3 * positions.size()); 50 | break; 51 | } 52 | 53 | last = fin.tellg(); 54 | } 55 | 56 | while (std::getline(fin, line)) { 57 | std::vector face = split(line, " "); 58 | if (face.empty() || face[0] != "f") { 59 | continue; 60 | } 61 | 62 | std::vector v1 = split(face[1], "/"); 63 | std::vector v2 = split(face[2], "/"); 64 | std::vector v3 = split(face[3], "/"); 65 | 66 | processVertex(v1, positions, texCoords, normals, _indices, _positions, _texCoords, _normals); 67 | processVertex(v2, positions, texCoords, normals, _indices, _positions, _texCoords, _normals); 68 | processVertex(v3, positions, texCoords, normals, _indices, _positions, _texCoords, _normals); 69 | } 70 | 71 | return loader.loadToVao(_positions, _texCoords, _normals, _indices); 72 | } 73 | 74 | void ObjLoader::processVertex(std::vector const& vertexData, 75 | std::vector const& positions, 76 | std::vector const& texCoords, 77 | std::vector const& normals, 78 | std::vector& _indices, 79 | std::vector& _positions, 80 | std::vector& _texCoords, 81 | std::vector& _normals) 82 | { 83 | GLuint idx = stoi(vertexData[0]) - 1; 84 | _indices.push_back(idx); 85 | 86 | glm::vec3 position = positions[stoi(vertexData[0]) - 1]; 87 | _positions[idx * 3] = position.x; 88 | _positions[idx * 3 + 1] = position.y; 89 | _positions[idx * 3 + 2] = position.z; 90 | 91 | glm::vec2 texCoord = texCoords[stoi(vertexData[1]) - 1]; 92 | _texCoords[idx * 2] = texCoord.x; 93 | _texCoords[idx * 2 + 1] = 1 - texCoord.y; 94 | 95 | glm::vec3 normal = normals[stoi(vertexData[2]) - 1]; 96 | _normals[idx * 3] = normal.x; 97 | _normals[idx * 3 + 1] = normal.y; 98 | _normals[idx * 3 + 2] = normal.z; 99 | } 100 | 101 | std::vector ObjLoader::split(std::string const& s, std::string const& delim) 102 | { 103 | std::vector arr; 104 | char* cs = const_cast(s.c_str()); 105 | char* token; 106 | token = strtok(cs, delim.c_str()); 107 | while (token) { 108 | arr.push_back(token); 109 | token = strtok(NULL, delim.c_str()); 110 | } 111 | return arr; 112 | } 113 | -------------------------------------------------------------------------------- /src/render_engine/obj_loader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "models/raw_model.hpp" 3 | #include "render_engine/loader.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace ObjLoader { 10 | RawModel loadObjModel(std::string const& filename, Loader& loader); 11 | 12 | void processVertex(std::vector const& vectorData, 13 | std::vector const& positions, 14 | std::vector const& texCoords, 15 | std::vector const& normals, 16 | std::vector& _indices, 17 | std::vector& _positions, 18 | std::vector& _texCoords, 19 | std::vector& _normals); 20 | 21 | std::vector split(std::string const& s, std::string const& delim); 22 | }; 23 | -------------------------------------------------------------------------------- /src/render_engine/terrain_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "render_engine/terrain_renderer.hpp" 2 | #include "render_engine/master_renderer.hpp" 3 | #include "toolbox/math.hpp" 4 | 5 | 6 | TerrainRenderer::TerrainRenderer(TerrainShader const* shader) 7 | : shader_(shader) 8 | { 9 | shader_->start(); 10 | shader_->connectTextureUnits(); 11 | shader_->stop(); 12 | } 13 | 14 | void TerrainRenderer::render(std::vector const& terrains) const { 15 | for (const auto& terrain : terrains) { 16 | prepareTerrain(terrain); 17 | loadModelMatrix(terrain); 18 | glDrawElements(GL_TRIANGLES, terrain->getRawModel().getVertexCount(), GL_UNSIGNED_INT, 0); 19 | unbindTerrain(); 20 | } 21 | } 22 | 23 | void TerrainRenderer::loadProjectionMatrix(glm::mat4 const& projectionMatrix) const { 24 | shader_->start(); 25 | shader_->loadProjectionMatrix(projectionMatrix); 26 | shader_->stop(); 27 | } 28 | 29 | void TerrainRenderer::prepareTerrain(Terrain const* terrain) const { 30 | glBindVertexArray(terrain->getRawModel().getVaoId()); 31 | glEnableVertexAttribArray(0); 32 | glEnableVertexAttribArray(1); 33 | glEnableVertexAttribArray(2); 34 | bindTextures(terrain); 35 | shader_->loadShineVariables(1, 0); 36 | } 37 | 38 | void TerrainRenderer::bindTextures(Terrain const* terrain) const { 39 | glActiveTexture(GL_TEXTURE0); 40 | glBindTexture(GL_TEXTURE_2D, terrain->getTexturePack().getBackgroundTexture().getTextureId()); 41 | glActiveTexture(GL_TEXTURE1); 42 | glBindTexture(GL_TEXTURE_2D, terrain->getTexturePack().getRTexture().getTextureId()); 43 | glActiveTexture(GL_TEXTURE2); 44 | glBindTexture(GL_TEXTURE_2D, terrain->getTexturePack().getGTexture().getTextureId()); 45 | glActiveTexture(GL_TEXTURE3); 46 | glBindTexture(GL_TEXTURE_2D, terrain->getTexturePack().getBTexture().getTextureId()); 47 | glActiveTexture(GL_TEXTURE4); 48 | glBindTexture(GL_TEXTURE_2D, terrain->getBlendMap().getTextureId()); 49 | } 50 | 51 | void TerrainRenderer::unbindTerrain() const { 52 | glDisableVertexAttribArray(0); 53 | glDisableVertexAttribArray(1); 54 | glDisableVertexAttribArray(2); 55 | glBindVertexArray(0); 56 | } 57 | 58 | void TerrainRenderer::loadModelMatrix(Terrain const* terrain) const { 59 | glm::mat4 transformationMatrix = Math::createTransformationMatrix( 60 | glm::vec3(terrain->getX(), 0.0f, terrain->getZ()), 61 | glm::vec3(0.0f, 0.0f, 0.0f), 62 | glm::vec3(1.0f, 1.0f, 1.0f)); 63 | shader_->loadTransformationMatrix(transformationMatrix); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/render_engine/terrain_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "terrain/terrain.hpp" 3 | #include "shaders/terrain_shader.hpp" 4 | #include 5 | 6 | class TerrainRenderer { 7 | public: 8 | TerrainRenderer(TerrainShader const* shader); 9 | 10 | void render(std::vector const& terrains) const; 11 | void loadProjectionMatrix(glm::mat4 const& projectionMatrix) const; 12 | 13 | private: 14 | TerrainShader const* shader_; 15 | 16 | void prepareTerrain(Terrain const* terrain) const; 17 | void bindTextures(Terrain const* terrain) const; 18 | void unbindTerrain() const; 19 | void loadModelMatrix(Terrain const* terrain) const; 20 | }; 21 | -------------------------------------------------------------------------------- /src/shaders/shader.cpp: -------------------------------------------------------------------------------- 1 | #include "shaders/shader.hpp" 2 | #define GLM_FORCE_RADIANS 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | Shader::Shader(std::string const& vertexShaderFile, std::string const& fragmentShaderFile) 9 | : program_(glCreateProgram()) 10 | , vertexShaderFile_(vertexShaderFile) 11 | , fragmentShaderFile_(fragmentShaderFile) 12 | { } 13 | 14 | Shader::~Shader() { 15 | if (program_.get()) { 16 | stop(); 17 | } 18 | } 19 | 20 | void Shader::start() const { 21 | glUseProgram(program_.get()); 22 | } 23 | void Shader::stop() const { 24 | glUseProgram(0); 25 | } 26 | 27 | void Shader::initialize() { 28 | gl::ShaderHandle vertexShader(compileShader(vertexShaderFile_, GL_VERTEX_SHADER)); 29 | gl::ShaderHandle fragmentShader(compileShader(fragmentShaderFile_, GL_FRAGMENT_SHADER)); 30 | 31 | glAttachShader(program_.get(), vertexShader.get()); 32 | glAttachShader(program_.get(), fragmentShader.get()); 33 | 34 | bindAttributes(); 35 | glLinkProgram(program_.get()); 36 | glValidateProgram(program_.get()); 37 | getAllUniformLocations(); 38 | 39 | glDetachShader(program_.get(), vertexShader.get()); 40 | glDetachShader(program_.get(), fragmentShader.get()); 41 | } 42 | 43 | void Shader::bindAttribute(GLuint attribute, GLchar const* variableName) { 44 | glBindAttribLocation(program_.get(), attribute, variableName); 45 | } 46 | 47 | GLint Shader::getUniformLocation(GLchar const* name) const { 48 | return glGetUniformLocation(program_.get(), name); 49 | } 50 | 51 | void Shader::loadFloat(GLint location, GLfloat value) const { 52 | glUniform1f(location, value); 53 | } 54 | 55 | void Shader::loadInteger(GLint location, GLint value) const { 56 | glUniform1i(location, value); 57 | } 58 | 59 | void Shader::loadVector2(GLint location, glm::vec2 const& value) const { 60 | glUniform2f(location, value.x, value.y); 61 | } 62 | 63 | void Shader::loadVector3(GLint location, glm::vec3 const& value) const { 64 | glUniform3f(location, value.x, value.y, value.z); 65 | } 66 | 67 | void Shader::loadVector4(GLint location, glm::vec4 const& value) const { 68 | glUniform4f(location, value.x, value.y, value.z, value.w); 69 | } 70 | 71 | void Shader::loadMatrix(GLint location, glm::mat4 const& matrix) const { 72 | glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); 73 | } 74 | 75 | void Shader::readTextFromFile(std::string const& filename, char*& output){ 76 | std::string buf = std::string(""); 77 | std::string line; 78 | 79 | std::ifstream in(filename.c_str()); 80 | while (std::getline(in, line)) { 81 | buf += line + "\n"; 82 | } 83 | output = new char[buf.length()+1]; 84 | strncpy(output, buf.c_str(), buf.length()); 85 | output[buf.length()] = '\0'; 86 | 87 | in.close(); 88 | } 89 | 90 | void Shader::printLog(GLuint handle, std::string const& filename) { 91 | int infologLength = 0; 92 | int maxLength; 93 | 94 | if (glIsShader(handle)) { 95 | glGetShaderiv( handle, GL_INFO_LOG_LENGTH, &maxLength); 96 | } else { 97 | glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &maxLength); 98 | } 99 | 100 | char infoLog[maxLength]; 101 | 102 | bool isShader; 103 | if (glIsShader(handle)) { 104 | glGetShaderInfoLog(handle, maxLength, &infologLength, infoLog); 105 | isShader = true; 106 | } else { 107 | glGetProgramInfoLog(handle, maxLength, &infologLength, infoLog); 108 | isShader = false; 109 | } 110 | 111 | if (infologLength > 0) { 112 | printf("[ERROR] %s Handle %d (%s): %s\n", (isShader ? "Shader" : "Program"), handle, filename.c_str(), infoLog); 113 | } 114 | } 115 | 116 | GLuint Shader::compileShader(std::string const& filename, GLenum shaderType) { 117 | char *shaderString; 118 | readTextFromFile(filename.c_str(), shaderString); 119 | 120 | GLuint shaderId = glCreateShader(shaderType); 121 | glShaderSource(shaderId, 1, (const char**)&shaderString, NULL); 122 | 123 | delete [] shaderString; 124 | 125 | glCompileShader(shaderId); printLog(shaderId, filename); 126 | return shaderId; 127 | } 128 | -------------------------------------------------------------------------------- /src/shaders/shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "toolbox/gl_handles.hpp" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Shader { 11 | public: 12 | Shader( 13 | std::string const& vertexShaderFile, 14 | std::string const& fragmentShaderFile); 15 | ~Shader(); 16 | 17 | void start() const; 18 | void stop() const; 19 | 20 | protected: 21 | void initialize(); 22 | virtual void bindAttributes() = 0; 23 | void bindAttribute(GLuint attribute, GLchar const* variableName); 24 | 25 | virtual void getAllUniformLocations() = 0; 26 | GLint getUniformLocation(GLchar const* name) const; 27 | void loadFloat (GLint location, GLfloat value) const; 28 | void loadInteger(GLint location, GLint value) const; 29 | void loadVector2(GLint location, glm::vec2 const& value) const; 30 | void loadVector3(GLint location, glm::vec3 const& value) const; 31 | void loadVector4(GLint location, glm::vec4 const& value) const; 32 | void loadMatrix (GLint location, glm::mat4 const& matrix) const; 33 | 34 | private: 35 | void printLog(GLuint handle, std::string const& filename=""); 36 | void readTextFromFile(std::string const& filename, char*& output); 37 | GLuint compileShader(std::string const& filename, GLenum shaderType); 38 | 39 | gl::ShaderHandle program_; 40 | std::string vertexShaderFile_, fragmentShaderFile_; 41 | }; 42 | -------------------------------------------------------------------------------- /src/shaders/static_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "shaders/static_shader.hpp" 2 | #include "toolbox/math.hpp" 3 | 4 | 5 | namespace { 6 | constexpr auto VERTEX_SHADER_FILE = "res/shaders/static.v.glsl"; 7 | constexpr auto FRAGMENT_SHADER_FILE = "res/shaders/static.f.glsl"; 8 | } 9 | 10 | StaticShader::StaticShader() 11 | : Shader(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE) 12 | { 13 | initialize(); 14 | } 15 | 16 | void StaticShader::bindAttributes() { 17 | bindAttribute(0, "position"); 18 | bindAttribute(1, "textureCoords"); 19 | bindAttribute(2, "normal"); 20 | } 21 | 22 | void StaticShader::getAllUniformLocations() { 23 | transformationMatrixLocation_ = getUniformLocation("transformationMatrix"); 24 | viewMatrixLocation_ = getUniformLocation("viewMatrix"); 25 | projectionMatrixLocation_ = getUniformLocation("projectionMatrix"); 26 | shineDamperLocation_ = getUniformLocation("shineDamper"); 27 | reflectivityLocation_ = getUniformLocation("reflectivity"); 28 | useFakeLightingLocation_ = getUniformLocation("useFakeLighting"); 29 | skyColorLocation_ = getUniformLocation("skyColor"); 30 | numberOfRowsLocation_ = getUniformLocation("numberOfRows"); 31 | offsetLocation_ = getUniformLocation("offset"); 32 | planeLocation_ = getUniformLocation("plane"); 33 | 34 | for (int i = 0; i < MAX_LIGHTS; i++) { 35 | lightPositionLocation_[i] = getUniformLocation( 36 | std::string("lightPosition[" + std::to_string(i) + "]").c_str()); 37 | lightColorLocation_[i] = getUniformLocation( 38 | std::string("lightColor[" + std::to_string(i) + "]").c_str()); 39 | attenuationLocation_[i] = getUniformLocation( 40 | std::string("attenuation[" + std::to_string(i) + "]").c_str()); 41 | } 42 | } 43 | 44 | void StaticShader::loadTransformationMatrix(glm::mat4 const& matrix) const { 45 | loadMatrix(transformationMatrixLocation_, matrix); 46 | } 47 | 48 | void StaticShader::loadViewMatrix(Camera const& camera) const { 49 | loadMatrix(viewMatrixLocation_, camera.getViewMatrix()); 50 | } 51 | 52 | void StaticShader::loadProjectionMatrix(glm::mat4 const& matrix) const { 53 | loadMatrix(projectionMatrixLocation_, matrix); 54 | } 55 | 56 | void StaticShader::loadLights(std::vector const& lights) const { 57 | for (int i = 0; i < MAX_LIGHTS; i++) { 58 | if (i < (int)lights.size()) { 59 | loadVector3(lightPositionLocation_[i], lights[i].getPosition()); 60 | loadVector3(lightColorLocation_[i], lights[i].getColor()); 61 | loadVector3(attenuationLocation_[i], lights[i].getAttenuation()); 62 | } else { 63 | loadVector3(lightPositionLocation_[i], glm::vec3(0, 0, 0)); 64 | loadVector3(lightColorLocation_[i], glm::vec3(0, 0, 0)); 65 | loadVector3(attenuationLocation_[i], glm::vec3(1, 0, 0)); 66 | } 67 | } 68 | } 69 | 70 | void StaticShader::loadShineVariables(GLfloat shineDamper, GLfloat reflectivity) const { 71 | loadFloat(shineDamperLocation_, shineDamper); 72 | loadFloat(reflectivityLocation_, reflectivity); 73 | } 74 | 75 | void StaticShader::loadFakeLightingVariable(GLboolean useFakeLighting) const { 76 | loadInteger(useFakeLightingLocation_, useFakeLighting); 77 | } 78 | 79 | void StaticShader::loadSkyColor(glm::vec3 const& rgbColor) const { 80 | loadVector3(skyColorLocation_, rgbColor); 81 | } 82 | 83 | void StaticShader::loadNumberOfRows(int numberOfRows) const { 84 | loadFloat(numberOfRowsLocation_, (GLfloat) numberOfRows); 85 | } 86 | 87 | void StaticShader::loadOffset(glm::vec2 const& offset) const { 88 | loadVector2(offsetLocation_, offset); 89 | } 90 | 91 | void StaticShader::loadClipPlane(glm::vec4 const& plane) const { 92 | loadVector4(planeLocation_, plane); 93 | } 94 | -------------------------------------------------------------------------------- /src/shaders/static_shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "shaders/shader.hpp" 3 | #include "entities/light.hpp" 4 | #include "entities/camera.hpp" 5 | #include 6 | #include 7 | 8 | class StaticShader final : public Shader { 9 | public: 10 | StaticShader(); 11 | 12 | void loadTransformationMatrix(glm::mat4 const& matrix) const; 13 | void loadViewMatrix(Camera const& camera) const; 14 | void loadProjectionMatrix(glm::mat4 const& matrix) const; 15 | void loadLights(std::vector const& lights) const; 16 | void loadShineVariables(GLfloat shineDamper, GLfloat reflectivity) const; 17 | void loadFakeLightingVariable(GLboolean useFakeLighting) const; 18 | void loadSkyColor(glm::vec3 const& rgbColor) const; 19 | void loadNumberOfRows(int numberOfRows) const; 20 | void loadOffset(glm::vec2 const& offset) const; 21 | void loadClipPlane(glm::vec4 const& plane) const; 22 | 23 | protected: 24 | virtual void bindAttributes() override; 25 | virtual void getAllUniformLocations() override; 26 | 27 | private: 28 | static constexpr int MAX_LIGHTS = 4; 29 | GLint transformationMatrixLocation_; 30 | GLint viewMatrixLocation_; 31 | GLint projectionMatrixLocation_; 32 | GLint lightPositionLocation_[MAX_LIGHTS]; 33 | GLint lightColorLocation_[MAX_LIGHTS]; 34 | GLint attenuationLocation_[MAX_LIGHTS]; 35 | GLint shineDamperLocation_; 36 | GLint reflectivityLocation_; 37 | GLint useFakeLightingLocation_; 38 | GLint skyColorLocation_; 39 | GLint numberOfRowsLocation_; 40 | GLint offsetLocation_; 41 | GLint planeLocation_; 42 | }; 43 | -------------------------------------------------------------------------------- /src/shaders/terrain_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "shaders/terrain_shader.hpp" 2 | 3 | 4 | namespace { 5 | constexpr auto VERTEX_SHADER_FILE = "res/shaders/terrain.v.glsl"; 6 | constexpr auto FRAGMENT_SHADER_FILE = "res/shaders/terrain.f.glsl"; 7 | } 8 | 9 | TerrainShader::TerrainShader() 10 | : Shader(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE) 11 | { 12 | initialize(); 13 | } 14 | 15 | void TerrainShader::bindAttributes() { 16 | bindAttribute(0, "position"); 17 | bindAttribute(1, "textureCoords"); 18 | bindAttribute(2, "normal"); 19 | } 20 | 21 | void TerrainShader::getAllUniformLocations() { 22 | transformationMatrixLocation_ = getUniformLocation("transformationMatrix"); 23 | viewMatrixLocation_ = getUniformLocation("viewMatrix"); 24 | projectionMatrixLocation_ = getUniformLocation("projectionMatrix"); 25 | shineDamperLocation_ = getUniformLocation("shineDamper"); 26 | reflectivityLocation_ = getUniformLocation("reflectivity"); 27 | skyColorLocation_ = getUniformLocation("skyColor"); 28 | backgroundTextureLocation_ = getUniformLocation("backgroundTexture"); 29 | rTextureLocation_ = getUniformLocation("rTexture"); 30 | gTextureLocation_ = getUniformLocation("gTexture"); 31 | bTextureLocation_ = getUniformLocation("bTexture"); 32 | blendMapLocation_ = getUniformLocation("blendMap"); 33 | planeLocation_ = getUniformLocation("plane"); 34 | 35 | for (int i = 0; i < MAX_LIGHTS; i++) { 36 | lightPositionLocation_[i] = getUniformLocation( 37 | std::string("lightPosition[" + std::to_string(i) + "]").c_str()); 38 | lightColorLocation_[i] = getUniformLocation( 39 | std::string("lightColor[" + std::to_string(i) + "]").c_str()); 40 | attenuationLocation_[i] = getUniformLocation( 41 | std::string("attenuation[" + std::to_string(i) + "]").c_str()); 42 | } 43 | } 44 | 45 | void TerrainShader::loadTransformationMatrix(glm::mat4 const& matrix) const { 46 | loadMatrix(transformationMatrixLocation_, matrix); 47 | } 48 | 49 | void TerrainShader::loadViewMatrix(Camera const& camera) const { 50 | loadMatrix(viewMatrixLocation_, camera.getViewMatrix()); 51 | } 52 | 53 | void TerrainShader::loadProjectionMatrix(glm::mat4 const& matrix) const { 54 | loadMatrix(projectionMatrixLocation_, matrix); 55 | } 56 | 57 | void TerrainShader::loadLights(std::vector const& lights) const { 58 | for (int i = 0; i < MAX_LIGHTS; i++) { 59 | if (i < (int)lights.size()) { 60 | loadVector3(lightPositionLocation_[i], lights[i].getPosition()); 61 | loadVector3(lightColorLocation_[i], lights[i].getColor()); 62 | loadVector3(attenuationLocation_[i], lights[i].getAttenuation()); 63 | } else { 64 | loadVector3(lightPositionLocation_[i], glm::vec3(0, 0, 0)); 65 | loadVector3(lightColorLocation_[i], glm::vec3(0, 0, 0)); 66 | loadVector3(attenuationLocation_[i], glm::vec3(1, 0, 0)); 67 | } 68 | } 69 | } 70 | 71 | void TerrainShader::loadShineVariables(GLfloat shineDamper, GLfloat reflectivity) const { 72 | loadFloat(shineDamperLocation_, shineDamper); 73 | loadFloat(reflectivityLocation_, reflectivity); 74 | } 75 | 76 | void TerrainShader::loadSkyColor(glm::vec3 const& rgbColor) const { 77 | loadVector3(skyColorLocation_, rgbColor); 78 | } 79 | 80 | void TerrainShader::connectTextureUnits() const { 81 | loadInteger(backgroundTextureLocation_, 0); 82 | loadInteger(rTextureLocation_, 1); 83 | loadInteger(gTextureLocation_, 2); 84 | loadInteger(bTextureLocation_, 3); 85 | loadInteger(blendMapLocation_, 4); 86 | } 87 | 88 | void TerrainShader::loadClipPlane(glm::vec4 const& plane) const { 89 | loadVector4(planeLocation_, plane); 90 | } 91 | -------------------------------------------------------------------------------- /src/shaders/terrain_shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "shaders/shader.hpp" 3 | #include "entities/light.hpp" 4 | #include "entities/camera.hpp" 5 | #include 6 | #include 7 | 8 | class TerrainShader final : public Shader { 9 | public: 10 | TerrainShader(); 11 | 12 | void loadTransformationMatrix(glm::mat4 const& matrix) const; 13 | void loadViewMatrix(Camera const& camera) const; 14 | void loadProjectionMatrix(glm::mat4 const& matrix) const; 15 | void loadLights(std::vector const& lights) const; 16 | void loadShineVariables(GLfloat shineDamper, GLfloat reflectivity) const; 17 | void loadSkyColor(glm::vec3 const& rgbColor) const; 18 | void loadClipPlane(glm::vec4 const& plane) const; 19 | void connectTextureUnits() const; 20 | 21 | protected: 22 | virtual void bindAttributes() override; 23 | virtual void getAllUniformLocations() override; 24 | 25 | private: 26 | static constexpr int MAX_LIGHTS = 4; 27 | GLint transformationMatrixLocation_; 28 | GLint viewMatrixLocation_; 29 | GLint projectionMatrixLocation_; 30 | GLint lightPositionLocation_[MAX_LIGHTS]; 31 | GLint lightColorLocation_[MAX_LIGHTS]; 32 | GLint attenuationLocation_[MAX_LIGHTS]; 33 | GLint shineDamperLocation_; 34 | GLint reflectivityLocation_; 35 | GLint skyColorLocation_; 36 | GLint backgroundTextureLocation_; 37 | GLint rTextureLocation_; 38 | GLint gTextureLocation_; 39 | GLint bTextureLocation_; 40 | GLint blendMapLocation_; 41 | GLint planeLocation_; 42 | }; 43 | -------------------------------------------------------------------------------- /src/skybox/skybox_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "skybox/skybox_renderer.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace { 9 | constexpr float SIZE = 500.0f; 10 | 11 | const std::vector VERTICES { 12 | -SIZE, SIZE, -SIZE, 13 | -SIZE, -SIZE, -SIZE, 14 | SIZE, -SIZE, -SIZE, 15 | SIZE, -SIZE, -SIZE, 16 | SIZE, SIZE, -SIZE, 17 | -SIZE, SIZE, -SIZE, 18 | 19 | -SIZE, -SIZE, SIZE, 20 | -SIZE, -SIZE, -SIZE, 21 | -SIZE, SIZE, -SIZE, 22 | -SIZE, SIZE, -SIZE, 23 | -SIZE, SIZE, SIZE, 24 | -SIZE, -SIZE, SIZE, 25 | 26 | SIZE, -SIZE, -SIZE, 27 | SIZE, -SIZE, SIZE, 28 | SIZE, SIZE, SIZE, 29 | SIZE, SIZE, SIZE, 30 | SIZE, SIZE, -SIZE, 31 | SIZE, -SIZE, -SIZE, 32 | 33 | -SIZE, -SIZE, SIZE, 34 | -SIZE, SIZE, SIZE, 35 | SIZE, SIZE, SIZE, 36 | SIZE, SIZE, SIZE, 37 | SIZE, -SIZE, SIZE, 38 | -SIZE, -SIZE, SIZE, 39 | 40 | -SIZE, SIZE, -SIZE, 41 | SIZE, SIZE, -SIZE, 42 | SIZE, SIZE, SIZE, 43 | SIZE, SIZE, SIZE, 44 | -SIZE, SIZE, SIZE, 45 | -SIZE, SIZE, -SIZE, 46 | 47 | -SIZE, -SIZE, -SIZE, 48 | -SIZE, -SIZE, SIZE, 49 | SIZE, -SIZE, -SIZE, 50 | SIZE, -SIZE, -SIZE, 51 | -SIZE, -SIZE, SIZE, 52 | SIZE, -SIZE, SIZE 53 | }; 54 | 55 | const std::vector DAY_TEXTURE_FILES { 56 | "res/textures/skybox/day/right.png", 57 | "res/textures/skybox/day/left.png", 58 | "res/textures/skybox/day/top.png", 59 | "res/textures/skybox/day/bottom.png", 60 | "res/textures/skybox/day/back.png", 61 | "res/textures/skybox/day/front.png" 62 | }; 63 | 64 | const std::vector NIGHT_TEXTURE_FILES { 65 | "res/textures/skybox/night/right.png", 66 | "res/textures/skybox/night/left.png", 67 | "res/textures/skybox/night/top.png", 68 | "res/textures/skybox/night/bottom.png", 69 | "res/textures/skybox/night/back.png", 70 | "res/textures/skybox/night/front.png" 71 | }; 72 | } 73 | 74 | 75 | SkyboxRenderer::SkyboxRenderer(Loader &loader) 76 | : cube_(loader.loadToVao(VERTICES, 3)) 77 | , dayTextureId_(loader.loadCubeMap(DAY_TEXTURE_FILES)) 78 | , nightTextureId_(loader.loadCubeMap(NIGHT_TEXTURE_FILES)) 79 | { 80 | shader_.start(); 81 | shader_.connectTextureUnits(); 82 | shader_.stop(); 83 | } 84 | 85 | void SkyboxRenderer::render(Camera const& camera, glm::vec3 const& fogColor) { 86 | shader_.start(); 87 | shader_.loadViewMatrix(camera); 88 | shader_.loadFogColor(fogColor); 89 | glBindVertexArray(cube_.getVaoId()); 90 | glEnableVertexAttribArray(0); 91 | bindTextures(); 92 | glDrawArrays(GL_TRIANGLES, 0, cube_.getVertexCount()); 93 | glDisableVertexAttribArray(0); 94 | glBindVertexArray(0); 95 | shader_.stop(); 96 | } 97 | 98 | void SkyboxRenderer::loadProjectionMatrix(glm::mat4 const& projectionMatrix) const { 99 | shader_.start(); 100 | shader_.loadProjectionMatrix(projectionMatrix); 101 | shader_.stop(); 102 | } 103 | 104 | void SkyboxRenderer::bindTextures() { 105 | time_ += DisplayManager::getFrameTime().asMilliseconds(); 106 | time_ = std::fmod(time_, 24000); 107 | float blendFactor = -((time_/1000.0f)-13)*((time_/1000.0f)-13) * 0.02f + 1; 108 | if (blendFactor < 0) blendFactor = 0; 109 | glActiveTexture(GL_TEXTURE0); 110 | glBindTexture(GL_TEXTURE_CUBE_MAP, dayTextureId_); 111 | glActiveTexture(GL_TEXTURE1); 112 | // glBindTexture(GL_TEXTURE_CUBE_MAP, nightTextureId_); 113 | glBindTexture(GL_TEXTURE_CUBE_MAP, dayTextureId_); 114 | shader_.loadBlendFactor(blendFactor); 115 | } 116 | -------------------------------------------------------------------------------- /src/skybox/skybox_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "render_engine/loader.hpp" 3 | #include "entities/camera.hpp" 4 | #include "models/raw_model.hpp" 5 | #include "skybox/skybox_shader.hpp" 6 | #include 7 | 8 | class SkyboxRenderer { 9 | public: 10 | SkyboxRenderer(Loader &loader); 11 | 12 | void render(Camera const& camera, glm::vec3 const& fogColor); 13 | void loadProjectionMatrix(glm::mat4 const& projectionMatrix) const; 14 | 15 | private: 16 | void bindTextures(); 17 | 18 | RawModel cube_; 19 | GLuint dayTextureId_; 20 | GLuint nightTextureId_; 21 | SkyboxShader shader_; 22 | float time_ = 0.0f; 23 | }; 24 | -------------------------------------------------------------------------------- /src/skybox/skybox_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "skybox/skybox_shader.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #define GLM_FORCE_RADIANS 4 | #include 5 | 6 | 7 | namespace { 8 | constexpr auto VERTEX_SHADER_FILE = "res/shaders/skybox.v.glsl"; 9 | constexpr auto FRAGMENT_SHADER_FILE = "res/shaders/skybox.f.glsl"; 10 | constexpr float ROTATE_SPEED = 1.0f; 11 | } 12 | 13 | SkyboxShader::SkyboxShader() 14 | : Shader(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE) 15 | { 16 | initialize(); 17 | } 18 | 19 | void SkyboxShader::bindAttributes() { 20 | bindAttribute(0, "position"); 21 | } 22 | 23 | void SkyboxShader::getAllUniformLocations() { 24 | viewMatrixLocation_ = getUniformLocation("viewMatrix"); 25 | projectionMatrixLocation_ = getUniformLocation("projectionMatrix"); 26 | fogColorLocation_ = getUniformLocation("fogColor"); 27 | cubeMapLocation_ = getUniformLocation("cubeMap"); 28 | cubeMap2Location_ = getUniformLocation("cubeMap2"); 29 | blendFactorLocation_ = getUniformLocation("blendFactor"); 30 | } 31 | 32 | void SkyboxShader::loadViewMatrix(Camera const& camera) { 33 | glm::mat4 matrix = camera.getViewMatrix(); 34 | matrix[3] = glm::vec4{0.0, 0.0, 0.0, matrix[3][3]}; 35 | rotation_ += ROTATE_SPEED * DisplayManager::getFrameTime().asSeconds(); 36 | matrix = glm::rotate(matrix, glm::radians(rotation_), {0, 1, 0}); 37 | loadMatrix(viewMatrixLocation_, matrix); 38 | } 39 | 40 | void SkyboxShader::loadProjectionMatrix(glm::mat4 const& matrix) const { 41 | loadMatrix(projectionMatrixLocation_, matrix); 42 | } 43 | 44 | void SkyboxShader::loadFogColor(glm::vec3 const& color) const { 45 | loadVector3(fogColorLocation_, color); 46 | } 47 | 48 | void SkyboxShader::loadBlendFactor(float blendFactor) const { 49 | loadFloat(blendFactorLocation_, blendFactor); 50 | } 51 | 52 | void SkyboxShader::connectTextureUnits() const { 53 | loadInteger(cubeMapLocation_, 0); 54 | loadInteger(cubeMap2Location_, 1); 55 | } 56 | -------------------------------------------------------------------------------- /src/skybox/skybox_shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "shaders/shader.hpp" 3 | #include "entities/camera.hpp" 4 | 5 | class SkyboxShader final : public Shader { 6 | public: 7 | SkyboxShader(); 8 | 9 | void loadViewMatrix(Camera const& camera); 10 | void loadProjectionMatrix(glm::mat4 const& matrix) const; 11 | void loadFogColor(glm::vec3 const& color) const; 12 | void loadBlendFactor(float blendFactor) const; 13 | void connectTextureUnits() const; 14 | 15 | protected: 16 | virtual void bindAttributes() override; 17 | virtual void getAllUniformLocations() override; 18 | 19 | private: 20 | GLint viewMatrixLocation_; 21 | GLint projectionMatrixLocation_; 22 | GLint fogColorLocation_; 23 | GLint cubeMapLocation_; 24 | GLint cubeMap2Location_; 25 | GLint blendFactorLocation_; 26 | float rotation_ = 0.0f; 27 | }; 28 | -------------------------------------------------------------------------------- /src/terrain/terrain.cpp: -------------------------------------------------------------------------------- 1 | #include "terrain/terrain.hpp" 2 | #include "toolbox/math.hpp" 3 | #define GLM_FORCE_RADIANS 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace { 11 | constexpr GLfloat SIZE = 400.0f; 12 | constexpr GLfloat MAX_HEIGHT = 40.0f; 13 | constexpr GLfloat MAX_PIXEL_COLOR = 16777216.0f; 14 | } 15 | 16 | Terrain::Terrain(GLfloat x, GLfloat z, Loader& loader,TerrainTexturePack texturePack, 17 | TerrainTexture blendMap, const std::string& heightMap 18 | ) 19 | : x_(x * SIZE) 20 | , z_(z * SIZE) 21 | , model_(generateTerrain(loader, heightMap)) 22 | , texturePack_(texturePack) 23 | , blendMap_(blendMap) 24 | { } 25 | 26 | GLfloat Terrain::getX() const { return x_; } 27 | GLfloat Terrain::getZ() const { return z_; } 28 | RawModel const& Terrain::getRawModel() const { return model_; } 29 | TerrainTexturePack const& Terrain::getTexturePack() const { return texturePack_; } 30 | TerrainTexture const& Terrain::getBlendMap() const { return blendMap_; } 31 | 32 | float Terrain::getHeightOfTerrain(float worldX, float worldZ) const { 33 | float terrainX = worldX - x_; 34 | float terrainZ = worldZ - z_; 35 | float gridSquareSize = SIZE / (heights_.size() - 1); 36 | int gridX = terrainX / gridSquareSize; 37 | int gridZ = terrainZ / gridSquareSize; 38 | if (gridX < 0 || gridX + 1 >= (int)heights_.size() || gridZ < 0 || gridZ + 1 >= (int)heights_.size()) { 39 | return 0.0f; 40 | } 41 | float xCoord = fmod(terrainX, gridSquareSize) / gridSquareSize; 42 | float zCoord = fmod(terrainZ, gridSquareSize) / gridSquareSize; 43 | float height; 44 | if (xCoord <= (1 - zCoord)) { 45 | height = Math::barryCentric( 46 | glm::vec3(0, heights_[gridX][gridZ], 0), 47 | glm::vec3(1, heights_[gridX + 1][gridZ], 0), 48 | glm::vec3(0, heights_[gridX][gridZ + 1], 1), 49 | glm::vec2(xCoord, zCoord)); 50 | } else { 51 | height = Math::barryCentric( 52 | glm::vec3(1, heights_[gridX + 1][gridZ], 0), 53 | glm::vec3(1, heights_[gridX + 1][gridZ + 1], 1), 54 | glm::vec3(0, heights_[gridX][gridZ + 1], 1), 55 | glm::vec2(xCoord, zCoord)); 56 | } 57 | return height; 58 | } 59 | 60 | RawModel Terrain::generateTerrain(Loader& loader, const std::string& heightMap) { 61 | sf::Image image; 62 | if (!image.loadFromFile(heightMap)) { 63 | printf("[ERROR]: Failed to load height map: %s\n", heightMap.c_str()); 64 | } 65 | 66 | int VERTEX_COUNT = image.getSize().y; 67 | 68 | heights_ = std::vector>(VERTEX_COUNT, std::vector(VERTEX_COUNT)); 69 | 70 | int count = VERTEX_COUNT * VERTEX_COUNT; 71 | std::vector positions(count * 3); 72 | std::vector texCoords(count * 2); 73 | std::vector normals(count * 3); 74 | std::vector indices(6 * (VERTEX_COUNT-1) * (VERTEX_COUNT-1)); 75 | int vertexPointer = 0; 76 | for (int i = 0; i < VERTEX_COUNT; i++) { 77 | for (int j = 0; j < VERTEX_COUNT; j++) { 78 | positions[vertexPointer*3] = (GLfloat)j / (VERTEX_COUNT-1) * SIZE; 79 | positions[vertexPointer*3 + 1] = heights_[j][i] = getHeight(j, i, image); 80 | positions[vertexPointer*3 + 1] = getHeight(j, i, image); 81 | positions[vertexPointer*3 + 2] = (GLfloat)i / (VERTEX_COUNT-1) * SIZE; 82 | texCoords[vertexPointer*2] = (GLfloat)j / (VERTEX_COUNT-1); 83 | texCoords[vertexPointer*2 + 1] = (GLfloat)i / (VERTEX_COUNT-1); 84 | glm::vec3 normal = calculateNormal(j, i, image); 85 | normals[vertexPointer*3] = normal.x; 86 | normals[vertexPointer*3 + 1] = normal.y; 87 | normals[vertexPointer*3 + 2] = normal.z; 88 | ++vertexPointer; 89 | } 90 | } 91 | int pointer = 0; 92 | for (int gz = 0; gz < VERTEX_COUNT-1; gz++) { 93 | for (int gx = 0; gx < VERTEX_COUNT-1; gx++) { 94 | GLuint topLeft = (gz*VERTEX_COUNT)+gx; 95 | GLuint topRight = topLeft + 1; 96 | GLuint bottomLeft = ((gz+1)*VERTEX_COUNT)+gx; 97 | GLuint bottomRight = bottomLeft + 1; 98 | indices[pointer++] = topLeft; 99 | indices[pointer++] = bottomLeft; 100 | indices[pointer++] = topRight; 101 | indices[pointer++] = topRight; 102 | indices[pointer++] = bottomLeft; 103 | indices[pointer++] = bottomRight; 104 | } 105 | } 106 | return loader.loadToVao(positions, texCoords, normals, indices); 107 | } 108 | 109 | glm::vec3 Terrain::calculateNormal(unsigned int x, unsigned int y, sf::Image const& image) { 110 | float heightL = getHeight(x - 1, y, image); 111 | float heightR = getHeight(x + 1, y, image); 112 | float heightD = getHeight(x, y - 1, image); 113 | float heightU = getHeight(x, y + 1, image); 114 | return glm::normalize(glm::vec3(heightL - heightR, 2.0f, heightD - heightU)); 115 | } 116 | 117 | GLfloat Terrain::getHeight(unsigned int x, unsigned int y, sf::Image const& image) { 118 | if (x > image.getSize().y || y > image.getSize().y) { 119 | return 0.0f; 120 | } 121 | 122 | sf::Color pixel = image.getPixel(x, y); 123 | int color = (pixel.a << 24) 124 | | (pixel.r << 16) 125 | | (pixel.g << 8) 126 | | (pixel.b << 0); 127 | GLfloat height = color; 128 | height += MAX_PIXEL_COLOR / 2.0f; 129 | height /= MAX_PIXEL_COLOR / 2.0f; 130 | height *= MAX_HEIGHT; 131 | return height; 132 | } 133 | -------------------------------------------------------------------------------- /src/terrain/terrain.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "render_engine/loader.hpp" 3 | #include "textures/terrain_texture_pack.hpp" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Terrain { 10 | public: 11 | Terrain(GLfloat x, GLfloat z, Loader& loader, TerrainTexturePack texturePack, 12 | TerrainTexture blendMap, const std::string& heightMap); 13 | 14 | GLfloat getX() const; 15 | GLfloat getZ() const; 16 | RawModel const& getRawModel() const; 17 | TerrainTexturePack const& getTexturePack() const; 18 | TerrainTexture const& getBlendMap() const; 19 | 20 | float getHeightOfTerrain(float worldX, float worldZ) const; 21 | 22 | private: 23 | std::vector> heights_; 24 | 25 | GLfloat x_; 26 | GLfloat z_; 27 | RawModel model_; 28 | TerrainTexturePack texturePack_; 29 | TerrainTexture blendMap_; 30 | 31 | RawModel generateTerrain(Loader& loader, const std::string& heightMap); 32 | glm::vec3 calculateNormal(unsigned int x, unsigned int y, sf::Image const& image); 33 | GLfloat getHeight(unsigned int x, unsigned int y, sf::Image const& image); 34 | }; 35 | -------------------------------------------------------------------------------- /src/textures/model_texture.cpp: -------------------------------------------------------------------------------- 1 | #include "textures/model_texture.hpp" 2 | 3 | 4 | ModelTexture::ModelTexture(GLuint textureId) 5 | : textureId_(textureId) 6 | , shineDamper_(1.0f) 7 | , reflectivity_(0.0f) 8 | , hasTransparency_(false) 9 | , usesFakeLighting_(false) 10 | { } 11 | 12 | GLuint ModelTexture::getTextureId() const { 13 | return textureId_; 14 | } 15 | 16 | GLfloat ModelTexture::getShineDamper() const { 17 | return shineDamper_; 18 | } 19 | void ModelTexture::setShineDamper(GLfloat shineDamper) { 20 | shineDamper_ = shineDamper; 21 | } 22 | 23 | GLfloat ModelTexture::getReflectivity() const { 24 | return reflectivity_; 25 | } 26 | void ModelTexture::setReflectivity(GLfloat reflectivity) { 27 | reflectivity_ = reflectivity; 28 | } 29 | 30 | GLboolean ModelTexture::hasTransparency() const { 31 | return hasTransparency_; 32 | } 33 | void ModelTexture::setTransparency(GLboolean hasTransparency) { 34 | hasTransparency_ = hasTransparency; 35 | } 36 | 37 | GLboolean ModelTexture::usesFakeLighting() const { 38 | return usesFakeLighting_; 39 | } 40 | void ModelTexture::setFakeLighting(GLboolean usesFakeLighting) { 41 | usesFakeLighting_ = usesFakeLighting; 42 | } 43 | 44 | int ModelTexture::getNumberOfRows() const { 45 | return numberOfRows_; 46 | } 47 | void ModelTexture::setNumberOfRows(int numberOfRows) { 48 | numberOfRows_ = numberOfRows; 49 | } 50 | -------------------------------------------------------------------------------- /src/textures/model_texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class ModelTexture { 5 | public: 6 | ModelTexture() = default; 7 | ModelTexture(GLuint textureId); 8 | 9 | GLuint getTextureId() const; 10 | 11 | GLfloat getShineDamper() const; 12 | void setShineDamper(GLfloat shineDamper); 13 | 14 | GLfloat getReflectivity() const; 15 | void setReflectivity(GLfloat reflectivity); 16 | 17 | GLboolean hasTransparency() const; 18 | void setTransparency(GLboolean hasTransparency); 19 | 20 | GLboolean usesFakeLighting() const; 21 | void setFakeLighting(GLboolean usesFakeLighting); 22 | 23 | int getNumberOfRows() const; 24 | void setNumberOfRows(int numberOfRows); 25 | 26 | private: 27 | GLuint textureId_; 28 | GLfloat shineDamper_; 29 | GLfloat reflectivity_; 30 | GLboolean hasTransparency_; 31 | GLboolean usesFakeLighting_; 32 | int numberOfRows_; 33 | }; 34 | -------------------------------------------------------------------------------- /src/textures/terrain_texture.cpp: -------------------------------------------------------------------------------- 1 | #include "textures/terrain_texture.hpp" 2 | 3 | 4 | TerrainTexture::TerrainTexture(GLuint textureId) 5 | : textureId_(textureId) 6 | { } 7 | 8 | GLuint TerrainTexture::getTextureId() const { 9 | return textureId_; 10 | } 11 | -------------------------------------------------------------------------------- /src/textures/terrain_texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class TerrainTexture { 5 | public: 6 | TerrainTexture(GLuint textureId); 7 | 8 | GLuint getTextureId() const; 9 | 10 | private: 11 | GLuint textureId_; 12 | }; 13 | -------------------------------------------------------------------------------- /src/textures/terrain_texture_pack.cpp: -------------------------------------------------------------------------------- 1 | #include "textures/terrain_texture_pack.hpp" 2 | 3 | 4 | TerrainTexturePack::TerrainTexturePack( 5 | TerrainTexture backgroundTexture, 6 | TerrainTexture rTexture, 7 | TerrainTexture gTexture, 8 | TerrainTexture bTexture 9 | ) 10 | : backgroundTexture_(backgroundTexture) 11 | , rTexture_(rTexture) 12 | , gTexture_(gTexture) 13 | , bTexture_(bTexture) 14 | { } 15 | 16 | TerrainTexture const& TerrainTexturePack::getBackgroundTexture() const { 17 | return backgroundTexture_; 18 | } 19 | 20 | TerrainTexture const& TerrainTexturePack::getRTexture() const { 21 | return rTexture_; 22 | } 23 | 24 | TerrainTexture const& TerrainTexturePack::getGTexture() const { 25 | return gTexture_; 26 | } 27 | 28 | TerrainTexture const& TerrainTexturePack::getBTexture() const { 29 | return bTexture_; 30 | } 31 | -------------------------------------------------------------------------------- /src/textures/terrain_texture_pack.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "textures/terrain_texture.hpp" 3 | 4 | class TerrainTexturePack { 5 | public: 6 | TerrainTexturePack( 7 | TerrainTexture backgroundTexture, 8 | TerrainTexture rTexture, 9 | TerrainTexture gTexture, 10 | TerrainTexture bTexture); 11 | 12 | TerrainTexture const& getBackgroundTexture() const; 13 | TerrainTexture const& getRTexture() const; 14 | TerrainTexture const& getGTexture() const; 15 | TerrainTexture const& getBTexture() const; 16 | 17 | private: 18 | TerrainTexture backgroundTexture_; 19 | TerrainTexture rTexture_; 20 | TerrainTexture gTexture_; 21 | TerrainTexture bTexture_; 22 | }; 23 | -------------------------------------------------------------------------------- /src/toolbox/debug.cpp: -------------------------------------------------------------------------------- 1 | #include "debug.hpp" 2 | 3 | 4 | std::string getOpenGLError(GLenum err) { 5 | switch (err) { 6 | case GL_INVALID_ENUM: 7 | return "invalid enum"; 8 | case GL_INVALID_VALUE: 9 | return "invalid value"; 10 | case GL_INVALID_OPERATION: 11 | return "invalid operation"; 12 | case GL_INVALID_FRAMEBUFFER_OPERATION: 13 | return "invalid framebuffer operation"; 14 | case GL_OUT_OF_MEMORY: 15 | return "out of memory"; 16 | default: 17 | return "unknown"; 18 | } 19 | } 20 | 21 | int printOpenGLErrors(const char *file, int line) { 22 | GLenum glErr; 23 | int retCode = 0; 24 | 25 | glErr = glGetError(); 26 | while (glErr != GL_NO_ERROR) { 27 | std::cerr << "glError in file " << file << " @ line " << line << ": " 28 | << getOpenGLError(glErr) << std::endl; 29 | retCode = 1; 30 | glErr = glGetError(); 31 | } 32 | return retCode; 33 | } 34 | -------------------------------------------------------------------------------- /src/toolbox/debug.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | std::string getOpenGLError(GLenum err); 7 | 8 | int printOpenGLErrors(const char *file, int line); 9 | 10 | /** 11 | * Prints all OpenGL errors that have occurred along with the file and line 12 | * number of the corresponding checkErrors() call. 13 | */ 14 | #define checkErrors() printOpenGLErrors(__FILE__, __LINE__) 15 | -------------------------------------------------------------------------------- /src/toolbox/gl_handles.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Original work Copyright (c) 2016 Tristan Brindle 3 | * License: MIT 4 | * Source: https://github.com/tcbrindle/thinmatrix-gl-tutorials 5 | */ 6 | 7 | #pragma once 8 | #include 9 | #include 10 | #include 11 | 12 | namespace gl { 13 | namespace detail { 14 | 15 | template 16 | class Handle { 17 | public: 18 | Handle() = default; 19 | Handle(GLuint id) : id(id) {} 20 | 21 | Handle(Handle&& other) 22 | : id(other.id) 23 | { 24 | other.id = 0; 25 | } 26 | 27 | Handle& operator=(Handle&& other) { 28 | std::swap(id, other.id); 29 | return *this; 30 | } 31 | 32 | ~Handle() { 33 | if (id) Deleter{}(id); 34 | } 35 | 36 | GLuint get() const { return id; } 37 | 38 | private: 39 | GLuint id = 0; 40 | }; 41 | 42 | template 43 | class MultiHandle { 44 | public: 45 | MultiHandle() = default; 46 | 47 | MultiHandle(MultiHandle&& other) 48 | : ids(std::move(other.ids)) 49 | { 50 | std::fill(std::begin(other.ids), std::end(other.ids), 0); 51 | } 52 | 53 | MultiHandle& operator=(MultiHandle&& other) { 54 | std::swap(ids, other.ids); 55 | return *this; 56 | } 57 | 58 | ~MultiHandle() { 59 | Deleter()(N, ids.data()); 60 | } 61 | 62 | GLuint* operator&() { 63 | return ids.data(); 64 | } 65 | 66 | GLuint get(std::size_t n = 0) const { 67 | return ids[n]; 68 | } 69 | 70 | private: 71 | std::array ids = {}; 72 | }; 73 | 74 | struct GLBufferDeleter { 75 | void operator()(GLsizei count, GLuint* ptr) const { 76 | glDeleteBuffers(count, ptr); 77 | } 78 | }; 79 | 80 | struct GLFramebufferDeleter { 81 | void operator()(GLsizei count, GLuint* ptr) const { 82 | glDeleteFramebuffers(count, ptr); 83 | } 84 | }; 85 | 86 | struct GLProgramDeleter { 87 | void operator()(GLuint handle) const { 88 | glDeleteProgram(handle); 89 | } 90 | }; 91 | 92 | struct GLRenderbufferDeleter { 93 | void operator() (GLsizei count, GLuint* ptr) const { 94 | glDeleteRenderbuffers(count, ptr); 95 | } 96 | }; 97 | 98 | struct GLShaderDeleter { 99 | void operator()(GLuint handle) const { 100 | glDeleteShader(handle); 101 | } 102 | }; 103 | 104 | struct GLTextureDeleter { 105 | void operator()(GLsizei count, GLuint* ptr) const { 106 | glDeleteTextures(count, ptr); 107 | } 108 | }; 109 | 110 | struct GLVertexArrayDeleter { 111 | void operator()(GLsizei count, GLuint* ptr) const { 112 | glDeleteVertexArrays(count, ptr); 113 | } 114 | }; 115 | 116 | } // end namespace detail 117 | 118 | using BufferHandle = detail::MultiHandle; 119 | using FramebufferHandle = detail::MultiHandle; 120 | using ProgramHandle = detail::Handle; 121 | using RenderbufferHandle = detail::MultiHandle; 122 | using ShaderHandle = detail::Handle; 123 | using TextureHandle = detail::MultiHandle; 124 | using VertexArrayHandle = detail::MultiHandle; 125 | 126 | } // end namespace gl 127 | -------------------------------------------------------------------------------- /src/toolbox/math.cpp: -------------------------------------------------------------------------------- 1 | #include "toolbox/math.hpp" 2 | #define GLM_FORCE_RADIANS 3 | #include 4 | #include 5 | 6 | 7 | glm::mat4 Math::createTransformationMatrix(glm::vec2 const& translation, 8 | glm::vec2 const& scale) 9 | { 10 | glm::mat4 matrix = glm::mat4(); 11 | 12 | matrix = glm::translate(matrix, glm::vec3(translation, 0.0f)); 13 | matrix = glm::scale (matrix, glm::vec3(scale, 1.0f)); 14 | 15 | return matrix; 16 | } 17 | 18 | glm::mat4 Math::createTransformationMatrix(glm::vec3 const& translation, 19 | glm::vec3 const& rotation, 20 | glm::vec3 const& scale) 21 | { 22 | glm::mat4 matrix = glm::mat4(); 23 | 24 | matrix = glm::translate(matrix, translation); 25 | matrix = glm::rotate (matrix, rotation.x, glm::vec3(1.0f, 0.0f, 0.0f)); 26 | matrix = glm::rotate (matrix, rotation.y, glm::vec3(0.0f, 1.0f, 0.0f)); 27 | matrix = glm::rotate (matrix, rotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); 28 | matrix = glm::scale (matrix, scale); 29 | 30 | return matrix; 31 | } 32 | 33 | float Math::barryCentric(glm::vec3 const& p1, glm::vec3 const& p2, glm::vec3 const& p3, 34 | glm::vec2 const& pos) 35 | { 36 | float det = (p2.z - p3.z) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.z - p3.z); 37 | float l1 = ((p2.z - p3.z) * (pos.x - p3.x) + (p3.x - p2.x) * (pos.y - p3.z)) / det; 38 | float l2 = ((p3.z - p1.z) * (pos.x - p3.x) + (p1.x - p3.x) * (pos.y - p3.z)) / det; 39 | float l3 = 1.0f - l1 - l2; 40 | return l1 * p1.y + l2 * p2.y + l3 * p3.y; 41 | } 42 | -------------------------------------------------------------------------------- /src/toolbox/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Math { 7 | 8 | glm::mat4 createTransformationMatrix( 9 | glm::vec2 const& translation, 10 | glm::vec2 const& scale); 11 | 12 | glm::mat4 createTransformationMatrix( 13 | glm::vec3 const& translation, 14 | glm::vec3 const& rotation, 15 | glm::vec3 const& scale); 16 | 17 | float barryCentric( 18 | glm::vec3 const& p1, 19 | glm::vec3 const& p2, 20 | glm::vec3 const& p3, 21 | glm::vec2 const& pos); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/toolbox/mouse_picker.cpp: -------------------------------------------------------------------------------- 1 | #include "toolbox/mouse_picker.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #define GLM_FORCE_RADIANS 4 | #include 5 | 6 | namespace { 7 | 8 | glm::vec2 getNormalizeDeviceCoords(float mouseX, float mouseY) { 9 | sf::Vector2u dimensions = DisplayManager::getWindow().getSize(); 10 | float x = (2.0f * mouseX) / (float)dimensions.x - 1.0f; 11 | float y = (2.0f * mouseY) / (float)dimensions.y - 1.0f; 12 | return {x, -y}; 13 | } 14 | 15 | glm::vec4 toEyeCoords(glm::vec4 const& clipCoords, glm::mat4 const& projection) { 16 | glm::vec4 eyeCoords = glm::inverse(projection) * clipCoords; 17 | return {eyeCoords.x, eyeCoords.y, -1.0f, 0.0f}; 18 | } 19 | 20 | glm::vec3 toWorldCoords(glm::vec4 const& eyeCoords, glm::mat4 const& view) { 21 | auto mouseRay = glm::vec3(glm::inverse(view) * eyeCoords); 22 | return glm::normalize(mouseRay); 23 | } 24 | 25 | } 26 | 27 | MousePicker::MousePicker(Camera const& cam, glm::mat4 const& projection) 28 | : camera_(cam) 29 | , projectionMatrix_(projection) 30 | , viewMatrix_(cam.getViewMatrix()) 31 | { } 32 | 33 | glm::vec3 const& MousePicker::getCurrentRay() const { 34 | return currentRay_; 35 | } 36 | 37 | void MousePicker::update() { 38 | viewMatrix_ = camera_.getViewMatrix(); 39 | currentRay_ = calculateMouseRay(); 40 | } 41 | 42 | glm::vec3 MousePicker::calculateMouseRay() { 43 | auto mousePos = sf::Mouse::getPosition(DisplayManager::getWindow()); 44 | auto normalizedCoords = getNormalizeDeviceCoords(mousePos.x, mousePos.y); 45 | auto clipCoords = glm::vec4(normalizedCoords, -1.0f, 1.0f); 46 | auto eyeCoords = toEyeCoords(clipCoords, projectionMatrix_); 47 | return toWorldCoords(eyeCoords, viewMatrix_); 48 | } 49 | -------------------------------------------------------------------------------- /src/toolbox/mouse_picker.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "entities/camera.hpp" 3 | #include 4 | #include 5 | 6 | class MousePicker { 7 | public: 8 | MousePicker(Camera const& cam, glm::mat4 const& projection); 9 | 10 | glm::vec3 const& getCurrentRay() const; 11 | 12 | void update(); 13 | 14 | private: 15 | glm::vec3 calculateMouseRay(); 16 | 17 | Camera const& camera_; 18 | glm::mat4 projectionMatrix_; 19 | glm::mat4 viewMatrix_; 20 | glm::vec3 currentRay_; 21 | }; 22 | -------------------------------------------------------------------------------- /src/water/water_frame_buffers.cpp: -------------------------------------------------------------------------------- 1 | #include "water/water_frame_buffers.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | 4 | 5 | namespace { 6 | constexpr int REFLECTION_WIDTH = 900, REFLECTION_HEIGHT = 675; 7 | constexpr int REFRACTION_WIDTH = 900, REFRACTION_HEIGHT = 675; 8 | } 9 | 10 | WaterFrameBuffers::WaterFrameBuffers() { 11 | initializeReflectionFrameBuffer(); 12 | initializeRefractionFrameBuffer(); 13 | } 14 | 15 | void WaterFrameBuffers::bindReflectionFrameBuffer() const { 16 | bindFrameBuffer(reflectionFbo_.get(), REFLECTION_WIDTH, REFLECTION_HEIGHT); 17 | } 18 | 19 | void WaterFrameBuffers::bindRefractionFrameBuffer() const { 20 | bindFrameBuffer(refractionFbo_.get(), REFRACTION_WIDTH, REFRACTION_HEIGHT); 21 | } 22 | 23 | void WaterFrameBuffers::unbindCurrentFrameBuffer() const { 24 | auto dimensions = DisplayManager::getWindow().getSize(); 25 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 26 | glViewport(0, 0, dimensions.x, dimensions.y); 27 | } 28 | 29 | GLuint WaterFrameBuffers::getReflectionTexture() const { 30 | return reflectionTexture_.get(); 31 | } 32 | 33 | GLuint WaterFrameBuffers::getRefractionTexture() const { 34 | return refractionTexture_.get(); 35 | } 36 | 37 | GLuint WaterFrameBuffers::getRefractionDepthTexture() const { 38 | return refractionDepthTexture_.get(); 39 | } 40 | 41 | void WaterFrameBuffers::bindFrameBuffer(GLuint fbo, int width, int height) const { 42 | glBindTexture(GL_TEXTURE_2D, 0); 43 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); 44 | glViewport(0, 0, width, height); 45 | } 46 | 47 | void WaterFrameBuffers::initializeReflectionFrameBuffer() { 48 | reflectionFbo_ = createFrameBuffer(); 49 | reflectionTexture_ = createColorTextureAttachment(REFLECTION_WIDTH, REFLECTION_HEIGHT); 50 | reflectionDepthBuffer_ = createDepthBufferAttachment(REFLECTION_WIDTH, REFLECTION_HEIGHT); 51 | unbindCurrentFrameBuffer(); 52 | } 53 | 54 | void WaterFrameBuffers::initializeRefractionFrameBuffer() { 55 | refractionFbo_ = createFrameBuffer(); 56 | refractionTexture_ = createColorTextureAttachment(REFRACTION_WIDTH, REFRACTION_HEIGHT); 57 | refractionDepthTexture_ = createDepthTextureAttachment(REFRACTION_WIDTH, REFRACTION_HEIGHT); 58 | unbindCurrentFrameBuffer(); 59 | } 60 | 61 | gl::FramebufferHandle WaterFrameBuffers::createFrameBuffer() { 62 | gl::FramebufferHandle fbo; 63 | glGenFramebuffers(1, &fbo); 64 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); 65 | glDrawBuffer(GL_COLOR_ATTACHMENT0); 66 | return fbo; 67 | } 68 | 69 | gl::TextureHandle WaterFrameBuffers::createColorTextureAttachment(int width, int height) { 70 | gl::TextureHandle tex; 71 | glGenTextures(1, &tex); 72 | glBindTexture(GL_TEXTURE_2D, tex.get()); 73 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, 74 | GL_UNSIGNED_BYTE, nullptr); 75 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 76 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 77 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.get(), 0); 78 | return tex; 79 | } 80 | 81 | gl::TextureHandle WaterFrameBuffers::createDepthTextureAttachment(int width, int height) { 82 | gl::TextureHandle tex; 83 | glGenTextures(1, &tex); 84 | glBindTexture(GL_TEXTURE_2D, tex.get()); 85 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, 86 | GL_DEPTH_COMPONENT, GL_FLOAT, nullptr); 87 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 88 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 89 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex.get(), 0); 90 | return tex; 91 | } 92 | 93 | gl::RenderbufferHandle WaterFrameBuffers::createDepthBufferAttachment(int width, int height) { 94 | gl::RenderbufferHandle buf; 95 | glGenRenderbuffers(1, &buf); 96 | glBindRenderbuffer(GL_RENDERBUFFER, buf.get()); 97 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); 98 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, buf.get()); 99 | return buf; 100 | } -------------------------------------------------------------------------------- /src/water/water_frame_buffers.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "toolbox/gl_handles.hpp" 3 | #include 4 | 5 | class WaterFrameBuffers { 6 | public: 7 | WaterFrameBuffers(); 8 | 9 | void bindReflectionFrameBuffer() const; 10 | void bindRefractionFrameBuffer() const; 11 | void unbindCurrentFrameBuffer() const; 12 | 13 | GLuint getReflectionTexture() const; 14 | GLuint getRefractionTexture() const; 15 | GLuint getRefractionDepthTexture() const; 16 | 17 | private: 18 | void initializeReflectionFrameBuffer(); 19 | void initializeRefractionFrameBuffer(); 20 | void bindFrameBuffer(GLuint fbo, int width, int height) const; 21 | 22 | gl::FramebufferHandle createFrameBuffer(); 23 | gl::TextureHandle createColorTextureAttachment(int width, int height); 24 | gl::TextureHandle createDepthTextureAttachment(int width, int height); 25 | gl::RenderbufferHandle createDepthBufferAttachment(int width, int height); 26 | 27 | gl::FramebufferHandle reflectionFbo_; 28 | gl::TextureHandle reflectionTexture_; 29 | gl::RenderbufferHandle reflectionDepthBuffer_; 30 | 31 | gl::FramebufferHandle refractionFbo_; 32 | gl::TextureHandle refractionTexture_; 33 | gl::TextureHandle refractionDepthTexture_; 34 | }; 35 | -------------------------------------------------------------------------------- /src/water/water_renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "water/water_renderer.hpp" 2 | #include "render_engine/display_manager.hpp" 3 | #include "toolbox/math.hpp" 4 | #include 5 | 6 | 7 | namespace { 8 | constexpr auto DUDV_MAP = "res/textures/water/waterDUDV.png"; 9 | constexpr auto NORMAL_MAP = "res/textures/water/normalMap.png"; 10 | constexpr float WAVE_SPEED = 0.03f; 11 | const std::vector POSITIONS 12 | { -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1 }; 13 | } 14 | 15 | constexpr float WaterTile::TILE_SIZE; 16 | 17 | WaterRenderer::WaterRenderer(Loader &loader, glm::mat4 const& projection, 18 | WaterFrameBuffers const& fbos) 19 | : quad_(loader.loadToVao(POSITIONS, 2)) 20 | , fbos_(fbos) 21 | , dudvTextureId_(loader.loadTexture(DUDV_MAP)) 22 | , normalMapTextureId_(loader.loadTexture(NORMAL_MAP)) 23 | { 24 | shader_.start(); 25 | shader_.connectTextureUnits(); 26 | shader_.loadProjectionMatrix(projection); 27 | shader_.stop(); 28 | } 29 | 30 | void WaterRenderer::render(std::vector const& water, Camera& camera, 31 | Light const& sun) 32 | { 33 | prepareRender(camera, sun); 34 | for (WaterTile const& tile : water) { 35 | glm::mat4 modelMatrix = Math::createTransformationMatrix( 36 | glm::vec3(tile.getX(), tile.getHeight(), tile.getZ()), 37 | glm::vec3(0), 38 | glm::vec3(WaterTile::TILE_SIZE)); 39 | shader_.loadModelMatrix(modelMatrix); 40 | glDrawArrays(GL_TRIANGLES, 0, quad_.getVertexCount()); 41 | } 42 | unbind(); 43 | } 44 | 45 | void WaterRenderer::prepareRender(Camera& camera, Light const& sun) { 46 | shader_.start(); 47 | shader_.loadViewMatrix(camera); 48 | shader_.loadLight(sun); 49 | moveFactor_ += WAVE_SPEED * DisplayManager::getFrameTime().asSeconds(); 50 | moveFactor_ = std::fmod(moveFactor_, 1); 51 | shader_.loadMoveFactor(moveFactor_); 52 | glBindVertexArray(quad_.getVaoId()); 53 | glEnableVertexAttribArray(0); 54 | glActiveTexture(GL_TEXTURE0); 55 | glBindTexture(GL_TEXTURE_2D, fbos_.getReflectionTexture()); 56 | glActiveTexture(GL_TEXTURE1); 57 | glBindTexture(GL_TEXTURE_2D, fbos_.getRefractionTexture()); 58 | glActiveTexture(GL_TEXTURE2); 59 | glBindTexture(GL_TEXTURE_2D, dudvTextureId_); 60 | glActiveTexture(GL_TEXTURE3); 61 | glBindTexture(GL_TEXTURE_2D, normalMapTextureId_); 62 | glActiveTexture(GL_TEXTURE4); 63 | glBindTexture(GL_TEXTURE_2D, fbos_.getRefractionDepthTexture()); 64 | glEnable(GL_BLEND); 65 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 66 | } 67 | 68 | void WaterRenderer::unbind() const { 69 | glDisable(GL_BLEND); 70 | glDisableVertexAttribArray(0); 71 | glBindVertexArray(0); 72 | shader_.stop(); 73 | } 74 | 75 | void WaterRenderer::loadProjectionMatrix(glm::mat4 const& projection) const { 76 | shader_.start(); 77 | shader_.loadProjectionMatrix(projection); 78 | shader_.stop(); 79 | } 80 | -------------------------------------------------------------------------------- /src/water/water_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "water/water_shader.hpp" 3 | #include "water/water_tile.hpp" 4 | #include "water/water_frame_buffers.hpp" 5 | #include "models/raw_model.hpp" 6 | #include 7 | 8 | class WaterRenderer { 9 | public: 10 | WaterRenderer( 11 | Loader &loader, 12 | glm::mat4 const& projection, 13 | WaterFrameBuffers const& fbos); 14 | 15 | void render( 16 | std::vector const& water, 17 | Camera& camera, 18 | Light const& sun); 19 | 20 | private: 21 | void prepareRender(Camera& camera, Light const& sun); 22 | void unbind() const; 23 | void loadProjectionMatrix(glm::mat4 const& projection) const; 24 | 25 | RawModel quad_; 26 | WaterShader shader_{}; 27 | WaterFrameBuffers const& fbos_; 28 | GLuint dudvTextureId_; 29 | GLuint normalMapTextureId_; 30 | float moveFactor_ = 0.0f; 31 | }; 32 | -------------------------------------------------------------------------------- /src/water/water_shader.cpp: -------------------------------------------------------------------------------- 1 | #include "water/water_shader.hpp" 2 | 3 | 4 | namespace { 5 | constexpr auto VERTEX_SHADER_FILE = "res/shaders/water.v.glsl"; 6 | constexpr auto FRAGMENT_SHADER_FILE = "res/shaders/water.f.glsl"; 7 | } 8 | 9 | WaterShader::WaterShader() 10 | : Shader(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE) 11 | { 12 | initialize(); 13 | } 14 | 15 | void WaterShader::bindAttributes() { 16 | bindAttribute(0, "position"); 17 | } 18 | 19 | void WaterShader::getAllUniformLocations() { 20 | modelMatrixLocation_ = getUniformLocation("modelMatrix"); 21 | viewMatrixLocation_ = getUniformLocation("viewMatrix"); 22 | projectionMatrixLocation_ = getUniformLocation("projectionMatrix"); 23 | reflectionTextureLocation_ = getUniformLocation("reflectionTexture"); 24 | refractionTextureLocation_ = getUniformLocation("refractionTexture"); 25 | dudvMapLocation_ = getUniformLocation("dudvMap"); 26 | normalMapLocation_ = getUniformLocation("normalMap"); 27 | depthMapLocation_ = getUniformLocation("depthMap"); 28 | moveFactorLocation_ = getUniformLocation("moveFactor"); 29 | cameraPositionLocation_ = getUniformLocation("cameraPosition"); 30 | lightPositionLocation_ = getUniformLocation("lightPosition"); 31 | lightColorLocation_ = getUniformLocation("lightColor"); 32 | } 33 | 34 | void WaterShader::loadModelMatrix(glm::mat4 const& matrix) const { 35 | loadMatrix(modelMatrixLocation_, matrix); 36 | } 37 | 38 | void WaterShader::loadViewMatrix(Camera& camera) const { 39 | loadMatrix(viewMatrixLocation_, camera.getViewMatrix()); 40 | loadVector3(cameraPositionLocation_, camera.getPosition()); 41 | } 42 | 43 | void WaterShader::loadProjectionMatrix(glm::mat4 const& matrix) const { 44 | loadMatrix(projectionMatrixLocation_, matrix); 45 | } 46 | 47 | void WaterShader::loadMoveFactor(GLfloat moveFactor) const { 48 | loadFloat(moveFactorLocation_, moveFactor); 49 | } 50 | 51 | void WaterShader::connectTextureUnits() const { 52 | loadInteger(reflectionTextureLocation_, 0); 53 | loadInteger(refractionTextureLocation_, 1); 54 | loadInteger(dudvMapLocation_, 2); 55 | loadInteger(normalMapLocation_, 3); 56 | loadInteger(depthMapLocation_, 4); 57 | } 58 | 59 | void WaterShader::loadLight(Light const& sun) const { 60 | loadVector3(lightPositionLocation_, sun.getPosition()); 61 | loadVector3(lightColorLocation_, sun.getColor()); 62 | } 63 | -------------------------------------------------------------------------------- /src/water/water_shader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "shaders/shader.hpp" 3 | #include "entities/light.hpp" 4 | #include "entities/camera.hpp" 5 | 6 | class WaterShader final : public Shader { 7 | public: 8 | WaterShader(); 9 | 10 | void loadModelMatrix(glm::mat4 const& matrix) const; 11 | void loadViewMatrix(Camera& camera) const; 12 | void loadProjectionMatrix(glm::mat4 const& matrix) const; 13 | void loadMoveFactor(GLfloat moveFactor) const; 14 | void loadLight(Light const& sun) const; 15 | void connectTextureUnits() const; 16 | 17 | protected: 18 | virtual void bindAttributes() override; 19 | virtual void getAllUniformLocations() override; 20 | 21 | private: 22 | GLint modelMatrixLocation_; 23 | GLint viewMatrixLocation_; 24 | GLint projectionMatrixLocation_; 25 | GLint reflectionTextureLocation_; 26 | GLint refractionTextureLocation_; 27 | GLint dudvMapLocation_; 28 | GLint normalMapLocation_; 29 | GLint depthMapLocation_; 30 | GLint moveFactorLocation_; 31 | GLint cameraPositionLocation_; 32 | GLint lightPositionLocation_; 33 | GLint lightColorLocation_; 34 | }; 35 | -------------------------------------------------------------------------------- /src/water/water_tile.cpp: -------------------------------------------------------------------------------- 1 | #include "water/water_tile.hpp" 2 | 3 | 4 | WaterTile::WaterTile(float x, float z, float height) 5 | : x_(x) 6 | , z_(z) 7 | , height_(height) 8 | { } 9 | 10 | float WaterTile::getX() const { 11 | return x_; 12 | } 13 | 14 | float WaterTile::getZ() const { 15 | return z_; 16 | } 17 | 18 | float WaterTile::getHeight() const { 19 | return height_; 20 | } 21 | -------------------------------------------------------------------------------- /src/water/water_tile.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class WaterTile { 4 | public: 5 | WaterTile(float x, float z, float height); 6 | 7 | float getX() const; 8 | float getZ() const; 9 | float getHeight() const; 10 | 11 | static constexpr float TILE_SIZE = 200.0f; 12 | 13 | private: 14 | float x_, z_; 15 | float height_; 16 | }; 17 | --------------------------------------------------------------------------------