From 6edbb3646f30471e1582e60c44a0062c37516e8e Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Wed, 18 Jan 2023 19:06:01 -0800 Subject: [PATCH] bit more --- Assets/floppy-resources.conf | 13 ++++++ Assets/shaders/TexturedQuadShader.frag | 29 ------------- Assets/shaders/TexturedQuadShader.vert | 29 ------------- CMakeLists.txt | 4 +- src/Bird.h | 10 +---- src/QuadShader.cpp | 22 ++++++++++ src/QuadShader.h | 52 ++++++++++++++++++++++ src/main.cpp | 60 +++++--------------------- 8 files changed, 103 insertions(+), 116 deletions(-) create mode 100644 Assets/floppy-resources.conf create mode 100644 src/QuadShader.cpp create mode 100644 src/QuadShader.h diff --git a/Assets/floppy-resources.conf b/Assets/floppy-resources.conf new file mode 100644 index 0000000..328fe6c --- /dev/null +++ b/Assets/floppy-resources.conf @@ -0,0 +1,13 @@ +group=floppy-resources + +[file] +filename=shaders/pipe_shader.frag +alias=pipe_shader.frag + +[file] +filename=shaders/pipe_shader.vert +alias=pipe_shader.vert + +[file] +filename=images/bird.png +alias=bird.png diff --git a/Assets/shaders/TexturedQuadShader.frag b/Assets/shaders/TexturedQuadShader.frag index 06d647f..624fc8c 100644 --- a/Assets/shaders/TexturedQuadShader.frag +++ b/Assets/shaders/TexturedQuadShader.frag @@ -1,32 +1,3 @@ -/* - This file is part of Magnum. - - Original authors — credit is appreciated but not required: - - 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, - 2020, 2021, 2022 — Vladimír Vondruš - - This is free and unencumbered software released into the public domain. - - Anyone is free to copy, modify, publish, use, compile, sell, or distribute - this software, either in source code form or as a compiled binary, for any - purpose, commercial or non-commercial, and by any means. - - In jurisdictions that recognize copyright laws, the author or authors of - this software dedicate any and all copyright interest in the software to - the public domain. We make this dedication for the benefit of the public - at large and to the detriment of our heirs and successors. We intend this - dedication to be an overt act of relinquishment in perpetuity of all - present and future rights to this software under copyright law. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - uniform vec3 color = vec3(1.0, 1.0, 1.0); uniform sampler2D textureData; diff --git a/Assets/shaders/TexturedQuadShader.vert b/Assets/shaders/TexturedQuadShader.vert index 2fd94f8..3c5c7c6 100644 --- a/Assets/shaders/TexturedQuadShader.vert +++ b/Assets/shaders/TexturedQuadShader.vert @@ -1,32 +1,3 @@ -/* - This file is part of Magnum. - - Original authors — credit is appreciated but not required: - - 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, - 2020, 2021, 2022 — Vladimír Vondruš - - This is free and unencumbered software released into the public domain. - - Anyone is free to copy, modify, publish, use, compile, sell, or distribute - this software, either in source code form or as a compiled binary, for any - purpose, commercial or non-commercial, and by any means. - - In jurisdictions that recognize copyright laws, the author or authors of - this software dedicate any and all copyright interest in the software to - the public domain. We make this dedication for the benefit of the public - at large and to the detriment of our heirs and successors. We intend this - dedication to be an overt act of relinquishment in perpetuity of all - present and future rights to this software under copyright law. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - layout(location = 0) in vec4 position; layout(location = 1) in vec2 textureCoordinates; diff --git a/CMakeLists.txt b/CMakeLists.txt index f23b8fb..e1d09fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ message(STATUS "Magnum found: ${MAGNUM_FOUND}") corrade_add_resource(RESOURCES Assets/resources.conf) - # Set the sources, allows VS to filter them properly file(GLOB SOURCES "src/*.cpp") file(GLOB HEADERS "src/*.h") @@ -31,6 +30,9 @@ include_directories(include) add_executable(${PNAME} ${SOURCES} ${RESOURCES}) + +message(STATUS "sources: ${SOURCES}") + add_dependencies(${PNAME} Magnum::TgaImporter) target_link_libraries(${PNAME} PRIVATE diff --git a/src/Bird.h b/src/Bird.h index 9ed4342..8dd11b6 100644 --- a/src/Bird.h +++ b/src/Bird.h @@ -1,9 +1,5 @@ -//#ifndef FLOPPY_BIRD_BIRD_H -//#define FLOPPY_BIRD_BIRD_H -// -//#include -//#include -//#include +#pragma once + //#include // //const float gravity = 9.8; @@ -26,5 +22,3 @@ // virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const; //}; // -// -//#endif //FLOPPY_BIRD_BIRD_H diff --git a/src/QuadShader.cpp b/src/QuadShader.cpp new file mode 100644 index 0000000..d20a7f1 --- /dev/null +++ b/src/QuadShader.cpp @@ -0,0 +1,22 @@ +#include "QuadShader.h" + +QuadShader::QuadShader() { + MAGNUM_ASSERT_GL_VERSION_SUPPORTED(GL::Version::GL330); + + const Utility::Resource rs{"texturedquad-data"}; + + GL::Shader vert{GL::Version::GL330, GL::Shader::Type::Vertex}; + GL::Shader frag{GL::Version::GL330, GL::Shader::Type::Fragment}; + + vert.addSource(rs.getString("TexturedQuadShader.vert")); + frag.addSource(rs.getString("TexturedQuadShader.frag")); + + CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile()); + + attachShaders({vert, frag}); + + CORRADE_INTERNAL_ASSERT_OUTPUT(link()); + + _colorUniform = uniformLocation("color"); + setUniform(uniformLocation("textureData"), TextureUnit); +} \ No newline at end of file diff --git a/src/QuadShader.h b/src/QuadShader.h new file mode 100644 index 0000000..e1a7e2a --- /dev/null +++ b/src/QuadShader.h @@ -0,0 +1,52 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Magnum; + +class QuadShader: public GL::AbstractShaderProgram { +public: + typedef GL::Attribute<0, Vector2> Position; + typedef GL::Attribute<1, Vector2> TextureCoordinates; + + explicit QuadShader(); + + QuadShader& setColor(const Color3& color) { + setUniform(_colorUniform, color); + return *this; + } + + QuadShader& bindTexture(GL::Texture2D& texture) { + texture.bind(TextureUnit); + return *this; + } + +private: + enum: Int { TextureUnit = 0 }; + + Int _colorUniform; +}; + diff --git a/src/main.cpp b/src/main.cpp index 4dd6e41..3cc287b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,51 +38,7 @@ #include #include -using namespace Magnum; - -class TexturedQuadShader: public GL::AbstractShaderProgram { -public: - typedef GL::Attribute<0, Vector2> Position; - typedef GL::Attribute<1, Vector2> TextureCoordinates; - - explicit TexturedQuadShader(); - - TexturedQuadShader& setColor(const Color3& color) { - setUniform(_colorUniform, color); - return *this; - } - - TexturedQuadShader& bindTexture(GL::Texture2D& texture) { - texture.bind(TextureUnit); - return *this; - } - -private: - enum: Int { TextureUnit = 0 }; - - Int _colorUniform; -}; - -TexturedQuadShader::TexturedQuadShader() { - MAGNUM_ASSERT_GL_VERSION_SUPPORTED(GL::Version::GL330); - - const Utility::Resource rs{"texturedquad-data"}; - - GL::Shader vert{GL::Version::GL330, GL::Shader::Type::Vertex}; - GL::Shader frag{GL::Version::GL330, GL::Shader::Type::Fragment}; - - vert.addSource(rs.getString("TexturedQuadShader.vert")); - frag.addSource(rs.getString("TexturedQuadShader.frag")); - - CORRADE_INTERNAL_ASSERT_OUTPUT(vert.compile() && frag.compile()); - - attachShaders({vert, frag}); - - CORRADE_INTERNAL_ASSERT_OUTPUT(link()); - - _colorUniform = uniformLocation("color"); - setUniform(uniformLocation("textureData"), TextureUnit); -} +#include "QuadShader.h" class MyApplication: public Platform::Application { public: @@ -92,16 +48,19 @@ private: void drawEvent() override; GL::Mesh _mesh; - TexturedQuadShader _shader; + QuadShader _shader; GL::Texture2D _texture; }; MyApplication::MyApplication(const Arguments& arguments): Platform::Application{arguments} { + + // =============== Vertex and index buffer stuff ===================== + struct QuadVertex { Vector2 position; Vector2 textureCoordinates; }; - const QuadVertex vertices[]{ + const QuadVertex vertices[] { {{ 0.5f, -0.5f}, {1.0f, 0.0f}}, /* Bottom right */ {{ 0.5f, 0.5f}, {1.0f, 1.0f}}, /* Top right */ {{-0.5f, -0.5f}, {0.0f, 0.0f}}, /* Bottom left */ @@ -114,11 +73,13 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application{ _mesh.setCount(Containers::arraySize(indices)) .addVertexBuffer(GL::Buffer{vertices}, 0, - TexturedQuadShader::Position{}, - TexturedQuadShader::TextureCoordinates{}) + QuadShader::Position{}, + QuadShader::TextureCoordinates{}) .setIndexBuffer(GL::Buffer{indices}, 0, GL::MeshIndexType::UnsignedInt); + // ====================== Materials, resources, Textures ======================= + PluginManager::Manager manager; Containers::Pointer importer = manager.loadAndInstantiate("TgaImporter"); @@ -128,6 +89,7 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application{ Containers::Optional image = importer->image2D(0); CORRADE_INTERNAL_ASSERT(image); + _texture.setWrapping(GL::SamplerWrapping::ClampToEdge) .setMagnificationFilter(GL::SamplerFilter::Linear) .setMinificationFilter(GL::SamplerFilter::Linear)