├── .appveyor.yml ├── .bintray.json ├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── bin └── assets │ └── shaders │ └── GLUL │ ├── AABB.fp │ ├── AABB.vp │ ├── G2D │ ├── Default.fp │ ├── Default.vp │ ├── Textured.fp │ └── Textured.vp │ ├── GL++ │ └── Models │ │ ├── MeshOBJ.fp │ │ └── MeshOBJ.vp │ └── GUI │ ├── Button.fp │ ├── Button.vp │ ├── Text.fp │ └── Text.vp ├── examples ├── 2d │ ├── bin │ │ └── assets │ │ │ ├── fonts │ │ │ └── arial.ttf │ │ │ └── textures │ │ │ └── tex.bmp │ └── src │ │ └── main.cpp ├── basic │ ├── bin │ │ └── assets │ │ │ └── shaders │ │ │ ├── basic.fp │ │ │ └── basic.vp │ └── src │ │ └── main.cpp ├── font │ ├── bin │ │ └── assets │ │ │ ├── fonts │ │ │ ├── arial.ttf │ │ │ └── verdanai.ttf │ │ │ └── shaders │ │ │ ├── font.fp │ │ │ └── font.vp │ └── src │ │ └── main.cpp ├── framework │ └── src │ │ ├── ExampleState.cpp │ │ ├── ExampleState.h │ │ └── main.cpp ├── gui │ ├── bin │ │ └── assets │ │ │ └── fonts │ │ │ ├── arial.ttf │ │ │ └── verdanai.ttf │ └── src │ │ └── main.cpp ├── image │ ├── bin │ │ └── assets │ │ │ ├── images │ │ │ ├── image0.bmp │ │ │ ├── image1.tga │ │ │ ├── image2.jpg │ │ │ └── image3.png │ │ │ └── shaders │ │ │ ├── image.fp │ │ │ └── image.vp │ └── src │ │ └── main.cpp ├── input │ └── src │ │ └── main.cpp └── models │ ├── bin │ └── assets │ │ └── models │ │ ├── suzanne │ │ └── suzanne.obj │ │ └── teapot │ │ ├── teapot.mtl │ │ └── teapot.obj │ └── src │ ├── InitializationState.cpp │ ├── InitializationState.h │ ├── WorkState.cpp │ ├── WorkState.h │ └── main.cpp ├── include └── GLUL │ ├── AABB.h │ ├── Clock.h │ ├── Config.h │ ├── Exception.h │ ├── Exceptions │ ├── FatalError.h │ ├── InitializationFailed.h │ └── InvalidArgument.h │ ├── File.h │ ├── Frameworks │ └── Application.h │ ├── G2D │ ├── Batch.h │ ├── Circle.h │ ├── Disk.h │ ├── Font.h │ ├── HorizontalAlignment.h │ ├── Line.h │ ├── LineLoop.h │ ├── LineStrip.h │ ├── Point.h │ ├── Primitive.h │ ├── Quad.h │ ├── Rectangle.h │ ├── Ring.h │ ├── Shape.h │ ├── Text.h │ ├── TexturedBatch.h │ ├── TexturedPoint.h │ ├── TexturedPrimitive.h │ ├── TexturedQuad.h │ ├── TexturedRectangle.h │ ├── TexturedShape.h │ ├── TexturedTriangle.h │ ├── Triangle.h │ ├── TriangleFan.h │ └── TriangleStrip.h │ ├── GL++ │ ├── Buffer.h │ ├── Buffer.hpp │ ├── Context.h │ ├── Framebuffer.h │ ├── MatrixStack.h │ ├── Models │ │ ├── Material.h │ │ ├── Mesh.h │ │ └── OBJ.h │ ├── Pipeline.h │ ├── PixelBuffer.h │ ├── Program.h │ ├── Shader.h │ ├── Texture.h │ ├── Uniform.h │ ├── VertexArray.h │ ├── VertexAttrib.h │ └── VertexBuffer.h │ ├── GUI │ ├── Button.h │ ├── Checkbox.h │ ├── Component.h │ ├── Container.h │ ├── Events │ │ ├── EventTemplate.hpp │ │ ├── Focus.h │ │ ├── FocusLoss.h │ │ ├── HandlerAggregator.hpp │ │ ├── KeyStroke.h │ │ ├── MouseClick.h │ │ ├── MouseEnter.h │ │ ├── MouseLeave.h │ │ ├── MouseMove.h │ │ ├── MouseRelease.h │ │ ├── TextInput.h │ │ └── ValueChange.hpp │ ├── Font.h │ ├── InnerText.h │ ├── Panel.h │ ├── ProgressBar.h │ ├── RadioButton.h │ ├── RadioButtonGroup.h │ ├── Slider.h │ ├── Styles │ │ ├── Border.h │ │ ├── HorizontalAlignment.h │ │ ├── Orientation.h │ │ └── VerticalAlignment.h │ ├── Text.h │ ├── TextField.h │ └── Window.h │ ├── Helpers │ └── HashEnum.h │ ├── Image.h │ ├── Input │ ├── Event.h │ ├── EventAggregator.h │ ├── EventHandler.h │ ├── EventTrigger.h │ ├── EventTypes │ │ ├── CharacterEvent.h │ │ ├── KeyEvent.h │ │ ├── MouseButtonEvent.h │ │ ├── MouseMovementEvent.h │ │ └── MouseScrollEvent.h │ ├── Keyboard.h │ ├── Mouse.h │ └── Types.h │ ├── Interfaces │ ├── Camera.h │ ├── ImageFile.h │ ├── Implementations │ │ ├── ImageFileBMP.h │ │ ├── ImageFileJPG.h │ │ ├── ImageFilePNG.h │ │ └── ImageFileTGA.h │ ├── MVC │ │ ├── ExtendedView.h │ │ └── View.h │ ├── Model.h │ └── State.h │ ├── Line.h │ ├── Logger.h │ ├── Point.h │ ├── Rectangle.h │ ├── String.h │ ├── TimeEvent.h │ ├── TimeLoop.h │ ├── Timer.h │ ├── Window.h │ └── Windows.h ├── project └── msvc │ ├── Examples │ ├── 2D example │ │ ├── 2D example.vcxproj │ │ ├── 2D example.vcxproj.filters │ │ └── 2D example.vcxproj.user │ ├── Basic example │ │ ├── Basic example.vcxproj │ │ ├── Basic example.vcxproj.filters │ │ └── Basic example.vcxproj.user │ ├── Font example │ │ ├── Font example.vcxproj │ │ ├── Font example.vcxproj.filters │ │ └── Font example.vcxproj.user │ ├── Framework example │ │ ├── Framework example.vcxproj │ │ ├── Framework example.vcxproj.filters │ │ └── Framework example.vcxproj.user │ ├── GUI example │ │ ├── GUI example.vcxproj │ │ ├── GUI example.vcxproj.filters │ │ └── GUI example.vcxproj.user │ ├── Image example │ │ ├── Image example.vcxproj │ │ ├── Image example.vcxproj.filters │ │ └── Image example.vcxproj.user │ ├── Input example │ │ ├── Input example.vcxproj │ │ ├── Input example.vcxproj.filters │ │ └── Input example.vcxproj.user │ └── Models example │ │ ├── Models example.vcxproj │ │ ├── Models example.vcxproj.filters │ │ └── Models example.vcxproj.user │ ├── GLUL.sln │ ├── GLUL │ ├── GLUL.vcxproj │ ├── GLUL.vcxproj.filters │ └── GLUL.vcxproj.user │ └── Tests │ └── Unit tests │ ├── Unit tests.vcxproj │ ├── Unit tests.vcxproj.filters │ └── Unit tests.vcxproj.user ├── scripts ├── linux │ └── install_dependencies.sh └── windows │ ├── install_msvc_dependencies.bat │ └── run_unit_tests.bat ├── src └── GLUL │ ├── AABB.cpp │ ├── Clock.cpp │ ├── Exception.cpp │ ├── Exceptions │ ├── FatalError.cpp │ ├── InitializationFailed.cpp │ └── InvalidArgument.cpp │ ├── File.cpp │ ├── Frameworks │ └── Application.cpp │ ├── G2D │ ├── Batch.cpp │ ├── Circle.cpp │ ├── Disk.cpp │ ├── Font.cpp │ ├── Line.cpp │ ├── LineLoop.cpp │ ├── LineStrip.cpp │ ├── Point.cpp │ ├── Primitive.cpp │ ├── Quad.cpp │ ├── Rectangle.cpp │ ├── Ring.cpp │ ├── Text.cpp │ ├── TexturedBatch.cpp │ ├── TexturedPoint.cpp │ ├── TexturedPrimitive.cpp │ ├── TexturedQuad.cpp │ ├── TexturedRectangle.cpp │ ├── TexturedTriangle.cpp │ ├── Triangle.cpp │ ├── TriangleFan.cpp │ └── TriangleStrip.cpp │ ├── GL++ │ ├── Buffer.cpp │ ├── Context.cpp │ ├── Framebuffer.cpp │ ├── MatrixStack.cpp │ ├── Models │ │ ├── Material.cpp │ │ ├── Mesh.cpp │ │ └── OBJ.cpp │ ├── Pipeline.cpp │ ├── PixelBuffer.cpp │ ├── Program.cpp │ ├── Shader.cpp │ ├── Texture.cpp │ ├── Uniform.cpp │ ├── VertexArray.cpp │ ├── VertexAttrib.cpp │ └── VertexBuffer.cpp │ ├── GUI │ ├── Button.cpp │ ├── Checkbox.cpp │ ├── Component.cpp │ ├── Container.cpp │ ├── Events │ │ ├── KeyStroke.cpp │ │ ├── MouseClick.cpp │ │ ├── MouseEnter.cpp │ │ ├── MouseLeave.cpp │ │ ├── MouseMove.cpp │ │ ├── MouseRelease.cpp │ │ └── TextInput.cpp │ ├── Font.cpp │ ├── InnerText.cpp │ ├── Panel.cpp │ ├── ProgressBar.cpp │ ├── RadioButton.cpp │ ├── RadioButtonGroup.cpp │ ├── Slider.cpp │ ├── Styles │ │ └── Border.cpp │ ├── Text.cpp │ ├── TextField.cpp │ └── Window.cpp │ ├── Image.cpp │ ├── Input │ ├── Event.cpp │ ├── EventAggregator.cpp │ ├── EventHandler.cpp │ ├── EventTrigger.cpp │ ├── EventTypes │ │ ├── CharacterEvent.cpp │ │ ├── KeyEvent.cpp │ │ ├── MouseButtonEvent.cpp │ │ ├── MouseMovementEvent.cpp │ │ └── MouseScrollEvent.cpp │ ├── Keyboard.cpp │ └── Mouse.cpp │ ├── Interfaces │ ├── Camera.cpp │ ├── ImageFile.cpp │ ├── Implementations │ │ ├── ImageFileBMP.cpp │ │ ├── ImageFileJPG.cpp │ │ ├── ImageFilePNG.cpp │ │ └── ImageFileTGA.cpp │ ├── Model.cpp │ └── State.cpp │ ├── Line.cpp │ ├── Logger.cpp │ ├── Point.cpp │ ├── Rectangle.cpp │ ├── String.cpp │ ├── TimeEvent.cpp │ ├── TimeLoop.cpp │ ├── Timer.cpp │ ├── Window.cpp │ └── Windows.cpp └── tests ├── bin └── test_assets │ ├── file │ ├── emptylines.txt │ ├── multilinetextfield.txt │ └── textfile.txt │ └── image │ ├── image.bmp │ ├── image.jpg │ ├── image.png │ ├── image.tga │ ├── image_cropping_test.bmp │ ├── image_greyscale.bmp │ ├── image_invert_colors.bmp │ ├── image_invert_h.bmp │ ├── image_invert_v.bmp │ ├── image_r180.bmp │ ├── image_r270.bmp │ └── image_r90.bmp └── src ├── GLUL ├── Clock.cpp ├── File.cpp ├── Image.cpp ├── Line.cpp ├── Point.cpp └── String.cpp └── main.cpp /.bintray.json: -------------------------------------------------------------------------------- 1 | { 2 | "package": { 3 | "name": "GLUL", 4 | "repo": "generic", 5 | "subject": "ripper37", 6 | "desc": "GLUL - OpenGL Utility Library", 7 | "website_url": "https://github.com/RippeR37/GLUL", 8 | "issue_tracker_url": "https://github.com/RippeR37/GLUL/issues", 9 | "vcs_url": "https://github.com/RippeR37/GLUL.git", 10 | "github_use_tag_release_notes": true, 11 | "github_release_notes_file": "README.md", 12 | "licenses": [ "MIT" ], 13 | "labels": [], 14 | "public_download_numbers": false, 15 | "public_stats": false, 16 | "attributes": [] 17 | }, 18 | 19 | "version": { 20 | "name": "0.3", 21 | "desc": "GLUL v0.3", 22 | "released": "2015-09-15", 23 | "vcs_tag": "v0.3", 24 | "attributes": [], 25 | "gpgSign": false 26 | }, 27 | 28 | "files": [ 29 | { 30 | "includePattern": "deploy/ubuntu/(.*\.tar.gz)", 31 | "uploadPattern": "linux/ubuntu/12.04/$1", 32 | "matrixParams": { 33 | "override": 1 34 | } 35 | } 36 | ], 37 | 38 | "publish": true 39 | 40 | } 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sdf 2 | *.opensdf 3 | *.pdb 4 | *.dll 5 | *.lib 6 | *.exe 7 | *.log 8 | *.ilk 9 | *.suo 10 | *.exp 11 | 12 | examples/*/bin/assets/*/GLUL/* 13 | examples/image/bin/lastImage.* 14 | examples/image/bin/screenshot.* 15 | 16 | libs/* 17 | personal/* 18 | 19 | project/msvc/Build/* 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Damian Dyńdo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/AABB.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 color; 4 | 5 | void main() { 6 | color = vec4(1.0, 0.0, 0.0, 1.0); 7 | } -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/AABB.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 vPos; 4 | 5 | uniform mat4 matrixMVP; 6 | 7 | void main() { 8 | gl_Position = matrixMVP * vec4(vPos, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/G2D/Default.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec4 fragmentColor; 4 | out vec4 finalColor; 5 | 6 | 7 | void main() { 8 | finalColor = fragmentColor; 9 | } 10 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/G2D/Default.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexData; 4 | layout(location = 1) in vec4 vertexColor; 5 | out vec4 fragmentColor; 6 | 7 | uniform vec2 windowSize; 8 | 9 | 10 | vec2 screenToDevice(vec2 position) { 11 | vec2 halfWindowSize = windowSize * 0.5; 12 | 13 | return (position / halfWindowSize) - 1.0; 14 | } 15 | 16 | void main() { 17 | gl_Position = vec4(screenToDevice(vertexData.xy), 0.0, 1.0); 18 | fragmentColor = vertexColor; 19 | } 20 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/G2D/Textured.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec4 fragmentColor; 4 | in vec2 fragmentUV; 5 | 6 | out vec4 finalColor; 7 | 8 | uniform sampler2D texSampler; 9 | 10 | 11 | void main() { 12 | finalColor = fragmentColor * texture(texSampler, fragmentUV); 13 | } 14 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/G2D/Textured.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexData; 4 | layout(location = 1) in vec4 vertexColor; 5 | 6 | out vec4 fragmentColor; 7 | out vec2 fragmentUV; 8 | 9 | uniform vec2 windowSize; 10 | 11 | 12 | vec2 screenToDevice(vec2 position) { 13 | vec2 halfWindowSize = windowSize * 0.5; 14 | 15 | return (position / halfWindowSize) - 1.0; 16 | } 17 | 18 | void main() { 19 | gl_Position = vec4(screenToDevice(vertexData.xy), 0.0, 1.0); 20 | 21 | fragmentColor = vertexColor; 22 | fragmentUV = vertexData.zw; 23 | } 24 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GL++/Models/MeshOBJ.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec2 fragmentUV; 4 | in vec3 fragmentNormal; 5 | in vec3 fragmentPosition; 6 | 7 | out vec4 color; 8 | 9 | uniform vec4 uColorD; 10 | uniform vec4 uColorA; 11 | uniform vec4 uColorS; 12 | 13 | uniform bvec4 hasTextures; 14 | uniform sampler2D texSampler; 15 | 16 | const float diffuseFactor = 0.5; 17 | const float ambientFactor = 0.3; 18 | const float specularFactor = 0.0; 19 | 20 | void main() { 21 | vec3 fragmentNormalNormalized = normalize(fragmentNormal); 22 | 23 | vec3 cameraPos = vec3(-1, 0.5, -4.0); 24 | vec3 lightDir = normalize(vec3(-1.0, 1.0, 0.5)); 25 | vec3 cameraToFragmentDir = fragmentPosition - cameraPos; 26 | 27 | float diffuseCosine = clamp(dot(fragmentNormalNormalized, lightDir), 0.0, 1.0); 28 | float specularPower = uColorS.a; 29 | float specularCosine = clamp(dot(normalize(cameraToFragmentDir), reflect(lightDir, fragmentNormalNormalized)), 0.0, 1.0); 30 | float specularCosineP = pow(specularCosine, specularPower); 31 | 32 | vec3 lightColor = vec3(1.0, 1.0, 1.0); 33 | 34 | if(hasTextures.x) 35 | lightColor = texture(texSampler, fragmentUV).rgb; 36 | 37 | color.rgb = vec3(0.0); 38 | color.rgb += uColorA.rgb * ambientFactor; 39 | color.rgb += uColorD.rgb * lightColor * diffuseFactor * diffuseCosine; 40 | color.rgb += uColorS.rgb * lightColor * specularFactor * specularCosineP; 41 | color.a = uColorA.a; 42 | } -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GL++/Models/MeshOBJ.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 vPos; 4 | layout(location = 1) in vec2 vTex; 5 | layout(location = 2) in vec3 vNor; 6 | 7 | out vec2 fragmentUV; 8 | out vec3 fragmentNormal; 9 | out vec3 fragmentPosition; 10 | 11 | uniform mat4 matrixMVP; 12 | 13 | void main() { 14 | gl_Position = matrixMVP * vec4(vPos, 1.0); 15 | 16 | fragmentUV = vTex; 17 | fragmentNormal = vNor; 18 | fragmentPosition = vPos; 19 | } -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GUI/Button.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec4 fragmentColor; 4 | out vec4 color; 5 | 6 | void main() { 7 | color = fragmentColor; 8 | } -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GUI/Button.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexData; 4 | layout(location = 1) in vec4 vertexColor; 5 | 6 | out vec4 fragmentColor; 7 | 8 | vec2 screenToDevice(vec2 position) { 9 | vec2 result; 10 | 11 | result.x = (position.x / 400.0) - 1.0; 12 | result.y = (position.y / 300.0) - 1.0; 13 | 14 | return result; 15 | } 16 | 17 | void main() { 18 | gl_Position = vec4(screenToDevice(vertexData.xy), 0.0, 1.0); 19 | 20 | fragmentColor = vertexColor; 21 | } 22 | -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GUI/Text.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec2 texCoords; 4 | 5 | out vec4 color; 6 | 7 | uniform sampler2D glyphAtlas; 8 | 9 | uniform vec4 fontColor; 10 | 11 | void main() { 12 | color = vec4(fontColor.rgb, fontColor.a * texture(glyphAtlas, texCoords).r); 13 | } -------------------------------------------------------------------------------- /bin/assets/shaders/GLUL/GUI/Text.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexData; 4 | 5 | out vec2 texCoords; 6 | 7 | vec2 screenToDevice(vec2 position) { 8 | vec2 result; 9 | 10 | result.x = (position.x / 400.0) - 1.0; 11 | result.y = (position.y / 300.0) - 1.0; 12 | 13 | return result; 14 | } 15 | 16 | void main() { 17 | texCoords = vertexData.zw; 18 | 19 | gl_Position = vec4(screenToDevice(vertexData.xy), 0.0, 1.0); 20 | } 21 | -------------------------------------------------------------------------------- /examples/2d/bin/assets/fonts/arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/2d/bin/assets/fonts/arial.ttf -------------------------------------------------------------------------------- /examples/2d/bin/assets/textures/tex.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/2d/bin/assets/textures/tex.bmp -------------------------------------------------------------------------------- /examples/basic/bin/assets/shaders/basic.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 color; 4 | 5 | void main() { 6 | color = vec4(0.0, 1.0, 0.0, 1.0); 7 | } -------------------------------------------------------------------------------- /examples/basic/bin/assets/shaders/basic.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexPosition; 4 | 5 | void main() { 6 | gl_Position = vertexPosition; 7 | } 8 | -------------------------------------------------------------------------------- /examples/font/bin/assets/fonts/arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/font/bin/assets/fonts/arial.ttf -------------------------------------------------------------------------------- /examples/font/bin/assets/fonts/verdanai.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/font/bin/assets/fonts/verdanai.ttf -------------------------------------------------------------------------------- /examples/font/bin/assets/shaders/font.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec2 texCoords; 4 | 5 | out vec4 color; 6 | 7 | uniform sampler2D texSampler; 8 | 9 | void main() { 10 | color = vec4(texture(texSampler, texCoords).r, 0.0, 0.0, 1.0); 11 | } -------------------------------------------------------------------------------- /examples/font/bin/assets/shaders/font.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexData; 4 | 5 | out vec2 texCoords; 6 | 7 | void main() { 8 | vec4 position = vec4(vertexData.xy, 0.0, 1.0); 9 | 10 | texCoords = vertexData.zw; 11 | 12 | gl_Position = position; 13 | } 14 | -------------------------------------------------------------------------------- /examples/framework/src/ExampleState.cpp: -------------------------------------------------------------------------------- 1 | #include "ExampleState.h" 2 | 3 | #include 4 | #include 5 | 6 | ExampleState::ExampleState(FW::Application& application) : Application(application) { } 7 | 8 | ExampleState::~ExampleState() {} 9 | 10 | void ExampleState::update(const double frameTime) { 11 | GLUL::TimeLoop::semiFixed(frameTime, 1.0f / 120.0f, [](double deltaTime) {(void)deltaTime; }); 12 | } 13 | 14 | void ExampleState::render() { 15 | GL::Context::Current->clearBuffers(GL::Context::BufferMask::Color); 16 | } 17 | 18 | void ExampleState::onLoad() { 19 | // Window 20 | Application.Window.setSize(800u, 600u); 21 | Application.Window.setTitle("Title"); 22 | Application.Window.create(); 23 | Application.Window.registerEvents(); 24 | Application.Window.setDestroyCallback([&]() { Application.signalExit(); }); 25 | 26 | // OpenGL context settings 27 | GL::Context::Current->setClearColor(glm::vec4(0.1f, 0.1f, 0.1f, 1.0f)); 28 | 29 | // Registering state as event handler 30 | GLUL::Windows::Get("FW::Application::Window::1")->eventAggregator.registerHandler(GLUL::Input::Event::Type::Key, this); 31 | } 32 | 33 | void ExampleState::onUnload() { 34 | // cleanup 35 | 36 | // Unregistering state as event handler 37 | GLUL::Windows::Get("FW::Application::Window::1")->eventAggregator.unregisterHandler(GLUL::Input::Event::Type::Key, this); 38 | } 39 | 40 | void ExampleState::signalExit() { 41 | changeTo(nullptr); 42 | } 43 | 44 | void ExampleState::handleInputEvent(const GLUL::Input::Event& inputEvent) { 45 | if(inputEvent.getType() == GLUL::Input::Event::Type::Key) { 46 | const GLUL::Input::KeyEvent& keyEvent = *inputEvent.asKeyEvent(); 47 | 48 | if(keyEvent.getAction() == GLUL::Input::Action::Press) { 49 | switch(keyEvent.getKey()) { 50 | case GLUL::Input::Key::Escacpe: 51 | signalExit(); break; 52 | 53 | default: 54 | break; 55 | } 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /examples/framework/src/ExampleState.h: -------------------------------------------------------------------------------- 1 | #ifndef EXAMPLESTATE_H_INCLUDED 2 | #define EXAMPLESTATE_H_INCLUDED 3 | 4 | #include 5 | 6 | class ExampleState : public GLUL::Interface::State { 7 | public: 8 | ExampleState(FW::Application& application); 9 | ~ExampleState(); 10 | 11 | ExampleState& operator=(const ExampleState&) = delete; 12 | 13 | void update(const double frameTime); 14 | void render(); 15 | void onLoad(); 16 | void onUnload(); 17 | void signalExit(); 18 | 19 | void handleInputEvent(const GLUL::Input::Event& inputEvent); 20 | 21 | private: 22 | FW::Application& Application; 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /examples/framework/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ExampleState.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | try { 9 | FW::Application application; 10 | ExampleState initialState(application); 11 | 12 | application.setArguments(argc, argv); 13 | application.run(&initialState); 14 | 15 | } catch(const GLUL::Exception::FatalError& exception) { 16 | GLUL::Log::Stream("Example", "logExample.log") << "Cought fatal error exception: " + std::string(exception.what()); 17 | return 1; 18 | 19 | } catch(const std::exception& exception) { 20 | GLUL::Log::Stream("Example", "logExample.log") << "Cought std::exception: " + std::string(exception.what()); 21 | return 1; 22 | 23 | } catch(...) { 24 | GLUL::Log::Stream("Example", "logExample.log") << "Cought unknown exception!"; 25 | return 1; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /examples/gui/bin/assets/fonts/arial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/gui/bin/assets/fonts/arial.ttf -------------------------------------------------------------------------------- /examples/gui/bin/assets/fonts/verdanai.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/gui/bin/assets/fonts/verdanai.ttf -------------------------------------------------------------------------------- /examples/image/bin/assets/images/image0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/image/bin/assets/images/image0.bmp -------------------------------------------------------------------------------- /examples/image/bin/assets/images/image1.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/image/bin/assets/images/image1.tga -------------------------------------------------------------------------------- /examples/image/bin/assets/images/image2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/image/bin/assets/images/image2.jpg -------------------------------------------------------------------------------- /examples/image/bin/assets/images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/examples/image/bin/assets/images/image3.png -------------------------------------------------------------------------------- /examples/image/bin/assets/shaders/image.fp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | in vec2 texCoords; 4 | 5 | out vec4 color; 6 | 7 | uniform sampler2D textureSampler; 8 | 9 | void main() { 10 | color = vec4(texture(textureSampler, texCoords).rgba); 11 | } -------------------------------------------------------------------------------- /examples/image/bin/assets/shaders/image.vp: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec4 vertexPositionTexCoords; 4 | 5 | out vec2 texCoords; 6 | 7 | void main() { 8 | gl_Position = vec4(vertexPositionTexCoords.xy, 0.0, 1.0); 9 | 10 | texCoords = vertexPositionTexCoords.zw; 11 | } 12 | -------------------------------------------------------------------------------- /examples/models/bin/assets/models/teapot/teapot.mtl: -------------------------------------------------------------------------------- 1 | # Test material made myself 2 | # Materials: 1 3 | 4 | newmtl green 5 | Ns 100.0 6 | Ka 0.000000 0.150000 0.000000 7 | Kd 0.150000 0.800000 0.150000 8 | Ks 0.330000 0.330000 0.330000 9 | Ns 35.00000 10 | d 1.000000 11 | illum 2 -------------------------------------------------------------------------------- /examples/models/src/InitializationState.cpp: -------------------------------------------------------------------------------- 1 | #include "InitializationState.h" 2 | 3 | #include 4 | #include 5 | 6 | InitializationState::InitializationState(FW::Application* application) { 7 | _application = application; 8 | } 9 | 10 | InitializationState::~InitializationState() { 11 | 12 | } 13 | 14 | void InitializationState::update(const double frameTime) { 15 | if(_workState) 16 | _workState->update(frameTime); 17 | } 18 | 19 | void InitializationState::render() { 20 | if(_workState) 21 | _workState->render(); 22 | } 23 | 24 | void InitializationState::onLoad() { 25 | if(!_workState) { 26 | if(_application) { 27 | // Window initialization 28 | _application->Window.setSize(800u, 600u); 29 | _application->Window.setTitle("Title"); 30 | _application->Window.create(); 31 | _application->Window.registerEvents(GLUL::Input::Event::Type::Key); 32 | _application->Window.setDestroyCallback([&]() { 33 | _application->signalExit(); 34 | }); 35 | 36 | // Set window's background color 37 | GL::Context::Current->setClearColor(glm::vec4(0.1f, 0.1f, 0.1f, 1.0f)); 38 | 39 | // Change to application's main state 40 | _workState.reset(new WorkState(this)); 41 | changeTo(_workState.get()); 42 | } 43 | 44 | } else { 45 | _workState.reset(nullptr); 46 | changeTo(nullptr); //otherwise - quit 47 | } 48 | } 49 | 50 | void InitializationState::onUnload() { 51 | if(!_workState) { 52 | _application->Window.destroy(); 53 | } 54 | } 55 | 56 | void InitializationState::signalExit() { 57 | changeTo(nullptr); 58 | } -------------------------------------------------------------------------------- /examples/models/src/InitializationState.h: -------------------------------------------------------------------------------- 1 | #ifndef INITIALIZATIONSTATE_H_INCLUDED 2 | #define INITIALIZATIONSTATE_H_INCLUDED 3 | 4 | #include "WorkState.h" 5 | 6 | #include 7 | 8 | #include 9 | 10 | class InitializationState : public GLUL::Interface::State { 11 | public: 12 | InitializationState(FW::Application* application); 13 | ~InitializationState(); 14 | 15 | void update(const double frameTime); 16 | void render(); 17 | void onLoad(); 18 | void onUnload(); 19 | void signalExit(); 20 | 21 | private: 22 | FW::Application* _application; 23 | std::unique_ptr _workState; 24 | }; 25 | 26 | #endif -------------------------------------------------------------------------------- /examples/models/src/WorkState.h: -------------------------------------------------------------------------------- 1 | #ifndef WORKSTATE_H_INCLUDED 2 | #define WORKSTATE_H_INCLUDED 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | class WorkState : public GLUL::Interface::State { 10 | public: 11 | WorkState(GLUL::Interface::State* parentState); 12 | ~WorkState(); 13 | 14 | void update(const double frameTime); 15 | void render(); 16 | void onLoad(); 17 | void onUnload(); 18 | void signalExit(); 19 | 20 | void handleInputEvent(const GLUL::Input::Event& inputEvent); 21 | 22 | private: 23 | GLUL::Interface::State* _parentState; 24 | 25 | GL::Pipeline _pipeline; 26 | GL::Model::OBJ _modelOBJ[2]; 27 | 28 | }; 29 | 30 | #endif -------------------------------------------------------------------------------- /examples/models/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "InitializationState.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char* argv[]) { 8 | try { 9 | FW::Application application; 10 | InitializationState initialState(&application); 11 | 12 | application.setArguments(argc, argv); 13 | application.run(&initialState); 14 | 15 | } catch(const GLUL::Exception::FatalError& exception) { 16 | GLUL::Log::Stream("Example", "logExample.log") << "Cought fatal error exception: " + std::string(exception.what()); 17 | return 1; 18 | 19 | } catch(const std::exception& exception) { 20 | GLUL::Log::Stream("Example", "logExample.log") << "Cought std::exception: " + std::string(exception.what()); 21 | return 1; 22 | 23 | } catch(...) { 24 | GLUL::Log::Stream("Example", "logExample.log") << "Cought unknown exception!"; 25 | return 1; 26 | } 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /include/GLUL/AABB.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | class GLUL_API AABB { 14 | public: 15 | AABB(); 16 | AABB(const glm::vec3& min, const glm::vec3& max); 17 | 18 | void clear(); 19 | 20 | bool intersect(const AABB& box2) const; 21 | void render(const GL::Pipeline& pipeline) const; 22 | void updateBy(const glm::vec3& vertex); 23 | 24 | void setMin(const glm::vec3& min); 25 | void setMax(const glm::vec3& max); 26 | void setMin(float x, float y, float z); 27 | void setMax(float x, float y, float z); 28 | 29 | void setMinX(float x); 30 | void setMinY(float y); 31 | void setMinZ(float z); 32 | void setMaxX(float x); 33 | void setMaxY(float y); 34 | void setMaxZ(float z); 35 | 36 | const glm::vec3& getMin() const; 37 | const glm::vec3& getMax() const; 38 | glm::vec3 getCenter() const; 39 | 40 | public: 41 | static bool intersect(const AABB& box1, const AABB& box2); 42 | static void render(const AABB& box, const GL::Pipeline& pipeline); 43 | static void setLines(const AABB& box, std::vector& lines); 44 | static std::vector getLines(const AABB& box); 45 | 46 | private: 47 | bool _initialized; 48 | glm::vec3 _min; 49 | glm::vec3 _max; 50 | }; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/GLUL/Config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | /** 5 | * Versions 6 | */ 7 | #define GLUL_VERSION_MAJOR 0 8 | #define GLUL_VERSION_MINOR 3 9 | #define GLUL_VERSION_PATCH 0 10 | 11 | 12 | /** 13 | * Identify OS 14 | */ 15 | #if defined(_WIN32) 16 | #define GLUL_OS_WINDOWS 17 | #elif defined(__APPLE__) && defined(__MACH__) 18 | #define GLUL_OS_OSX 19 | #elif defined(__unix__) && defined(__linux__) 20 | #define GLUL_OS_LINUX 21 | #else 22 | #error This operating system is not supported by this library. 23 | #endif 24 | 25 | 26 | /** 27 | * Portable import/export macros for DLL build targets 28 | */ 29 | #if defined(GLUL_DLL) 30 | 31 | #if defined(GLUL_OS_WINDOWS) 32 | 33 | #define GLUL_API_EXPORT __declspec(dllexport) 34 | #define GLUL_API_IMPORT __declspec(dllimport) 35 | 36 | #ifdef _MSC_VER 37 | #pragma warning(disable: 4251) 38 | #endif 39 | 40 | #else 41 | 42 | #if __GNUC__ >= 4 43 | #define GLUL_API_EXPORT __attribute__ ((__visibility__ ("default"))) 44 | #define GLUL_API_IMPORT __attribute__ ((__visibility__ ("default"))) 45 | #else 46 | #define GLUL_API_EXPORT 47 | #define GLUL_API_IMPORT 48 | #endif 49 | 50 | #endif 51 | 52 | #else 53 | 54 | #define GLUL_API_EXPORT 55 | #define GLUL_API_IMPORT 56 | 57 | #endif 58 | 59 | 60 | /** 61 | * Define GLUL_API based on build target 62 | */ 63 | #if defined(GLUL_EXPORT) 64 | #define GLUL_API GLUL_API_EXPORT 65 | #else 66 | #define GLUL_API GLUL_API_IMPORT 67 | #endif 68 | -------------------------------------------------------------------------------- /include/GLUL/Exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class GLUL_API Exception : public std::exception { 12 | 13 | public: 14 | Exception() throw(); 15 | Exception(const std::string& description) throw(); 16 | virtual ~Exception() throw(); 17 | 18 | virtual void print() const; 19 | 20 | const char* what() const throw(); 21 | const std::string& getDescription() const throw(); 22 | 23 | protected: 24 | std::string _description; 25 | 26 | public: 27 | class FatalError; 28 | class InitializationFailed; 29 | class InvalidArgument; 30 | }; 31 | 32 | } 33 | 34 | #include 35 | #include 36 | #include 37 | -------------------------------------------------------------------------------- /include/GLUL/Exceptions/FatalError.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | class GLUL_API Exception::FatalError : public Exception { 9 | public: 10 | FatalError() throw(); 11 | FatalError(const std::string& description) throw(); 12 | 13 | }; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /include/GLUL/Exceptions/InitializationFailed.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | class GLUL_API Exception::InitializationFailed : public Exception { 9 | public: 10 | InitializationFailed() throw(); 11 | InitializationFailed(const std::string& description) throw(); 12 | 13 | }; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /include/GLUL/Exceptions/InvalidArgument.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | class GLUL_API Exception::InvalidArgument : public Exception { 9 | public: 10 | InvalidArgument() throw(); 11 | InvalidArgument(const std::string& description) throw(); 12 | 13 | }; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /include/GLUL/File.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class GLUL_API File { 12 | public: 13 | 14 | public: 15 | static bool exists(const std::string& path); 16 | 17 | static std::string readText(const std::string& path, bool throwException = false) throw(Exception::FatalError); 18 | 19 | static std::string getPath(const std::string& path); 20 | static std::string getFilename(const std::string& path); 21 | static std::string getFilenameExtensionless(const std::string& path); 22 | static std::string getExtension(const std::string& path); 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /include/GLUL/Frameworks/Application.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace FW { 10 | 11 | class GLUL_API Application { 12 | public: 13 | Application(); 14 | ~Application(); 15 | 16 | void run(GLUL::Interface::State* initialState); 17 | void signalExit(); 18 | 19 | const std::string& getArgument(int id) throw(std::out_of_range); 20 | const std::vector& getArguments(); 21 | 22 | void setArguments(int argumentsCount, char* arguments[]); 23 | 24 | GLUL::Window& Window; 25 | 26 | private: 27 | GLUL::Window& getWindow(); 28 | GLUL::Interface::State* getState(); 29 | void setState(GLUL::Interface::State* const newState); 30 | 31 | GLUL::Window _window; 32 | GLUL::Interface::State* _state; 33 | std::vector _arguments; 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Batch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | namespace GLUL { 16 | 17 | namespace G2D { 18 | 19 | class GLUL_API Primitive; 20 | 21 | class GLUL_API Batch { 22 | public: 23 | struct DrawCall { 24 | GLint offset; 25 | GLsizei count; 26 | GL::VertexArray::DrawTarget target; 27 | }; 28 | 29 | public: 30 | Batch(); 31 | Batch(const Primitive& primitive); 32 | Batch(const std::vector>& primitives); 33 | Batch(const std::initializer_list>& primitives); 34 | 35 | void addPrimitive(const Primitive& primitive); 36 | void addPrimitives(const std::vector>& primitives); 37 | void addPrimitives(const std::initializer_list>& primitives); 38 | 39 | void compute(); 40 | 41 | void clear(); 42 | void clearLocal(); 43 | 44 | void render() const; 45 | void render(const GL::Program& program) const; 46 | 47 | private: 48 | void _initializeVAO(); 49 | void _pushCall(GL::VertexArray::DrawTarget drawTarget, 50 | const std::vector& vertexData, const std::vector& colorData); 51 | 52 | static GL::Program& getDefaultProgram(); 53 | 54 | std::vector _drawCalls; 55 | std::vector _vertexData; 56 | std::vector _colorData; 57 | mutable GL::Program _program; 58 | mutable GL::VertexArray _vao; 59 | mutable GL::VertexBuffer _vbo; 60 | mutable GL::VertexBuffer _cbo; 61 | 62 | friend class Primitive; 63 | friend class Shape; 64 | }; 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Circle : public Shape { 14 | public: 15 | Circle(); 16 | Circle(const Point& center, float radius); 17 | Circle(const glm::vec2& center, float radius); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | Point center; 23 | float radius; 24 | unsigned int pointCount; 25 | 26 | static unsigned int defaultPointCount(float radius); 27 | 28 | protected: 29 | void _pushToBatch(Batch& batch) const; 30 | 31 | using Primitive::setColor; 32 | }; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Disk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Disk : public Shape { 14 | public: 15 | Disk(); 16 | Disk(const Point& center, float innerRadius, float outerRadius); 17 | Disk(const glm::vec2& center, float innerRadius, float outerRadius); 18 | 19 | void setColor(const glm::vec4& color); 20 | void setInnerColor(const glm::vec3& innerColor); 21 | void setInnerColor(const glm::vec4& innerColor); 22 | void setOuterColor(const glm::vec3& outerColor); 23 | void setOuterColor(const glm::vec4& outerColor); 24 | const glm::vec4& getColor() const; 25 | const glm::vec4& getInnerColor() const; 26 | const glm::vec4& getOuterColor() const; 27 | 28 | Point center; 29 | float innerRadius; 30 | float outerRadius; 31 | unsigned int pointCount; 32 | 33 | static unsigned int defaultPointCount(float outerRadius); 34 | 35 | protected: 36 | void _pushToBatch(Batch& batch) const; 37 | 38 | glm::vec4 _outerColor; 39 | 40 | using Primitive::setColor; 41 | }; 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /include/GLUL/G2D/HorizontalAlignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace G2D { 7 | 8 | enum class HorizontalAlignment { 9 | Left, 10 | Center, 11 | Right 12 | }; 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Line.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Line : public Primitive { 14 | public: 15 | Line(unsigned int thickness = 1u); 16 | Line(const Point& point1, const Point& point2, unsigned int thickness = 1u); 17 | Line(const glm::vec2& position1, const glm::vec2& position2, unsigned int thickness = 1u); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | void setThickness(unsigned int thickness); 23 | 24 | std::array points; 25 | 26 | protected: 27 | void _pushToBatch(Batch& batch) const; 28 | 29 | using Primitive::setColor; 30 | }; 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /include/GLUL/G2D/LineLoop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace G2D { 13 | 14 | class GLUL_API LineLoop : public Primitive { 15 | public: 16 | LineLoop(); 17 | LineLoop(const std::vector& points); 18 | LineLoop(const std::vector& points); 19 | LineLoop(std::initializer_list>& points); 20 | LineLoop(std::initializer_list>& points); 21 | 22 | void setColor(const glm::vec4& color); 23 | const glm::vec4& getColor() const; 24 | 25 | std::vector points; 26 | 27 | protected: 28 | void _pushToBatch(Batch& batch) const; 29 | 30 | using Primitive::setColor; 31 | }; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/GLUL/G2D/LineStrip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace G2D { 9 | 10 | class GLUL_API LineStrip : public Primitive { 11 | public: 12 | LineStrip(); 13 | LineStrip(const std::vector& points); 14 | LineStrip(const std::vector& points); 15 | LineStrip(std::initializer_list>& points); 16 | LineStrip(std::initializer_list>& points); 17 | 18 | void setColor(const glm::vec4& color); 19 | const glm::vec4& getColor() const; 20 | 21 | std::vector points; 22 | 23 | protected: 24 | void _pushToBatch(Batch& batch) const; 25 | 26 | using Primitive::setColor; 27 | }; 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace G2D { 11 | 12 | class GLUL_API Point : public Primitive { 13 | public: 14 | Point(unsigned int size = 1u); 15 | Point(const glm::vec2& position, unsigned int size = 1u); 16 | Point(const glm::vec2& position, const glm::vec3& color, unsigned int size = 1u); 17 | Point(const glm::vec2& position, const glm::vec4& color, unsigned int size = 1u); 18 | 19 | Point& operator=(const glm::vec2& position); 20 | 21 | void setPosition(const glm::vec2& position); 22 | void setPosition(const Point& point); 23 | const glm::vec2& getPosition() const; 24 | 25 | void setColor(const glm::vec4& color); 26 | const glm::vec4& getColor() const; 27 | 28 | unsigned int size; 29 | 30 | protected: 31 | void _pushToBatch(Batch& batch) const; 32 | 33 | glm::vec2 _position; 34 | glm::vec4 _color; 35 | 36 | using Primitive::setColor; 37 | }; 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Primitive.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace G2D { 13 | 14 | class GLUL_API Primitive { 15 | public: 16 | void render() const; 17 | void render(const GL::Program& program) const; 18 | 19 | void setColor(const glm::vec3& color); 20 | virtual void setColor(const glm::vec4& color) = 0; 21 | virtual const glm::vec4& getColor() const = 0; 22 | 23 | protected: 24 | virtual void _pushToBatch(Batch& batch) const = 0; 25 | 26 | void _pushDrawCall(Batch& batch, GL::VertexArray::DrawTarget drawTarget, 27 | const std::vector& vertexData, const std::vector& colorData) const; 28 | 29 | friend class Batch; 30 | }; 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Quad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Quad : public Shape { 14 | public: 15 | Quad(); 16 | Quad(const Point& point1, const Point& point2, const Point& point3, const Point& point4); 17 | Quad(const Point& bottomLeftPoint, float size); 18 | Quad(const Point& bottomLeftPoint, const glm::vec2& size); 19 | Quad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4); 20 | Quad(const glm::vec2& bottomLeftPosition, float size); 21 | Quad(const glm::vec2& bottomLeftPosition, const glm::vec2& size); 22 | 23 | void setSquare(const Point& bottomLeftPoint, float size); 24 | void setRectangle(const Point& bottomLeftPoint, const glm::vec2& size); 25 | 26 | void setColor(const glm::vec4& color); 27 | const glm::vec4& getColor() const; 28 | 29 | std::array points; 30 | 31 | protected: 32 | void _pushToBatch(Batch& batch) const; 33 | 34 | using Primitive::setColor; 35 | }; 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | namespace G2D { 14 | 15 | class GLUL_API Rectangle : public Shape { 16 | public: 17 | Rectangle(); 18 | Rectangle(const glm::vec2& position, float size); 19 | Rectangle(const glm::vec2& position, float size, const glm::vec3& color); 20 | Rectangle(const glm::vec2& position, float size, const glm::vec4& color); 21 | Rectangle(const glm::vec2& position, const glm::vec2& size); 22 | Rectangle(const glm::vec2& position, const glm::vec2& size, const glm::vec3& color); 23 | Rectangle(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color); 24 | explicit Rectangle(const Point& point, float size); 25 | explicit Rectangle(const Point& point, const glm::vec2& size); 26 | 27 | void setPosition(const glm::vec2& position); 28 | const glm::vec2& getPosition() const; 29 | 30 | void setSize(float size); 31 | void setSize(const glm::vec2& size); 32 | const glm::vec2& getSize() const; 33 | 34 | void setColor(const glm::vec4& color); 35 | const glm::vec4& getColor() const; 36 | 37 | protected: 38 | void _pushToBatch(Batch& batch) const; 39 | 40 | glm::vec2 _position; 41 | glm::vec2 _size; 42 | glm::vec4 _color; 43 | 44 | using Primitive::setColor; 45 | }; 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Ring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Ring : public Shape { 14 | public: 15 | Ring(); 16 | Ring(const Point& center, float innerRadius, float outerRadius); 17 | Ring(const glm::vec2& center, float innerRadius, float outerRadius); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | Point center; 23 | float innerRadius; 24 | float outerRadius; 25 | unsigned int pointCount; 26 | 27 | static unsigned int defaultPointCount(float outerRadius); 28 | 29 | protected: 30 | void _pushToBatch(Batch& batch) const; 31 | 32 | using Primitive::setColor; 33 | }; 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace G2D { 9 | 10 | class GLUL_API Shape : public Primitive { 11 | 12 | }; 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedPoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API TexturedPoint { 14 | public: 15 | TexturedPoint(); 16 | TexturedPoint(const glm::vec2& position); 17 | TexturedPoint(const glm::vec2& position, const glm::vec2& texCoords); 18 | TexturedPoint(const glm::vec2& position, const glm::vec2& texCoords, const glm::vec3& color); 19 | TexturedPoint(const glm::vec2& position, const glm::vec2& texCoords, const glm::vec4& color); 20 | explicit TexturedPoint(const Point& point); 21 | explicit TexturedPoint(const Point& point, const glm::vec2& texCoords); 22 | 23 | void setPosition(const glm::vec2& position); 24 | void setPosition(const Point& point); 25 | void setPosition(const TexturedPoint& point); 26 | void setTexCoords(const glm::vec2& texCoords); 27 | void setTexCoords(const TexturedPoint& point); 28 | void setColor(const glm::vec3& color); 29 | void setColor(const glm::vec4& color); 30 | 31 | const glm::vec2& getPosition() const; 32 | const glm::vec2& getTexCoords() const; 33 | const glm::vec4& getColor() const; 34 | 35 | protected: 36 | glm::vec2 _position; 37 | glm::vec2 _texCoords; 38 | glm::vec4 _color; 39 | }; 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedPrimitive.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace G2D { 13 | 14 | class GLUL_API TexturedPrimitive { 15 | public: 16 | virtual void render(const GL::Texture& texture, unsigned int textureUnit = 0u) const; 17 | virtual void render(const GL::Program& program, const GL::Texture& texture, unsigned int textureUnit = 0u) const; 18 | 19 | virtual void setColor(const glm::vec3& color) = 0; 20 | virtual void setColor(const glm::vec4& color) = 0; 21 | virtual const glm::vec4& getColor() const = 0; 22 | 23 | protected: 24 | virtual void _pushToBatch(TexturedBatch& texBatch, const GL::Texture& texture) const = 0; 25 | 26 | void _pushDrawCall(TexturedBatch& texBatch, GL::VertexArray::DrawTarget drawTarget, 27 | const std::vector& vertexData, const std::vector& colorData, 28 | const GL::Texture& texture) const; 29 | 30 | friend class TexturedBatch; 31 | }; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedQuad.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API TexturedQuad : public TexturedShape { 14 | public: 15 | TexturedQuad(); 16 | TexturedQuad(const TexturedPoint& point1, const TexturedPoint& point2, 17 | const TexturedPoint& point3, const TexturedPoint& point4); 18 | TexturedQuad(const TexturedPoint& bottomLeftPoint, float size, float texSize); 19 | TexturedQuad(const TexturedPoint& bottomLeftPoint, const glm::vec2& size, const glm::vec2& texSize); 20 | 21 | void setSquare(const TexturedPoint& bottomLeftPoint, float size, float texSize); 22 | void setRectangle(const TexturedPoint& bottomLeftPoint, const glm::vec2& size, const glm::vec2& texSize); 23 | 24 | void setColor(const glm::vec3& color); 25 | void setColor(const glm::vec4& color); 26 | const glm::vec4& getColor() const; 27 | 28 | std::array points; 29 | 30 | protected: 31 | void _pushToBatch(TexturedBatch& texBatch, const GL::Texture& texture) const; 32 | }; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedRectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API TexturedRectangle : public TexturedShape { 14 | public: 15 | TexturedRectangle(); 16 | TexturedRectangle(const glm::vec2& position, float size); 17 | TexturedRectangle(const glm::vec2& position, float size, const glm::vec2& texPosition, float texSize); 18 | TexturedRectangle(const glm::vec2& position, const glm::vec2& size); 19 | TexturedRectangle(const glm::vec2& position, const glm::vec2& size, const glm::vec2& texPosition, const glm::vec2& texSize); 20 | explicit TexturedRectangle(const TexturedPoint& point, float size, float texSize); 21 | explicit TexturedRectangle(const TexturedPoint& point, const glm::vec2& size, const glm::vec2& texSize); 22 | 23 | 24 | void setPosition(const glm::vec2& position); 25 | const glm::vec2& getPosition() const; 26 | 27 | void setSize(float size); 28 | void setSize(const glm::vec2& size); 29 | const glm::vec2& getSize() const; 30 | 31 | void setColor(const glm::vec3& color); 32 | void setColor(const glm::vec4& color); 33 | const glm::vec4& getColor() const; 34 | 35 | void setTexPosition(const glm::vec2& texPosition); 36 | const glm::vec2& getTexPosition() const; 37 | 38 | void setTexSize(float texSize); 39 | void setTexSize(const glm::vec2& texSize); 40 | const glm::vec2& getTexSize() const; 41 | 42 | protected: 43 | void _pushToBatch(TexturedBatch& texBatch, const GL::Texture& texture) const; 44 | 45 | glm::vec2 _position; 46 | glm::vec2 _size; 47 | glm::vec4 _color; 48 | glm::vec2 _texPos; 49 | glm::vec2 _texSize; 50 | }; 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedShape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace G2D { 9 | 10 | class GLUL_API TexturedShape : public TexturedPrimitive { 11 | 12 | }; 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TexturedTriangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API TexturedTriangle : public TexturedShape { 14 | public: 15 | TexturedTriangle(); 16 | TexturedTriangle(const TexturedPoint& point1, const TexturedPoint& point2, const TexturedPoint& point3); 17 | 18 | void setColor(const glm::vec3& color); 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | std::array points; 23 | 24 | protected: 25 | void _pushToBatch(TexturedBatch& texBatch, const GL::Texture& texture) const; 26 | 27 | using TexturedPrimitive::setColor; 28 | }; 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/GLUL/G2D/Triangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace G2D { 12 | 13 | class GLUL_API Triangle : public Shape { 14 | public: 15 | Triangle(); 16 | Triangle(const Point& point1, const Point& point2, const Point& point3); 17 | Triangle(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | std::array points; 23 | 24 | protected: 25 | void _pushToBatch(Batch& batch) const; 26 | 27 | using Primitive::setColor; 28 | }; 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TriangleFan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | namespace G2D { 10 | 11 | class GLUL_API TriangleFan : public Shape { 12 | public: 13 | TriangleFan(); 14 | TriangleFan(const std::vector& points); 15 | TriangleFan(const std::vector& points); 16 | TriangleFan(std::initializer_list>& points); 17 | TriangleFan(std::initializer_list>& points); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | std::vector points; 23 | 24 | protected: 25 | void _pushToBatch(Batch& batch) const; 26 | 27 | using Primitive::setColor; 28 | }; 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/GLUL/G2D/TriangleStrip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | namespace G2D { 10 | 11 | class GLUL_API TriangleStrip : public Shape { 12 | public: 13 | TriangleStrip(); 14 | TriangleStrip(const std::vector& points); 15 | TriangleStrip(const std::vector& points); 16 | TriangleStrip(std::initializer_list>& points); 17 | TriangleStrip(std::initializer_list>& points); 18 | 19 | void setColor(const glm::vec4& color); 20 | const glm::vec4& getColor() const; 21 | 22 | std::vector points; 23 | 24 | protected: 25 | void _pushToBatch(Batch& batch) const; 26 | 27 | using Primitive::setColor; 28 | }; 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Buffer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GL { 7 | 8 | template 9 | void Buffer::setData(const std::vector& data) { 10 | glBufferData(static_cast(getTarget()), data.size() * sizeof(T), data.data(), static_cast(getUsage())); 11 | } 12 | 13 | template 14 | void Buffer::setData(const std::vector& data, Usage usage) { 15 | setUsage(usage); 16 | setData(data); 17 | } 18 | 19 | template 20 | void Buffer::setSubData(const std::vector& data, GLintptr offset) { 21 | setSubData(data, offset, data.size() * sizeof(T)); 22 | } 23 | 24 | template 25 | void Buffer::setSubData(const std::vector& data, GLintptr offset, GLsizeiptr size) { 26 | glBufferSubData(static_cast(getTarget()), offset, size, &data.data()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /include/GLUL/GL++/MatrixStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | 11 | namespace GL { 12 | 13 | class GLUL_API MatrixStack { 14 | public: 15 | MatrixStack(); 16 | ~MatrixStack(); 17 | 18 | MatrixStack& operator*=(const glm::mat4& matrix); // alias for multiply(const glm::mat4&) 19 | MatrixStack& operator+=(const glm::mat4& matrix); // alias for push(const glm::mat4&) 20 | MatrixStack& operator<<(const glm::mat4& matrix); // alias for push(const glm::mat4&) 21 | MatrixStack& operator>>(glm::mat4& matrix); // alias for pop() with value assignment 22 | MatrixStack& operator--(); // alias for pop() 23 | MatrixStack& operator++(); // alias for push() 24 | 25 | void clear(); 26 | 27 | void set(); 28 | void set(const glm::mat4& matrix); 29 | void multiply(const glm::mat4& matrix); 30 | 31 | void pop(); 32 | void push(); 33 | void push(const glm::mat4& matrix); 34 | void load(const glm::mat4& matrix); 35 | 36 | void rotate(float angle, float x, float y, float z); 37 | void rotate(float angle, const glm::vec3& vector); 38 | 39 | void translate(float x, float y, float z); 40 | void translate(const glm::vec3& vector); 41 | 42 | void scale(float x, float y, float z); 43 | void scale(const glm::vec3& vector); 44 | 45 | const glm::mat4& get() const; 46 | 47 | private: 48 | std::stack _stack; 49 | 50 | }; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Models/Material.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | 13 | namespace GL { 14 | 15 | namespace Model { 16 | 17 | // Unsupported: 18 | // 19 | // map_Ns - specular gighlight component 20 | // map_d - alpha texture map 21 | // map_bump, bump - bump map 22 | // disp - displacement map 23 | // decal - stencil decal texture 24 | // 25 | // and special options for these 26 | 27 | class GLUL_API Material { 28 | public: 29 | static const Material Default; 30 | 31 | public: 32 | Material(const std::string& name); 33 | 34 | bool processInput(const std::vector& tokens); 35 | 36 | 37 | public: 38 | std::string name; // name 39 | glm::vec3 colorAmbient; // Ka 40 | glm::vec3 colorDiffuse; // Kd 41 | glm::vec3 colorSpecular; // Ks 42 | float exponentSpecular; // Ns 43 | float alphaFactor; // d, Tr 44 | unsigned int illumination; // illum 45 | std::string textureAmbient; // map_Ka 46 | std::string textureDiffuse; // map_Kd 47 | std::string textureSpecular; // map_Ks 48 | }; 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Models/Mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | 13 | namespace GL { 14 | 15 | namespace Model { 16 | 17 | class Material; 18 | 19 | class GLUL_API Mesh { 20 | public: 21 | Mesh(std::unordered_map* textures = nullptr); 22 | Mesh(const std::string& materialName, std::unordered_map* textures = nullptr); 23 | Mesh(const Mesh& mesh) = delete; 24 | Mesh(Mesh&& mesh); 25 | 26 | void build(); 27 | void computeNormals( 28 | GLUL::Interface::Model::NormalType type = GLUL::Interface::Model::NormalType::Default, 29 | bool overwrite = false); 30 | 31 | void render(const GL::Pipeline& pipeline, const GL::Program& program, const Material& material) const; 32 | void renderAABB(const GL::Pipeline& pipeline) const; 33 | 34 | void addData(const glm::vec3& vertex); 35 | void addData(const glm::vec3& vertex, const glm::vec2& texCoord); 36 | void addData(const glm::vec3& vertex, const glm::vec2& texCoord, const glm::vec3& normal); 37 | void addData(const glm::vec3& vertex, const glm::vec3& normal); 38 | 39 | bool hasNormals() const; 40 | const GLUL::AABB& getAABB() const; 41 | 42 | public: 43 | std::string materialName; 44 | std::vector vertices; 45 | std::vector normals; 46 | std::vector texCoords; 47 | 48 | private: 49 | GLUL::AABB _aabb; 50 | GL::VertexArray _vao; 51 | GL::VertexBuffer _vboV; 52 | GL::VertexBuffer _vboT; 53 | GL::VertexBuffer _vboN; 54 | 55 | std::unordered_map* _textures; 56 | }; 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Pipeline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | 12 | namespace GL { 13 | 14 | class GLUL_API Pipeline { 15 | public: 16 | enum class ViewSource { 17 | Camera, 18 | Matrix 19 | }; 20 | 21 | public: 22 | Pipeline(); 23 | ~Pipeline(); 24 | 25 | void setViewSource(ViewSource source); 26 | void setCamera(const GLUL::Interface::Camera* camera); 27 | 28 | void setModel() const; 29 | void setModel(const glm::mat4& modelMatrix) const; 30 | 31 | void setView(); 32 | void setView(const GLUL::Interface::Camera* camera); 33 | void setView(const glm::mat4& viewMatrix); 34 | 35 | void setProjection(); 36 | void setProjection(float fov, float aspect, float near, float far); 37 | void setProjection(const glm::mat4& projectionMatrix); 38 | 39 | const glm::mat4 getMV() const; 40 | const glm::mat4 getMVP() const; 41 | const glm::mat4& getModel() const; 42 | const glm::mat4& getView() const throw(GLUL::Exception::FatalError); 43 | const glm::mat4& getProjection() const; 44 | const GLUL::Interface::Camera* getCamera() const; 45 | 46 | private: 47 | glm::mat4 _model; 48 | glm::mat4 _view; 49 | glm::mat4 _projection; 50 | 51 | ViewSource _viewSource; 52 | const GLUL::Interface::Camera* _camera; 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Program.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | namespace GL { 17 | 18 | class GLUL_API Program { 19 | public: 20 | Program(); 21 | Program(Program&& program); 22 | Program(const std::string& vsPath, const std::string& fsPath); 23 | Program(const Shader& vertexShader, const Shader& fragmentShader); 24 | Program(const Program&) = delete; 25 | ~Program(); 26 | 27 | Program& operator=(const Program&) = delete; 28 | Program& operator=(Program&& program); 29 | 30 | Uniform& operator[](const std::string& uniformName) throw(std::out_of_range); 31 | const Uniform& operator[](const std::string& uniformName) const throw(std::out_of_range); 32 | 33 | void create(); 34 | void destroy(); 35 | 36 | void load(const Shader& vertexShader, const Shader& fragmentShader); 37 | void use() const; 38 | void unbind() const; 39 | 40 | bool isLinked() const; 41 | GLuint getID() const; 42 | 43 | GLuint getUniformLocation(const std::string& uniformName) const throw(std::out_of_range); 44 | const Uniform& getUniform(const std::string& uniformName) const throw(std::out_of_range); 45 | 46 | private: 47 | void mapUniforms(const Shader& shader); 48 | bool link(const Shader& vertexShader, const Shader& fragmentShader) throw(GLUL::Exception::FatalError); 49 | 50 | bool isCreated() const; 51 | 52 | bool _isLinked; 53 | bool _isCreated; 54 | GLuint _programID; 55 | std::unordered_map _uniforms; 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | 12 | namespace GL { 13 | 14 | class GLUL_API Shader { 15 | public: 16 | enum class Type : GLenum { 17 | VertexShader = GL_VERTEX_SHADER, 18 | FragmentShader = GL_FRAGMENT_SHADER, 19 | GeometryShader = GL_GEOMETRY_SHADER, 20 | }; 21 | 22 | public: 23 | Shader(Type type); 24 | Shader(const std::string& path, Type type); 25 | Shader(Shader&& shader); 26 | Shader(const Shader&) = delete; 27 | ~Shader(); 28 | 29 | Shader& operator=(const Shader&) = delete; 30 | Shader& operator=(Shader&& shader); 31 | 32 | void create(); 33 | void destroy(); 34 | 35 | void load(const std::string& path); 36 | 37 | bool isCompiled() const; 38 | GLuint getID() const; 39 | Type getType() const; 40 | 41 | private: 42 | bool compile() throw(GLUL::Exception::FatalError); 43 | 44 | bool isCreated() const; 45 | 46 | bool _isCreated; 47 | bool _isCompiled; 48 | Type _type; 49 | GLuint _shaderID; 50 | std::string _path; 51 | std::string _code; 52 | 53 | public: 54 | friend class Program; 55 | }; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /include/GLUL/GL++/Uniform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace GL { 11 | 12 | class GLUL_API Uniform { 13 | public: 14 | Uniform(); 15 | Uniform(GLuint location); 16 | ~Uniform(); 17 | 18 | GLuint getLocation() const; 19 | 20 | void setSampler(GLint value) const; 21 | 22 | public: 23 | template void operator=(const T& value) const; 24 | 25 | template void set(T v0) const; 26 | template void set(T v0, T v1) const; 27 | template void set(T v0, T v1, T v2) const; 28 | template void set(T v0, T v1, T v2, T v3) const; 29 | 30 | template void setVec(const T& value, GLsizei count = 1) const; 31 | template void setMatrix(const T& value, GLsizei count = 1, GLboolean transpose = GL_FALSE) const; 32 | 33 | private: 34 | GLint _location; 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /include/GLUL/GL++/VertexAttrib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace GL { 11 | 12 | class GLUL_API VertexAttrib { 13 | public: 14 | VertexAttrib(); 15 | VertexAttrib(GLuint index_, GLint size_, GLenum type_, GLsizei stride_, GLvoid* offset_); 16 | VertexAttrib(GLuint index_, GLint size_, GLenum type_, GLsizei stride_, std::size_t offset_); 17 | ~VertexAttrib(); 18 | 19 | void set(); 20 | 21 | public: 22 | GLuint index; 23 | GLint size; 24 | GLenum type; 25 | GLboolean normalized; 26 | GLsizei stride; 27 | GLvoid* offset; 28 | }; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/GLUL/GL++/VertexBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace GL { 11 | 12 | class GLUL_API VertexBuffer : public GL::Buffer { 13 | public: 14 | class GLUL_API Data { 15 | public: 16 | Data() : data(nullptr), size(0) { } 17 | Data(GLvoid* data_, GLsizeiptr size_) : data(data_), size(size_) { } 18 | 19 | GLvoid* data; 20 | GLsizeiptr size; 21 | std::list pointers; 22 | }; 23 | 24 | public: 25 | VertexBuffer(); 26 | VertexBuffer(Usage usage); 27 | VertexBuffer(VertexBuffer&& vbo); 28 | VertexBuffer(const VertexBuffer&) = delete; 29 | ~VertexBuffer(); 30 | 31 | VertexBuffer& operator=(const VertexBuffer&) = delete; 32 | VertexBuffer& operator=(VertexBuffer&& vbo); 33 | 34 | void bind() const; 35 | 36 | void setData(const VertexBuffer::Data& data); 37 | 38 | void setTarget(); 39 | void setAttributes(const std::list& attributes); 40 | 41 | Target getTarget() const; 42 | const std::list& getAttributes() const; 43 | 44 | using Buffer::setData; 45 | 46 | private: 47 | std::list _attributePointers; 48 | 49 | using Buffer::setTarget; 50 | }; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Button.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | 17 | namespace GLUL { 18 | 19 | namespace GUI { 20 | 21 | class GLUL_API Button : public Component { 22 | public: 23 | Button(Container& parent); 24 | Button(Container* const parent = nullptr); 25 | ~Button(); 26 | 27 | const Button& render() const; 28 | Button& update(double deltaTime); 29 | 30 | const Button& validate() const; 31 | 32 | const glm::vec4& getColor() const; 33 | float getAlpha() const; 34 | 35 | Button& setColor(const glm::vec3& color); 36 | Button& setColor(const glm::vec4& color); 37 | Button& setAlpha(float alpha); 38 | Button& setSize(const glm::vec2& size); 39 | Button& setPosition(const glm::vec2& position); 40 | 41 | InnerText text; 42 | Style::Border border; 43 | 44 | private: 45 | std::vector getVertices() const; 46 | 47 | bool _glInitialized; 48 | glm::vec4 _color; 49 | GL::VertexArray _vao; 50 | GL::VertexBuffer _vbo; 51 | 52 | private: 53 | static GL::Program& getProgram(); 54 | }; 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Container.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace GUI { 13 | 14 | class GLUL_API Container : public Component { 15 | public: 16 | Container(Container& parent); 17 | Container(Container* const parent = nullptr); 18 | virtual ~Container(); 19 | 20 | virtual const Container& render() const; 21 | virtual Container& update(double deltaTime); 22 | virtual const Container& validate() const; 23 | 24 | virtual Container& add(Component& component); 25 | virtual Container& add(Component* const component); 26 | 27 | virtual const glm::vec2 getOffset() const; 28 | 29 | virtual Container& setInvalid(); 30 | virtual Container& setFocused(bool flag); 31 | 32 | private: 33 | void notifyChildsOfInvalidState(); 34 | void handleChildDestruction(Component* component); 35 | void initializeEventForwarding(); 36 | 37 | bool isUnderMouse(Component* component) const; 38 | 39 | void setupClipping() const; 40 | void enableClipping() const; 41 | void revertClipping() const; 42 | 43 | 44 | bool _wasScissorTestActive; 45 | GLUL::Rectangle _scissorTestBox; 46 | std::list _components; 47 | std::set _componentsUnderMouse; 48 | 49 | public: 50 | friend Component; 51 | }; 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/EventTemplate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace GUI { 12 | 13 | class Component; 14 | 15 | namespace Event { 16 | 17 | template 18 | class EventTemplate { 19 | public: 20 | class Handler { 21 | public: 22 | typedef std::function CallbackType; 23 | 24 | public: 25 | Handler(const std::string& name, const CallbackType& callback) : 26 | name(name), callback(callback) { } 27 | 28 | Handler& operator=(const Handler&) = delete; 29 | 30 | const std::string name; 31 | const CallbackType callback; 32 | }; 33 | 34 | public: 35 | EventTemplate() { } 36 | virtual ~EventTemplate() { } 37 | 38 | EventTemplate& operator=(const EventTemplate&) = delete; 39 | }; 40 | 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/Focus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace GUI { 9 | 10 | namespace Event { 11 | 12 | class GLUL_API Focus : public EventTemplate { 13 | public: 14 | Focus& operator=(const Focus&) = delete; 15 | }; 16 | 17 | } 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/FocusLoss.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace GUI { 9 | 10 | namespace Event { 11 | 12 | class GLUL_API FocusLoss : public EventTemplate { 13 | public: 14 | FocusLoss& operator=(const FocusLoss&) = delete; 15 | }; 16 | 17 | } 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/HandlerAggregator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace GUI { 13 | 14 | namespace Event { 15 | 16 | template 17 | class HandlerAggregator { 18 | public: 19 | HandlerAggregator& operator+=(const typename EventTemplate::Handler& handler) { 20 | return add(handler); 21 | } 22 | 23 | HandlerAggregator& operator-=(const std::string& handlerName) { 24 | return remove(handlerName); 25 | } 26 | 27 | void operator()(Component& component, const EventType& eventArg) { 28 | call(component, eventArg); 29 | } 30 | 31 | HandlerAggregator& add(const typename EventTemplate::Handler& handler) { 32 | _handlers[handler.name] = handler.callback; 33 | return *this; 34 | } 35 | 36 | HandlerAggregator& remove(const std::string& handlerName) { 37 | _handlers.erase(handlerName); 38 | return *this; 39 | } 40 | 41 | void call(Component& component, const EventType& eventArg) { 42 | for(auto& handlerEntry : _handlers) { 43 | handlerEntry.second(component, eventArg); // handlerEntry is std::pair of (handlerName, handler) 44 | } 45 | } 46 | 47 | private: 48 | std::map::Handler::CallbackType> _handlers; 49 | }; 50 | 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/KeyStroke.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace GUI { 12 | 13 | namespace Event { 14 | 15 | class GLUL_API KeyStroke : public EventTemplate { 16 | public: 17 | KeyStroke(const GLUL::Input::Key& key); 18 | KeyStroke& operator=(const KeyStroke&) = delete; 19 | 20 | const GLUL::Input::Key key; 21 | }; 22 | 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/MouseClick.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace GUI { 12 | 13 | namespace Event { 14 | 15 | class GLUL_API MouseClick : public EventTemplate { 16 | public: 17 | MouseClick(const GLUL::Input::MouseButton& button, const glm::vec2& position); 18 | MouseClick& operator=(const MouseClick&) = delete; 19 | 20 | const GLUL::Input::MouseButton button; 21 | const glm::vec2 position; 22 | }; 23 | 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/MouseEnter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | namespace Event { 13 | 14 | class GLUL_API MouseEnter : public EventTemplate { 15 | public: 16 | MouseEnter(const glm::vec2& position); 17 | MouseEnter& operator=(const MouseEnter&) = delete; 18 | 19 | const glm::vec2 position; 20 | }; 21 | 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/MouseLeave.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | namespace Event { 13 | 14 | class GLUL_API MouseLeave : public EventTemplate { 15 | public: 16 | MouseLeave(); 17 | MouseLeave& operator=(const MouseLeave&) = delete; 18 | }; 19 | 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/MouseMove.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | namespace Event { 13 | 14 | class GLUL_API MouseMove : public EventTemplate { 15 | public: 16 | MouseMove(const glm::vec2& position); 17 | MouseMove& operator=(const MouseMove&) = delete; 18 | 19 | const glm::vec2 position; 20 | }; 21 | 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/MouseRelease.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace GUI { 12 | 13 | namespace Event { 14 | 15 | class GLUL_API MouseRelease : public EventTemplate { 16 | public: 17 | MouseRelease(const GLUL::Input::MouseButton& button, const glm::vec2& position); 18 | MouseRelease& operator=(const MouseRelease&) = delete; 19 | 20 | const GLUL::Input::MouseButton button; 21 | const glm::vec2 position; 22 | }; 23 | 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/TextInput.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | namespace Event { 13 | 14 | class GLUL_API TextInput : public EventTemplate { 15 | public: 16 | TextInput(const std::string& text); 17 | TextInput& operator=(const TextInput&) = delete; 18 | 19 | const std::string text; 20 | }; 21 | 22 | } 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Events/ValueChange.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | namespace Event { 13 | 14 | template 15 | class ValueChange : public EventTemplate> { 16 | public: 17 | ValueChange(const ValueType& oldValue, const ValueType& newValue) 18 | : oldValue(oldValue), newValue(newValue) { } 19 | 20 | ValueChange& operator=(const ValueChange&) = delete; 21 | 22 | ValueType oldValue; 23 | ValueType newValue; 24 | }; 25 | 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace GUI { 13 | 14 | class GLUL_API Font { 15 | private: 16 | struct Metric { 17 | glm::vec2 advance; 18 | glm::vec2 size; 19 | glm::vec2 texPosStart; 20 | glm::vec2 texPosEnd; 21 | glm::vec2 glyphPos; 22 | }; 23 | 24 | 25 | public: 26 | Font() throw(GLUL::Exception::FatalError); 27 | Font(const std::string& path) throw(GLUL::Exception::FatalError); 28 | ~Font(); 29 | 30 | void load(const std::string& path); 31 | void load(const std::string& path, unsigned int fontHeight); 32 | 33 | void generate(unsigned int fontHeight); 34 | 35 | float getLineHeight() const; 36 | float getAscender() const; 37 | float getDescender() const; 38 | unsigned int getHeight() const; 39 | 40 | const std::string& getPath() const; 41 | const GL::Texture& getTexture() const; 42 | const Metric& getMetric(unsigned char character) const; 43 | 44 | private: 45 | void setPath(const std::string& path); 46 | 47 | unsigned int _height; 48 | std::string _path; 49 | GL::Texture _texture; 50 | Metric _glyphs[128]; 51 | void* _face; 52 | 53 | 54 | private: 55 | static void initializeFT() throw(GLUL::Exception::FatalError); 56 | }; 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /include/GLUL/GUI/InnerText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace GUI { 11 | 12 | class GLUL_API InnerText { 13 | public: 14 | InnerText(const Component& component); 15 | 16 | InnerText& operator=(const std::string& text); 17 | 18 | void update(double deltaTime); 19 | void render() const; 20 | 21 | InnerText& setFont(const Font& font); 22 | InnerText& setFont(const Font* font); 23 | InnerText& setText(const std::string& text); 24 | InnerText& setColor(const glm::vec3& color); 25 | InnerText& setColor(const glm::vec4& color); 26 | InnerText& setAlpha(float alpha); 27 | InnerText& setHorizontalAlignment(Style::HorizontalAlignment horizontalAlignment); 28 | InnerText& setVerticalAlignment(Style::VerticalAlignment verticalAlignment); 29 | InnerText& setAlignment(Style::HorizontalAlignment horizontalAlignment, Style::VerticalAlignment verticalAlignment); 30 | 31 | const Font* getFont() const; 32 | const std::string& getText() const; 33 | const glm::vec4& getColor() const; 34 | float getAlpha() const; 35 | Style::HorizontalAlignment getHorizontalAlignment() const; 36 | Style::VerticalAlignment getVerticalAlignment() const; 37 | 38 | private: 39 | void updatePosition(); 40 | 41 | Text _text; 42 | Style::HorizontalAlignment _horizontalAlignment; 43 | Style::VerticalAlignment _verticalAlignment; 44 | const Component& _component; 45 | 46 | private: 47 | friend class Button; 48 | friend class TextField; 49 | }; 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /include/GLUL/GUI/RadioButtonGroup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | namespace GUI { 14 | 15 | class GLUL_API RadioButton; 16 | 17 | class GLUL_API RadioButtonGroup { 18 | public: 19 | RadioButtonGroup(Container& parent); 20 | RadioButtonGroup(Container* const parent = nullptr); 21 | 22 | RadioButtonGroup(const RadioButtonGroup&) = delete; 23 | RadioButtonGroup& operator=(const RadioButtonGroup&) = delete; 24 | 25 | RadioButton& create(); 26 | void remove(RadioButton& radioButton); 27 | 28 | void set(RadioButton& radioButton); 29 | 30 | public: 31 | Event::HandlerAggregator> onValueChange; 32 | 33 | private: 34 | bool _isInGroup(RadioButton& radioButton); 35 | bool _setDifferentThanCurrent(); 36 | 37 | Container* _parent; 38 | RadioButton* _setButton; 39 | std::vector> _buttons; 40 | }; 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Styles/Border.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace GUI { 12 | 13 | namespace Style { 14 | 15 | class GLUL_API Border { 16 | public: 17 | Border(Component& component); 18 | 19 | Border& operator=(const Border&) = delete; 20 | 21 | void set(unsigned int width); 22 | void set(unsigned int width, int offset); 23 | void set(unsigned int width, int offset, const glm::vec3& color); 24 | void set(unsigned int width, int offset, const glm::vec4& color); 25 | 26 | Border& setWidth(unsigned int width); 27 | Border& setOffset(int offset); 28 | Border& setColor(const glm::vec3& color); 29 | Border& setColor(const glm::vec4& color); 30 | 31 | unsigned int getWidth() const; 32 | int getOffset() const; 33 | const glm::vec4& getColor() const; 34 | 35 | private: 36 | void _setWidth(unsigned int width); 37 | void _setOffset(int offset); 38 | void _setColor(const glm::vec3& color); 39 | void _setColor(const glm::vec4& color); 40 | 41 | void updateComponent(); 42 | 43 | unsigned int _width; 44 | int _offset; 45 | glm::vec4 _color; 46 | Component& _component; 47 | }; 48 | 49 | } 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Styles/HorizontalAlignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Style { 9 | 10 | enum class HorizontalAlignment { 11 | Left, 12 | Center, 13 | Right 14 | }; 15 | 16 | } 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Styles/Orientation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Style { 9 | 10 | enum class Orientation { 11 | Horizontal, 12 | Vertical 13 | }; 14 | 15 | } 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Styles/VerticalAlignment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Style { 9 | 10 | enum class VerticalAlignment { 11 | Top, 12 | Center, 13 | Bottom 14 | }; 15 | 16 | } 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | 16 | namespace GLUL { 17 | 18 | namespace GUI { 19 | 20 | class GLUL_API Text : public Component { 21 | public: 22 | Text(Container& parent); 23 | Text(Container* const parent = nullptr); 24 | ~Text(); 25 | 26 | const Text& render() const; 27 | Text& update(double deltaTime); 28 | 29 | const Text& validate() const; 30 | 31 | const Font* getFont() const; 32 | const std::string& getText() const; 33 | const glm::vec4& getColor() const; 34 | float getAlpha() const; 35 | float getScale() const; 36 | unsigned int getFontHeight() const; 37 | 38 | Text& setEnabled(bool flag); 39 | Text& setFocused(bool flag); 40 | Text& setVisible(bool flag); 41 | Text& setFont(const Font& font); 42 | Text& setFont(const Font* font); 43 | Text& setText(const std::string& text); 44 | Text& setSize(const glm::vec2& size); 45 | Text& setSize(unsigned int newHeight); 46 | Text& setScale(float scale); 47 | Text& setColor(const glm::vec3& color); 48 | Text& setColor(const glm::vec4& color); 49 | Text& setAlpha(float alpha); 50 | Text& setPosition(const glm::vec2& position); 51 | 52 | 53 | private: 54 | std::vector getVertices() const; 55 | 56 | const Font* _font; 57 | std::string _text; 58 | glm::vec4 _color; 59 | float _scale; 60 | 61 | bool _glInitialized; 62 | GL::VertexArray _vao; 63 | GL::VertexBuffer _vbo; 64 | 65 | private: 66 | static GL::Program& getProgram(); 67 | }; 68 | 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /include/GLUL/GUI/TextField.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | namespace GLUL { 19 | 20 | namespace GUI { 21 | 22 | class GLUL_API TextField : public Component { 23 | public: 24 | TextField(Container& parent); 25 | TextField(Container* const parent = nullptr); 26 | ~TextField(); 27 | 28 | const TextField& render() const; 29 | TextField& update(double deltaTime); 30 | 31 | const TextField& validate() const; 32 | 33 | const glm::vec4& getColor() const; 34 | float getAlpha() const; 35 | const std::string& getValue() const; 36 | 37 | TextField& setColor(const glm::vec3& color); 38 | TextField& setColor(const glm::vec4& color); 39 | TextField& setAlpha(const float alpha); 40 | TextField& setValue(const std::string& value); 41 | TextField& setSize(const glm::vec2& size); 42 | TextField& setPosition(const glm::vec2& position); 43 | 44 | InnerText text; 45 | Style::Border border; 46 | 47 | public: 48 | Event::HandlerAggregator> onValueChange; 49 | 50 | private: 51 | std::vector getVertices() const; 52 | 53 | bool _glInitialized; 54 | glm::vec4 _color; 55 | GL::VertexArray _vao; 56 | GL::VertexBuffer _vbo; 57 | 58 | private: 59 | static GL::Program& getProgram(); 60 | }; 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /include/GLUL/GUI/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace GUI { 13 | 14 | class GLUL_API Window : public GLUL::Window, public Container, protected GLUL::Input::EventHandler { 15 | public: 16 | Window(); 17 | Window(unsigned int width, unsigned int height, const std::string& title); 18 | Window(const glm::uvec2& size, const std::string& title); 19 | virtual ~Window(); 20 | 21 | virtual void update(); 22 | 23 | const glm::vec2& getSize() const; 24 | 25 | Window& setSize(unsigned int width, unsigned int height); 26 | Window& setSize(const glm::vec2& size); 27 | Window& setSize(const glm::uvec2& size); 28 | 29 | protected: 30 | virtual void handleInputEvent(const GLUL::Input::Event& inputEvent); 31 | 32 | using Container::update; 33 | }; 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /include/GLUL/Helpers/HashEnum.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace GLUL { 9 | 10 | namespace Helper { 11 | 12 | struct GLUL_API HashEnum { 13 | public: 14 | template 15 | std::size_t operator()(T t) const { 16 | return std::hash()(static_cast(t)); 17 | } 18 | }; 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /include/GLUL/Input/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Input { 9 | 10 | class CharacterEvent; 11 | class KeyEvent; 12 | class MouseButtonEvent; 13 | class MouseMovementEvent; 14 | class MouseScrollEvent; 15 | 16 | class GLUL_API Event { 17 | public: 18 | enum class Type { 19 | Character, 20 | Key, 21 | MouseButton, 22 | MouseMovement, 23 | MouseScroll, 24 | }; 25 | 26 | public: 27 | Event(Type type); 28 | 29 | Type getType() const; 30 | 31 | public: 32 | Event* asEvent(); 33 | const Event* asEvent() const; 34 | 35 | virtual CharacterEvent* asCharacterEvent(); 36 | virtual KeyEvent* asKeyEvent(); 37 | virtual MouseButtonEvent* asMouseButtonEvent(); 38 | virtual MouseMovementEvent* asMouseMovementEvent(); 39 | virtual MouseScrollEvent* asMouseScrollEvent(); 40 | 41 | virtual const CharacterEvent* asCharacterEvent() const; 42 | virtual const KeyEvent* asKeyEvent() const; 43 | virtual const MouseButtonEvent* asMouseButtonEvent() const; 44 | virtual const MouseMovementEvent* asMouseMovementEvent() const; 45 | virtual const MouseScrollEvent* asMouseScrollEvent() const; 46 | 47 | private: 48 | virtual void _abstract() = 0; 49 | 50 | Type _type; 51 | }; 52 | 53 | } 54 | 55 | } 56 | 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | 12 | namespace GLUL { 13 | 14 | namespace Input { 15 | 16 | class EventAggregator; 17 | 18 | class GLUL_API EventHandler { 19 | friend class EventAggregator; 20 | 21 | public: 22 | virtual ~EventHandler(); 23 | 24 | virtual void handleInputEvent(const Event& inputEvent) = 0; 25 | 26 | private: 27 | void _unregisterNotifications(); 28 | void _removeAggregator(Event::Type type, EventAggregator* eventAggregator); 29 | 30 | std::unordered_map, Helper::HashEnum> _inputEventAggregators; 31 | }; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTrigger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | namespace Input { 14 | 15 | class GLUL_API EventTrigger { 16 | public: 17 | EventTrigger(EventAggregator& eventAggregator); 18 | ~EventTrigger(); 19 | 20 | EventTrigger& operator=(const EventTrigger&) = delete; 21 | 22 | void reset(); 23 | 24 | void setFunction(Event::Type type, const std::function& trigger); 25 | void setFunction(std::initializer_list types, const std::function& trigger); 26 | 27 | private: 28 | bool _registered; 29 | unsigned int _triggerID; 30 | EventAggregator& _eventAggregator; 31 | std::vector _types; 32 | }; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTypes/CharacterEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace Input { 11 | 12 | class GLUL_API CharacterEvent : public Event { 13 | public: 14 | CharacterEvent(); 15 | CharacterEvent(unsigned int code); 16 | 17 | unsigned int getCharacter() const; 18 | void setCharacter(unsigned int code); 19 | 20 | bool isASCII() const; 21 | unsigned char asASCII() const; 22 | 23 | public: 24 | CharacterEvent* asCharacterEvent(); 25 | const CharacterEvent* asCharacterEvent() const; 26 | 27 | private: 28 | void _abstract() { } 29 | 30 | unsigned int _code; 31 | }; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTypes/KeyEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace Input { 11 | 12 | class GLUL_API KeyEvent : public Event { 13 | public: 14 | KeyEvent(); 15 | KeyEvent(Key key, Action action); 16 | 17 | Key getKey() const; 18 | Action getAction() const; 19 | 20 | void setKey(Key key); 21 | void setAction(Action action); 22 | 23 | public: 24 | KeyEvent* asKeyEvent(); 25 | const KeyEvent* asKeyEvent() const; 26 | 27 | private: 28 | void _abstract() { } 29 | 30 | Key _key; 31 | Action _action; 32 | }; 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTypes/MouseButtonEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | namespace Input { 13 | 14 | class GLUL_API MouseButtonEvent : public Event { 15 | public: 16 | MouseButtonEvent(); 17 | MouseButtonEvent(MouseButton button, Action action, float x, float y); 18 | MouseButtonEvent(MouseButton button, Action action, const glm::vec2& position); 19 | 20 | float getX() const; 21 | float getY() const; 22 | const glm::vec2& getPosition() const; 23 | MouseButton getMouseButton() const; 24 | Action getAction() const; 25 | 26 | void setX(float x); 27 | void setY(float y); 28 | void setPosition(const glm::vec2& position); 29 | void setMouseButton(MouseButton button); 30 | void setAction(Action action); 31 | 32 | public: 33 | MouseButtonEvent* asMouseButtonEvent(); 34 | const MouseButtonEvent* asMouseButtonEvent() const; 35 | 36 | private: 37 | void _abstract() { } 38 | 39 | MouseButton _button; 40 | Action _action; 41 | glm::vec2 _position; 42 | }; 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTypes/MouseMovementEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace Input { 12 | 13 | class GLUL_API MouseMovementEvent : public Event { 14 | public: 15 | MouseMovementEvent(); 16 | MouseMovementEvent(float x, float y); 17 | MouseMovementEvent(const glm::vec2& position); 18 | 19 | float getX() const; 20 | float getY() const; 21 | const glm::vec2& getPosition() const; 22 | 23 | void setX(float x); 24 | void setY(float y); 25 | void setPosition(const glm::vec2& position); 26 | 27 | public: 28 | MouseMovementEvent* asMouseMovementEvent(); 29 | const MouseMovementEvent* asMouseMovementEvent() const; 30 | 31 | private: 32 | void _abstract() { } 33 | 34 | glm::vec2 _position; 35 | }; 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /include/GLUL/Input/EventTypes/MouseScrollEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace GLUL { 7 | 8 | namespace Input { 9 | 10 | class GLUL_API MouseScrollEvent : public Event { 11 | public: 12 | MouseScrollEvent(); 13 | MouseScrollEvent(ScrollDirection scrollDirection); 14 | 15 | ScrollDirection getDirection() const; 16 | 17 | void setDirection(ScrollDirection scrollDirection); 18 | 19 | public: 20 | MouseScrollEvent* asMouseScrollEvent(); 21 | const MouseScrollEvent* asMouseScrollEvent() const; 22 | 23 | private: 24 | void _abstract() { } 25 | 26 | ScrollDirection _direction; 27 | }; 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /include/GLUL/Input/Keyboard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class Window; 12 | 13 | namespace Input { 14 | 15 | class GLUL_API Keyboard { 16 | public: 17 | static Input::Action getState(Key key); 18 | static Input::Action getState(Key key, GLUL::Window* window); 19 | }; 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /include/GLUL/Input/Mouse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class Window; 12 | 13 | namespace Input { 14 | 15 | class GLUL_API Mouse { 16 | public: 17 | void setMode(CursorMode cursorMode); 18 | void setMode(CursorMode cursorMode, GLUL::Window* window); 19 | 20 | static Input::Action getState(MouseButton mouseButton); 21 | static Input::Action getState(MouseButton mouseButton, GLUL::Window* window); 22 | 23 | static glm::vec2 getPosition(); 24 | static glm::vec2 getPosition(GLUL::Window* window); 25 | }; 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace Interface { 11 | 12 | class GLUL_API Camera { 13 | public: 14 | Camera(); 15 | virtual ~Camera(); 16 | 17 | virtual void update(double deltaTime) = 0; 18 | virtual void updateMouse(double x, double y) = 0; 19 | virtual void updateKeyboard(int key, int scancode, int action, int mods) = 0; 20 | virtual void updateMouseWheel(double x, double y) = 0; 21 | virtual void updateMouseButton(int button, int action, int mods) = 0; 22 | 23 | virtual const glm::vec2 getPos2D() const = 0; 24 | virtual const glm::vec3& getPos3D() const = 0; 25 | 26 | virtual const glm::mat4& getMatrix() const; 27 | virtual const glm::mat4& getProjection() const; 28 | virtual const glm::vec3& getUp() const; 29 | virtual const glm::vec3& getRight() const; 30 | virtual const glm::vec3& getDirection() const; 31 | 32 | 33 | protected: 34 | glm::vec3 _up; 35 | glm::vec3 _right; 36 | glm::vec3 _direction; 37 | glm::vec3 _position; 38 | 39 | glm::mat4 _matrix; 40 | glm::mat4 _projectionMatrix; 41 | }; 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/ImageFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | namespace Interface { 12 | 13 | class GLUL_API ImageFile { 14 | public: 15 | ImageFile(); 16 | virtual ~ImageFile(); 17 | 18 | virtual Image read(const std::string& path) const throw(GLUL::Exception::InitializationFailed) = 0; 19 | virtual void save(const Image& image, const std::string& path) const throw(GLUL::Exception::InitializationFailed) = 0; 20 | 21 | protected: 22 | void setImage(Image& image, unsigned int width, unsigned int height, unsigned int bits, unsigned char* data) const; 23 | 24 | std::vector getRGBDataOf(const Image& image) const; 25 | }; 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Implementations/ImageFileBMP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Interface { 9 | 10 | class GLUL_API ImageFileBMP : public Interface::ImageFile { 11 | private: 12 | struct BMPheader { 13 | unsigned char bmpID[4]; // xxBM where xx is skipped due to alignment 14 | unsigned int fileSize; 15 | unsigned short reserved[2]; // not used 16 | unsigned int dataOffset; 17 | 18 | unsigned int headerSize; // BITMAPINFOHEADER = 40 19 | unsigned int width; 20 | unsigned int height; 21 | unsigned short planes; // 1 22 | unsigned short bpp; 23 | unsigned int compression; 24 | unsigned int imageSize; 25 | unsigned int xPelsPerMeter; 26 | unsigned int yPelsPerMeter; 27 | unsigned int clrUsed; 28 | unsigned int clrImportantRotateAndReserved; 29 | }; 30 | 31 | public: 32 | Image read(const std::string& path) const throw(GLUL::Exception::InitializationFailed); 33 | void save(const Image& image, const std::string& path) const throw(GLUL::Exception::InitializationFailed); 34 | }; 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Implementations/ImageFileJPG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Interface { 9 | 10 | class GLUL_API ImageFileJPG : public Interface::ImageFile { 11 | public: 12 | ImageFileJPG(); // uses defaultQuality value 13 | ImageFileJPG(int quality); 14 | 15 | Image read(const std::string& path) const throw(GLUL::Exception::InitializationFailed); 16 | void save(const Image& image, const std::string& path) const throw(GLUL::Exception::InitializationFailed); 17 | 18 | static int defaultQuality; 19 | 20 | private: 21 | int _quality; 22 | }; 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Implementations/ImageFilePNG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Interface { 9 | 10 | class GLUL_API ImageFilePNG : public Interface::ImageFile { 11 | public: 12 | Image read(const std::string& path) const throw(GLUL::Exception::InitializationFailed); 13 | void save(const Image& image, const std::string& path) const throw(GLUL::Exception::InitializationFailed); 14 | }; 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Implementations/ImageFileTGA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Interface { 9 | 10 | class GLUL_API ImageFileTGA : public Interface::ImageFile { 11 | public: 12 | Image read(const std::string& path) const throw(GLUL::Exception::InitializationFailed); 13 | void save(const Image& image, const std::string& path) const throw(GLUL::Exception::InitializationFailed); 14 | }; 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/MVC/View.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | namespace Interface { 9 | 10 | namespace MVC { 11 | 12 | /*** 13 | * Template class of view where type T is view's assigned model 14 | */ 15 | template 16 | class GLUL_API View { 17 | public: 18 | virtual ~View() { } 19 | 20 | virtual void init(const T& object) = 0; 21 | virtual void render(const T& object) = 0; 22 | }; 23 | 24 | 25 | /*** 26 | * Template specialization of view for views without models 27 | */ 28 | template<> 29 | class GLUL_API View { 30 | public: 31 | virtual ~View() { } 32 | 33 | virtual void init() = 0; 34 | virtual void render() = 0; 35 | }; 36 | 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/Model.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | namespace Interface { 14 | 15 | class GLUL_API Model { 16 | public: 17 | enum class NormalType { 18 | Flat, 19 | Smooth, 20 | Default, 21 | }; 22 | 23 | public: 24 | Model(); 25 | virtual ~Model(); 26 | 27 | virtual bool load(const std::string& path, GLUL::Interface::Model::NormalType forcedNormalType) = 0; 28 | virtual bool reload(); 29 | virtual bool clear() = 0; 30 | 31 | virtual void render(const GL::Pipeline& pipeline) const; 32 | virtual void render(const GL::Pipeline& pipeline, const GL::Program& program) const = 0; 33 | virtual void renderAABB(const GL::Pipeline& pipeline, bool detailed) const; 34 | virtual void update(double deltaTime); 35 | 36 | virtual void printStats(bool detailed) const; 37 | 38 | virtual void computeNormals(GLUL::Interface::Model::NormalType type, bool overwrite) = 0; 39 | 40 | virtual void setMatrix(); 41 | virtual void setMatrix(const glm::mat4& matrix); 42 | 43 | bool hasVertices() const; 44 | bool hasTexCoords() const; 45 | bool hasNormals() const; 46 | const AABB& getAABB() const; 47 | const std::string& getPath() const; 48 | const glm::mat4& getMatrix() const; 49 | 50 | protected: 51 | glm::mat4& getMatrix(); 52 | 53 | bool _hasVertices; 54 | bool _hasTexCoords; 55 | bool _hasNormals; 56 | AABB _aabb; 57 | std::string _path; 58 | glm::mat4 _matrix; 59 | GL::Program _program; 60 | }; 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /include/GLUL/Interfaces/State.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace FW { 8 | class Application; 9 | } 10 | 11 | namespace GLUL { 12 | 13 | namespace Interface { 14 | 15 | class GLUL_API State : public Input::EventHandler { 16 | public: 17 | State(); 18 | virtual ~State(); 19 | 20 | virtual void update(const double frameTime) = 0; 21 | virtual void render() = 0; 22 | virtual void onLoad() = 0; 23 | virtual void onUnload() = 0; 24 | 25 | virtual void signalExit() = 0; 26 | virtual void handleInputEvent(const Input::Event& inputEvent); 27 | 28 | State* getNext(); 29 | 30 | static const State* const Quit; 31 | 32 | protected: 33 | void changeTo(State* nextState); 34 | bool shouldSkip(); 35 | 36 | State* _next; 37 | 38 | private: 39 | void _update(const double frameTime); 40 | void _render(); 41 | void _onLoad(); 42 | void _onUnload(); 43 | 44 | public: 45 | friend class FW::Application; 46 | }; 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /include/GLUL/Line.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class GLUL_API Line { 12 | public: 13 | Line(); 14 | Line(const Point& start, const Point& end); 15 | Line(const glm::vec2& start, const glm::vec2& end); 16 | Line(const Line& line); 17 | 18 | Line& operator=(const Line& line); 19 | 20 | void setLine(const Line& line); 21 | void setLine(const Point& start, const Point& end); 22 | void setLine(const glm::vec2& start, const glm::vec2& end); 23 | 24 | double distance(const Point& point) const; 25 | double distance(const glm::vec2& point) const; 26 | 27 | const Point& getPoint1() const; 28 | const Point& getPoint2() const; 29 | 30 | const glm::vec2& getPosition1() const; 31 | const glm::vec2& getPosition2() const; 32 | 33 | glm::vec2 getNormal() const; 34 | glm::vec2 getReflectedVector(const glm::vec2& inputVector) const; 35 | 36 | public: 37 | static glm::vec2 getNormal(const Line& line); 38 | static glm::vec2 getNormal(const glm::vec2& point1, const glm::vec2& point2); 39 | 40 | static glm::vec2 getReflectedVector(const glm::vec2& inputVector, const glm::vec2& normal); 41 | 42 | protected: 43 | Point _point1; 44 | Point _point2; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /include/GLUL/Logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | namespace GLUL { 11 | 12 | class GLUL_API Logger { 13 | public: 14 | class GLUL_API LoggerStream { 15 | public: 16 | void operator<<(const std::string& message); 17 | void log(const std::string& message); 18 | void logError(const std::string& errorMessage); 19 | void logWarning(const std::string& warningMessage); 20 | 21 | private: 22 | LoggerStream(); 23 | LoggerStream(const LoggerStream&) = delete; 24 | ~LoggerStream(); 25 | 26 | bool open(); 27 | void close(); 28 | 29 | void setName(const std::string& name); 30 | void setPath(const std::string& path); 31 | 32 | std::ofstream& getStream(); 33 | 34 | std::string _name; 35 | std::string _path; 36 | std::ofstream _stream; 37 | 38 | public: 39 | friend class Logger; 40 | friend struct std::pair; 41 | }; 42 | 43 | 44 | public: 45 | static LoggerStream& Stream(const std::string& streamName, const std::string& streamPath); 46 | static LoggerStream& Stream(const std::string& streamName); 47 | 48 | static LoggerStream& LibraryStream(); 49 | 50 | private: 51 | Logger(); 52 | Logger(const Logger&) = delete; 53 | ~Logger(); 54 | 55 | Logger& operator=(const Logger&) = delete; 56 | 57 | static Logger& getInstance(); 58 | 59 | std::unordered_map _streams; 60 | }; 61 | 62 | typedef Logger Log; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /include/GLUL/Point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | class Line; 10 | 11 | class GLUL_API Point { 12 | public: 13 | Point(); 14 | Point(const Point& point); 15 | Point(const glm::vec2& point); 16 | Point(const float x, const float y); 17 | 18 | Point& operator=(const Point& point); 19 | Point& operator=(const glm::vec2& point); 20 | 21 | void setPoint(const Point& point); 22 | void setPoint(const glm::vec2& point); 23 | void setPoint(const float x, const float y); 24 | 25 | double distance(const Point& point) const; 26 | double distance(const glm::vec2& point) const; 27 | double distance(const Line& line) const; 28 | 29 | float getX() const; 30 | float getY() const; 31 | const glm::vec2& getPosition() const; 32 | 33 | protected: 34 | glm::vec2 _position; 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /include/GLUL/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | class GLUL_API Rectangle { 10 | public: 11 | Rectangle(); 12 | Rectangle(const Point& point, float width, float height); 13 | Rectangle(float originX, float originY, float width, float height); 14 | 15 | bool intersect(const Line& line) const; 16 | bool intersect(const Point& point) const; 17 | bool intersect(const Rectangle& rectangle) const; 18 | 19 | const Point& getPoint() const; 20 | const glm::vec2& getSize() const; 21 | const glm::vec2& getPosition() const; 22 | float getWidth() const; 23 | float getHeight() const; 24 | 25 | void setPoint(const Point& point); 26 | void setSize(const glm::vec2& size); 27 | void setSize(float width, float height); 28 | void setWidth(float width); 29 | void setHeight(float height); 30 | 31 | private: 32 | Point _point; 33 | glm::vec2 _size; 34 | }; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /include/GLUL/String.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | 9 | namespace GLUL { 10 | 11 | class GLUL_API String { 12 | public: 13 | typedef std::vector stringVector; 14 | 15 | public: 16 | static stringVector& split(stringVector& input, const std::string& data, char delimiter, bool skipEmpty = true); 17 | static stringVector split(const std::string& data, char delimiter, bool skipEmpty = true); 18 | 19 | static std::string& trim(std::string& string); 20 | static std::string& ltrim(std::string& string); 21 | static std::string& rtrim(std::string& string); 22 | 23 | static bool startsWith(const std::string& string, const std::string& prefix); 24 | static bool endsWith(const std::string& string, const std::string& sufix); 25 | }; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /include/GLUL/TimeEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | class GLUL_API TimeEvent { 11 | public: 12 | enum class Type { 13 | DelayedEvent, 14 | UpdateEvent 15 | }; 16 | 17 | public: 18 | TimeEvent(double time, const std::function& delayedEvent); 19 | TimeEvent(const std::function& updateEvent); 20 | 21 | bool operator==(const TimeEvent& e); 22 | 23 | void execute(); 24 | void execute(double deltaTime); 25 | 26 | void setTime(double time); 27 | void setDone(); 28 | 29 | Type getType() const; 30 | bool isDone() const; 31 | double getTime() const; 32 | unsigned int getID() const; 33 | 34 | private: 35 | static unsigned int getNewID(); 36 | 37 | bool _isDone; 38 | unsigned int _id; 39 | double _time; 40 | Type _type; 41 | std::function _delayedEvent; 42 | std::function _updateEvent; 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /include/GLUL/TimeLoop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | class GLUL_API TimeLoop { 11 | public: 12 | TimeLoop(); 13 | 14 | void fixed(double time, double timeStep, const std::function& function); 15 | static void variable(double time, const std::function& function); 16 | static void semiFixed(double time, double timeStep, const std::function& function); 17 | 18 | private: 19 | double _accumulator; 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /include/GLUL/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | 11 | namespace GLUL { 12 | 13 | class GLUL_API Timer { 14 | public: 15 | Timer(); 16 | 17 | unsigned int insertEvent(double delay, const std::function& event); 18 | unsigned int insertEvent(const TimeEvent& event); 19 | void deleteEvent(unsigned int id); 20 | 21 | void update(); 22 | void update(double timeElapsed); 23 | void resetClock(); 24 | 25 | const std::list& getEvents() const; 26 | 27 | private: 28 | Clock _clock; 29 | std::list _events; 30 | 31 | public: 32 | friend class TimeEvent; 33 | }; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /include/GLUL/Windows.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | struct GLFWwindow; 11 | 12 | namespace GLUL { 13 | 14 | class Window; 15 | 16 | class GLUL_API Windows { 17 | friend class Window; 18 | 19 | public: 20 | static Window* Active(); 21 | 22 | static Window* Get(GLUL::Window* window); 23 | static Window* Get(GLFWwindow* handle); 24 | static Window* Get(const std::string& windowID); 25 | 26 | static void registerWindow(GLUL::Window* window, const std::string& windowID); 27 | static void registerWindow(GLUL::Window& window, const std::string& windowID); 28 | 29 | private: 30 | Windows(); 31 | ~Windows(); 32 | 33 | static void registerWindow(GLUL::Window* window); 34 | static void unregisterWindow(GLUL::Window* window); 35 | 36 | static void setActiveWindow(GLUL::Window* window); 37 | static void setActiveWindow(GLFWwindow* window); 38 | 39 | static Windows _instance; 40 | 41 | GLUL::Window* _active; 42 | std::unordered_map _handles; 43 | std::unordered_map _namedWindows; 44 | }; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /project/msvc/Examples/2D example/2D example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/2D example/2D example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Basic example/Basic example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/Basic example/Basic example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Font example/Font example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/Font example/Font example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Framework example/Framework example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Header Files 16 | 17 | 18 | 19 | 20 | Source Files 21 | 22 | 23 | Source Files 24 | 25 | 26 | -------------------------------------------------------------------------------- /project/msvc/Examples/Framework example/Framework example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/GUI example/GUI example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/GUI example/GUI example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Image example/Image example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/Image example/Image example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Input example/Input example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | 10 | 11 | Source Files 12 | 13 | 14 | -------------------------------------------------------------------------------- /project/msvc/Examples/Input example/Input example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/Examples/Models example/Models example.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | Source Files 22 | 23 | 24 | 25 | 26 | Header Files 27 | 28 | 29 | Header Files 30 | 31 | 32 | -------------------------------------------------------------------------------- /project/msvc/Examples/Models example/Models example.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /project/msvc/GLUL/GLUL.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | 12 | $(OutputPath) 13 | WindowsLocalDebugger 14 | 15 | 16 | $(OutputPath) 17 | WindowsLocalDebugger 18 | 19 | -------------------------------------------------------------------------------- /project/msvc/Tests/Unit tests/Unit tests.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {39096ef8-57b1-4631-ac50-97562e0769de} 10 | 11 | 12 | 13 | 14 | Source Files 15 | 16 | 17 | Source Files 18 | 19 | 20 | Source Files 21 | 22 | 23 | Source Files 24 | 25 | 26 | Source Files 27 | 28 | 29 | Source Files 30 | 31 | 32 | Main 33 | 34 | 35 | -------------------------------------------------------------------------------- /project/msvc/Tests/Unit tests/Unit tests.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutputPath) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutputPath) 9 | WindowsLocalDebugger 10 | 11 | -------------------------------------------------------------------------------- /scripts/linux/install_dependencies.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | echo "###############################" 5 | echo "### Installing dependencies ###" 6 | echo "###############################" 7 | 8 | 9 | DEPENDENCY_GLM_BRANCH="0.9.5" 10 | DEPENDENCY_GLEW_VERSION="1.13.0" 11 | DEPENDENCY_FT2_VERSION="2.6" 12 | DEPENDENCY_FT2_VERSION_FILE="26" 13 | 14 | 15 | echo "Configuring directories..." 16 | cd ../../ 17 | mkdir external 18 | cd external 19 | echo "Done." 20 | 21 | 22 | echo "Installing GLM..." 23 | git clone -b $DEPENDENCY_GLM_BRANCH --depth 1 https://github.com/g-truc/glm.git glm 24 | cd glm 25 | cmake . 26 | sudo make install 27 | cd .. 28 | echo "Done." 29 | 30 | 31 | echo "Installing GLEW..." 32 | wget -O glew-${DEPENDENCY_GLEW_VERSION}.zip https://sourceforge.net/projects/glew/files/glew/${DEPENDENCY_GLEW_VERSION}/glew-${DEPENDENCY_GLEW_VERSION}.zip/download 33 | unzip glew-${DEPENDENCY_GLEW_VERSION}.zip 34 | cd glew-${DEPENDENCY_GLEW_VERSION} 35 | make 36 | sudo make install 37 | cd .. 38 | echo "Done." 39 | 40 | 41 | echo "Installing GLFW..." 42 | git clone -q --depth 1 https://github.com/glfw/glfw.git glfw 43 | cd glfw 44 | cmake -DBUILD_SHARED_LIBS=ON 45 | sudo make install 46 | cd .. 47 | echo "Done." 48 | 49 | 50 | echo "Installing FreeType2..." 51 | wget -O ft${DEPENDENCY_FT2_VERSION_FILE}.zip http://sourceforge.net/projects/freetype/files/freetype2/${DEPENDENCY_FT2_VERSION}/ft${DEPENDENCY_FT2_VERSION_FILE}.zip/download 52 | unzip ft${DEPENDENCY_FT2_VERSION_FILE}.zip 53 | cd freetype-${DEPENDENCY_FT2_VERSION} 54 | cmake . 55 | sudo make install 56 | cd .. 57 | echo "Done." 58 | 59 | 60 | echo "Ending instalation..." 61 | cd .. 62 | echo "Done." 63 | -------------------------------------------------------------------------------- /scripts/windows/run_unit_tests.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | 5 | echo "##########################" 6 | echo "### RUNNING UNIT TESTS ###" 7 | echo "##########################" 8 | 9 | cd ..\..\tests\bin\ 10 | "Unit tests.exe" 11 | -------------------------------------------------------------------------------- /src/GLUL/Clock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | Clock::Clock() { 10 | reset(); 11 | } 12 | 13 | void Clock::reset() { 14 | TimePoint tpNow = now(); 15 | 16 | _tpStart = _tpLast = tpNow; 17 | } 18 | 19 | Clock::TimePoint Clock::now() { 20 | return _NativeClock::now(); 21 | } 22 | 23 | Clock::Duration Clock::getElapsedTime() { 24 | TimePoint tpNow = now(); 25 | Duration result = tpNow - _tpLast; 26 | 27 | _tpLast = tpNow; 28 | 29 | return result; 30 | } 31 | 32 | Clock::Duration Clock::getTotalTime() { 33 | TimePoint tpNow = now(); 34 | Duration result = tpNow - _tpStart; 35 | 36 | _tpLast = tpNow; 37 | 38 | return result; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/GLUL/Exception.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | namespace GLUL { 7 | 8 | Exception::Exception() throw() { 9 | _description = std::string("Exception thrown"); 10 | } 11 | 12 | Exception::Exception(const std::string& description) throw() { 13 | _description = description; 14 | } 15 | 16 | Exception::~Exception() throw() { 17 | 18 | } 19 | 20 | void Exception::print() const { 21 | std::cerr << _description << std::endl; 22 | } 23 | 24 | const char* Exception::what() const throw() { 25 | return _description.c_str(); 26 | } 27 | 28 | const std::string& Exception::getDescription() const throw() { 29 | return _description; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/GLUL/Exceptions/FatalError.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | Exception::FatalError::FatalError() throw() { 7 | _description = std::string("Fatal error has occured"); 8 | } 9 | 10 | Exception::FatalError::FatalError(const std::string& description) throw() { 11 | _description = description; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/GLUL/Exceptions/InitializationFailed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | Exception::InitializationFailed::InitializationFailed() throw() { 7 | _description = std::string("Initialization has failed"); 8 | } 9 | 10 | Exception::InitializationFailed::InitializationFailed(const std::string& description) throw() { 11 | _description = description; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/GLUL/Exceptions/InvalidArgument.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | Exception::InvalidArgument::InvalidArgument() throw() { 7 | _description = std::string("Invalid argument provided"); 8 | } 9 | 10 | Exception::InvalidArgument::InvalidArgument(const std::string& description) throw() { 11 | _description = description; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/GLUL/File.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | bool File::exists(const std::string& path) { 10 | bool result; 11 | std::ifstream file(path.c_str()); 12 | 13 | result = file.good(); 14 | 15 | return result; 16 | } 17 | 18 | std::string File::readText(const std::string& path, bool throwException) throw(GLUL::Exception::FatalError) { 19 | std::ifstream fileStream; 20 | std::string result = ""; 21 | std::string line = ""; 22 | 23 | fileStream.open(path, std::fstream::in); 24 | if(fileStream.is_open()) { 25 | while(std::getline(fileStream, line)) { 26 | result += line; 27 | 28 | if(fileStream.eof() == false) { 29 | result += "\n"; 30 | } 31 | } 32 | 33 | fileStream.close(); 34 | } else { 35 | GLUL::Log::LibraryStream().logError("Could not open file: '" + path + "'"); 36 | 37 | if(throwException) { 38 | std::string errorMsg = "Could not open file: '" + path + "'"; 39 | throw Exception::FatalError(errorMsg.c_str()); 40 | } 41 | } 42 | 43 | return result; 44 | } 45 | 46 | std::string File::getPath(const std::string& path) { 47 | std::string result; 48 | 49 | result = path.substr(0, path.find_last_of("/\\") + 1); 50 | 51 | return result; 52 | } 53 | 54 | std::string File::getFilename(const std::string& path) { 55 | std::string result; 56 | 57 | result = path.substr(path.find_last_of("/\\") + 1); 58 | 59 | return result; 60 | } 61 | 62 | std::string File::getFilenameExtensionless(const std::string& path) { 63 | std::string result; 64 | std::string fileName = File::getFilename(path); 65 | 66 | result = fileName.substr(0, fileName.find_last_of(".")); 67 | 68 | return result; 69 | } 70 | 71 | std::string File::getExtension(const std::string& filePath) { 72 | std::string result; 73 | 74 | result = filePath.substr(filePath.find_last_of(".") + 1); 75 | 76 | return result; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/GLUL/Frameworks/Application.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace FW { 6 | 7 | Application::Application() : Window(_window) { 8 | GLUL::Log::LibraryStream(); 9 | GLUL::Windows::registerWindow(Window, "FW::Application::Window::1"); 10 | 11 | setArguments(0, nullptr); 12 | _state = nullptr; 13 | } 14 | 15 | Application::~Application() { 16 | 17 | } 18 | 19 | void Application::run(GLUL::Interface::State* initialState) { 20 | setState(initialState); 21 | 22 | while(getState() != GLUL::Interface::State::Quit) { 23 | getWindow().update(); 24 | 25 | getState()->_update(getWindow().getFrameTime()); 26 | getState()->_render(); 27 | 28 | setState(getState()->getNext()); 29 | } 30 | } 31 | 32 | void Application::signalExit() { 33 | if(getState()) 34 | getState()->signalExit(); 35 | } 36 | 37 | const std::string& Application::getArgument(int id) throw(std::out_of_range) { 38 | return _arguments.at(id); 39 | } 40 | 41 | const std::vector& Application::getArguments() { 42 | return _arguments; 43 | } 44 | 45 | void Application::setArguments(int argumentCount, char* arguments[]) { 46 | _arguments.resize(argumentCount); 47 | 48 | for(int i = 0; i < argumentCount; ++i) 49 | _arguments[i] = std::string(arguments[i]); 50 | } 51 | 52 | 53 | GLUL::Window& Application::getWindow() { 54 | return _window; 55 | } 56 | 57 | GLUL::Interface::State* Application::getState() { 58 | return _state; 59 | } 60 | 61 | void Application::setState(GLUL::Interface::State* const newState) { 62 | if(getState() != newState) { 63 | if(getState() != nullptr) 64 | getState()->_onUnload(); 65 | 66 | _state = newState; 67 | 68 | if(getState() != nullptr) 69 | getState()->_onLoad(); 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/GLUL/G2D/Circle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | namespace G2D { 10 | 11 | Circle::Circle() : radius(0.0f), pointCount(0u) { } 12 | 13 | Circle::Circle(const Point& center, float radius) 14 | : center(center), radius(radius), pointCount(defaultPointCount(radius)) { } 15 | 16 | Circle::Circle(const glm::vec2& center, float radius) : Circle(Point { center }, radius) { } 17 | 18 | void Circle::setColor(const glm::vec4& color) { 19 | center.setColor(color); 20 | } 21 | 22 | const glm::vec4& Circle::getColor() const { 23 | return center.getColor(); 24 | } 25 | 26 | unsigned int Circle::defaultPointCount(float radius) { 27 | unsigned int result; 28 | 29 | result = 4u * std::min(static_cast(std::sqrt(radius)), 2u) * 4u; 30 | 31 | return result; 32 | } 33 | 34 | void Circle::_pushToBatch(Batch& batch) const { 35 | TriangleFan triangleFan; 36 | Point currentPoint = center; 37 | 38 | // Reserve memory 39 | triangleFan.points.reserve(2u + pointCount); 40 | 41 | // Center point 42 | triangleFan.points.push_back(center); 43 | 44 | // Circle points 45 | const float pi = 3.14159265358979323846f; 46 | const float pi2 = pi * 2.0f; 47 | const float steps_div = static_cast(pointCount); 48 | 49 | for(unsigned int i = 0; i <= pointCount; ++i) { 50 | auto offset = glm::vec2 { std::cos(pi2 * (i / steps_div)), std::sin(pi2 * (i / steps_div)) }; 51 | 52 | currentPoint.setPosition(center.getPosition() + (radius * offset)); 53 | triangleFan.points.push_back(currentPoint); 54 | } 55 | 56 | batch.addPrimitive(triangleFan); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/GLUL/G2D/LineLoop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace G2D { 8 | 9 | LineLoop::LineLoop() { } 10 | 11 | LineLoop::LineLoop(const std::vector& points) { 12 | this->points = points; 13 | } 14 | 15 | LineLoop::LineLoop(const std::vector& points) { 16 | this->points.reserve(points.size()); 17 | 18 | for(auto& point : points) 19 | this->points.push_back(Point { point }); 20 | } 21 | 22 | LineLoop::LineLoop(std::initializer_list>& points) { 23 | this->points.reserve(points.size()); 24 | 25 | for(auto& point : points) 26 | this->points.push_back(point); 27 | } 28 | 29 | LineLoop::LineLoop(std::initializer_list>& points) { 30 | this->points.reserve(points.size()); 31 | 32 | for(auto& point : points) 33 | this->points.push_back(Point { point }); 34 | } 35 | 36 | void LineLoop::setColor(const glm::vec4& color) { 37 | for(auto& point : points) 38 | point.setColor(color); 39 | } 40 | 41 | const glm::vec4& LineLoop::getColor() const { 42 | static glm::vec4 emptyColor; 43 | 44 | if(points.empty()) 45 | return emptyColor; 46 | else 47 | return points[0].getColor(); 48 | } 49 | 50 | void LineLoop::_pushToBatch(Batch& batch) const { 51 | // Normal lines 52 | for(std::size_t i = 0; i < points.size() - 1; ++i) 53 | batch.addPrimitive(Line { points[i], points[i + 1] }); 54 | 55 | // Loop's line 56 | batch.addPrimitive(Line { points.back(), points.front() }); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/GLUL/G2D/LineStrip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace G2D { 8 | 9 | LineStrip::LineStrip() { } 10 | 11 | LineStrip::LineStrip(const std::vector& points) { 12 | this->points = points; 13 | } 14 | 15 | LineStrip::LineStrip(const std::vector& points) { 16 | this->points.reserve(points.size()); 17 | 18 | for(auto& point : points) 19 | this->points.push_back(Point { point }); 20 | } 21 | 22 | LineStrip::LineStrip(std::initializer_list>& points) { 23 | this->points.reserve(points.size()); 24 | 25 | for(auto& point : points) 26 | this->points.push_back(point); 27 | } 28 | 29 | LineStrip::LineStrip(std::initializer_list>& points) { 30 | this->points.reserve(points.size()); 31 | 32 | for(auto& point : points) 33 | this->points.push_back(Point { point }); 34 | } 35 | 36 | void LineStrip::setColor(const glm::vec4& color) { 37 | for(auto& point : points) 38 | point.setColor(color); 39 | } 40 | 41 | const glm::vec4& LineStrip::getColor() const { 42 | static glm::vec4 emptyColor; 43 | 44 | if(points.empty()) 45 | return emptyColor; 46 | else 47 | return points[0].getColor(); 48 | } 49 | 50 | void LineStrip::_pushToBatch(Batch& batch) const { 51 | for(std::size_t i = 0; i < points.size() - 1; ++i) 52 | batch.addPrimitive(Line { points[i], points[i + 1] }); 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/GLUL/G2D/Point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace G2D { 8 | 9 | Point::Point(unsigned int size) : size(size), _color({ 1.0f }) { } 10 | 11 | Point::Point(const glm::vec2& position, unsigned int size) : Point(size) { 12 | setPosition(position); 13 | } 14 | 15 | Point::Point(const glm::vec2& position, const glm::vec3& color, unsigned int size) 16 | : Point(position, glm::vec4 { color, 1.0f }, size) { } 17 | 18 | Point::Point(const glm::vec2& position, const glm::vec4& color, unsigned int size) : Point(position, size) 19 | { 20 | setColor(color); 21 | } 22 | 23 | Point& Point::operator=(const glm::vec2& position) { 24 | setPosition(position); 25 | 26 | return *this; 27 | } 28 | 29 | void Point::setPosition(const glm::vec2& position) { 30 | _position = position; 31 | } 32 | 33 | void Point::setPosition(const Point& point) { 34 | _position = point.getPosition(); 35 | } 36 | 37 | const glm::vec2& Point::getPosition() const { 38 | return _position; 39 | } 40 | 41 | void Point::setColor(const glm::vec4& color) { 42 | _color = color; 43 | } 44 | 45 | const glm::vec4& Point::getColor() const { 46 | return _color; 47 | } 48 | 49 | void Point::_pushToBatch(Batch& batch) const { 50 | Quad quad; 51 | Point bottomLeftPoint = *this; 52 | 53 | bottomLeftPoint.setPosition(getPosition() - glm::vec2 { static_cast((size / 2)) }); 54 | quad.setSquare(bottomLeftPoint, static_cast(size)); 55 | 56 | batch.addPrimitive(quad); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/GLUL/G2D/Primitive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace G2D { 7 | 8 | void Primitive::render() const { 9 | render(Batch::getDefaultProgram()); 10 | } 11 | 12 | void Primitive::render(const GL::Program& program) const { 13 | static Batch geometry; 14 | 15 | geometry.addPrimitive(*this); 16 | geometry.compute(); 17 | geometry.render(program); 18 | geometry.clear(); 19 | } 20 | 21 | void Primitive::setColor(const glm::vec3& color) { 22 | setColor(glm::vec4 { color, getColor().a }); 23 | } 24 | 25 | void Primitive::_pushDrawCall(Batch& batch, 26 | GL::VertexArray::DrawTarget drawTarget, 27 | const std::vector& vertexData, 28 | const std::vector& colorData) const 29 | { 30 | batch._pushCall(drawTarget, vertexData, colorData); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/GLUL/G2D/Ring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace G2D { 11 | 12 | Ring::Ring() : innerRadius(0.0f), outerRadius(0.0f), pointCount(0u) { } 13 | 14 | Ring::Ring(const Point& center, float innerRadius, float outerRadius) 15 | : center(center), innerRadius(innerRadius), outerRadius(outerRadius), pointCount(defaultPointCount(outerRadius)) { } 16 | 17 | Ring::Ring(const glm::vec2& center, float innerRadius, float outerRadius) 18 | : Ring(Point { center }, innerRadius, outerRadius) { } 19 | 20 | void Ring::setColor(const glm::vec4& color) { 21 | center.setColor(color); 22 | } 23 | 24 | const glm::vec4& Ring::getColor() const { 25 | return center.getColor(); 26 | } 27 | 28 | unsigned int Ring::defaultPointCount(float outerRadius) { 29 | return Circle::defaultPointCount(outerRadius); 30 | } 31 | 32 | void Ring::_pushToBatch(Batch& batch) const { 33 | TriangleStrip triangleStrip; 34 | Point currentInnerPoint = center; 35 | Point currentOuterPoint = center; 36 | 37 | // Reserve memory 38 | triangleStrip.points.reserve(2 * (pointCount + 1)); 39 | 40 | // Ring points 41 | const float pi = 3.14159265358979323846f; 42 | const float pi2 = pi * 2.0f; 43 | const float steps_div = static_cast(pointCount); 44 | 45 | for(unsigned int i = 0; i <= pointCount; ++i) { 46 | auto offset = glm::vec2 { std::cos(pi2 * (i / steps_div)), std::sin(pi2 * (i / steps_div)) }; 47 | 48 | currentInnerPoint.setPosition(center.getPosition() + (innerRadius * offset)); 49 | currentOuterPoint.setPosition(center.getPosition() + (outerRadius * offset)); 50 | 51 | triangleStrip.points.push_back(currentInnerPoint); 52 | triangleStrip.points.push_back(currentOuterPoint); 53 | } 54 | 55 | batch.addPrimitive(triangleStrip); 56 | } 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/GLUL/G2D/TexturedPrimitive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace G2D { 7 | 8 | void TexturedPrimitive::render(const GL::Texture& texture, unsigned int textureUnit) const { 9 | render(TexturedBatch::getDefaultProgram(), texture, textureUnit); 10 | } 11 | 12 | void TexturedPrimitive::render(const GL::Program& program, const GL::Texture& texture, unsigned int textureUnit) const { 13 | static TexturedBatch geometry; 14 | 15 | geometry.addPrimitive(*this, texture); 16 | geometry.compute(); 17 | geometry.render(program, textureUnit); 18 | geometry.clear(); 19 | } 20 | 21 | void TexturedPrimitive::setColor(const glm::vec3& color) { 22 | setColor(glm::vec4 { color, getColor().a }); 23 | } 24 | 25 | void TexturedPrimitive::_pushDrawCall( 26 | TexturedBatch& texBatch, 27 | GL::VertexArray::DrawTarget drawTarget, 28 | const std::vector& vertexData, 29 | const std::vector& colorData, 30 | const GL::Texture& texture) const 31 | { 32 | texBatch._pushCall(drawTarget, vertexData, colorData, texture); 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/GLUL/G2D/TexturedTriangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace G2D { 7 | 8 | TexturedTriangle::TexturedTriangle() : points({}) { } 9 | 10 | TexturedTriangle::TexturedTriangle( 11 | const TexturedPoint& point1, 12 | const TexturedPoint& point2, 13 | const TexturedPoint& point3) 14 | { 15 | points[0] = point1; 16 | points[1] = point2; 17 | points[2] = point3; 18 | } 19 | 20 | void TexturedTriangle::setColor(const glm::vec3& color) { 21 | for(auto& point : points) 22 | point.setColor(color); 23 | } 24 | 25 | void TexturedTriangle::setColor(const glm::vec4& color) { 26 | for(auto& point : points) 27 | point.setColor(color); 28 | } 29 | 30 | const glm::vec4& TexturedTriangle::getColor() const { 31 | return points[0].getColor(); 32 | } 33 | 34 | void TexturedTriangle::_pushToBatch(TexturedBatch& texBatch, const GL::Texture& texture) const { 35 | std::vector vertexData { 36 | glm::vec4 { points[0].getPosition(), points[0].getTexCoords() }, 37 | glm::vec4 { points[1].getPosition(), points[1].getTexCoords() }, 38 | glm::vec4 { points[2].getPosition(), points[2].getTexCoords() } 39 | }; 40 | 41 | std::vector colorData { 42 | points[0].getColor(), 43 | points[1].getColor(), 44 | points[2].getColor() 45 | }; 46 | 47 | _pushDrawCall(texBatch, GL::VertexArray::DrawTarget::Triangles, vertexData, colorData, texture); 48 | } 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/GLUL/G2D/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace G2D { 7 | 8 | Triangle::Triangle() : points({}) { } 9 | 10 | Triangle::Triangle(const Point& point1, const Point& point2, const Point& point3) { 11 | points[0] = point1; 12 | points[1] = point2; 13 | points[2] = point3; 14 | } 15 | 16 | Triangle::Triangle(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3) 17 | : Triangle(Point(position1), Point(position2), Point(position3)) { } 18 | 19 | void Triangle::setColor(const glm::vec4& color) { 20 | for(auto& point : points) 21 | point.setColor(color); 22 | } 23 | 24 | const glm::vec4& Triangle::getColor() const { 25 | return points[0].getColor(); 26 | } 27 | 28 | void Triangle::_pushToBatch(Batch& batch) const { 29 | std::vector vertexData { 30 | glm::vec4(points[0].getPosition(), 0.0f, 1.0f), 31 | glm::vec4(points[1].getPosition(), 0.0f, 1.0f), 32 | glm::vec4(points[2].getPosition(), 0.0f, 1.0f) 33 | }; 34 | 35 | std::vector colorData { 36 | points[0].getColor(), 37 | points[1].getColor(), 38 | points[2].getColor() 39 | }; 40 | 41 | _pushDrawCall(batch, GL::VertexArray::DrawTarget::Triangles, vertexData, colorData); 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/GLUL/G2D/TriangleFan.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace G2D { 8 | 9 | TriangleFan::TriangleFan() { } 10 | 11 | TriangleFan::TriangleFan(const std::vector& points) { 12 | this->points = points; 13 | } 14 | 15 | TriangleFan::TriangleFan(const std::vector& points) { 16 | this->points.reserve(points.size()); 17 | 18 | for(auto& point : points) 19 | this->points.push_back(Point { point }); 20 | } 21 | 22 | TriangleFan::TriangleFan(std::initializer_list>& points) { 23 | this->points.reserve(points.size()); 24 | 25 | for(auto& point : points) 26 | this->points.push_back(point); 27 | } 28 | 29 | TriangleFan::TriangleFan(std::initializer_list>& points) { 30 | this->points.reserve(points.size()); 31 | 32 | for(auto& point : points) 33 | this->points.push_back(Point { point }); 34 | } 35 | 36 | void TriangleFan::setColor(const glm::vec4& color) { 37 | for(auto& point : points) 38 | point.setColor(color); 39 | } 40 | 41 | const glm::vec4& TriangleFan::getColor() const { 42 | static glm::vec4 emptyColor; 43 | 44 | if(points.empty()) 45 | return emptyColor; 46 | else 47 | return points[0].getColor(); 48 | } 49 | 50 | void TriangleFan::_pushToBatch(Batch& batch) const { 51 | for(std::size_t i = 1; i < points.size() - 1; ++i) 52 | batch.addPrimitive(Triangle { points[0], points[i], points[i + 1] }); 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/GLUL/G2D/TriangleStrip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace G2D { 8 | 9 | TriangleStrip::TriangleStrip() { } 10 | 11 | TriangleStrip::TriangleStrip(const std::vector& points) { 12 | this->points = points; 13 | } 14 | 15 | TriangleStrip::TriangleStrip(const std::vector& points) { 16 | this->points.reserve(points.size()); 17 | 18 | for(auto& point : points) 19 | this->points.push_back(Point { point }); 20 | } 21 | 22 | TriangleStrip::TriangleStrip(std::initializer_list>& points) { 23 | this->points.reserve(points.size()); 24 | 25 | for(auto& point : points) 26 | this->points.push_back(point); 27 | } 28 | 29 | TriangleStrip::TriangleStrip(std::initializer_list>& points) { 30 | this->points.reserve(points.size()); 31 | 32 | for(auto& point : points) 33 | this->points.push_back(Point { point }); 34 | } 35 | 36 | void TriangleStrip::setColor(const glm::vec4& color) { 37 | for(auto& point : points) 38 | point.setColor(color); 39 | } 40 | 41 | const glm::vec4& TriangleStrip::getColor() const { 42 | static glm::vec4 emptyColor; 43 | 44 | if(points.empty()) 45 | return emptyColor; 46 | else 47 | return points[0].getColor(); 48 | } 49 | 50 | void TriangleStrip::_pushToBatch(Batch& batch) const { 51 | for(std::size_t i = 0; i < points.size() - 2; ++i) { 52 | if(i % 2 == 0) { 53 | batch.addPrimitive(Triangle { points[i], points[i + 1], points[i + 2] }); 54 | 55 | } else { 56 | // Inverted order 57 | // This is to ensure each triangle has same orientation (CW/CCW) 58 | batch.addPrimitive(Triangle { points[i], points[i + 2], points[i + 1] }); 59 | } 60 | } 61 | } 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/GLUL/GL++/VertexAttrib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GL { 5 | 6 | VertexAttrib::VertexAttrib() 7 | : VertexAttrib(0, 0, GL_FLOAT, 0, nullptr) 8 | { 9 | normalized = GL_FALSE; 10 | } 11 | 12 | VertexAttrib::VertexAttrib(GLuint index_, GLint size_, GLenum type_, GLsizei stride_, GLvoid* offset_) { 13 | index = index_; 14 | size = size_; 15 | type = type_; 16 | normalized = GL_FALSE; 17 | stride = stride_; 18 | offset = offset_; 19 | } 20 | 21 | VertexAttrib::VertexAttrib(GLuint index_, GLint size_, GLenum type_, GLsizei stride_, std::size_t offset_) 22 | : VertexAttrib(index_, size_, type_, stride_, reinterpret_cast(offset_)) { } 23 | 24 | VertexAttrib::~VertexAttrib() { 25 | 26 | } 27 | 28 | void VertexAttrib::set() { 29 | glVertexAttribPointer(index, size, type, normalized, stride, offset); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/GLUL/GL++/VertexBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GL { 5 | 6 | VertexBuffer::VertexBuffer() : Buffer(Target::Array) { 7 | 8 | } 9 | 10 | VertexBuffer::VertexBuffer(Usage usage) : Buffer(Target::Array, usage) { 11 | 12 | } 13 | 14 | VertexBuffer::VertexBuffer(VertexBuffer&& vbo) : Buffer(std::move(vbo)) { 15 | std::swap(_attributePointers, vbo._attributePointers); 16 | } 17 | 18 | VertexBuffer::~VertexBuffer() { 19 | 20 | } 21 | 22 | VertexBuffer& VertexBuffer::operator=(VertexBuffer&& vbo) { 23 | std::swap(_usage, vbo._usage); 24 | std::swap(_target, vbo._target); 25 | std::swap(_bufferID, vbo._bufferID); 26 | std::swap(_isCreated, vbo._isCreated); 27 | std::swap(_attributePointers, vbo._attributePointers); 28 | 29 | return *this; 30 | } 31 | 32 | void VertexBuffer::bind() const { 33 | glBindBuffer(static_cast(Buffer::Target::Array), getID()); 34 | } 35 | 36 | void VertexBuffer::setData(const VertexBuffer::Data& data) { 37 | Buffer::setData(data.size, data.data); 38 | setAttributes(data.pointers); 39 | } 40 | 41 | void VertexBuffer::setTarget() { 42 | _target = Target::Array; 43 | } 44 | 45 | void VertexBuffer::setAttributes(const std::list& attributes) { 46 | _attributePointers = attributes; 47 | } 48 | 49 | Buffer::Target VertexBuffer::getTarget() const { 50 | return Target::Array; 51 | } 52 | 53 | const std::list& VertexBuffer::getAttributes() const { 54 | return _attributePointers; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/KeyStroke.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | KeyStroke::KeyStroke(const GLUL::Input::Key& key) : key(key) { } 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/MouseClick.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | MouseClick::MouseClick(const GLUL::Input::MouseButton& button, const glm::vec2& position) : button(button), position(position) { 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/MouseEnter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | MouseEnter::MouseEnter(const glm::vec2& position) : position(position) { 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/MouseLeave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | MouseLeave::MouseLeave() { 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/MouseMove.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | MouseMove::MouseMove(const glm::vec2& position) : position(position) { 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/MouseRelease.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | MouseRelease::MouseRelease(const GLUL::Input::MouseButton& button, const glm::vec2& position) : button(button), position(position) { 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/GLUL/GUI/Events/TextInput.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace GUI { 7 | 8 | namespace Event { 9 | 10 | TextInput::TextInput(const std::string& text) : text(text) { } 11 | 12 | } 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/GLUL/Input/Event.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | Event::Event(Type type) { 9 | _type = type; 10 | } 11 | 12 | 13 | Event::Type Event::getType() const { 14 | return _type; 15 | } 16 | 17 | 18 | Event* Event::asEvent() { 19 | return static_cast(this); 20 | } 21 | 22 | const Event* Event::asEvent() const { 23 | return static_cast(this); 24 | } 25 | 26 | 27 | 28 | CharacterEvent* Event::asCharacterEvent() { 29 | return nullptr; 30 | } 31 | 32 | KeyEvent* Event::asKeyEvent() { 33 | return nullptr; 34 | } 35 | 36 | MouseButtonEvent* Event::asMouseButtonEvent() { 37 | return nullptr; 38 | } 39 | 40 | MouseMovementEvent* Event::asMouseMovementEvent() { 41 | return nullptr; 42 | } 43 | 44 | MouseScrollEvent* Event::asMouseScrollEvent() { 45 | return nullptr; 46 | } 47 | 48 | const CharacterEvent* Event::asCharacterEvent() const { 49 | return nullptr; 50 | } 51 | 52 | const KeyEvent* Event::asKeyEvent() const { 53 | return nullptr; 54 | } 55 | 56 | const MouseButtonEvent* Event::asMouseButtonEvent() const { 57 | return nullptr; 58 | } 59 | 60 | const MouseMovementEvent* Event::asMouseMovementEvent() const { 61 | return nullptr; 62 | } 63 | 64 | const MouseScrollEvent* Event::asMouseScrollEvent() const { 65 | return nullptr; 66 | } 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventHandler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace Input { 8 | 9 | std::unordered_map, GLUL::Helper::HashEnum> _inputEventAggregators; 10 | 11 | EventHandler::~EventHandler() { 12 | _unregisterNotifications(); 13 | } 14 | 15 | void EventHandler::_unregisterNotifications() { 16 | for(auto& typeSet : _inputEventAggregators) { 17 | for(auto& aggregator : typeSet.second) { 18 | aggregator->unregisterHandler(typeSet.first, this, false); 19 | } 20 | } 21 | 22 | _inputEventAggregators.clear(); 23 | } 24 | 25 | void EventHandler::_removeAggregator(Event::Type type, EventAggregator* eventAggregator) { 26 | _inputEventAggregators[type].erase(eventAggregator); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTrigger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | namespace GLUL { 6 | 7 | namespace Input { 8 | 9 | EventTrigger::EventTrigger(EventAggregator& eventAggregator) : _eventAggregator(eventAggregator) { 10 | _registered = false; 11 | _triggerID = 0; 12 | } 13 | 14 | EventTrigger::~EventTrigger() { 15 | reset(); 16 | } 17 | 18 | void EventTrigger::reset() { 19 | if(_registered) { 20 | for(Event::Type type : _types) { 21 | _eventAggregator.unregisterTrigger(type, _triggerID); 22 | } 23 | } 24 | 25 | _types.clear(); 26 | _registered = false; 27 | } 28 | 29 | void EventTrigger::setFunction(Event::Type type, const std::function& trigger) { 30 | reset(); 31 | 32 | _triggerID = _eventAggregator.registerTrigger(type, trigger); 33 | _types = { type }; 34 | 35 | _registered = true; 36 | } 37 | 38 | void EventTrigger::setFunction(std::initializer_list types, const std::function& trigger) { 39 | reset(); 40 | 41 | _triggerID = _eventAggregator.registerTrigger(types, trigger); 42 | _types = types; 43 | 44 | _registered = true; 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTypes/CharacterEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | CharacterEvent::CharacterEvent() : CharacterEvent(0u) { 9 | 10 | } 11 | 12 | CharacterEvent::CharacterEvent(unsigned int code) : Event(Type::Character) { 13 | setCharacter(code); 14 | } 15 | 16 | unsigned int CharacterEvent::getCharacter() const { 17 | return _code; 18 | } 19 | 20 | void CharacterEvent::setCharacter(unsigned int code) { 21 | _code = code; 22 | } 23 | 24 | bool CharacterEvent::isASCII() const { 25 | return (_code < 256); 26 | } 27 | 28 | unsigned char CharacterEvent::asASCII() const { 29 | return static_cast(_code); 30 | } 31 | 32 | 33 | CharacterEvent* CharacterEvent::asCharacterEvent() { 34 | return this; 35 | } 36 | 37 | const CharacterEvent* CharacterEvent::asCharacterEvent() const { 38 | return this; 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTypes/KeyEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | KeyEvent::KeyEvent() : Event(Type::Key) { 9 | _key = Key::Enter; 10 | _action = Action::Press; 11 | } 12 | 13 | KeyEvent::KeyEvent(Key key, Action action) : Event(Type::Key) { 14 | setKey(key); 15 | setAction(action); 16 | } 17 | 18 | Key KeyEvent::getKey() const { 19 | return _key; 20 | } 21 | 22 | Action KeyEvent::getAction() const { 23 | return _action; 24 | } 25 | 26 | void KeyEvent::setKey(Key key) { 27 | _key = key; 28 | } 29 | 30 | void KeyEvent::setAction(Action action) { 31 | _action = action; 32 | } 33 | 34 | 35 | KeyEvent* KeyEvent::asKeyEvent() { 36 | return this; 37 | } 38 | 39 | const KeyEvent* KeyEvent::asKeyEvent() const { 40 | return this; 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTypes/MouseButtonEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | MouseButtonEvent::MouseButtonEvent() : Event(Type::MouseButton) { 9 | _button = MouseButton::Left; 10 | _action = Action::Press; 11 | } 12 | 13 | MouseButtonEvent::MouseButtonEvent(MouseButton button, Action action, float x, float y) : MouseButtonEvent(button, action, glm::vec2(x, y)) { 14 | 15 | } 16 | 17 | MouseButtonEvent::MouseButtonEvent(MouseButton button, Action action, const glm::vec2& position) : Event(Type::MouseButton) { 18 | setMouseButton(button); 19 | setAction(action); 20 | setPosition(position); 21 | } 22 | 23 | 24 | float MouseButtonEvent::getX() const { 25 | return getPosition().x; 26 | } 27 | 28 | float MouseButtonEvent::getY() const { 29 | return getPosition().y; 30 | } 31 | 32 | const glm::vec2& MouseButtonEvent::getPosition() const { 33 | return _position; 34 | } 35 | 36 | MouseButton MouseButtonEvent::getMouseButton() const { 37 | return _button; 38 | } 39 | 40 | Action MouseButtonEvent::getAction() const { 41 | return _action; 42 | } 43 | 44 | void MouseButtonEvent::setX(float x) { 45 | _position.x = x; 46 | } 47 | 48 | void MouseButtonEvent::setY(float y) { 49 | _position.y = y; 50 | } 51 | 52 | void MouseButtonEvent::setPosition(const glm::vec2& position) { 53 | _position = position; 54 | } 55 | 56 | void MouseButtonEvent::setMouseButton(MouseButton button) { 57 | _button = button; 58 | } 59 | 60 | void MouseButtonEvent::setAction(Action action) { 61 | _action = action; 62 | } 63 | 64 | 65 | MouseButtonEvent* MouseButtonEvent::asMouseButtonEvent() { 66 | return this; 67 | } 68 | 69 | const MouseButtonEvent* MouseButtonEvent::asMouseButtonEvent() const { 70 | return this; 71 | } 72 | 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTypes/MouseMovementEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | MouseMovementEvent::MouseMovementEvent() : Event(Type::MouseMovement) { 9 | setPosition(glm::vec2(0.0f)); 10 | } 11 | 12 | MouseMovementEvent::MouseMovementEvent(float x, float y) : Event(Type::MouseMovement) { 13 | setPosition(glm::vec2(x, y)); 14 | } 15 | 16 | MouseMovementEvent::MouseMovementEvent(const glm::vec2& position) : Event(Type::MouseMovement) { 17 | setPosition(position); 18 | } 19 | 20 | float MouseMovementEvent::getX() const { 21 | return _position.x; 22 | } 23 | 24 | float MouseMovementEvent::getY() const { 25 | return _position.y; 26 | } 27 | 28 | const glm::vec2& MouseMovementEvent::getPosition() const { 29 | return _position; 30 | } 31 | 32 | void MouseMovementEvent::setX(float x) { 33 | _position.x = x; 34 | } 35 | 36 | void MouseMovementEvent::setY(float y) { 37 | _position.y = y; 38 | } 39 | 40 | void MouseMovementEvent::setPosition(const glm::vec2& position) { 41 | _position = position; 42 | } 43 | 44 | 45 | MouseMovementEvent* MouseMovementEvent::asMouseMovementEvent() { 46 | return this; 47 | } 48 | 49 | const MouseMovementEvent* MouseMovementEvent::asMouseMovementEvent() const { 50 | return this; 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/GLUL/Input/EventTypes/MouseScrollEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | namespace Input { 7 | 8 | MouseScrollEvent::MouseScrollEvent() : Event(Type::MouseScroll) { 9 | _direction = ScrollDirection::Up; 10 | } 11 | 12 | MouseScrollEvent::MouseScrollEvent(ScrollDirection scrollDirection) : Event(Type::MouseScroll) { 13 | setDirection(scrollDirection); 14 | } 15 | 16 | 17 | ScrollDirection MouseScrollEvent::getDirection() const { 18 | return _direction; 19 | } 20 | 21 | void MouseScrollEvent::setDirection(ScrollDirection scrollDirection) { 22 | _direction = scrollDirection; 23 | } 24 | 25 | 26 | MouseScrollEvent* MouseScrollEvent::asMouseScrollEvent() { 27 | return this; 28 | } 29 | 30 | const MouseScrollEvent* MouseScrollEvent::asMouseScrollEvent() const { 31 | return this; 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/GLUL/Input/Keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | 8 | namespace GLUL { 9 | 10 | namespace Input { 11 | 12 | Input::Action Keyboard::getState(Key key) { 13 | return getState(key, GLUL::Windows::Active()); 14 | } 15 | 16 | Input::Action Keyboard::getState(Key key, GLUL::Window* window) { 17 | Input::Action result = Input::Action::Release; 18 | 19 | if(window) { 20 | int libResult = glfwGetKey(window->getHandle(), static_cast(key)); 21 | 22 | switch(libResult) { 23 | case GLFW_PRESS: result = Input::Action::Press; break; 24 | case GLFW_REPEAT: result = Input::Action::Repeat; break; 25 | case GLFW_RELEASE: result = Input::Action::Release; break; 26 | 27 | default: 28 | break; 29 | } 30 | } 31 | 32 | return result; 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/GLUL/Interfaces/Camera.cpp: -------------------------------------------------------------------------------- 1 | #ifndef GLM_FORCE_RADIANS 2 | #define GLM_FORCE_RADIANS 3 | #endif 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace GLUL { 10 | 11 | namespace Interface { 12 | 13 | Camera::Camera() { 14 | _matrix = glm::mat4(1.0f); 15 | _projectionMatrix = glm::perspective(glm::radians(60.0f), 4.0f / 3.0f, 0.1f, 1000.0f); 16 | } 17 | 18 | Camera::~Camera() { 19 | 20 | } 21 | 22 | const glm::mat4& Camera::getMatrix() const { 23 | return _matrix; 24 | } 25 | 26 | const glm::mat4& Camera::getProjection() const { 27 | return _projectionMatrix; 28 | } 29 | 30 | const glm::vec3& Camera::getUp() const { 31 | return _up; 32 | } 33 | 34 | const glm::vec3& Camera::getRight() const { 35 | return _right; 36 | } 37 | 38 | const glm::vec3& Camera::getDirection() const { 39 | return _direction; 40 | } 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /src/GLUL/Interfaces/ImageFile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace GLUL { 4 | 5 | namespace Interface { 6 | 7 | ImageFile::ImageFile() { 8 | 9 | } 10 | 11 | ImageFile::~ImageFile() { 12 | 13 | } 14 | 15 | void ImageFile::setImage(Image& image, unsigned int width, unsigned int height, unsigned int bits, unsigned char* data) const { 16 | unsigned int rowStride; 17 | 18 | image._width = width; 19 | image._height = height; 20 | image._bits = bits; 21 | image._data = data; 22 | 23 | rowStride = width * (bits / 8); 24 | rowStride = rowStride + (3 - ((rowStride - 1) % 4)); 25 | 26 | image._size = height * rowStride; 27 | } 28 | 29 | std::vector ImageFile::getRGBDataOf(const Image& image) const { 30 | std::vector result; 31 | 32 | result.reserve(image.getWidth() * image.getHeight() * 3); 33 | 34 | for(unsigned int row = 0; row < image.getHeight(); ++row) { 35 | for(unsigned int coll = 0; coll < image.getWidth(); ++coll) { 36 | glm::uvec4 pixel = image.getPixel(coll, row); 37 | 38 | result.push_back(static_cast(pixel.r)); 39 | result.push_back(static_cast(pixel.g)); 40 | result.push_back(static_cast(pixel.b)); 41 | } 42 | } 43 | 44 | return result; 45 | } 46 | 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/GLUL/Interfaces/Model.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace GLUL { 4 | 5 | namespace Interface { 6 | 7 | Model::Model() : _hasVertices(false), _hasTexCoords(false), _hasNormals(false), _path("") { 8 | 9 | } 10 | 11 | Model::~Model() { 12 | 13 | } 14 | 15 | bool Model::reload() { 16 | if(clear()) 17 | if(load(getPath(), GLUL::Interface::Model::NormalType::Default)) 18 | return true; 19 | 20 | return false; 21 | } 22 | 23 | void Model::render(const GL::Pipeline& pipeline) const { 24 | render(pipeline, _program); 25 | } 26 | 27 | void Model::renderAABB(const GL::Pipeline& pipeline, bool detailed) const { 28 | (void) detailed; 29 | 30 | _aabb.render(pipeline); 31 | } 32 | 33 | void Model::update(double deltaTime) { 34 | (void) deltaTime; 35 | } 36 | 37 | void Model::printStats(bool detailed) const { 38 | (void) detailed; 39 | } 40 | 41 | void Model::setMatrix() { 42 | setMatrix(glm::mat4(1.0f)); 43 | } 44 | 45 | void Model::setMatrix(const glm::mat4& matrix) { 46 | _matrix = matrix; 47 | } 48 | 49 | bool Model::hasVertices() const { 50 | return _hasVertices; 51 | } 52 | 53 | bool Model::hasTexCoords() const { 54 | return _hasTexCoords; 55 | } 56 | 57 | bool Model::hasNormals() const { 58 | return _hasNormals; 59 | } 60 | 61 | const AABB& Model::getAABB() const { 62 | return _aabb; 63 | } 64 | 65 | const std::string& Model::getPath() const { 66 | return _path; 67 | } 68 | 69 | const glm::mat4& Model::getMatrix() const { 70 | return _matrix; 71 | } 72 | 73 | glm::mat4& Model::getMatrix() { 74 | return _matrix; 75 | } 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /src/GLUL/Interfaces/State.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace GLUL { 4 | 5 | namespace Interface { 6 | 7 | State::State() { 8 | _next = this; 9 | } 10 | 11 | State::~State() { 12 | _next = nullptr; 13 | } 14 | 15 | void State::handleInputEvent(const Input::Event& inputEvent) { 16 | if(shouldSkip()) 17 | return; 18 | 19 | (void) inputEvent; 20 | } 21 | 22 | State* State::getNext() { 23 | return _next; 24 | } 25 | 26 | void State::_update(const double frameTime) { 27 | if(!shouldSkip()) 28 | update(frameTime); 29 | } 30 | 31 | void State::_render() { 32 | if(!shouldSkip()) 33 | render(); 34 | } 35 | 36 | void State::_onLoad() { 37 | changeTo(this); 38 | onLoad(); 39 | } 40 | 41 | void State::_onUnload() { 42 | onUnload(); 43 | } 44 | 45 | void State::changeTo(State* nextState) { 46 | _next = nextState; 47 | } 48 | 49 | bool State::shouldSkip() { 50 | return (getNext() != this); 51 | } 52 | 53 | const State* const State::Quit = nullptr; 54 | 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /src/GLUL/Point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | Point::Point() { 10 | setPoint(glm::vec2(0.0f)); 11 | } 12 | 13 | Point::Point(const Point& point) { 14 | setPoint(point); 15 | } 16 | 17 | Point::Point(const glm::vec2& point) { 18 | setPoint(point); 19 | } 20 | 21 | Point::Point(const float x, const float y) { 22 | setPoint(x, y); 23 | } 24 | 25 | Point& Point::operator=(const Point& point) { 26 | setPoint(point); 27 | 28 | return *this; 29 | } 30 | 31 | Point& Point::operator=(const glm::vec2& point) { 32 | setPoint(point); 33 | 34 | return *this; 35 | } 36 | 37 | void Point::setPoint(const Point& point) { 38 | setPoint(point.getPosition()); 39 | } 40 | 41 | void Point::setPoint(const glm::vec2& point) { 42 | _position = point; 43 | } 44 | 45 | void Point::setPoint(const float x, const float y) { 46 | setPoint(glm::vec2(x, y)); 47 | } 48 | 49 | double Point::distance(const Point& point) const { 50 | return glm::distance(getPosition(), point.getPosition()); 51 | } 52 | 53 | double Point::distance(const glm::vec2& point) const { 54 | return glm::distance(getPosition(), point); 55 | } 56 | 57 | double Point::distance(const Line& line) const { 58 | glm::vec2 vec = line.getPosition2() - line.getPosition1(); 59 | 60 | float dotProduct = glm::dot(vec, vec); 61 | float factor = ((getX() - line.getPosition1().x) * vec.x + (getY() - line.getPosition1().y) * vec.y) / dotProduct; 62 | 63 | if(factor > 1) factor = 1; 64 | else if(factor < 0) factor = 0; 65 | 66 | glm::vec2 scaled = line.getPosition1() + factor * vec; 67 | glm::vec2 dist = scaled - getPosition(); 68 | 69 | return glm::length(dist); 70 | } 71 | 72 | float Point::getX() const { 73 | return getPosition().x; 74 | } 75 | 76 | float Point::getY() const { 77 | return getPosition().y; 78 | } 79 | 80 | const glm::vec2& Point::getPosition() const { 81 | return _position; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/GLUL/TimeEvent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | namespace GLUL { 5 | 6 | TimeEvent::TimeEvent(double time, const std::function& delayedEvent) : 7 | _isDone(false), 8 | _id(TimeEvent::getNewID()), 9 | _time(time), 10 | _type(Type::DelayedEvent), 11 | _delayedEvent(delayedEvent) 12 | { 13 | 14 | } 15 | 16 | 17 | TimeEvent::TimeEvent(const std::function& updateEvent) : 18 | _isDone(false), 19 | _id(TimeEvent::getNewID()), 20 | _time(0.0), 21 | _type(Type::UpdateEvent), 22 | _updateEvent(updateEvent) 23 | { 24 | 25 | } 26 | 27 | bool TimeEvent::operator==(const TimeEvent& e) { 28 | return getID() == e.getID(); 29 | } 30 | 31 | void TimeEvent::execute() { 32 | if(_type == Type::DelayedEvent) 33 | _delayedEvent(); 34 | } 35 | 36 | void TimeEvent::execute(double deltaTime) { 37 | if(_type == Type::UpdateEvent) 38 | _updateEvent(*this, deltaTime); 39 | } 40 | 41 | void TimeEvent::setTime(double time) { 42 | _time = time; 43 | } 44 | 45 | void TimeEvent::setDone() { 46 | _isDone = true; 47 | } 48 | 49 | TimeEvent::Type TimeEvent::getType() const { 50 | return _type; 51 | } 52 | 53 | bool TimeEvent::isDone() const { 54 | if(getType() == Type::DelayedEvent) 55 | return (getTime() <= 0); 56 | 57 | return _isDone; 58 | } 59 | 60 | double TimeEvent::getTime() const { 61 | return _time; 62 | } 63 | 64 | unsigned int TimeEvent::getID() const { 65 | return _id; 66 | } 67 | 68 | unsigned int TimeEvent::getNewID() { 69 | static unsigned int nextID = 0; 70 | 71 | return nextID++; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/GLUL/TimeLoop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace GLUL { 6 | 7 | TimeLoop::TimeLoop() { 8 | _accumulator = 0.0; 9 | } 10 | 11 | void TimeLoop::fixed(double time, double timeStep, const std::function& function) { 12 | _accumulator += time; 13 | 14 | while(_accumulator > timeStep) { 15 | function(timeStep); 16 | _accumulator -= timeStep; 17 | } 18 | } 19 | 20 | void TimeLoop::variable(double time, const std::function& function) { 21 | function(time); 22 | } 23 | 24 | void TimeLoop::semiFixed(double time, double timeStep, const std::function& function) { 25 | double currentTimeStep; 26 | 27 | while(time > 0) { 28 | currentTimeStep = std::min(time, timeStep); 29 | function(currentTimeStep); 30 | time -= timeStep; 31 | } 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /src/GLUL/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | 7 | namespace GLUL { 8 | 9 | Timer::Timer() { 10 | _clock.reset(); 11 | } 12 | 13 | unsigned int Timer::insertEvent(double delay, const std::function& event) { 14 | return insertEvent(TimeEvent(delay, event)); 15 | } 16 | 17 | unsigned int Timer::insertEvent(const TimeEvent& event) { 18 | _events.push_back(event); 19 | return event.getID(); 20 | } 21 | 22 | void Timer::deleteEvent(unsigned int id) { 23 | _events.remove_if([id](const TimeEvent& event) -> bool { return event.getID() == id; }); 24 | } 25 | 26 | void Timer::update() { 27 | double timeElapsed = _clock.getElapsedTime(); 28 | update(timeElapsed); 29 | } 30 | 31 | void Timer::update(double timeElapsed) { 32 | _clock.reset(); 33 | 34 | for(std::list::iterator event = _events.begin(); event != _events.end(); ) { 35 | 36 | switch(event->getType()) { 37 | case TimeEvent::Type::DelayedEvent: 38 | event->setTime(event->getTime() - timeElapsed); 39 | if(event->isDone()) 40 | event->execute(); 41 | break; 42 | 43 | case TimeEvent::Type::UpdateEvent: 44 | event->execute(timeElapsed); 45 | break; 46 | } 47 | 48 | if(event->isDone()) 49 | event = _events.erase(event); 50 | else 51 | ++event; 52 | } 53 | } 54 | 55 | void Timer::resetClock() { 56 | _clock.reset(); 57 | } 58 | 59 | const std::list& Timer::getEvents() const { 60 | return _events; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /tests/bin/test_assets/file/emptylines.txt: -------------------------------------------------------------------------------- 1 | sample text for unit test 2 | 3 | thrid line 4 | 5 | 6 | last line will be empty 7 | -------------------------------------------------------------------------------- /tests/bin/test_assets/file/multilinetextfield.txt: -------------------------------------------------------------------------------- 1 | sample text for unit test 2 | second line 3 | thrid -------------------------------------------------------------------------------- /tests/bin/test_assets/file/textfile.txt: -------------------------------------------------------------------------------- 1 | sample text for unit test -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image.jpg -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image.png -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image.tga -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_cropping_test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_cropping_test.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_greyscale.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_greyscale.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_invert_colors.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_invert_colors.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_invert_h.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_invert_h.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_invert_v.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_invert_v.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_r180.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_r180.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_r270.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_r270.bmp -------------------------------------------------------------------------------- /tests/bin/test_assets/image/image_r90.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RippeR37/GLUL/2e5cd72192d039d281c5df09a816901f6fea28f9/tests/bin/test_assets/image/image_r90.bmp -------------------------------------------------------------------------------- /tests/src/GLUL/Clock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | TEST(GLUL_Clock, Now_Notdecreasing) { 11 | auto time1 = GLUL::Clock::now(); 12 | auto time2 = GLUL::Clock::now(); 13 | 14 | ASSERT_TRUE(time1 <= time2); 15 | } 16 | 17 | TEST(GLUL_Clock, Get_Elapsed_With_Sleep) { 18 | GLUL::Clock clock; 19 | double t1, t2, t3; 20 | 21 | t1 = clock.getElapsedTime(); 22 | t2 = clock.getElapsedTime(); 23 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 24 | t3 = clock.getElapsedTime(); 25 | 26 | ASSERT_TRUE(t1 <= t2); 27 | ASSERT_TRUE(t2 <= t3); 28 | ASSERT_TRUE(t3 - t2 >= 0.1); 29 | } 30 | 31 | TEST(GLUL_Clock, Reset) { 32 | GLUL::Clock clock; 33 | double t1, t2; 34 | 35 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 36 | t1 = clock.getElapsedTime(); 37 | clock.reset(); 38 | t2 = clock.getElapsedTime(); 39 | 40 | ASSERT_TRUE(t2 < t1); 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main(int argc, char* argv[]) { 5 | ::testing::InitGoogleTest(&argc, argv); 6 | 7 | return RUN_ALL_TESTS(); 8 | } 9 | --------------------------------------------------------------------------------