├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── chapter-01 ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── lwjglb │ └── HelloWorld.java ├── chapter-02 ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Window.java │ │ ├── graph │ │ │ └── Render.java │ │ └── scene │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-03 ├── pom.xml ├── resources │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Mesh.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ └── ShaderProgram.java │ │ └── scene │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-04 ├── pom.xml ├── resources │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Mesh.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ └── ShaderProgram.java │ │ └── scene │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-05 ├── pom.xml ├── resources │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Mesh.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-06 ├── pom.xml ├── resources │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Entity.java │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-07 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ └── cube.png │ │ └── default │ │ │ └── default_texture.png │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Entity.java │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-08 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ └── cube.png │ │ └── default │ │ │ └── default_texture.png │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-09 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ └── cube.png │ │ └── default │ │ │ └── default_texture.png │ └── shaders │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-10 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ ├── cube.png │ │ │ └── cube_old.obj │ │ └── default │ │ │ └── default_texture.png │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ └── Scene.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-11 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ ├── cube.png │ │ │ └── cube_old.obj │ │ └── default │ │ │ └── default_texture.png │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ └── scene.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ └── lights │ │ │ ├── AmbientLight.java │ │ │ ├── DirLight.java │ │ │ ├── PointLight.java │ │ │ ├── SceneLights.java │ │ │ └── SpotLight.java │ │ └── game │ │ ├── LightControls.java │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-12 ├── pom.xml ├── resources │ ├── models │ │ ├── default │ │ │ └── default_texture.png │ │ ├── quad │ │ │ ├── quad.mtl │ │ │ ├── quad.obj │ │ │ └── quad.png │ │ └── skybox │ │ │ ├── skybox.mtl │ │ │ ├── skybox.obj │ │ │ └── skybox.png │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ ├── AmbientLight.java │ │ │ ├── DirLight.java │ │ │ ├── PointLight.java │ │ │ ├── SceneLights.java │ │ │ └── SpotLight.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-13 ├── pom.xml ├── resources │ ├── models │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ ├── AmbientLight.java │ │ │ ├── DirLight.java │ │ │ ├── PointLight.java │ │ │ ├── SceneLights.java │ │ │ └── SpotLight.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-14 ├── pom.xml ├── resources │ ├── models │ │ ├── default │ │ │ └── default_texture.png │ │ └── wall │ │ │ ├── wall.mtl │ │ │ ├── wall.obj │ │ │ ├── wall.png │ │ │ ├── wall_nonormals.mtl │ │ │ ├── wall_nonormals.obj │ │ │ └── wall_normals.png │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ ├── AmbientLight.java │ │ │ ├── DirLight.java │ │ │ ├── PointLight.java │ │ │ ├── SceneLights.java │ │ │ └── SpotLight.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-15 ├── pom.xml ├── resources │ ├── models │ │ ├── bob │ │ │ ├── boblamp.md5anim │ │ │ ├── boblamp.md5mesh │ │ │ ├── guard1_body.png │ │ │ ├── guard1_body_h.png │ │ │ ├── guard1_body_s.png │ │ │ ├── guard1_face.png │ │ │ ├── guard1_face_local.png │ │ │ ├── guard1_face_s.png │ │ │ ├── guard1_helmet.png │ │ │ ├── guard1_helmet_h.png │ │ │ ├── guard1_helmet_s.png │ │ │ ├── iron_grill.png │ │ │ ├── round_grill.png │ │ │ └── round_grill_h.png │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ └── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ ├── AmbientLight.java │ │ │ ├── DirLight.java │ │ │ ├── PointLight.java │ │ │ ├── SceneLights.java │ │ │ └── SpotLight.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-16 ├── pom.xml ├── resources │ ├── models │ │ ├── bob │ │ │ ├── boblamp.md5anim │ │ │ ├── boblamp.md5mesh │ │ │ ├── guard1_body.png │ │ │ ├── guard1_body_h.png │ │ │ ├── guard1_body_s.png │ │ │ ├── guard1_face.png │ │ │ ├── guard1_face_local.png │ │ │ ├── guard1_face_s.png │ │ │ ├── guard1_helmet.png │ │ │ ├── guard1_helmet_h.png │ │ │ ├── guard1_helmet_s.png │ │ │ ├── iron_grill.png │ │ │ ├── round_grill.png │ │ │ └── round_grill_h.png │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ ├── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── skybox.frag │ │ └── skybox.vert │ └── sounds │ │ ├── creak1.ogg │ │ ├── creak1.ogg.License.txt │ │ ├── woo_scary.License.txt │ │ └── woo_scary.ogg └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-17 ├── pom.xml ├── resources │ ├── models │ │ ├── bob │ │ │ ├── boblamp.md5anim │ │ │ ├── boblamp.md5mesh │ │ │ ├── guard1_body.png │ │ │ ├── guard1_body_h.png │ │ │ ├── guard1_body_s.png │ │ │ ├── guard1_face.png │ │ │ ├── guard1_face_local.png │ │ │ ├── guard1_face_s.png │ │ │ ├── guard1_helmet.png │ │ │ ├── guard1_helmet_h.png │ │ │ ├── guard1_helmet_s.png │ │ │ ├── iron_grill.png │ │ │ ├── round_grill.png │ │ │ └── round_grill_h.png │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── shadow.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── ArrTexture.java │ │ │ ├── CascadeShadow.java │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── ShadowBuffer.java │ │ │ ├── ShadowRender.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-18 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ ├── cube.png │ │ │ └── cube_old.obj │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── shadow.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── ArrTexture.java │ │ │ ├── CascadeShadow.java │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── ShadowBuffer.java │ │ │ ├── ShadowRender.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-19 ├── pom.xml ├── resources │ ├── models │ │ ├── bob │ │ │ ├── boblamp.md5anim │ │ │ ├── boblamp.md5mesh │ │ │ ├── guard1_body.png │ │ │ ├── guard1_body_h.png │ │ │ ├── guard1_body_s.png │ │ │ ├── guard1_face.png │ │ │ ├── guard1_face_local.png │ │ │ ├── guard1_face_s.png │ │ │ ├── guard1_helmet.png │ │ │ ├── guard1_helmet_h.png │ │ │ ├── guard1_helmet_s.png │ │ │ ├── iron_grill.png │ │ │ ├── round_grill.png │ │ │ └── round_grill_h.png │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── lights.frag │ │ ├── lights.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── shadow.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── ArrTexture.java │ │ │ ├── CascadeShadow.java │ │ │ ├── GBuffer.java │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── LightsRender.java │ │ │ ├── Material.java │ │ │ ├── Mesh.java │ │ │ ├── Model.java │ │ │ ├── QuadMesh.java │ │ │ ├── Render.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── ShadowBuffer.java │ │ │ ├── ShadowRender.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-20 ├── pom.xml ├── resources │ ├── models │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ ├── cube.png │ │ │ └── cube_old.obj │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── anim.comp │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── lights.frag │ │ ├── lights.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── shadow.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── ArrTexture.java │ │ │ ├── CascadeShadow.java │ │ │ ├── GBuffer.java │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── LightsRender.java │ │ │ ├── Material.java │ │ │ ├── MaterialCache.java │ │ │ ├── Mesh.java │ │ │ ├── MeshData.java │ │ │ ├── Model.java │ │ │ ├── QuadMesh.java │ │ │ ├── Render.java │ │ │ ├── RenderBuffers.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── ShadowBuffer.java │ │ │ ├── ShadowRender.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties ├── chapter-21 ├── pom.xml ├── resources │ ├── models │ │ ├── bob │ │ │ ├── boblamp.md5anim │ │ │ ├── boblamp.md5mesh │ │ │ ├── guard1_body.png │ │ │ ├── guard1_body_h.png │ │ │ ├── guard1_body_s.png │ │ │ ├── guard1_face.png │ │ │ ├── guard1_face_local.png │ │ │ ├── guard1_face_s.png │ │ │ ├── guard1_helmet.png │ │ │ ├── guard1_helmet_h.png │ │ │ ├── guard1_helmet_s.png │ │ │ ├── iron_grill.png │ │ │ ├── round_grill.png │ │ │ └── round_grill_h.png │ │ ├── cube │ │ │ ├── cube.mtl │ │ │ ├── cube.obj │ │ │ ├── cube.png │ │ │ └── cube_old.obj │ │ ├── default │ │ │ └── default_texture.png │ │ ├── skybox │ │ │ ├── skybox.mtl │ │ │ └── skybox.obj │ │ └── terrain │ │ │ ├── terrain.mtl │ │ │ └── terrain.obj │ └── shaders │ │ ├── anim.comp │ │ ├── gui.frag │ │ ├── gui.vert │ │ ├── lights.frag │ │ ├── lights.vert │ │ ├── scene.frag │ │ ├── scene.vert │ │ ├── shadow.vert │ │ ├── skybox.frag │ │ └── skybox.vert └── src │ └── main │ ├── java │ └── org │ │ └── lwjglb │ │ ├── engine │ │ ├── Engine.java │ │ ├── IAppLogic.java │ │ ├── IGuiInstance.java │ │ ├── MouseInput.java │ │ ├── Utils.java │ │ ├── Window.java │ │ ├── graph │ │ │ ├── AnimationRender.java │ │ │ ├── ArrTexture.java │ │ │ ├── CascadeShadow.java │ │ │ ├── GBuffer.java │ │ │ ├── GuiMesh.java │ │ │ ├── GuiRender.java │ │ │ ├── LightsRender.java │ │ │ ├── Material.java │ │ │ ├── MaterialCache.java │ │ │ ├── Mesh.java │ │ │ ├── MeshData.java │ │ │ ├── Model.java │ │ │ ├── QuadMesh.java │ │ │ ├── Render.java │ │ │ ├── RenderBuffers.java │ │ │ ├── SceneRender.java │ │ │ ├── ShaderProgram.java │ │ │ ├── ShadowBuffer.java │ │ │ ├── ShadowRender.java │ │ │ ├── SkyBoxRender.java │ │ │ ├── Texture.java │ │ │ ├── TextureCache.java │ │ │ └── UniformsMap.java │ │ ├── scene │ │ │ ├── AnimationData.java │ │ │ ├── Camera.java │ │ │ ├── Entity.java │ │ │ ├── Fog.java │ │ │ ├── ModelLoader.java │ │ │ ├── Node.java │ │ │ ├── Projection.java │ │ │ ├── Scene.java │ │ │ ├── SkyBox.java │ │ │ └── lights │ │ │ │ ├── AmbientLight.java │ │ │ │ ├── DirLight.java │ │ │ │ ├── PointLight.java │ │ │ │ ├── SceneLights.java │ │ │ │ └── SpotLight.java │ │ └── sound │ │ │ ├── SoundBuffer.java │ │ │ ├── SoundListener.java │ │ │ ├── SoundManager.java │ │ │ └── SoundSource.java │ │ └── game │ │ └── Main.java │ └── resources │ └── tinylog.properties └── pom.xml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: lwjglgamedev -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Set up JDK 18 for x64 12 | uses: actions/setup-java@v1 13 | with: 14 | java-version: 18 15 | architecture: x64 16 | - name: Build with Maven 17 | run: mvn --batch-mode --update-snapshots clean package 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | .settings/ 4 | *.iml 5 | .classpath 6 | .factorypath 7 | .project 8 | target/ 9 | build/ 10 | *.log 11 | *.cap 12 | *.cmd -------------------------------------------------------------------------------- /chapter-02/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-02/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | public Render() { 12 | GL.createCapabilities(); 13 | } 14 | 15 | public void cleanup() { 16 | // Nothing to be done here yet 17 | } 18 | 19 | public void render(Window window, Scene scene) { 20 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-02/src/main/java/org/lwjglb/engine/scene/Scene.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | public class Scene { 4 | 5 | public Scene() { 6 | } 7 | 8 | public void cleanup() { 9 | // Nothing to be done here yet 10 | } 11 | } -------------------------------------------------------------------------------- /chapter-02/src/main/java/org/lwjglb/game/Main.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.game; 2 | 3 | import org.lwjglb.engine.*; 4 | import org.lwjglb.engine.graph.Render; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | public class Main implements IAppLogic { 8 | 9 | public static void main(String[] args) { 10 | Main main = new Main(); 11 | Engine gameEng = new Engine("chapter-02", new Window.WindowOptions(), main); 12 | gameEng.start(); 13 | } 14 | 15 | @Override 16 | public void cleanup() { 17 | // Nothing to be done yet 18 | } 19 | 20 | @Override 21 | public void init(Window window, Scene scene, Render render) { 22 | // Nothing to be done yet 23 | } 24 | 25 | @Override 26 | public void input(Window window, Scene scene, long diffTimeMillis) { 27 | // Nothing to be done yet 28 | } 29 | 30 | @Override 31 | public void update(Window window, Scene scene, long diffTimeMillis) { 32 | // Nothing to be done yet 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-02/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-03/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | out vec4 fragColor; 4 | 5 | void main() 6 | { 7 | fragColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /chapter-03/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 inPosition; 4 | 5 | void main() 6 | { 7 | gl_Position = vec4(inPosition, 1.0); 8 | } -------------------------------------------------------------------------------- /chapter-03/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-03/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-03/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | sceneRender = new SceneRender(); 16 | } 17 | 18 | public void cleanup() { 19 | sceneRender.cleanup(); 20 | } 21 | 22 | public void render(Window window, Scene scene) { 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | glViewport(0, 0, window.getWidth(), window.getHeight()); 25 | 26 | sceneRender.render(scene); 27 | } 28 | } -------------------------------------------------------------------------------- /chapter-03/src/main/java/org/lwjglb/engine/scene/Scene.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.Mesh; 4 | 5 | import java.util.*; 6 | 7 | public class Scene { 8 | 9 | private Map meshMap; 10 | 11 | public Scene() { 12 | meshMap = new HashMap<>(); 13 | } 14 | 15 | public void addMesh(String meshId, Mesh mesh) { 16 | meshMap.put(meshId, mesh); 17 | } 18 | 19 | public void cleanup() { 20 | meshMap.values().forEach(Mesh::cleanup); 21 | } 22 | 23 | public Map getMeshMap() { 24 | return meshMap; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapter-03/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-04/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 outColor; 4 | out vec4 fragColor; 5 | 6 | void main() 7 | { 8 | fragColor = vec4(outColor, 1.0); 9 | } -------------------------------------------------------------------------------- /chapter-04/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 color; 5 | 6 | out vec3 outColor; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(position, 1.0); 11 | outColor = color; 12 | } -------------------------------------------------------------------------------- /chapter-04/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-04/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-04/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | sceneRender = new SceneRender(); 16 | } 17 | 18 | public void cleanup() { 19 | sceneRender.cleanup(); 20 | } 21 | 22 | public void render(Window window, Scene scene) { 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | glViewport(0, 0, window.getWidth(), window.getHeight()); 25 | 26 | sceneRender.render(scene); 27 | } 28 | } -------------------------------------------------------------------------------- /chapter-04/src/main/java/org/lwjglb/engine/scene/Scene.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.Mesh; 4 | 5 | import java.util.*; 6 | 7 | public class Scene { 8 | 9 | private Map meshMap; 10 | 11 | public Scene() { 12 | meshMap = new HashMap<>(); 13 | } 14 | 15 | public void addMesh(String meshId, Mesh mesh) { 16 | meshMap.put(meshId, mesh); 17 | } 18 | 19 | public void cleanup() { 20 | meshMap.values().forEach(Mesh::cleanup); 21 | } 22 | 23 | public Map getMeshMap() { 24 | return meshMap; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /chapter-04/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-05/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 outColor; 4 | out vec4 fragColor; 5 | 6 | void main() 7 | { 8 | fragColor = vec4(outColor, 1.0); 9 | } -------------------------------------------------------------------------------- /chapter-05/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 color; 5 | 6 | out vec3 outColor; 7 | 8 | uniform mat4 projectionMatrix; 9 | 10 | void main() 11 | { 12 | gl_Position = projectionMatrix * vec4(position, 1.0); 13 | outColor = color; 14 | } -------------------------------------------------------------------------------- /chapter-05/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-05/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-05/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | sceneRender = new SceneRender(); 16 | } 17 | 18 | public void cleanup() { 19 | sceneRender.cleanup(); 20 | } 21 | 22 | public void render(Window window, Scene scene) { 23 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 | glViewport(0, 0, window.getWidth(), window.getHeight()); 25 | 26 | sceneRender.render(scene); 27 | } 28 | } -------------------------------------------------------------------------------- /chapter-05/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-05/src/main/java/org/lwjglb/engine/scene/Scene.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.Mesh; 4 | 5 | import java.util.*; 6 | 7 | public class Scene { 8 | 9 | private Map meshMap; 10 | private Projection projection; 11 | 12 | public Scene(int width, int height) { 13 | meshMap = new HashMap<>(); 14 | projection = new Projection(width, height); 15 | } 16 | 17 | public void addMesh(String meshId, Mesh mesh) { 18 | meshMap.put(meshId, mesh); 19 | } 20 | 21 | public void cleanup() { 22 | meshMap.values().forEach(Mesh::cleanup); 23 | } 24 | 25 | public Map getMeshMap() { 26 | return meshMap; 27 | } 28 | 29 | public Projection getProjection() { 30 | return projection; 31 | } 32 | 33 | public void resize(int width, int height) { 34 | projection.updateProjMatrix(width, height); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /chapter-05/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-06/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec3 outColor; 4 | out vec4 fragColor; 5 | 6 | void main() 7 | { 8 | fragColor = vec4(outColor, 1.0); 9 | } -------------------------------------------------------------------------------- /chapter-06/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 color; 5 | 6 | out vec3 outColor; 7 | 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 modelMatrix; 10 | 11 | void main() 12 | { 13 | gl_Position = projectionMatrix * modelMatrix * vec4(position, 1.0); 14 | outColor = color; 15 | } -------------------------------------------------------------------------------- /chapter-06/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-06/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-06/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List meshList; 12 | 13 | public Model(String id, List meshList) { 14 | this.id = id; 15 | this.meshList = meshList; 16 | entitiesList = new ArrayList<>(); 17 | } 18 | 19 | public void cleanup() { 20 | meshList.forEach(Mesh::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMeshList() { 32 | return meshList; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /chapter-06/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | glEnable(GL_DEPTH_TEST); 16 | sceneRender = new SceneRender(); 17 | } 18 | 19 | public void cleanup() { 20 | sceneRender.cleanup(); 21 | } 22 | 23 | public void render(Window window, Scene scene) { 24 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 25 | glViewport(0, 0, window.getWidth(), window.getHeight()); 26 | 27 | sceneRender.render(scene); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter-06/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-06/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-07/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-07/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-07/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-07/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-07/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D txtSampler; 8 | 9 | void main() 10 | { 11 | fragColor = texture(txtSampler, outTextCoord); 12 | } -------------------------------------------------------------------------------- /chapter-07/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec2 texCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 modelMatrix; 10 | 11 | void main() 12 | { 13 | gl_Position = projectionMatrix * modelMatrix * vec4(position, 1.0); 14 | outTextCoord = texCoord; 15 | } -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/graph/Material.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class Material { 6 | 7 | private List meshList; 8 | private String texturePath; 9 | 10 | public Material() { 11 | meshList = new ArrayList<>(); 12 | } 13 | 14 | public void cleanup() { 15 | meshList.forEach(Mesh::cleanup); 16 | } 17 | 18 | public List getMeshList() { 19 | return meshList; 20 | } 21 | 22 | public String getTexturePath() { 23 | return texturePath; 24 | } 25 | 26 | public void setTexturePath(String texturePath) { 27 | this.texturePath = texturePath; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | glEnable(GL_DEPTH_TEST); 16 | sceneRender = new SceneRender(); 17 | } 18 | 19 | public void cleanup() { 20 | sceneRender.cleanup(); 21 | } 22 | 23 | public void render(Window window, Scene scene) { 24 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 25 | glViewport(0, 0, window.getWidth(), window.getHeight()); 26 | 27 | sceneRender.render(scene); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-07/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-07/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-08/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-08/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-08/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-08/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-08/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | uniform sampler2D txtSampler; 8 | 9 | void main() 10 | { 11 | fragColor = texture(txtSampler, outTextCoord); 12 | } -------------------------------------------------------------------------------- /chapter-08/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec2 texCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 viewMatrix; 10 | uniform mat4 modelMatrix; 11 | 12 | void main() 13 | { 14 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 15 | outTextCoord = texCoord; 16 | } -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/graph/Material.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class Material { 6 | 7 | private List meshList; 8 | private String texturePath; 9 | 10 | public Material() { 11 | meshList = new ArrayList<>(); 12 | } 13 | 14 | public void cleanup() { 15 | meshList.forEach(Mesh::cleanup); 16 | } 17 | 18 | public List getMeshList() { 19 | return meshList; 20 | } 21 | 22 | public String getTexturePath() { 23 | return texturePath; 24 | } 25 | 26 | public void setTexturePath(String texturePath) { 27 | this.texturePath = texturePath; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | glEnable(GL_DEPTH_TEST); 16 | sceneRender = new SceneRender(); 17 | } 18 | 19 | public void cleanup() { 20 | sceneRender.cleanup(); 21 | } 22 | 23 | public void render(Window window, Scene scene) { 24 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 25 | glViewport(0, 0, window.getWidth(), window.getHeight()); 26 | 27 | sceneRender.render(scene); 28 | } 29 | } -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-08/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-08/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-09/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-09/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-09/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-09/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-09/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-09/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | struct Material 8 | { 9 | vec4 diffuse; 10 | }; 11 | 12 | uniform sampler2D txtSampler; 13 | uniform Material material; 14 | 15 | void main() 16 | { 17 | fragColor = texture(txtSampler, outTextCoord) + material.diffuse; 18 | } -------------------------------------------------------------------------------- /chapter-09/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec2 texCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 viewMatrix; 10 | uniform mat4 modelMatrix; 11 | 12 | void main() 13 | { 14 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 15 | outTextCoord = texCoord; 16 | } -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/graph/Render.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjgl.opengl.GL; 4 | import org.lwjglb.engine.Window; 5 | import org.lwjglb.engine.scene.Scene; 6 | 7 | import static org.lwjgl.opengl.GL11.*; 8 | 9 | public class Render { 10 | 11 | private SceneRender sceneRender; 12 | 13 | public Render() { 14 | GL.createCapabilities(); 15 | glEnable(GL_DEPTH_TEST); 16 | glEnable(GL_CULL_FACE); 17 | glCullFace(GL_BACK); 18 | sceneRender = new SceneRender(); 19 | } 20 | 21 | public void cleanup() { 22 | sceneRender.cleanup(); 23 | } 24 | 25 | public void render(Window window, Scene scene) { 26 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 27 | glViewport(0, 0, window.getWidth(), window.getHeight()); 28 | 29 | sceneRender.render(scene); 30 | } 31 | } -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-09/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-09/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-10/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-10/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-10/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-10/resources/models/cube/cube_old.obj: -------------------------------------------------------------------------------- 1 | mtllib cube.mtl 2 | o cube 3 | v -0.500000 -0.500000 0.500000 4 | v 0.500000 -0.500000 0.500000 5 | v -0.500000 0.500000 0.500000 6 | v 0.500000 0.500000 0.500000 7 | v -0.500000 0.500000 -0.500000 8 | v 0.500000 0.500000 -0.500000 9 | v -0.500000 -0.500000 -0.500000 10 | v 0.500000 -0.500000 -0.500000 11 | 12 | vt 0.000000 0.000000 13 | vt 1.000000 0.000000 14 | vt 0.000000 1.000000 15 | vt 1.000000 1.000000 16 | 17 | vn 0.000000 0.000000 1.000000 18 | vn 0.000000 1.000000 0.000000 19 | vn 0.000000 0.000000 -1.000000 20 | vn 0.000000 -1.000000 0.000000 21 | vn 1.000000 0.000000 0.000000 22 | vn -1.000000 0.000000 0.000000 23 | 24 | g cubemtl 25 | usemtl cubemtl 26 | f 1/1/1 2/2/1 3/3/1 27 | f 3/3/1 2/2/1 4/4/1 28 | f 3/1/2 4/2/2 5/3/2 29 | f 5/3/2 4/2/2 6/4/2 30 | f 5/4/3 6/3/3 7/2/3 31 | f 7/2/3 6/3/3 8/1/3 32 | f 7/1/4 8/2/4 1/3/4 33 | f 1/3/4 8/2/4 2/4/4 34 | f 2/1/5 8/2/5 4/3/5 35 | f 4/3/5 8/2/5 6/4/5 36 | f 7/1/6 1/2/6 5/3/6 37 | f 5/3/6 1/2/6 3/4/6 -------------------------------------------------------------------------------- /chapter-10/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-10/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-10/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-10/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-10/resources/shaders/scene.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | 5 | out vec4 fragColor; 6 | 7 | struct Material 8 | { 9 | vec4 diffuse; 10 | }; 11 | 12 | uniform sampler2D txtSampler; 13 | uniform Material material; 14 | 15 | void main() 16 | { 17 | fragColor = texture(txtSampler, outTextCoord) + material.diffuse; 18 | } -------------------------------------------------------------------------------- /chapter-10/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec2 texCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | uniform mat4 projectionMatrix; 9 | uniform mat4 viewMatrix; 10 | uniform mat4 modelMatrix; 11 | 12 | void main() 13 | { 14 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 15 | outTextCoord = texCoord; 16 | } -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-10/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-10/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-11/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-11/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-11/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-11/resources/models/cube/cube_old.obj: -------------------------------------------------------------------------------- 1 | mtllib cube.mtl 2 | o cube 3 | v -0.500000 -0.500000 0.500000 4 | v 0.500000 -0.500000 0.500000 5 | v -0.500000 0.500000 0.500000 6 | v 0.500000 0.500000 0.500000 7 | v -0.500000 0.500000 -0.500000 8 | v 0.500000 0.500000 -0.500000 9 | v -0.500000 -0.500000 -0.500000 10 | v 0.500000 -0.500000 -0.500000 11 | 12 | vt 0.000000 0.000000 13 | vt 1.000000 0.000000 14 | vt 0.000000 1.000000 15 | vt 1.000000 1.000000 16 | 17 | vn 0.000000 0.000000 1.000000 18 | vn 0.000000 1.000000 0.000000 19 | vn 0.000000 0.000000 -1.000000 20 | vn 0.000000 -1.000000 0.000000 21 | vn 1.000000 0.000000 0.000000 22 | vn -1.000000 0.000000 0.000000 23 | 24 | g cubemtl 25 | usemtl cubemtl 26 | f 1/1/1 2/2/1 3/3/1 27 | f 3/3/1 2/2/1 4/4/1 28 | f 3/1/2 4/2/2 5/3/2 29 | f 5/3/2 4/2/2 6/4/2 30 | f 5/4/3 6/3/3 7/2/3 31 | f 7/2/3 6/3/3 8/1/3 32 | f 7/1/4 8/2/4 1/3/4 33 | f 1/3/4 8/2/4 2/4/4 34 | f 2/1/5 8/2/5 4/3/5 35 | f 4/3/5 8/2/5 6/4/5 36 | f 7/1/6 1/2/6 5/3/6 37 | f 5/3/6 1/2/6 3/4/6 -------------------------------------------------------------------------------- /chapter-11/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-11/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-11/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-11/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-11/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec2 texCoord; 6 | 7 | out vec3 outPosition; 8 | out vec3 outNormal; 9 | out vec2 outTextCoord; 10 | 11 | uniform mat4 projectionMatrix; 12 | uniform mat4 viewMatrix; 13 | uniform mat4 modelMatrix; 14 | 15 | void main() 16 | { 17 | mat4 modelViewMatrix = viewMatrix * modelMatrix; 18 | vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 19 | gl_Position = projectionMatrix * mvPosition; 20 | outPosition = mvPosition.xyz; 21 | outNormal = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz; 22 | outTextCoord = texCoord; 23 | } -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-11/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-11/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-12/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-12/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-12/resources/models/quad/quad.mtl: -------------------------------------------------------------------------------- 1 | newmtl quadmtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd quad.png -------------------------------------------------------------------------------- /chapter-12/resources/models/quad/quad.obj: -------------------------------------------------------------------------------- 1 | mtllib quad.mtl 2 | o quad 3 | v 1.000000 0.000000 -1.000000 4 | v -1.000000 0.000000 -1.000000 5 | v -1.000000 0.000000 1.000000 6 | v 1.000000 0.000000 1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | g quadmtl 16 | usemtl quadmtl 17 | f 1/1/1 3/3/1 4/4/1 18 | f 1/1/1 2/2/1 3/3/1 -------------------------------------------------------------------------------- /chapter-12/resources/models/quad/quad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-12/resources/models/quad/quad.png -------------------------------------------------------------------------------- /chapter-12/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skyboxmtl 2 | Kd 1.00 1.00 1.00 3 | Ka 0.00 0.00 0.00 4 | Ks 0.00 0.00 0.00 5 | map_Kd skybox.png -------------------------------------------------------------------------------- /chapter-12/resources/models/skybox/skybox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-12/resources/models/skybox/skybox.png -------------------------------------------------------------------------------- /chapter-12/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-12/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-12/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec2 texCoord; 6 | 7 | out vec3 outPosition; 8 | out vec3 outNormal; 9 | out vec2 outTextCoord; 10 | 11 | uniform mat4 projectionMatrix; 12 | uniform mat4 viewMatrix; 13 | uniform mat4 modelMatrix; 14 | 15 | void main() 16 | { 17 | mat4 modelViewMatrix = viewMatrix * modelMatrix; 18 | vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 19 | gl_Position = projectionMatrix * mvPosition; 20 | outPosition = mvPosition.xyz; 21 | outNormal = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz; 22 | outTextCoord = texCoord; 23 | } -------------------------------------------------------------------------------- /chapter-12/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-12/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-12/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-12/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-13/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-13/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-13/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-13/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrainmtl 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-13/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 -1.000000 4 | v -1.000000 0.000000 -1.000000 5 | v -1.000000 0.000000 1.000000 6 | v 1.000000 0.000000 1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | g terrainmtl 16 | usemtl terrainmtl 17 | f 1/1/1 3/3/1 4/4/1 18 | f 1/3/1 2/2/1 3/3/1 19 | -------------------------------------------------------------------------------- /chapter-13/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-13/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-13/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec2 texCoord; 6 | 7 | out vec3 outPosition; 8 | out vec3 outNormal; 9 | out vec2 outTextCoord; 10 | 11 | uniform mat4 projectionMatrix; 12 | uniform mat4 viewMatrix; 13 | uniform mat4 modelMatrix; 14 | 15 | void main() 16 | { 17 | mat4 modelViewMatrix = viewMatrix * modelMatrix; 18 | vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 19 | gl_Position = projectionMatrix * mvPosition; 20 | outPosition = mvPosition.xyz; 21 | outNormal = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz; 22 | outTextCoord = texCoord; 23 | } -------------------------------------------------------------------------------- /chapter-13/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-13/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-13/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-13/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-14/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-14/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall.mtl: -------------------------------------------------------------------------------- 1 | newmtl wallmtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd wall.png 6 | map_Kn wall_normals.png -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall.obj: -------------------------------------------------------------------------------- 1 | mtllib wall.mtl 2 | o wall 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | g wallmtl 16 | usemtl wallmtl 17 | f 3/3/1 1/1/1 4/4/1 18 | f 2/2/1 1/1/1 3/3/1 -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-14/resources/models/wall/wall.png -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall_nonormals.mtl: -------------------------------------------------------------------------------- 1 | newmtl wall_nonormals 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd wall.png -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall_nonormals.obj: -------------------------------------------------------------------------------- 1 | mtllib wall_nonormals.mtl 2 | o wall 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | g wall_nonormals 16 | usemtl wall_nonormals 17 | f 3/3/1 1/1/1 4/4/1 18 | f 2/2/1 1/1/1 3/3/1 -------------------------------------------------------------------------------- /chapter-14/resources/models/wall/wall_normals.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-14/resources/models/wall/wall_normals.png -------------------------------------------------------------------------------- /chapter-14/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-14/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-14/resources/shaders/scene.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=2) in vec3 tangent; 6 | layout (location=3) in vec3 bitangent; 7 | layout (location=4) in vec2 texCoord; 8 | 9 | out vec3 outPosition; 10 | out vec3 outNormal; 11 | out vec3 outTangent; 12 | out vec3 outBitangent; 13 | out vec2 outTextCoord; 14 | 15 | uniform mat4 projectionMatrix; 16 | uniform mat4 viewMatrix; 17 | uniform mat4 modelMatrix; 18 | 19 | void main() 20 | { 21 | mat4 modelViewMatrix = viewMatrix * modelMatrix; 22 | vec4 mvPosition = modelViewMatrix * vec4(position, 1.0); 23 | gl_Position = projectionMatrix * mvPosition; 24 | outPosition = mvPosition.xyz; 25 | outNormal = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz; 26 | outTangent = normalize(modelViewMatrix * vec4(tangent, 0)).xyz; 27 | outBitangent = normalize(modelViewMatrix * vec4(bitangent, 0)).xyz; 28 | outTextCoord = texCoord; 29 | } -------------------------------------------------------------------------------- /chapter-14/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-14/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | 6 | public class Utils { 7 | 8 | private Utils() { 9 | // Utility class 10 | } 11 | 12 | public static String readFile(String filePath) { 13 | String str; 14 | try { 15 | str = new String(Files.readAllBytes(Paths.get(filePath))); 16 | } catch (IOException excp) { 17 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 18 | } 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/graph/Model.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import org.lwjglb.engine.scene.Entity; 4 | 5 | import java.util.*; 6 | 7 | public class Model { 8 | 9 | private final String id; 10 | private List entitiesList; 11 | private List materialList; 12 | 13 | public Model(String id, List materialList) { 14 | this.id = id; 15 | entitiesList = new ArrayList<>(); 16 | this.materialList = materialList; 17 | } 18 | 19 | public void cleanup() { 20 | materialList.forEach(Material::cleanup); 21 | } 22 | 23 | public List getEntitiesList() { 24 | return entitiesList; 25 | } 26 | 27 | public String getId() { 28 | return id; 29 | } 30 | 31 | public List getMaterialList() { 32 | return materialList; 33 | } 34 | } -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-14/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-14/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_body.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_body_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_body_h.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_body_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_body_s.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_face.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_face_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_face_local.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_face_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_face_s.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_helmet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_helmet.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_helmet_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_helmet_h.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/guard1_helmet_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/guard1_helmet_s.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/iron_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/iron_grill.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/round_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/round_grill.png -------------------------------------------------------------------------------- /chapter-15/resources/models/bob/round_grill_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/bob/round_grill_h.png -------------------------------------------------------------------------------- /chapter-15/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-15/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-15/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-15/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-15/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-15/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-15/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-15/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-15/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.List; 6 | 7 | public class Utils { 8 | 9 | private Utils() { 10 | // Utility class 11 | } 12 | 13 | public static float[] listFloatToArray(List list) { 14 | int size = list != null ? list.size() : 0; 15 | float[] floatArr = new float[size]; 16 | for (int i = 0; i < size; i++) { 17 | floatArr[i] = list.get(i); 18 | } 19 | return floatArr; 20 | } 21 | 22 | public static int[] listIntToArray(List list) { 23 | return list.stream().mapToInt((Integer v) -> v).toArray(); 24 | } 25 | 26 | public static String readFile(String filePath) { 27 | String str; 28 | try { 29 | str = new String(Files.readAllBytes(Paths.get(filePath))); 30 | } catch (IOException excp) { 31 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 32 | } 33 | return str; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache, false); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-15/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-15/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_body.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_body_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_body_h.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_body_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_body_s.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_face.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_face_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_face_local.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_face_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_face_s.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_helmet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_helmet.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_helmet_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_helmet_h.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/guard1_helmet_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/guard1_helmet_s.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/iron_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/iron_grill.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/round_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/round_grill.png -------------------------------------------------------------------------------- /chapter-16/resources/models/bob/round_grill_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/bob/round_grill_h.png -------------------------------------------------------------------------------- /chapter-16/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-16/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-16/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-16/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-16/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-16/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-16/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-16/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-16/resources/sounds/creak1.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/sounds/creak1.ogg -------------------------------------------------------------------------------- /chapter-16/resources/sounds/creak1.ogg.License.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | RPG Audio 4 | 5 | by Kenney Vleugels (Kenney.nl) 6 | 7 | ------------------------------ 8 | 9 | License (Creative Commons Zero, CC0) 10 | http://creativecommons.org/publicdomain/zero/1.0/ 11 | 12 | You may use these assets in personal and commercial projects. 13 | Credit (Kenney or www.kenney.nl) would be nice but is not mandatory. 14 | 15 | ------------------------------ 16 | 17 | Donate: http://support.kenney.nl 18 | Request: http://request.kenney.nl 19 | 20 | Follow on Twitter for updates: 21 | @KenneyNL -------------------------------------------------------------------------------- /chapter-16/resources/sounds/woo_scary.License.txt: -------------------------------------------------------------------------------- 1 | Downloaded from: https://potat0master.itch.io/free-background-music-for-visual-novels-bgm-pack-1 2 | Author: Potat0Master (https://potat0master.itch.io/) 3 | License: 4 | 5 | "This background music pack has a royalty free license. Meaning, you can use these for both personal and commercial projects, as many times as you want. Giving credit is not necessary but would be appreciated. 6 | 7 | You can edit and modify these for your own use. However, you cannot resell or distribute them in the form that it is downloaded or even when it is modified. 8 | 9 | Still not sure if it is okay to use them? 10 | 11 | If you are using this music pack for your own visual novel or any other game, you have nothing to worry about. You can go ahead and make your visual novel using this music pack and even sell your game. 12 | 13 | Thank you for your support." -------------------------------------------------------------------------------- /chapter-16/resources/sounds/woo_scary.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-16/resources/sounds/woo_scary.ogg -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.List; 6 | 7 | public class Utils { 8 | 9 | private Utils() { 10 | // Utility class 11 | } 12 | 13 | public static float[] listFloatToArray(List list) { 14 | int size = list != null ? list.size() : 0; 15 | float[] floatArr = new float[size]; 16 | for (int i = 0; i < size; i++) { 17 | floatArr[i] = list.get(i); 18 | } 19 | return floatArr; 20 | } 21 | 22 | public static int[] listIntToArray(List list) { 23 | return list.stream().mapToInt((Integer v) -> v).toArray(); 24 | } 25 | 26 | public static String readFile(String filePath) { 27 | String str; 28 | try { 29 | str = new String(Files.readAllBytes(Paths.get(filePath))); 30 | } catch (IOException excp) { 31 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 32 | } 33 | return str; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache, false); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-16/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-16/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_body.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_body_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_body_h.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_body_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_body_s.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_face.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_face_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_face_local.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_face_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_face_s.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_helmet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_helmet.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_helmet_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_helmet_h.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/guard1_helmet_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/guard1_helmet_s.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/iron_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/iron_grill.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/round_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/round_grill.png -------------------------------------------------------------------------------- /chapter-17/resources/models/bob/round_grill_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/bob/round_grill_h.png -------------------------------------------------------------------------------- /chapter-17/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-17/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-17/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-17/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-17/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-17/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-17/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-17/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-17/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.List; 6 | 7 | public class Utils { 8 | 9 | private Utils() { 10 | // Utility class 11 | } 12 | 13 | public static float[] listFloatToArray(List list) { 14 | int size = list != null ? list.size() : 0; 15 | float[] floatArr = new float[size]; 16 | for (int i = 0; i < size; i++) { 17 | floatArr[i] = list.get(i); 18 | } 19 | return floatArr; 20 | } 21 | 22 | public static int[] listIntToArray(List list) { 23 | return list.stream().mapToInt((Integer v) -> v).toArray(); 24 | } 25 | 26 | public static String readFile(String filePath) { 27 | String str; 28 | try { 29 | str = new String(Files.readAllBytes(Paths.get(filePath))); 30 | } catch (IOException excp) { 31 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 32 | } 33 | return str; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f projMatrix; 12 | 13 | public Projection(int width, int height) { 14 | projMatrix = new Matrix4f(); 15 | updateProjMatrix(width, height); 16 | } 17 | 18 | public Matrix4f getProjMatrix() { 19 | return projMatrix; 20 | } 21 | 22 | public void updateProjMatrix(int width, int height) { 23 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache, false); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-17/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-17/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-18/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-18/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-18/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-18/resources/models/cube/cube_old.obj: -------------------------------------------------------------------------------- 1 | mtllib cube.mtl 2 | o cube 3 | v -0.500000 -0.500000 0.500000 4 | v 0.500000 -0.500000 0.500000 5 | v -0.500000 0.500000 0.500000 6 | v 0.500000 0.500000 0.500000 7 | v -0.500000 0.500000 -0.500000 8 | v 0.500000 0.500000 -0.500000 9 | v -0.500000 -0.500000 -0.500000 10 | v 0.500000 -0.500000 -0.500000 11 | 12 | vt 0.000000 0.000000 13 | vt 1.000000 0.000000 14 | vt 0.000000 1.000000 15 | vt 1.000000 1.000000 16 | 17 | vn 0.000000 0.000000 1.000000 18 | vn 0.000000 1.000000 0.000000 19 | vn 0.000000 0.000000 -1.000000 20 | vn 0.000000 -1.000000 0.000000 21 | vn 1.000000 0.000000 0.000000 22 | vn -1.000000 0.000000 0.000000 23 | 24 | g cubemtl 25 | usemtl cubemtl 26 | f 1/1/1 2/2/1 3/3/1 27 | f 3/3/1 2/2/1 4/4/1 28 | f 3/1/2 4/2/2 5/3/2 29 | f 5/3/2 4/2/2 6/4/2 30 | f 5/4/3 6/3/3 7/2/3 31 | f 7/2/3 6/3/3 8/1/3 32 | f 7/1/4 8/2/4 1/3/4 33 | f 1/3/4 8/2/4 2/4/4 34 | f 2/1/5 8/2/5 4/3/5 35 | f 4/3/5 8/2/5 6/4/5 36 | f 7/1/6 1/2/6 5/3/6 37 | f 5/3/6 1/2/6 3/4/6 -------------------------------------------------------------------------------- /chapter-18/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-18/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-18/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-18/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-18/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-18/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-18/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-18/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-18/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.List; 6 | 7 | public class Utils { 8 | 9 | private Utils() { 10 | // Utility class 11 | } 12 | 13 | public static float[] listFloatToArray(List list) { 14 | int size = list != null ? list.size() : 0; 15 | float[] floatArr = new float[size]; 16 | for (int i = 0; i < size; i++) { 17 | floatArr[i] = list.get(i); 18 | } 19 | return floatArr; 20 | } 21 | 22 | public static int[] listIntToArray(List list) { 23 | return list.stream().mapToInt((Integer v) -> v).toArray(); 24 | } 25 | 26 | public static String readFile(String filePath) { 27 | String str; 28 | try { 29 | str = new String(Files.readAllBytes(Paths.get(filePath))); 30 | } catch (IOException excp) { 31 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 32 | } 33 | return str; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f invProjMatrix; 12 | private Matrix4f projMatrix; 13 | 14 | public Projection(int width, int height) { 15 | projMatrix = new Matrix4f(); 16 | invProjMatrix = new Matrix4f(); 17 | updateProjMatrix(width, height); 18 | } 19 | 20 | public Matrix4f getInvProjMatrix() { 21 | return invProjMatrix; 22 | } 23 | 24 | public Matrix4f getProjMatrix() { 25 | return projMatrix; 26 | } 27 | 28 | public void updateProjMatrix(int width, int height) { 29 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 30 | invProjMatrix.set(projMatrix).invert(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache, false); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-18/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-18/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_body.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_body_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_body_h.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_body_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_body_s.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_face.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_face_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_face_local.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_face_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_face_s.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_helmet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_helmet.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_helmet_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_helmet_h.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/guard1_helmet_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/guard1_helmet_s.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/iron_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/iron_grill.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/round_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/round_grill.png -------------------------------------------------------------------------------- /chapter-19/resources/models/bob/round_grill_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/bob/round_grill_h.png -------------------------------------------------------------------------------- /chapter-19/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-19/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-19/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-19/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-19/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-19/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-19/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-19/resources/shaders/lights.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 inPos; 4 | layout (location=1) in vec2 inCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | void main() 9 | { 10 | outTextCoord = inCoord; 11 | gl_Position = vec4(inPos, 1.0f); 12 | } -------------------------------------------------------------------------------- /chapter-19/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-19/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/Utils.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.*; 5 | import java.util.List; 6 | 7 | public class Utils { 8 | 9 | private Utils() { 10 | // Utility class 11 | } 12 | 13 | public static float[] listFloatToArray(List list) { 14 | int size = list != null ? list.size() : 0; 15 | float[] floatArr = new float[size]; 16 | for (int i = 0; i < size; i++) { 17 | floatArr[i] = list.get(i); 18 | } 19 | return floatArr; 20 | } 21 | 22 | public static int[] listIntToArray(List list) { 23 | return list.stream().mapToInt((Integer v) -> v).toArray(); 24 | } 25 | 26 | public static String readFile(String filePath) { 27 | String str; 28 | try { 29 | str = new String(Files.readAllBytes(Paths.get(filePath))); 30 | } catch (IOException excp) { 31 | throw new RuntimeException("Error reading file [" + filePath + "]", excp); 32 | } 33 | return str; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/graph/TextureCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class TextureCache { 6 | 7 | public static final String DEFAULT_TEXTURE = "resources/models/default/default_texture.png"; 8 | 9 | private Map textureMap; 10 | 11 | public TextureCache() { 12 | textureMap = new HashMap<>(); 13 | textureMap.put(DEFAULT_TEXTURE, new Texture(DEFAULT_TEXTURE)); 14 | } 15 | 16 | public void cleanup() { 17 | textureMap.values().forEach(Texture::cleanup); 18 | } 19 | 20 | public Texture createTexture(String texturePath) { 21 | return textureMap.computeIfAbsent(texturePath, Texture::new); 22 | } 23 | 24 | public Texture getTexture(String texturePath) { 25 | Texture texture = null; 26 | if (texturePath != null) { 27 | texture = textureMap.get(texturePath); 28 | } 29 | if (texture == null) { 30 | texture = textureMap.get(DEFAULT_TEXTURE); 31 | } 32 | return texture; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f invProjMatrix; 12 | private Matrix4f projMatrix; 13 | 14 | public Projection(int width, int height) { 15 | projMatrix = new Matrix4f(); 16 | invProjMatrix = new Matrix4f(); 17 | updateProjMatrix(width, height); 18 | } 19 | 20 | public Matrix4f getInvProjMatrix() { 21 | return invProjMatrix; 22 | } 23 | 24 | public Matrix4f getProjMatrix() { 25 | return projMatrix; 26 | } 27 | 28 | public void updateProjMatrix(int width, int height) { 29 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 30 | invProjMatrix.set(projMatrix).invert(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/scene/SkyBox.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.lwjglb.engine.graph.*; 4 | 5 | public class SkyBox { 6 | 7 | private Entity skyBoxEntity; 8 | private Model skyBoxModel; 9 | 10 | public SkyBox(String skyBoxModelPath, TextureCache textureCache) { 11 | skyBoxModel = ModelLoader.loadModel("skybox-model", skyBoxModelPath, textureCache, false); 12 | skyBoxEntity = new Entity("skyBoxEntity-entity", skyBoxModel.getId()); 13 | } 14 | 15 | public Entity getSkyBoxEntity() { 16 | return skyBoxEntity; 17 | } 18 | 19 | public Model getSkyBoxModel() { 20 | return skyBoxModel; 21 | } 22 | } -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-19/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-19/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-20/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-20/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-20/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-20/resources/models/cube/cube_old.obj: -------------------------------------------------------------------------------- 1 | mtllib cube.mtl 2 | o cube 3 | v -0.500000 -0.500000 0.500000 4 | v 0.500000 -0.500000 0.500000 5 | v -0.500000 0.500000 0.500000 6 | v 0.500000 0.500000 0.500000 7 | v -0.500000 0.500000 -0.500000 8 | v 0.500000 0.500000 -0.500000 9 | v -0.500000 -0.500000 -0.500000 10 | v 0.500000 -0.500000 -0.500000 11 | 12 | vt 0.000000 0.000000 13 | vt 1.000000 0.000000 14 | vt 0.000000 1.000000 15 | vt 1.000000 1.000000 16 | 17 | vn 0.000000 0.000000 1.000000 18 | vn 0.000000 1.000000 0.000000 19 | vn 0.000000 0.000000 -1.000000 20 | vn 0.000000 -1.000000 0.000000 21 | vn 1.000000 0.000000 0.000000 22 | vn -1.000000 0.000000 0.000000 23 | 24 | g cubemtl 25 | usemtl cubemtl 26 | f 1/1/1 2/2/1 3/3/1 27 | f 3/3/1 2/2/1 4/4/1 28 | f 3/1/2 4/2/2 5/3/2 29 | f 5/3/2 4/2/2 6/4/2 30 | f 5/4/3 6/3/3 7/2/3 31 | f 7/2/3 6/3/3 8/1/3 32 | f 7/1/4 8/2/4 1/3/4 33 | f 1/3/4 8/2/4 2/4/4 34 | f 2/1/5 8/2/5 4/3/5 35 | f 4/3/5 8/2/5 6/4/5 36 | f 7/1/6 1/2/6 5/3/6 37 | f 5/3/6 1/2/6 3/4/6 -------------------------------------------------------------------------------- /chapter-20/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-20/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-20/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-20/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-20/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-20/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-20/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-20/resources/shaders/lights.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 inPos; 4 | layout (location=1) in vec2 inCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | void main() 9 | { 10 | outTextCoord = inCoord; 11 | gl_Position = vec4(inPos, 1.0f); 12 | } -------------------------------------------------------------------------------- /chapter-20/resources/shaders/shadow.vert: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | const int MAX_DRAW_ELEMENTS = 100; 4 | const int MAX_ENTITIES = 50; 5 | 6 | layout (location=0) in vec3 position; 7 | layout (location=1) in vec3 normal; 8 | layout (location=2) in vec3 tangent; 9 | layout (location=3) in vec3 bitangent; 10 | layout (location=4) in vec2 texCoord; 11 | 12 | struct DrawElement 13 | { 14 | int modelMatrixIdx; 15 | }; 16 | 17 | uniform mat4 modelMatrix; 18 | uniform mat4 projViewMatrix; 19 | uniform DrawElement drawElements[MAX_DRAW_ELEMENTS]; 20 | uniform mat4 modelMatrices[MAX_ENTITIES]; 21 | 22 | void main() 23 | { 24 | vec4 initPos = vec4(position, 1.0); 25 | uint idx = gl_BaseInstance + gl_InstanceID; 26 | int modelMatrixIdx = drawElements[idx].modelMatrixIdx; 27 | mat4 modelMatrix = modelMatrices[modelMatrixIdx]; 28 | gl_Position = projViewMatrix * modelMatrix * initPos; 29 | } -------------------------------------------------------------------------------- /chapter-20/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-20/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/graph/MaterialCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class MaterialCache { 6 | 7 | public static final int DEFAULT_MATERIAL_IDX = 0; 8 | 9 | private List materialsList; 10 | 11 | public MaterialCache() { 12 | materialsList = new ArrayList<>(); 13 | Material defaultMaterial = new Material(); 14 | materialsList.add(defaultMaterial); 15 | } 16 | 17 | public void addMaterial(Material material) { 18 | materialsList.add(material); 19 | material.setMaterialIdx(materialsList.size() - 1); 20 | } 21 | 22 | public Material getMaterial(int idx) { 23 | return materialsList.get(idx); 24 | } 25 | 26 | public List getMaterialsList() { 27 | return materialsList; 28 | } 29 | } -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f invProjMatrix; 12 | private Matrix4f projMatrix; 13 | 14 | public Projection(int width, int height) { 15 | projMatrix = new Matrix4f(); 16 | invProjMatrix = new Matrix4f(); 17 | updateProjMatrix(width, height); 18 | } 19 | 20 | public Matrix4f getInvProjMatrix() { 21 | return invProjMatrix; 22 | } 23 | 24 | public Matrix4f getProjMatrix() { 25 | return projMatrix; 26 | } 27 | 28 | public void updateProjMatrix(int width, int height) { 29 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 30 | invProjMatrix.set(projMatrix).invert(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-20/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-20/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_body.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_body.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_body_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_body_h.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_body_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_body_s.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_face.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_face_local.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_face_local.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_face_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_face_s.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_helmet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_helmet.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_helmet_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_helmet_h.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/guard1_helmet_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/guard1_helmet_s.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/iron_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/iron_grill.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/round_grill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/round_grill.png -------------------------------------------------------------------------------- /chapter-21/resources/models/bob/round_grill_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/bob/round_grill_h.png -------------------------------------------------------------------------------- /chapter-21/resources/models/cube/cube.mtl: -------------------------------------------------------------------------------- 1 | newmtl cubemtl 2 | Kd 0.00 0.00 0.00 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | map_Kd cube.png -------------------------------------------------------------------------------- /chapter-21/resources/models/cube/cube.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/cube/cube.png -------------------------------------------------------------------------------- /chapter-21/resources/models/cube/cube_old.obj: -------------------------------------------------------------------------------- 1 | mtllib cube.mtl 2 | o cube 3 | v -0.500000 -0.500000 0.500000 4 | v 0.500000 -0.500000 0.500000 5 | v -0.500000 0.500000 0.500000 6 | v 0.500000 0.500000 0.500000 7 | v -0.500000 0.500000 -0.500000 8 | v 0.500000 0.500000 -0.500000 9 | v -0.500000 -0.500000 -0.500000 10 | v 0.500000 -0.500000 -0.500000 11 | 12 | vt 0.000000 0.000000 13 | vt 1.000000 0.000000 14 | vt 0.000000 1.000000 15 | vt 1.000000 1.000000 16 | 17 | vn 0.000000 0.000000 1.000000 18 | vn 0.000000 1.000000 0.000000 19 | vn 0.000000 0.000000 -1.000000 20 | vn 0.000000 -1.000000 0.000000 21 | vn 1.000000 0.000000 0.000000 22 | vn -1.000000 0.000000 0.000000 23 | 24 | g cubemtl 25 | usemtl cubemtl 26 | f 1/1/1 2/2/1 3/3/1 27 | f 3/3/1 2/2/1 4/4/1 28 | f 3/1/2 4/2/2 5/3/2 29 | f 5/3/2 4/2/2 6/4/2 30 | f 5/4/3 6/3/3 7/2/3 31 | f 7/2/3 6/3/3 8/1/3 32 | f 7/1/4 8/2/4 1/3/4 33 | f 1/3/4 8/2/4 2/4/4 34 | f 2/1/5 8/2/5 4/3/5 35 | f 4/3/5 8/2/5 6/4/5 36 | f 7/1/6 1/2/6 5/3/6 37 | f 5/3/6 1/2/6 3/4/6 -------------------------------------------------------------------------------- /chapter-21/resources/models/default/default_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lwjglgamedev/lwjglbook/31ec2d3746e7cacbba09f827272a728549851af6/chapter-21/resources/models/default/default_texture.png -------------------------------------------------------------------------------- /chapter-21/resources/models/skybox/skybox.mtl: -------------------------------------------------------------------------------- 1 | newmtl skybox 2 | Kd 0.65 0.65 0.65 3 | Ka 0.65 0.65 0.65 4 | Ks 0.65 0.65 0.65 -------------------------------------------------------------------------------- /chapter-21/resources/models/terrain/terrain.mtl: -------------------------------------------------------------------------------- 1 | newmtl terrain_mat 2 | Kd 0.59 0.45 0.35 3 | Ka 0.59 0.45 0.35 4 | Ks 0.59 0.45 0.35 5 | -------------------------------------------------------------------------------- /chapter-21/resources/models/terrain/terrain.obj: -------------------------------------------------------------------------------- 1 | mtllib terrain.mtl 2 | g default 3 | v 1.000000 0.000000 1.000000 4 | v -1.000000 0.000000 1.000000 5 | v -1.000000 0.000000 -1.000000 6 | v 1.000000 0.000000 -1.000000 7 | 8 | vt 1.000000 0.000000 9 | vt 0.000000 0.000000 10 | vt 0.000000 1.000000 11 | vt 1.000000 1.000000 12 | 13 | vn 0.000000 1.000000 0.000000 14 | 15 | f 1/1/1 3/3/1 4/4/1 16 | f 1/3/1 2/2/1 3/3/1 17 | -------------------------------------------------------------------------------- /chapter-21/resources/shaders/gui.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 frgTextCoords; 4 | in vec4 frgColor; 5 | 6 | uniform sampler2D txtSampler; 7 | 8 | out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = frgColor * texture(txtSampler, frgTextCoords); 13 | } -------------------------------------------------------------------------------- /chapter-21/resources/shaders/gui.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec2 inPos; 4 | layout (location=1) in vec2 inTextCoords; 5 | layout (location=2) in vec4 inColor; 6 | 7 | out vec2 frgTextCoords; 8 | out vec4 frgColor; 9 | 10 | uniform vec2 scale; 11 | 12 | void main() 13 | { 14 | frgTextCoords = inTextCoords; 15 | frgColor = inColor; 16 | gl_Position = vec4(inPos * scale + vec2(-1.0, 1.0), 0.0, 1.0); 17 | } -------------------------------------------------------------------------------- /chapter-21/resources/shaders/lights.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 inPos; 4 | layout (location=1) in vec2 inCoord; 5 | 6 | out vec2 outTextCoord; 7 | 8 | void main() 9 | { 10 | outTextCoord = inCoord; 11 | gl_Position = vec4(inPos, 1.0f); 12 | } -------------------------------------------------------------------------------- /chapter-21/resources/shaders/shadow.vert: -------------------------------------------------------------------------------- 1 | #version 460 2 | 3 | const int MAX_DRAW_ELEMENTS = 100; 4 | const int MAX_ENTITIES = 50; 5 | 6 | layout (location=0) in vec3 position; 7 | layout (location=1) in vec3 normal; 8 | layout (location=2) in vec3 tangent; 9 | layout (location=3) in vec3 bitangent; 10 | layout (location=4) in vec2 texCoord; 11 | 12 | struct DrawElement 13 | { 14 | int modelMatrixIdx; 15 | }; 16 | 17 | uniform mat4 modelMatrix; 18 | uniform mat4 projViewMatrix; 19 | uniform DrawElement drawElements[MAX_DRAW_ELEMENTS]; 20 | uniform mat4 modelMatrices[MAX_ENTITIES]; 21 | 22 | void main() 23 | { 24 | vec4 initPos = vec4(position, 1.0); 25 | uint idx = gl_BaseInstance + gl_InstanceID; 26 | int modelMatrixIdx = drawElements[idx].modelMatrixIdx; 27 | mat4 modelMatrix = modelMatrices[modelMatrixIdx]; 28 | gl_Position = projViewMatrix * modelMatrix * initPos; 29 | } -------------------------------------------------------------------------------- /chapter-21/resources/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 outTextCoord; 4 | out vec4 fragColor; 5 | 6 | uniform vec4 diffuse; 7 | uniform sampler2D txtSampler; 8 | uniform int hasTexture; 9 | 10 | void main() 11 | { 12 | if (hasTexture == 1) { 13 | fragColor = texture(txtSampler, outTextCoord); 14 | } else { 15 | fragColor = diffuse; 16 | } 17 | } -------------------------------------------------------------------------------- /chapter-21/resources/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout (location=0) in vec3 position; 4 | layout (location=1) in vec3 normal; 5 | layout (location=4) in vec2 texCoord; 6 | 7 | out vec2 outTextCoord; 8 | 9 | uniform mat4 projectionMatrix; 10 | uniform mat4 viewMatrix; 11 | uniform mat4 modelMatrix; 12 | 13 | void main() 14 | { 15 | gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0); 16 | outTextCoord = texCoord; 17 | } -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/IAppLogic.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.graph.Render; 4 | import org.lwjglb.engine.scene.Scene; 5 | 6 | public interface IAppLogic { 7 | 8 | void cleanup(); 9 | 10 | void init(Window window, Scene scene, Render render); 11 | 12 | void input(Window window, Scene scene, long diffTimeMillis, boolean inputConsumed); 13 | 14 | void update(Window window, Scene scene, long diffTimeMillis); 15 | } -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/IGuiInstance.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine; 2 | 3 | import org.lwjglb.engine.scene.Scene; 4 | 5 | public interface IGuiInstance { 6 | void drawGui(); 7 | 8 | boolean handleGuiInput(Scene scene, Window window); 9 | } 10 | -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/graph/MaterialCache.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.graph; 2 | 3 | import java.util.*; 4 | 5 | public class MaterialCache { 6 | 7 | public static final int DEFAULT_MATERIAL_IDX = 0; 8 | 9 | private List materialsList; 10 | 11 | public MaterialCache() { 12 | materialsList = new ArrayList<>(); 13 | Material defaultMaterial = new Material(); 14 | materialsList.add(defaultMaterial); 15 | } 16 | 17 | public void addMaterial(Material material) { 18 | materialsList.add(material); 19 | material.setMaterialIdx(materialsList.size() - 1); 20 | } 21 | 22 | public Material getMaterial(int idx) { 23 | return materialsList.get(idx); 24 | } 25 | 26 | public List getMaterialsList() { 27 | return materialsList; 28 | } 29 | } -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/scene/Fog.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class Fog { 6 | 7 | private boolean active; 8 | private Vector3f color; 9 | private float density; 10 | 11 | public Fog() { 12 | active = false; 13 | color = new Vector3f(); 14 | } 15 | 16 | public Fog(boolean active, Vector3f color, float density) { 17 | this.color = color; 18 | this.density = density; 19 | this.active = active; 20 | } 21 | 22 | public Vector3f getColor() { 23 | return color; 24 | } 25 | 26 | public float getDensity() { 27 | return density; 28 | } 29 | 30 | public boolean isActive() { 31 | return active; 32 | } 33 | 34 | public void setActive(boolean active) { 35 | this.active = active; 36 | } 37 | 38 | public void setColor(Vector3f color) { 39 | this.color = color; 40 | } 41 | 42 | public void setDensity(float density) { 43 | this.density = density; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/scene/Node.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | import java.util.*; 6 | 7 | public class Node { 8 | private final List children; 9 | 10 | private final String name; 11 | 12 | private final Node parent; 13 | 14 | private Matrix4f nodeTransformation; 15 | 16 | public Node(String name, Node parent, Matrix4f nodeTransformation) { 17 | this.name = name; 18 | this.parent = parent; 19 | this.nodeTransformation = nodeTransformation; 20 | this.children = new ArrayList<>(); 21 | } 22 | 23 | public void addChild(Node node) { 24 | this.children.add(node); 25 | } 26 | 27 | public List getChildren() { 28 | return children; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public Matrix4f getNodeTransformation() { 36 | return nodeTransformation; 37 | } 38 | 39 | public Node getParent() { 40 | return parent; 41 | } 42 | } -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/scene/Projection.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene; 2 | 3 | import org.joml.Matrix4f; 4 | 5 | public class Projection { 6 | 7 | private static final float FOV = (float) Math.toRadians(60.0f); 8 | private static final float Z_FAR = 1000.f; 9 | private static final float Z_NEAR = 0.01f; 10 | 11 | private Matrix4f invProjMatrix; 12 | private Matrix4f projMatrix; 13 | 14 | public Projection(int width, int height) { 15 | projMatrix = new Matrix4f(); 16 | invProjMatrix = new Matrix4f(); 17 | updateProjMatrix(width, height); 18 | } 19 | 20 | public Matrix4f getInvProjMatrix() { 21 | return invProjMatrix; 22 | } 23 | 24 | public Matrix4f getProjMatrix() { 25 | return projMatrix; 26 | } 27 | 28 | public void updateProjMatrix(int width, int height) { 29 | projMatrix.setPerspective(FOV, (float) width / height, Z_NEAR, Z_FAR); 30 | invProjMatrix.set(projMatrix).invert(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/scene/lights/AmbientLight.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.scene.lights; 2 | 3 | import org.joml.Vector3f; 4 | 5 | public class AmbientLight { 6 | 7 | private Vector3f color; 8 | 9 | private float intensity; 10 | 11 | public AmbientLight(float intensity, Vector3f color) { 12 | this.intensity = intensity; 13 | this.color = color; 14 | } 15 | 16 | public AmbientLight() { 17 | this(1.0f, new Vector3f(1.0f, 1.0f, 1.0f)); 18 | } 19 | 20 | public Vector3f getColor() { 21 | return color; 22 | } 23 | 24 | public float getIntensity() { 25 | return intensity; 26 | } 27 | 28 | public void setColor(Vector3f color) { 29 | this.color = color; 30 | } 31 | 32 | public void setColor(float r, float g, float b) { 33 | color.set(r, g, b); 34 | } 35 | 36 | public void setIntensity(float intensity) { 37 | this.intensity = intensity; 38 | } 39 | } -------------------------------------------------------------------------------- /chapter-21/src/main/java/org/lwjglb/engine/sound/SoundListener.java: -------------------------------------------------------------------------------- 1 | package org.lwjglb.engine.sound; 2 | 3 | import org.joml.Vector3f; 4 | 5 | import static org.lwjgl.openal.AL10.*; 6 | 7 | public class SoundListener { 8 | 9 | public SoundListener(Vector3f position) { 10 | alListener3f(AL_POSITION, position.x, position.y, position.z); 11 | alListener3f(AL_VELOCITY, 0, 0, 0); 12 | } 13 | 14 | public void setOrientation(Vector3f at, Vector3f up) { 15 | float[] data = new float[6]; 16 | data[0] = at.x; 17 | data[1] = at.y; 18 | data[2] = at.z; 19 | data[3] = up.x; 20 | data[4] = up.y; 21 | data[5] = up.z; 22 | alListenerfv(AL_ORIENTATION, data); 23 | } 24 | 25 | public void setPosition(Vector3f position) { 26 | alListener3f(AL_POSITION, position.x, position.y, position.z); 27 | } 28 | 29 | public void setSpeed(Vector3f speed) { 30 | alListener3f(AL_VELOCITY, speed.x, speed.y, speed.z); 31 | } 32 | } -------------------------------------------------------------------------------- /chapter-21/src/main/resources/tinylog.properties: -------------------------------------------------------------------------------- 1 | writer = console 2 | writer.format = {date: HH:mm:ss.SSS} [{level}] - [{class}] - {message} --------------------------------------------------------------------------------