Implement DrawLine2D + DrawPixel2D
This commit is contained in:
@@ -60,23 +60,51 @@ namespace JGL {
|
|||||||
// TODO: Implement (CORRECT!!!) matrix transformation
|
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawPixel2D(const Color3 &, int x, int y);
|
|
||||||
void DrawPixel2D(const Color3& color, const Vector2 &coordinates);
|
void DrawPixel2D(const Color3& color, const Vector2 &coordinates)
|
||||||
void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B);
|
{
|
||||||
|
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 DrawLine3D(const Color3& color, const Vector3 &A, const Vector3 &B);
|
||||||
void DrawCubicBezierCurve2D();
|
void DrawCubicBezierCurve2D();
|
||||||
void OutlineCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions);
|
void OutlineCircle2D(const Color3& color, const Vector2& center, float radius, int subdivisions);
|
||||||
void FillSphere3D();
|
void FillSphere3D();
|
||||||
void WireframeSphere3D();
|
void WireframeSphere3D();
|
||||||
void FillCircle2D();
|
void FillCircle2D();
|
||||||
void OutlineTriangle();
|
void OutlineTriangle2D();
|
||||||
void FillTriangle();
|
void FillTriangle2D();
|
||||||
void FillTexturedTriangle();
|
void FillTexturedTriangle2D();
|
||||||
void FillTexturedPolygon();
|
void FillTexturedPolygon2D();
|
||||||
void DrawSprite();
|
void DrawSprite2D();
|
||||||
void DrawPartialSprite();
|
void DrawPartialSprite2D();
|
||||||
void DrawString();
|
void DrawString2D();
|
||||||
void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color)
|
void DrawString3D();
|
||||||
|
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size)
|
||||||
{
|
{
|
||||||
auto vp_pos = ScreenToViewport(pos);
|
auto vp_pos = ScreenToViewport(pos);
|
||||||
auto vp_size = ScreenToViewport(size);
|
auto vp_size = ScreenToViewport(size);
|
||||||
@@ -88,11 +116,12 @@ namespace JGL {
|
|||||||
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
|
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
|
||||||
glEnd();
|
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_pos = ScreenToViewport(pos);
|
||||||
auto vp_size = ScreenToViewport(size);
|
auto vp_size = ScreenToViewport(size);
|
||||||
glBegin(GL_LINE_LOOP);
|
glBegin(GL_LINE_LOOP);
|
||||||
|
glLineWidth(thickness);
|
||||||
glColor3f(color.r, color.g, color.b);
|
glColor3f(color.r, color.g, color.b);
|
||||||
glVertex2f(vp_pos.x, vp_pos.y);
|
glVertex2f(vp_pos.x, vp_pos.y);
|
||||||
glVertex2f(vp_pos.x, vp_pos.y + vp_size.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);
|
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
void FillRoundedRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float radius);
|
void FillRoundedRect2D (const Color3& color, const Vector2& pos, const Vector2& size, float radius);
|
||||||
void OutlineRoundedRect2D(const Vector2& pos, const Vector2& size, const Color3& color, float radius, float thickness = 1);
|
void OutlineRoundedRect2D(const Color3& color, const Vector2& pos, const Vector2& size, float radius, float thickness = 1);
|
||||||
void OutlinePolygon2D ();
|
void OutlinePolygon2D (const Color3& color, std::vector<Vector2> points);
|
||||||
void FillPolygon2D ();
|
void FillPolygon2D (const Color3& color, std::vector<Vector2> points, float thickness = 1);
|
||||||
void GradientFillRect2D ();
|
void GradientFillRect2D ();
|
||||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||||
void DrawMatrixGizmo (const Matrix4x4&);
|
void DrawMatrixGizmo (const Matrix4x4&);
|
||||||
|
5
main.cpp
5
main.cpp
@@ -42,8 +42,9 @@ void display() {
|
|||||||
glVertex2f(-0.9f, -0.3f);
|
glVertex2f(-0.9f, -0.3f);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
JGL::FillRect2D({0, 0}, {128, 128}, JGL::Colors::White);
|
JGL::FillRect2D(JGL::Colors::White, {0, 0}, {128, 128});
|
||||||
JGL::OutlineRect2D({0, 0}, {128, 128}, JGL::Colors::BrightRed);
|
JGL::OutlineRect2D(JGL::Colors::BrightRed, {0, 0}, {128, 128}, 4);
|
||||||
|
JGL::DrawPixel2D(JGL::Colors::BrightGreen, {0, 0});
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
glColor3f(0.0f, 0.0f, 1.f); // Blue
|
glColor3f(0.0f, 0.0f, 1.f); // Blue
|
||||||
|
Reference in New Issue
Block a user