|
|
|
@@ -4,8 +4,8 @@
|
|
|
|
|
#include "internals/internals.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
|
|
|
|
|
State current_state = default_state;
|
|
|
|
|
void J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
|
|
|
|
|
State new_state = default_state;
|
|
|
|
|
state_stack.Push(State::SaveState());
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
@@ -16,34 +16,51 @@ void JGL::J2D::Begin(RenderTarget* render_target, bool clear_buffers) {
|
|
|
|
|
if (!render_target->GetTexture()->Inverted())
|
|
|
|
|
Logger::Warning("You're rendering onto a texture that is upside-down. Your draw commands won't work how you'd expect.");
|
|
|
|
|
|
|
|
|
|
current_state.current_fbo = render_target->GetGLFramebufferObjectHandle();
|
|
|
|
|
current_state.viewport[2] = render_target->GetDimensions().x;
|
|
|
|
|
current_state.viewport[3] = render_target->GetDimensions().y;
|
|
|
|
|
new_state.current_fbo = render_target->GetGLFramebufferObjectHandle();
|
|
|
|
|
new_state.viewport[2] = render_target->GetDimensions().x;
|
|
|
|
|
new_state.viewport[3] = render_target->GetDimensions().y;
|
|
|
|
|
|
|
|
|
|
current_state.clear_color[0] = render_target->GetClearColor().RN();
|
|
|
|
|
current_state.clear_color[1] = render_target->GetClearColor().GN();
|
|
|
|
|
current_state.clear_color[2] = render_target->GetClearColor().BN();
|
|
|
|
|
current_state.clear_color[3] = render_target->GetClearColor().AN();
|
|
|
|
|
new_state.clear_color[0] = render_target->GetClearColor().RN();
|
|
|
|
|
new_state.clear_color[1] = render_target->GetClearColor().GN();
|
|
|
|
|
new_state.clear_color[2] = render_target->GetClearColor().BN();
|
|
|
|
|
new_state.clear_color[3] = render_target->GetClearColor().AN();
|
|
|
|
|
new_state.current_render_target = render_target;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
current_state.viewport[2] = window_size.x;
|
|
|
|
|
current_state.viewport[3] = window_size.y;
|
|
|
|
|
new_state.viewport[2] = window_size.x;
|
|
|
|
|
new_state.viewport[3] = window_size.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
State::RestoreState(current_state);
|
|
|
|
|
State::RestoreState(new_state);
|
|
|
|
|
current_state = new_state;
|
|
|
|
|
|
|
|
|
|
if (current_state.current_render_target)
|
|
|
|
|
JGL::RenderTarget::SetActiveGLRenderTarget(*current_state.current_render_target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (render_target != nullptr && clear_buffers) {
|
|
|
|
|
glClearColor(render_target->GetClearColor().RedChannelNormalized(), render_target->GetClearColor().GreenChannelNormalized(), render_target->GetClearColor().BlueChannelNormalized(), render_target->GetClearColor().AlphaChannelNormalized());
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glOrtho(0, current_state.viewport[2], current_state.viewport[3], 0, -1, 1);
|
|
|
|
|
glOrtho(0, new_state.viewport[2], new_state.viewport[3], 0, -1, 1);
|
|
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glLoadIdentity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::End() {
|
|
|
|
|
void J2D::End() {
|
|
|
|
|
if (current_state.current_render_target) {
|
|
|
|
|
current_state.current_render_target->MSAABlit();
|
|
|
|
|
FilteringMode filtering_mode = current_state.current_render_target->GetTexture()->GetFilteringMode();
|
|
|
|
|
|
|
|
|
|
if (filtering_mode == FilteringMode::MIPMAP_NEAREST ||
|
|
|
|
|
filtering_mode == FilteringMode::MIPMAP_BILINEAR ||
|
|
|
|
|
filtering_mode == FilteringMode::MIPMAP_TRILINEAR)
|
|
|
|
|
current_state.current_render_target->RegenerateMipMaps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Change back to the previous projection.
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
@@ -55,10 +72,14 @@ void JGL::J2D::End() {
|
|
|
|
|
Logger::Fatal("Calling J2D::End before J2D::Begin.");
|
|
|
|
|
|
|
|
|
|
State::RestoreState(*previous_state);
|
|
|
|
|
if (previous_state->current_render_target)
|
|
|
|
|
JGL::RenderTarget::SetActiveGLRenderTarget(*current_state.current_render_target);
|
|
|
|
|
|
|
|
|
|
current_state = *previous_state;
|
|
|
|
|
state_stack.Pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float radius) {
|
|
|
|
|
void J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float radius) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -69,11 +90,11 @@ void JGL::J2D::DrawPoint(const Color4& color, const Vector2& coordinates, float
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPoint(const Color4& color, float x, float y, float radius) {
|
|
|
|
|
void J2D::DrawPoint(const Color4& color, float x, float y, float radius) {
|
|
|
|
|
DrawPoint(color, {x, y}, radius);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness) {
|
|
|
|
|
void J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
Vector2 vertices[] = {A, B};
|
|
|
|
@@ -85,8 +106,8 @@ void JGL::J2D::DrawLine(const Color4& color, const Vector2& A, const Vector2& B,
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawLine(const Color4& color, float x, float y, float w, float h, float thickness) {
|
|
|
|
|
JGL::J2D::DrawLine(color, {x, y}, {w, h}, thickness);
|
|
|
|
|
void J2D::DrawLine(const Color4& color, float x, float y, float w, float h, float thickness) {
|
|
|
|
|
J2D::DrawLine(color, {x, y}, {w, h}, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void J2D::DrawLines(const Color4& color, const Vector2* points, const size_t& point_count, float thickness) {
|
|
|
|
@@ -100,7 +121,7 @@ void J2D::DrawLines(const Color4& color, const Vector2* points, const size_t& po
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float thickness) {
|
|
|
|
|
void J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float thickness) {
|
|
|
|
|
float distance = Vector2::Distance(A, B);
|
|
|
|
|
Vector2 direction = (B - A).Normalized();
|
|
|
|
|
|
|
|
|
@@ -113,14 +134,14 @@ void JGL::J2D::DrawDottedLine(const Color4& color, const Vector2& A, const Vecto
|
|
|
|
|
for (unsigned int i = 0; i < point_count; ++i)
|
|
|
|
|
points[i] = A + direction * (i * spacing);
|
|
|
|
|
|
|
|
|
|
return JGL::J2D::DrawPoints(color, points.data(), points.size(), thickness);
|
|
|
|
|
return J2D::DrawPoints(color, points.data(), points.size(), thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawDottedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float thickness) {
|
|
|
|
|
return JGL::J2D::DrawDottedLine(color, {x1, y1}, {x2, y2}, spacing, thickness);
|
|
|
|
|
void J2D::DrawDottedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float thickness) {
|
|
|
|
|
return J2D::DrawDottedLine(color, {x1, y1}, {x2, y2}, spacing, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float dash_length, float thickness) {
|
|
|
|
|
void J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vector2& B, float spacing, float dash_length, float thickness) {
|
|
|
|
|
float distance = Vector2::Distance(A, B);
|
|
|
|
|
Vector2 direction = (B - A).Normalized();
|
|
|
|
|
float length_of_dash_and_gap = dash_length + spacing;
|
|
|
|
@@ -133,7 +154,7 @@ void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vecto
|
|
|
|
|
for (unsigned int i = 0; i < dash_count; i++) {
|
|
|
|
|
A_current = A + direction * (i * length_of_dash_and_gap);
|
|
|
|
|
B_current = A_current + (direction * dash_length);
|
|
|
|
|
JGL::J2D::DrawLine(color, A_current, B_current, thickness);
|
|
|
|
|
J2D::DrawLine(color, A_current, B_current, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For the little piece at the end.
|
|
|
|
@@ -141,15 +162,15 @@ void JGL::J2D::DrawDashedLine(const Color4& color, const Vector2& A, const Vecto
|
|
|
|
|
if (distance_left > 0) {
|
|
|
|
|
A_current = A + direction * (dash_count * length_of_dash_and_gap);
|
|
|
|
|
B_current = A_current + direction * std::min(dash_length, distance_left);
|
|
|
|
|
JGL::J2D::DrawLine(color, A_current, B_current, thickness);
|
|
|
|
|
J2D::DrawLine(color, A_current, B_current, thickness);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawDashedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float dash_length, float thickness) {
|
|
|
|
|
return JGL::J2D::DrawDashedLine(color, {x1, y1}, {x2, y2}, spacing, dash_length, thickness);
|
|
|
|
|
void J2D::DrawDashedLine(const Color4& color, float x1, float y1, float x2, float y2, float spacing, float dash_length, float thickness) {
|
|
|
|
|
return J2D::DrawDashedLine(color, {x1, y1}, {x2, y2}, spacing, dash_length, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness) {
|
|
|
|
|
void J2D::DrawGradientLine(const Color4& color1, const Color4& color2, const Vector2& A, const Vector2& B, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -167,10 +188,10 @@ void JGL::J2D::DrawGradientLine(const Color4& color1, const Color4& color2, cons
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawGradientLine(const Color4& color1, const Color4& color2, float x, float y, float w, float h, float thickness) {
|
|
|
|
|
JGL::J2D::DrawGradientLine(color1, color2, {x, y}, {w, h}, thickness);
|
|
|
|
|
J2D::DrawGradientLine(color1, color2, {x, y}, {w, h}, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
|
|
|
|
|
void J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -183,24 +204,33 @@ void JGL::J2D::OutlineRect(const Color4& color, const Vector2& pos, const Vector
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
|
|
|
|
|
void J2D::FillRect(const Color4& color, const Vector2& pos, const Vector2& size) {
|
|
|
|
|
BatchFillRect(&color, &pos, &size, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void J2D::BatchFillRect(const Color4* colors, const Vector2* positions, const Vector2* sizes, const size_t& rect_count) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
|
glColor4ubv(color.ptr());
|
|
|
|
|
if (rect_count <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, ShapeCache::square_origin_topleft_vertex_data->GetHandle());
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), nullptr);
|
|
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glTranslatef(pos.x, pos.y + size.y, 0);
|
|
|
|
|
glScalef(size.x, size.y, 1);
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
for (size_t i = 0; i < rect_count; i++) {
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glColor4ubv(colors[i].ptr());
|
|
|
|
|
glTranslatef(positions[i].x, positions[i].y + sizes[i].y, 0);
|
|
|
|
|
glScalef(sizes[i].x, sizes[i].y, 1);
|
|
|
|
|
glDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
}
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillGradientRect(const Color4& color1, const Color4& color2, const Direction& gradient, const Vector2& pos, const Vector2& size) {
|
|
|
|
|
void J2D::FillGradientRect(const Color4& color1, const Color4& color2, const Direction& gradient, const Vector2& pos, const Vector2& size) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -233,38 +263,40 @@ void JGL::J2D::FillGradientRect(const Color4& color1, const Color4& color2, cons
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
void J2D::FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, unsigned int subdivisions) {
|
|
|
|
|
std::array<Color4, 4> colors = { color, color, color, color };
|
|
|
|
|
std::array<Vector2, 2> rect_positions = { Vector2(pos.x + radius, pos.y), {pos.x, pos.y + radius} };
|
|
|
|
|
std::array<Vector2, 2> rect_sizes = { Vector2(size.x - 2 * radius, size.y), {size.x, size.y - 2 * radius} };
|
|
|
|
|
std::array<float, 4> circle_radii = { radius, radius, radius, radius };
|
|
|
|
|
std::array<Vector2, 4> circle_positions
|
|
|
|
|
{
|
|
|
|
|
Vector2(pos.x + radius, pos.y + radius), {pos.x + size.x - radius, pos.y + radius},
|
|
|
|
|
{pos.x + radius, pos.y + size.y - radius}, {pos.x + size.x - radius, pos.y + size.y - radius}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
JGL::J2D::FillRect(color, {pos.x + radius, pos.y}, {size.x - 2 * radius, size.y});
|
|
|
|
|
JGL::J2D::FillRect(color, {pos.x, pos.y + radius}, {size.x, size.y - 2 * radius});
|
|
|
|
|
|
|
|
|
|
JGL::J2D::FillCircle(color, {pos.x + radius, pos.y + radius}, radius, subdivisions);
|
|
|
|
|
JGL::J2D::FillCircle(color, {pos.x + size.x - radius, pos.y + radius}, radius, subdivisions);
|
|
|
|
|
JGL::J2D::FillCircle(color, {pos.x + radius, pos.y + size.y - radius}, radius, subdivisions);
|
|
|
|
|
JGL::J2D::FillCircle(color, {pos.x + size.x - radius, pos.y + size.y - radius}, radius, subdivisions);
|
|
|
|
|
J2D::BatchFillRect(colors.data(), rect_positions.data(), rect_sizes.data(), 2);
|
|
|
|
|
J2D::BatchFillCircle(colors.data(), circle_positions.data(), circle_radii.data(), subdivisions, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
void J2D::DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
float originX, float originY,float scaleX, float scaleY,
|
|
|
|
|
const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(*texture, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation, const Vector2& origin,
|
|
|
|
|
void J2D::DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation, const Vector2& origin,
|
|
|
|
|
const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
|
|
|
|
|
DrawSprite(*texture, position, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position,
|
|
|
|
|
void J2D::DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position,
|
|
|
|
|
const Vector2& sub_texture_size, float rad_rotation, const Vector2& origin,
|
|
|
|
|
const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawPartialSprite(*texture, position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX,
|
|
|
|
|
void J2D::DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX,
|
|
|
|
|
float sub_texture_positionY, unsigned int sub_texture_sizeX,
|
|
|
|
|
unsigned int sub_texture_sizeY, float rad_rotation, float originX, float originY,
|
|
|
|
|
float scaleX, float scaleY, const Color4& color, Direction inversion) {
|
|
|
|
@@ -272,27 +304,27 @@ void JGL::J2D::DrawPartialSprite(const Texture* texture, float positionX, float
|
|
|
|
|
rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis, float rad_rotation,
|
|
|
|
|
void J2D::DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale, const Color4& color) {
|
|
|
|
|
DrawMirrorSprite(*texture, position, mirror_axis, rad_rotation, origin, scale, color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
void J2D::DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
void J2D::DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
void J2D::DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(render_target, position, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position, float rad_rotation, const Vector2& origin,
|
|
|
|
|
void J2D::DrawSprite(const RenderTarget& rt, const Vector2& position, float rad_rotation, const Vector2& origin,
|
|
|
|
|
const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
|
|
|
|
|
//Correct for the render-target being upside-down.
|
|
|
|
@@ -315,14 +347,14 @@ void JGL::J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position,
|
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
|
|
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
|
|
|
|
|
JGL::J2D::DrawPartialSprite(*rt.GetTexture(), r_position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
|
|
|
|
|
J2D::DrawPartialSprite(*rt.GetTexture(), r_position, {0, 0}, Vector2(rt.GetDimensions()), rad_rotation, origin, scale, color, d);
|
|
|
|
|
|
|
|
|
|
if (rt.OwnsTexture())
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale,const Color4& color, JGL::Direction inversion) {
|
|
|
|
|
void J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale,const Color4& color, Direction inversion) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -409,23 +441,23 @@ void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, con
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, const Vector2& position, float rad_rotation,
|
|
|
|
|
void J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, const Vector2& position, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale,const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(*texture, *alpha_mask, position, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
void J2D::DrawSprite(const Texture& texture, const Texture& alpha_mask, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
float originX, float originY,float scaleX, float scaleY,const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(texture, alpha_mask, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
void J2D::DrawSprite(const Texture* texture, const Texture* alpha_mask, float positionX, float positionY, float rad_rotation,
|
|
|
|
|
float originX, float originY,float scaleX, float scaleY,const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(*texture, *alpha_mask, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget& rt, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size,
|
|
|
|
|
float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color, JGL::Direction inversion) {
|
|
|
|
|
void J2D::DrawPartialRenderTarget(const RenderTarget& rt, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size,
|
|
|
|
|
float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
|
|
|
|
|
//Correct for the render-target being upside-down.
|
|
|
|
|
Direction d{};
|
|
|
|
@@ -450,18 +482,18 @@ void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget& rt, const Vector
|
|
|
|
|
auto r_position = Vector2(Math::Floor(position.x), Math::Floor(position.y));
|
|
|
|
|
auto r_sub_texture_position = Vector2(Math::Floor(sub_texture_position.x), Math::Floor(sub_texture_position.y));
|
|
|
|
|
|
|
|
|
|
JGL::J2D::DrawPartialSprite(*rt.GetTexture(), r_position, r_sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
|
|
|
|
|
J2D::DrawPartialSprite(*rt.GetTexture(), r_position, r_sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, d);
|
|
|
|
|
|
|
|
|
|
if (rt.OwnsTexture())
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialRenderTarget(const JGL::RenderTarget* rt, const Vector2& position,const Vector2& sub_texture_position,const Vector2& sub_texture_size, float rad_rotation,
|
|
|
|
|
void J2D::DrawPartialRenderTarget(const RenderTarget* rt, const Vector2& position,const Vector2& sub_texture_position,const Vector2& sub_texture_size, float rad_rotation,
|
|
|
|
|
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawPartialRenderTarget(*rt, position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_rotation, const Vector2& origin,
|
|
|
|
|
void J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_rotation, const Vector2& origin,
|
|
|
|
|
const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
@@ -523,7 +555,7 @@ void JGL::J2D::DrawSprite(const Texture& texture, const Vector2& pos, float rad_
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawSprite(const Texture& texture, float positionX, float positionY, float rad_rotation, float originX,
|
|
|
|
|
void J2D::DrawSprite(const Texture& texture, float positionX, float positionY, float rad_rotation, float originX,
|
|
|
|
|
float originY, float scaleX, float scaleY, const Color4& color, Direction inversion) {
|
|
|
|
|
DrawSprite(texture,
|
|
|
|
|
{positionX, positionY},
|
|
|
|
@@ -533,7 +565,7 @@ void JGL::J2D::DrawSprite(const Texture& texture, float positionX, float positio
|
|
|
|
|
color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position,
|
|
|
|
|
void J2D::DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position,
|
|
|
|
|
const Vector2& sub_texture_size, float rad_rotation, const Vector2& origin,
|
|
|
|
|
const Vector2& scale, const Color4& color, Direction inversion) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
@@ -611,22 +643,22 @@ void JGL::J2D::DrawPartialSprite(const Texture& texture, const Vector2& position
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPartialSprite(const JGL::Texture& texture, float positionX, float positionY, float sub_texture_positionX,
|
|
|
|
|
void J2D::DrawPartialSprite(const Texture& texture, float positionX, float positionY, float sub_texture_positionX,
|
|
|
|
|
float sub_texture_positionY, unsigned int sub_texture_sizeX,
|
|
|
|
|
unsigned int sub_texture_sizeY, float originX, float originY, float rad_rotation,
|
|
|
|
|
float scaleX, float scaleY, const Color4& color, JGL::Direction inversion) {
|
|
|
|
|
float scaleX, float scaleY, const Color4& color, Direction inversion) {
|
|
|
|
|
|
|
|
|
|
JGL::J2D::DrawPartialSprite(texture, {positionX, positionY}, {sub_texture_positionX, sub_texture_positionY},
|
|
|
|
|
J2D::DrawPartialSprite(texture, {positionX, positionY}, {sub_texture_positionX, sub_texture_positionY},
|
|
|
|
|
{(float) sub_texture_sizeX, (float) sub_texture_sizeY}, rad_rotation, {originX, originY},
|
|
|
|
|
{scaleX, scaleY}, color, inversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position, Direction mirror_axis, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
|
|
|
|
|
void J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position, Direction mirror_axis, float rad_rotation, const Vector2& origin, const Vector2& scale, const Color4& color) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
|
if (mirror_axis == Direction::None)
|
|
|
|
|
Logger::Warning("Drawing non-mirrored sprite with JGL::J2D::DrawMirrorSprite?");
|
|
|
|
|
Logger::Warning("Drawing non-mirrored sprite with J2D::DrawMirrorSprite?");
|
|
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture.GetHandle());
|
|
|
|
|
Vector2 size = Vector2(texture.GetDimensions());
|
|
|
|
@@ -705,7 +737,7 @@ void JGL::J2D::DrawMirrorSprite(const Texture& texture, const Vector2& position,
|
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
|
|
|
|
|
void J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -732,10 +764,17 @@ void JGL::J2D::OutlineCircle(const Color4& color, const Vector2& center, float r
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
|
|
|
|
|
void J2D::FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions) {
|
|
|
|
|
BatchFillCircle(&color, ¢er, &radius, subdivisions, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void J2D::BatchFillCircle(const Color4* colors, const Vector2* positions, float* radii, unsigned int subdivisions, const size_t& circle_count) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
|
if (circle_count <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
GLfloat angle, x, y;
|
|
|
|
|
float step = (2.f * Math::Pi) / (float) subdivisions;
|
|
|
|
|
std::vector<Vector2> vertices(subdivisions);
|
|
|
|
@@ -745,8 +784,8 @@ void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radi
|
|
|
|
|
* wait around for the container to resize. This gets rid of it for what we can guarantee. */
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (angle = 0.0f; angle < (2.f * Math::Pi); angle += step) {
|
|
|
|
|
x = radius * std::sin(angle) + center.x;
|
|
|
|
|
y = radius * std::cos(angle) + center.y;
|
|
|
|
|
x = std::sin(angle);
|
|
|
|
|
y = std::cos(angle);
|
|
|
|
|
if (i < subdivisions)
|
|
|
|
|
vertices[i] = {x, y};
|
|
|
|
|
else
|
|
|
|
@@ -754,13 +793,19 @@ void JGL::J2D::FillCircle(const Color4& color, const Vector2& center, float radi
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glColor4ubv(color.ptr());
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, (int) vertices.size());
|
|
|
|
|
for (size_t j = 0; j < circle_count; j++) {
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
glColor4ubv(colors[j].ptr());
|
|
|
|
|
glTranslatef(positions[j].x, positions[j].y, 0);
|
|
|
|
|
glScalef(radii[j], radii[j], 0);
|
|
|
|
|
glDrawArrays(GL_TRIANGLE_FAN, 0, (int) vertices.size());
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
}
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness) {
|
|
|
|
|
void J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -773,7 +818,7 @@ void JGL::J2D::OutlineTriangle(const Color4& color, const Triangle2D& tri, float
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
|
|
|
|
|
void J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -785,7 +830,7 @@ void JGL::J2D::FillTriangle(const Color4& color, const Triangle2D& tri) {
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri) {
|
|
|
|
|
void J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
@@ -802,31 +847,32 @@ void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO render all in once pass with GL_LINE_LOOP instead of separate lines.
|
|
|
|
|
void JGL::J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
|
|
|
|
|
void J2D::DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
|
|
|
|
|
int subdivisions, float thickness) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 last = controlA;
|
|
|
|
|
const Vector2& first = controlB;
|
|
|
|
|
for (int i = 0; i < subdivisions; ++i)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::vector<Vector2> vertices(2 * subdivisions + 2);
|
|
|
|
|
for (int i = 0; i < subdivisions; ++i) {
|
|
|
|
|
float alpha = (float) i / (float) subdivisions;
|
|
|
|
|
Vector2 step = J3ML::Algorithm::Bezier(alpha, controlA, pointA, pointB, controlB);
|
|
|
|
|
DrawLine(color, last, step, thickness);
|
|
|
|
|
vertices[2 * i] = last;
|
|
|
|
|
vertices[2 * i + 1] = step;
|
|
|
|
|
last = step;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Have to manually draw the last segment of the curve.
|
|
|
|
|
DrawLine(color, last, first, thickness);
|
|
|
|
|
vertices[2 * subdivisions] = last;
|
|
|
|
|
vertices[2 * subdivisions + 1] = first;
|
|
|
|
|
DrawLines(color, vertices.data(), vertices.size(), thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
|
|
|
|
|
void J2D::OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
|
if (points[0] != points[points_size -1])
|
|
|
|
|
throw std::runtime_error("JGL::J2D::OutlinePolygon: The first point and the last point must connect.");
|
|
|
|
|
throw std::runtime_error("J2D::OutlinePolygon: The first point and the last point must connect.");
|
|
|
|
|
|
|
|
|
|
glLineWidth(thickness);
|
|
|
|
|
glColor4ubv(color.ptr());
|
|
|
|
@@ -835,12 +881,12 @@ void JGL::J2D::OutlinePolygon(const Color4& color, const Vector2* points, int po
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawGradientLine(const Color4& color_a, const Color4& color_b, float x, float y, float w, float h,
|
|
|
|
|
void J2D::DrawGradientLine(const Color4& color_a, const Color4& color_b, float x, float y, float w, float h,
|
|
|
|
|
float thickness) {
|
|
|
|
|
DrawGradientLine(color_a, color_b, {x, y}, {w, h}, thickness);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end, unsigned int subdivisions, float thickness)
|
|
|
|
|
void J2D::DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end, unsigned int subdivisions, float thickness)
|
|
|
|
|
{
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
@@ -873,7 +919,7 @@ void JGL::J2D::DrawArc(const Color4& color, const Vector2& center, float radius,
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness)
|
|
|
|
|
void J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness)
|
|
|
|
|
{
|
|
|
|
|
// A rounded rectangle of size 2a x 2b with rounding radius r is given by
|
|
|
|
|
// f(x; a, r) + f(y; b, r) = 1
|
|
|
|
@@ -888,7 +934,6 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
|
|
|
|
|
|
|
|
|
|
// TODO: Calculate vertices for top-left quarter-circle.
|
|
|
|
|
|
|
|
|
|
Vector2 tl = pos;
|
|
|
|
|
Vector2 tr = pos + Vector2(size.x, 0);
|
|
|
|
|
Vector2 br = pos + size;
|
|
|
|
|
Vector2 bl = pos + Vector2(0, size.y);
|
|
|
|
@@ -899,10 +944,10 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
|
|
|
|
|
Vector2 anchor_br = pos + size - Vector2(radius, radius);
|
|
|
|
|
Vector2 anchor_bl = pos + Vector2(radius, size.y - radius);
|
|
|
|
|
|
|
|
|
|
//JGL::J2D::Begin();
|
|
|
|
|
//JGL::J2D::DrawPoints(Colors::Red, {tl, tr, br, bl}, 2);
|
|
|
|
|
//JGL::J2D::DrawPoints(Colors::Blue, {anchor_tl, anchor_tr, anchor_br, anchor_bl}, 2);
|
|
|
|
|
//JGL::J2D::End();
|
|
|
|
|
//J2D::Begin();
|
|
|
|
|
//J2D::DrawPoints(Colors::Red, {tl, tr, br, bl}, 2);
|
|
|
|
|
//J2D::DrawPoints(Colors::Blue, {anchor_tl, anchor_tr, anchor_br, anchor_bl}, 2);
|
|
|
|
|
//J2D::End();
|
|
|
|
|
|
|
|
|
|
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
|
|
|
|
|
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
|
|
|
|
@@ -916,7 +961,7 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
|
|
|
|
|
Vector2 anchor_bottomleft_left = pos + Vector2(0, size.y - radius);
|
|
|
|
|
Vector2 anchor_topleft_left = pos + Vector2(0, radius);
|
|
|
|
|
|
|
|
|
|
//JGL::J2D::Begin();
|
|
|
|
|
//J2D::Begin();
|
|
|
|
|
|
|
|
|
|
// The 3.01f, etc is a tiny-bit of overshoot to compensate for the fact that
|
|
|
|
|
// this is not being plotted as a continuous line-loop.
|
|
|
|
@@ -924,25 +969,24 @@ void JGL::J2D::OutlineRoundedRect(const Color4& color, const Vector2& pos, const
|
|
|
|
|
|
|
|
|
|
unsigned int subdivisions = 9;
|
|
|
|
|
|
|
|
|
|
JGL::J2D::DrawArc(color, anchor_tl, radius, Math::Pi, 3.01f*Math::Pi/2.f, subdivisions, thickness);
|
|
|
|
|
JGL::J2D::DrawLine(color, anchor_topleft_top, anchor_topright_top, thickness);
|
|
|
|
|
JGL::J2D::DrawArc(color, anchor_tr, radius, 3.f*Math::Pi/2.f, 2.02*Math::Pi, subdivisions, thickness);
|
|
|
|
|
JGL::J2D::DrawLine(color, anchor_topright_right, anchor_bottomright_right, thickness);
|
|
|
|
|
JGL::J2D::DrawArc(color, anchor_br, radius, 0.0f, 1.01f*Math::Pi/2, subdivisions, thickness);
|
|
|
|
|
JGL::J2D::DrawLine(color, anchor_bottomright_bottom, anchor_bottomleft_bottom, thickness);
|
|
|
|
|
JGL::J2D::DrawArc(color, anchor_bl, radius, Math::Pi/2, Math::Pi*1.01f, subdivisions, thickness);
|
|
|
|
|
JGL::J2D::DrawLine(color, anchor_bottomleft_left, anchor_topleft_left, thickness);
|
|
|
|
|
//JGL::J2D::End();
|
|
|
|
|
J2D::DrawArc(color, anchor_tl, radius, Math::Pi, 3.01f*Math::Pi/2.f, subdivisions, thickness);
|
|
|
|
|
J2D::DrawLine(color, anchor_topleft_top, anchor_topright_top, thickness);
|
|
|
|
|
J2D::DrawArc(color, anchor_tr, radius, 3.f*Math::Pi/2.f, 2.02*Math::Pi, subdivisions, thickness);
|
|
|
|
|
J2D::DrawLine(color, anchor_topright_right, anchor_bottomright_right, thickness);
|
|
|
|
|
J2D::DrawArc(color, anchor_br, radius, 0.0f, 1.01f*Math::Pi/2, subdivisions, thickness);
|
|
|
|
|
J2D::DrawLine(color, anchor_bottomright_bottom, anchor_bottomleft_bottom, thickness);
|
|
|
|
|
J2D::DrawArc(color, anchor_bl, radius, Math::Pi/2, Math::Pi*1.01f, subdivisions, thickness);
|
|
|
|
|
J2D::DrawLine(color, anchor_bottomleft_left, anchor_topleft_left, thickness);
|
|
|
|
|
//J2D::End();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius) {
|
|
|
|
|
void J2D::FillChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius) {
|
|
|
|
|
FillRoundedRect(color, pos, size, radius, 4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius,
|
|
|
|
|
float thickness) {
|
|
|
|
|
void J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius, float thickness) {
|
|
|
|
|
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
|
|
|
|
|
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
|
|
|
|
|
Vector2 anchor_topright_right = pos + Vector2(size.x, radius);
|
|
|
|
@@ -960,7 +1004,7 @@ void JGL::J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius) {
|
|
|
|
|
void J2D::DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius) {
|
|
|
|
|
glPointSize(radius);
|
|
|
|
|
glColor4ubv(color.ptr());
|
|
|
|
|
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points);
|
|
|
|
@@ -968,16 +1012,16 @@ void JGL::J2D::DrawPoints(const Color4& color, const Vector2* points, int num_po
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC) {
|
|
|
|
|
void J2D::FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC) {
|
|
|
|
|
FillTriangle(color, {triA, triB, triC});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Vector2& tri_a,
|
|
|
|
|
void J2D::FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Vector2& tri_a,
|
|
|
|
|
const Vector2& tri_b, const Vector2& tri_c) {
|
|
|
|
|
FillGradientTriangle(a_color, b_color, c_color, {tri_a, tri_b, tri_c});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::OutlineEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, float thickness,
|
|
|
|
|
void J2D::OutlineEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, float thickness,
|
|
|
|
|
int subdivisions) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
@@ -1004,7 +1048,7 @@ void JGL::J2D::OutlineEllipse(const Color4& color, const Vector2& position, floa
|
|
|
|
|
glColor4fv(default_state.draw_color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JGL::J2D::FillEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, int subdivisions) {
|
|
|
|
|
void J2D::FillEllipse(const Color4& color, const Vector2& position, float radius_x, float radius_y, int subdivisions) {
|
|
|
|
|
if (!state_stack.Size())
|
|
|
|
|
Logger::Error("Drawing J2D element before J2D begin.");
|
|
|
|
|
|
|
|
|
|