53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
#pragma once
|
|
|
|
class Shape
|
|
{
|
|
protected:
|
|
GLuint buffers[2];
|
|
GLuint arrays[2];
|
|
GLuint count[2];
|
|
GLvoid* ioff[2];
|
|
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
|
public:
|
|
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
|
|
void draw_fill() const;
|
|
void draw_stroke() const;
|
|
};
|
|
|
|
class Plane : public Shape
|
|
{
|
|
void create_impl(float w, float h, int div, GLushort* idx, vertex_t* vertices);
|
|
public:
|
|
template<int div>
|
|
bool create(float w, float h)
|
|
{
|
|
static GLushort idx[div * div * 6 + 8];
|
|
static vertex_t vertices[(div+1)*(div+1)];
|
|
create_impl(w, h, div, idx, vertices);
|
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
|
}
|
|
};
|
|
|
|
class Circle : public Shape
|
|
{
|
|
void create_impl(float radius, int div, GLushort* idx, vertex_t* vertices);
|
|
void create_impl(float radius_out, float radius_in, int div, GLushort* idx, vertex_t* vertices);
|
|
public:
|
|
template<int div>
|
|
bool create(float radius)
|
|
{
|
|
static GLushort idx[div * 3 + div * 2];
|
|
static vertex_t vertices[div + 1];
|
|
create_impl(radius, div, idx, vertices);
|
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
|
}
|
|
template<int div>
|
|
bool create(float radius_out, float radius_in)
|
|
{
|
|
static GLushort idx[div*6 + div*4];
|
|
static vertex_t vertices[div * 2];
|
|
create_impl(radius_out, radius_in, div, idx, vertices);
|
|
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
|
|
}
|
|
};
|