master
mitchellhansen 2 years ago
parent 100dcaf79d
commit 6edbb3646f

@ -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

@ -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š <mosra@centrum.cz>
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;

@ -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š <mosra@centrum.cz>
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;

@ -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

@ -1,9 +1,5 @@
//#ifndef FLOPPY_BIRD_BIRD_H
//#define FLOPPY_BIRD_BIRD_H
//
//#include <SFML/Graphics/Sprite.hpp>
//#include <SFML/Graphics/Texture.hpp>
//#include <SFML/Graphics/RenderTarget.hpp>
#pragma once
//#include <memory>
//
//const float gravity = 9.8;
@ -26,5 +22,3 @@
// virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
//};
//
//
//#endif //FLOPPY_BIRD_BIRD_H

@ -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);
}

@ -0,0 +1,52 @@
#pragma once
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/Resource.h>
#include <Magnum/ImageView.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/Platform/Sdl2Application.h>
#include <Magnum/Trade/AbstractImporter.h>
#include <Magnum/Trade/ImageData.h>
#include <Magnum/GL/Texture.h>
#include <Magnum/Math/Color.h>
#include <Corrade/Containers/Iterable.h>
#include <Corrade/Containers/StringView.h>
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Resource.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/Shader.h>
#include <Magnum/GL/Version.h>
#include <Magnum/GL/AbstractShaderProgram.h>
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;
};

@ -38,51 +38,7 @@
#include <Magnum/GL/Shader.h>
#include <Magnum/GL/Version.h>
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<Trade::AbstractImporter> manager;
Containers::Pointer<Trade::AbstractImporter> importer =
manager.loadAndInstantiate("TgaImporter");
@ -128,6 +89,7 @@ MyApplication::MyApplication(const Arguments& arguments): Platform::Application{
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
CORRADE_INTERNAL_ASSERT(image);
_texture.setWrapping(GL::SamplerWrapping::ClampToEdge)
.setMagnificationFilter(GL::SamplerFilter::Linear)
.setMinificationFilter(GL::SamplerFilter::Linear)

Loading…
Cancel
Save