Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include <Magnum/DebugTools/Screenshot.h>
  2. #include <Magnum/GL/Buffer.h>
  3. #include <Magnum/GL/Framebuffer.h>
  4. #include <Magnum/GL/Mesh.h>
  5. #include <Magnum/GL/Renderbuffer.h>
  6. #include <Magnum/GL/RenderbufferFormat.h>
  7. #ifdef MAGNUM_TARGET_HEADLESS
  8. #include <Magnum/Platform/WindowlessEglApplication.h>
  9. #elif defined(CORRADE_TARGET_IOS)
  10. #include <Magnum/Platform/WindowlessIosApplication.h>
  11. #elif defined(CORRADE_TARGET_APPLE)
  12. #include <Magnum/Platform/WindowlessCglApplication.h>
  13. #elif defined(CORRADE_TARGET_UNIX)
  14. #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_DESKTOP_GLES)
  15. #include <Magnum/Platform/WindowlessGlxApplication.h>
  16. #else
  17. #include <Magnum/Platform/WindowlessEglApplication.h>
  18. #endif
  19. #elif defined(CORRADE_TARGET_WINDOWS)
  20. #if !defined(MAGNUM_TARGET_GLES) || defined(MAGNUM_TARGET_DESKTOP_GLES)
  21. #include <Magnum/Platform/WindowlessWglApplication.h>
  22. #else
  23. #include <Magnum/Platform/WindowlessWindowsEglApplication.h>
  24. #endif
  25. #else
  26. #error no windowless application available on this platform
  27. #endif
  28. #include <Magnum/Shaders/VertexColor.h>
  29.  
  30. using namespace Magnum;
  31.  
  32. class MyApplication: public Platform::WindowlessApplication {
  33. public:
  34. using Platform::WindowlessApplication::WindowlessApplication;
  35.  
  36. int exec() override;
  37. };
  38.  
  39. int MyApplication::exec() {
  40. using namespace Math::Literals;
  41.  
  42. struct TriangleVertex {
  43. Vector2 position;
  44. Color3 color;
  45. };
  46. const TriangleVertex data[]{
  47. {{-0.5f, -0.5f}, 0xff0000_rgbf}, /* Left vertex, red color */
  48. {{ 0.5f, -0.5f}, 0x00ff00_rgbf}, /* Right vertex, green color */
  49. {{ 0.0f, 0.5f}, 0x0000ff_rgbf} /* Top vertex, blue color */
  50. };
  51.  
  52. GL::Buffer buffer;
  53. buffer.setData(data);
  54.  
  55. GL::Mesh mesh;
  56. mesh.setCount(3)
  57. .addVertexBuffer(std::move(buffer), 0,
  58. Shaders::VertexColor2D::Position{},
  59. Shaders::VertexColor2D::Color3{});
  60.  
  61. GL::Renderbuffer renderbuffer;
  62. renderbuffer.setStorage(GL::RenderbufferFormat::RGBA8, {640, 480});
  63. GL::Framebuffer framebuffer{{{}, {640, 480}}};
  64. framebuffer.attachRenderbuffer(GL::Framebuffer::ColorAttachment{0}, renderbuffer)
  65. .clear(GL::FramebufferClear::Color)
  66. .bind();
  67.  
  68. Shaders::VertexColor2D shader;
  69. mesh.draw(shader);
  70.  
  71. if(DebugTools::screenshot(framebuffer, "triangle.png"))
  72. return 0;
  73. else {
  74. Error{} << "oh noes!";
  75. return 1;
  76. }
  77. }
  78.  
  79. MAGNUM_WINDOWLESSAPPLICATION_MAIN(MyApplication)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement