diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 735c5ce..3265c6b 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + diff --git a/include/glez.h b/include/glez.h index 65645b5..22184c6 100644 --- a/include/glez.h +++ b/include/glez.h @@ -98,7 +98,7 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color, void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, glez_texture_t texture, float tx, float ty, float tw, - float th); + float th, float angle); void glez_string(float x, float y, const char *string, glez_font_t font, glez_rgba_t color, float *out_x, float *out_y); diff --git a/src/glez.c b/src/glez.c index 75e17af..01209e0 100644 --- a/src/glez.c +++ b/src/glez.c @@ -11,6 +11,7 @@ #include "internal/draw.h" #include "internal/fonts.h" #include "internal/textures.h" +#include #include #include @@ -136,10 +137,9 @@ void glez_rect_outline(float x, float y, float w, float h, glez_rgba_t color, glez_line(x + w, y + h, -w, 0, color, thickness); glez_line(x, y + h, 0, -h, color, thickness); } - void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, glez_texture_t texture, float tx, float ty, float tw, - float th) + float th, float angle) { internal_texture_t *tex = internal_texture_get(texture); internal_texture_bind(texture); @@ -185,6 +185,36 @@ void glez_rect_textured(float x, float y, float w, float h, glez_rgba_t color, vertices[3].color = color; vertices[3].mode = DRAW_MODE_TEXTURED; + if (angle) { + float v1[2] = {vertices[0].position.x, vertices[0].position.y}; + float v2[2] = {vertices[1].position.x, vertices[1].position.y}; + float v3[2] = {vertices[2].position.x, vertices[2].position.y}; + float v4[2] = {vertices[3].position.x, vertices[3].position.y}; + vertices[0].position.x = -tw; + vertices[1].position.x = -tw; + vertices[2].position.x = tw; + vertices[3].position.x = tw; + + vertices[0].position.y = -th; + vertices[1].position.y = th; + vertices[2].position.y = th; + vertices[3].position.y = -th; + for (int i = 0; i < 4; i++) { + float x = vertices[i].position.x; + float y = vertices[i].position.y; + vertices[i].position.x = x *cos(angle) - y *sin(angle); + vertices[i].position.y = x *sin(angle) + y *cos(angle); + } + vertices[0].position.x += v1[0]; + vertices[0].position.y += v1[1]; + vertices[1].position.x += v2[0]; + vertices[1].position.y += v2[1]; + vertices[2].position.x += v3[0]; + vertices[2].position.y += v3[1]; + vertices[3].position.x += v4[0]; + vertices[3].position.y += v4[1]; + } + vertex_buffer_push_back(program.buffer, vertices, 4, indices, 6); }