Writing JGL library interface

This commit is contained in:
scientiist
2024-01-19 12:26:53 -06:00
parent 742dfd65e8
commit c4d926dd3e
2 changed files with 60 additions and 12 deletions

View File

@@ -4,12 +4,42 @@
#pragma once
// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
namespace JGL
{
void DrawPixel();
void DrawLine();
void OutlineCircle();
void FillCircle();
namespace JGL {
namespace J2D {
}
namespace J3D {
}
struct Color3 {
int r;
int g;
int b;
};
namespace Colors {
}
struct HSV {
float hue;
float saturation;
float value;
};
Vector2 ScreenToViewport(const Vector2& v);
Vector2 ViewportToScreen(const Vector2& v);
Color3 GetColor();
void SetColor(const Color3 &color);
void DrawPixel2D(const Color3 &, int x, int y);
void DrawPixel2D(const Vector2 &coordinates);
void DrawLine2D(const Vector2 &A, const Vector2 &B);
void DrawLine3D(const Vector3 &A, const Vector3 &B);
void DrawCubicBezierCurve2D();
void OutlineCircle2D(const Vector2 center, float radius, int subdivisions, Color3 color);
void FillSphere3D();
void WireframeSphere3D();
void FillCircle2D();
void OutlineTriangle();
void FillTriangle();
void FillTexturedTriangle();
@@ -17,10 +47,26 @@ namespace JGL
void DrawSprite();
void DrawPartialSprite();
void DrawString();
void FillRect();
void OutlineRect();
void OutlinePolygon();
void FillPolygon();
void GradientFillRect();
void FillRect2D(const Vector2 &pos, const Vector2 &size, const Color3 &color)
{
pos = ScreenToViewport(pos);
size = ScreenToViewport(size);
glBegin(GL_QUADS);
glColor3f(color.r, color.g, color.b);
glVertex2f(pos.x, pos.y);
glVertex2f(pos.x, pos.y + size.y);
glVertex2f(pos.x + size.x, pos.y + size.y);
glVertex2f(pos.x + size.x, pos.y);
glEnd();
}
void OutlineRect2D (const Vector2& pos, const Vector2& size, const Color3& color, float thickness = 1);
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 GradientFillRect2D ();
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
void DrawMatrixGizmo (const Matrix4x4&);
void DrawAxisAngleGizmo (const AxisAngle&, const Vector3&);
void DrawQuaternionGizmo (const Quaternion&, const Vector3&);
}

View File

@@ -40,6 +40,8 @@ void display() {
glVertex2f(-0.9f, -0.3f);
glEnd();
FillRect2D()
glBegin(GL_TRIANGLES);
glColor3f(0.0f, 0.0f, 1.f); // Blue
glVertex2f(0.1f, -0.6f);