Created
May 7, 2018 12:14
-
-
Save uzername/16eb95fac771e53354efe2dfb3a1d008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MyMagnumRenderer_guard | |
#define MyMagnumRenderer_guard | |
#include <Magnum/GL/Buffer.h> | |
#include <Magnum/GL/DefaultFramebuffer.h> | |
#include <Magnum/GL/Mesh.h> | |
#include <Magnum/Platform/GLContext.h> | |
#include <Magnum/Shaders/VertexColor.h> | |
using namespace Magnum; | |
using namespace Math::Literals; | |
struct TriangleVertex { | |
Vector2 position; | |
Color3 color; | |
}; | |
class MyMagnumRenderer | |
{ | |
public: | |
Platform::GLContext* shared_ctx = NULL; | |
~MyMagnumRenderer(); | |
void activateMagnum(); | |
void drawEvent(); | |
private: | |
const TriangleVertex data[3]{ | |
{ { -0.5f, -0.5f }, 0xff0000_rgbf }, /* Left vertex, red color */ | |
{ { 0.5f, -0.5f }, 0x00ff00_rgbf }, /* Right vertex, green color */ | |
{ { 0.0f, 0.5f }, 0x0000ff_rgbf } /* Top vertex, blue color */ | |
}; | |
GL::Buffer _buffer; | |
GL::Mesh _mesh; | |
Shaders::VertexColor2D _shader; | |
}; | |
MyMagnumRenderer::~MyMagnumRenderer() | |
{ | |
delete shared_ctx; | |
} | |
void MyMagnumRenderer::activateMagnum() { | |
shared_ctx = new Platform::GLContext(); | |
_buffer.setData(data, GL::BufferUsage::StaticDraw); | |
_mesh.setPrimitive(GL::MeshPrimitive::Triangles) | |
.setCount(3) | |
.addVertexBuffer(_buffer, 0, | |
Shaders::VertexColor2D::Position{}, | |
Shaders::VertexColor2D::Color{ Shaders::VertexColor2D::Color::Components::Three }); | |
} | |
void MyMagnumRenderer::drawEvent() { | |
GL::defaultFramebuffer.clear(GL::FramebufferClear::Color); | |
_mesh.draw(_shader); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment