Implement DrawLine2D + DrawPixel2D

This commit is contained in:
2024-01-20 15:54:25 -05:00
parent c5f60e3699
commit 52a6aa5b78
2 changed files with 48 additions and 18 deletions

View File

@@ -60,23 +60,51 @@ namespace JGL {
// TODO: Implement (CORRECT!!!) matrix transformation
}
void DrawPixel2D(const Color3 &, int x, int y);
void DrawPixel2D(const Color3& color, const Vector2 &coordinates);
void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B);
void DrawPixel2D(const Color3& color, const Vector2 &coordinates)
{
auto vp_pos = ScreenToViewport(coordinates);
glBegin(GL_POINT);
glColor3f(color.r, color.g, color.b);
glVertex2f(vp_pos.x, vp_pos.y);
glEnd();
}
void DrawPixel2D(const Color3& color, float x, float y)
{
DrawPixel2D(color, {x, y});
}
void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B, float thickness = 1)
{
auto vp_a = ScreenToViewport(A);
auto vp_b = ScreenToViewport(B);
glBegin(GL_LINE);
glLineWidth(thickness);
glColor3f(color.r, color.g, color.b);
glVertex2f(vp_a.x, vp_a.y);
glVertex2f(vp_b.x, vp_b.y);
glEnd();
}
void DrawLine2D(const Color3& color, float x, float y, float w, float h, float thickness = 1)
{
DrawLine2D(color, {x, y}, {w, h}, thickness);
}
void DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B);
void DrawCubicBezierCurve2D();
void OutlineCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions);
void FillSphere3D();
void WireframeSphere3D();
void FillCircle2D();
void OutlineTriangle();
void FillTriangle();
void FillTexturedTriangle();
void FillTexturedPolygon();
void DrawSprite();
void DrawPartialSprite();
void DrawString();
void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color)
void OutlineTriangle2D();
void FillTriangle2D();
void FillTexturedTriangle2D();
void FillTexturedPolygon2D();
void DrawSprite2D();
void DrawPartialSprite2D();
void DrawString2D();
void DrawString3D();
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size)
{
auto vp_pos = ScreenToViewport(pos);
auto vp_size = ScreenToViewport(size);
@@ -88,11 +116,12 @@ namespace JGL {
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
glEnd();
}
void OutlineRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float thickness = 1)
void OutlineRect2D ( const Color3& color, const Vector2& pos, const Vector2& size, float thickness = 1)
{
auto vp_pos = ScreenToViewport(pos);
auto vp_size = ScreenToViewport(size);
glBegin(GL_LINE_LOOP);
glLineWidth(thickness);
glColor3f(color.r, color.g, color.b);
glVertex2f(vp_pos.x, vp_pos.y);
glVertex2f(vp_pos.x, vp_pos.y + vp_size.y);
@@ -100,10 +129,10 @@ namespace JGL {
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
glEnd();
}
void FillRoundedRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float radius);
void OutlineRoundedRect2D(const Vector2& pos, const Vector2& size, const Color3& color, float radius, float thickness = 1);
void OutlinePolygon2D ();
void FillPolygon2D ();
void FillRoundedRect2D (const Color3& color, const Vector2& pos, const Vector2& size, float radius);
void OutlineRoundedRect2D(const Color3& color, const Vector2& pos, const Vector2& size, float radius, float thickness = 1);
void OutlinePolygon2D (const Color3& color, std::vector<Vector2> points);
void FillPolygon2D (const Color3& color, std::vector<Vector2> points, float thickness = 1);
void GradientFillRect2D ();
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
void DrawMatrixGizmo (const Matrix4x4&);