Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Magnum/DebugTools/Screenshot.h>
- #include <Magnum/GL/Buffer.h>
- #include <Magnum/GL/Framebuffer.h>
- #include <Magnum/GL/Mesh.h>
- #include <Magnum/GL/Renderbuffer.h>
- #include <Magnum/GL/RenderbufferFormat.h>
- #ifdef MAGNUM_TARGET_HEADLESS
- #include <Magnum/Platform/WindowlessEglApplication.h>
- #elif defined(CORRADE_TARGET_IOS)
- #include <Magnum/Platform/WindowlessIosApplication.h>
- #elif defined(CORRADE_TARGET_APPLE)
- #include <Magnum/Platform/WindowlessCglApplication.h>
- #elif defined(CORRADE_TARGET_UNIX)
- #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_DESKTOP_GLES)
- #include <Magnum/Platform/WindowlessGlxApplication.h>
- #else
- #include <Magnum/Platform/WindowlessEglApplication.h>
- #endif
- #elif defined(CORRADE_TARGET_WINDOWS)
- #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_DESKTOP_GLES)
- #include <Magnum/Platform/WindowlessWglApplication.h>
- #else
- #include <Magnum/Platform/WindowlessWindowsEglApplication.h>
- #endif
- #else
- #error no windowless application available on this platform
- #endif
- #include <Magnum/Shaders/VertexColor.h>
- using namespace Magnum;
- class MyApplication: public Platform::WindowlessApplication {
- public:
- using Platform::WindowlessApplication::WindowlessApplication;
- int exec() override;
- };
- int MyApplication::exec() {
- using namespace Math::Literals;
- struct TriangleVertex {
- Vector2 position;
- Color3 color;
- };
- const TriangleVertex data[]{
- {{-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;
- buffer.setData(data);
- GL::Mesh mesh;
- mesh.setCount(3)
- .addVertexBuffer(std::move(buffer), 0,
- Shaders::VertexColor2D::Position{},
- Shaders::VertexColor2D::Color3{});
- GL::Renderbuffer renderbuffer;
- renderbuffer.setStorage(GL::RenderbufferFormat::RGBA8, {640, 480});
- GL::Framebuffer framebuffer{{{}, {640, 480}}};
- framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, renderbuffer)
- .clear(GL::FramebufferClear::Color)
- .bind();
- Shaders::VertexColor2D shader;
- mesh.draw(shader);
- if(DebugTools::screenshot(framebuffer, "triangle.png"))
- return 0;
- else {
- Error{} << "oh noes!";
- return 1;
- }
- }
- MAGNUM_WINDOWLESSAPPLICATION_MAIN(MyApplication)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement