// // Drawer.h // OSXGLEssentials // // Created by Joshua Moerman on 10/03/14. // // #pragma once #include #include #include #include #include struct Vertex { using Position = moggle::vector3; using Color = moggle::vector3; Position position; Color color; }; inline moggle::vector3 convert(b2Vec2 const & p){ return {p.x, p.y, 0.0f}; } inline moggle::vector3 convert(b2Color const & p){ return {p.r, p.g, p.b}; } struct Drawer : b2Draw { // camera position Vertex::Position camera = {0, 0}; // print debugging info bool verbose = false; // bundle needed to load shaders Drawer(std::string const & bundle); // draw buffer void draw(); // clear buffer void clear(); // resize any stuff void resize(float width, float height); // Box 2D drawing interface // Implementation will fill its buffers virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override; virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) override; virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) override; virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) override; virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) override; virtual void DrawTransform(const b2Transform& xf) override; private: moggle::shader_program program; moggle::matrix4 projection; std::vector segments; std::vector sizes; GLuint vao, buf; };