diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-02-18 05:55:42 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-02-18 05:56:52 +0100 |
| commit | 8f499100e85472a68dda49be7471e97080639614 (patch) | |
| tree | 36d5395d15e576019b106e4f43bfbfe7247e960a /TexturedQuadExample.cpp | |
| parent | cbcf2471bb8a59db55efcad11691eab73d0ec2f5 (diff) | |
rename source files
Diffstat (limited to 'TexturedQuadExample.cpp')
| -rw-r--r-- | TexturedQuadExample.cpp | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/TexturedQuadExample.cpp b/TexturedQuadExample.cpp deleted file mode 100644 index ec166d6e..00000000 --- a/TexturedQuadExample.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "chunk.hpp" - -#include <Corrade/Containers/Optional.h> -#include <Corrade/Containers/ArrayViewStl.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 "TexturedQuadShader.h" - -namespace Magnum::Examples { - -struct TexturedQuadExample: Platform::Application { - explicit TexturedQuadExample(const Arguments& arguments); - void drawEvent() override; - - const Utility::Resource rs{"texturedquad-data"}; - PluginManager::Manager<Trade::AbstractImporter> plugins; - Containers::Pointer<Trade::AbstractImporter> tga_importer = - plugins.loadAndInstantiate("TgaImporter"); - - GL::Mesh _mesh; - TexturedQuadShader _shader; - atlas_texture atlas = make_atlas("images/tiles.tga", {8, 4}); - - atlas_texture make_atlas(const std::string& file, Vector2i dims) - { - if(!tga_importer || !tga_importer->openFile(file)) - std::exit(1); - - Containers::Optional<Trade::ImageData2D> image = tga_importer->image2D(0); - CORRADE_INTERNAL_ASSERT(image); - - return atlas_texture{*image, dims}; - } -}; - -TexturedQuadExample::TexturedQuadExample(const Arguments& arguments): - Platform::Application{arguments, Configuration{} - .setTitle("Magnum Textured Quad Example") - .setSize({512, 512})} -{ - struct QuadVertex { - Vector3 position; - Vector2 textureCoordinates; - }; - QuadVertex vertices[4]; - auto positions = atlas.floor_quad({}, {2, 2}); - auto texcoords = atlas.texcoords_for_id(2); - auto indices = atlas.indices(0); - - for (unsigned i = 0; i < std::size(vertices); i++) - vertices[i] = { positions[i], texcoords[i] }; - - _mesh.setCount(std::size(indices)) - .addVertexBuffer(GL::Buffer{vertices}, 0, - TexturedQuadShader::Position{}, - TexturedQuadShader::TextureCoordinates{}) - .setIndexBuffer(GL::Buffer{indices}, 0, - GL::MeshIndexType::UnsignedShort); -} - -void TexturedQuadExample::drawEvent() { - GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); - - using namespace Math::Literals; - - _shader - .setColor(0xffffff_rgbf) - .bindTexture(atlas.texture()) - .draw(_mesh); - - swapBuffers(); -} - -} // namespace Magnum::Examples - -MAGNUM_APPLICATION_MAIN(Magnum::Examples::TexturedQuadExample); - -#include <windows.h> - -#if defined _MSC_VER -int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int /* nCmdShow */) -{ - return main(__argc, __argv); -} -#endif |
