You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.7 KiB
66 lines
1.7 KiB
//
|
|
// Drawer.h
|
|
// OSXGLEssentials
|
|
//
|
|
// Created by Joshua Moerman on 10/03/14.
|
|
//
|
|
//
|
|
|
|
#pragma once
|
|
|
|
#include <Box2D/Box2D.h>
|
|
|
|
#include <moggle/core/gl.hpp>
|
|
#include <moggle/math/matrix.hpp>
|
|
#include <moggle/core/shader.hpp>
|
|
|
|
#include <vector>
|
|
|
|
struct Vertex {
|
|
using Position = moggle::vector3<float>;
|
|
using Color = moggle::vector3<float>;
|
|
|
|
Position position;
|
|
Color color;
|
|
};
|
|
|
|
inline moggle::vector3<float> convert(b2Vec2 const & p){ return {p.x, p.y, 0.0f}; }
|
|
inline moggle::vector3<float> 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<float> projection;
|
|
std::vector<Vertex> segments;
|
|
std::vector<GLuint> sizes;
|
|
GLuint vao, buf;
|
|
};
|
|
|
|
|
|
|