added rect shape with corrected uv interpolation

This commit is contained in:
2017-01-18 23:01:00 +00:00
parent 5f6bcda211
commit 90ee10405d
3 changed files with 51 additions and 9 deletions

View File

@@ -43,6 +43,29 @@ void Shape::draw_stroke() const
glDrawElements(GL_LINES, count[1], GL_UNSIGNED_SHORT, ioff[1]);
}
bool Rect::create(float w, float h)
{
static GLushort idx[6 + 8] {
0, 1, 2,
0, 2, 3,
0, 1,
1, 2,
2, 3,
3, 0,
};
static vertex_t vertices[4];
vertices[0] = { { -w/2, -h/2, 0, 1 }, { 0, 0 } }; // A
vertices[1] = { { -w/2, h/2, 0, 1 }, { 0, 1 } }; // B
vertices[2] = { { w/2, 0, 0, 1 }, { 1, 1 } }; // C
vertices[3] = { { w/2, -h/2, 0, 1 }, { 1, 0 } }; // D
count[0] = 6;
count[1] = 8;
ioff[0] = (GLvoid*)0;
ioff[1] = (GLvoid*)(count[0] * sizeof(GLushort));
adjust_quad_uvs(vertices[0], vertices[1], vertices[2], vertices[3]);
return create_buffers(idx, vertices, sizeof(idx), sizeof(vertices));
}
void Plane::create_impl(float w, float h, int div, GLushort *idx, Shape::vertex_t *vertices)
{
count[0] = div * div * 6;
@@ -166,6 +189,18 @@ void Circle::create_impl(float radius_out, float radius_in, int div, GLushort* i
*pidx2++ = i*2+1; // B
*pidx2++ = ((i+1)*2+1) % (div*2); // C
}
//if (radius_in != 0 && map == kUVMapping::Tube)
//{
// for (int i = 0; i < div; i++)
// {
// int a = i*2; // A
// int b = i*2+1; // B
// int c = ((i+1)*2+1) % (div*2); // C
// int d = ((i+1)*2) % (div*2); // D
// adjust_quad_uvs(vertices[a], vertices[b], vertices[c], vertices[d]);
// }
//}
}
void Rounded::create_impl(float w, float h, float r, int div, GLushort* idx, GLushort* idx_tmp, Shape::vertex_t* vertices)