Files
JGL/include/JGL/JGL.h
2024-01-20 14:02:43 -05:00

112 lines
3.9 KiB
C++

//
// Created by dawsh on 1/17/24.
//
#pragma once
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector2.h>
// OpenGL Wrapper for rendering 2D graphics primitives in both a 2D and 3D context
namespace JGL {
// All functions accept coordinates in pixel-screen space [0, 600]
// and are internally transformed to OpenGL clip space [-1, +1]
using namespace LinearAlgebra;
namespace J2D {
}
namespace J3D {
}
struct Color3 {
int r;
int g;
int b;
};
namespace Colors {
static const Color3 BrightRed {255, 0, 0};
static const Color3 BrightGreen { 0, 255, 0};
static const Color3 BrightBlue { 0, 0, 255};
static const Color3 White {255, 255, 255};
static const Color3 Black { 0, 0, 0};
static const Color3 Gray {128, 128, 128};
static const Color3 DarkGray {192, 192, 192};
static const Color3 LightGray { 64, 64, 64};
static const Color3 Maroon {};
static const Color3 Fuchsia {};
static const Color3 Lime {};
static const Color3 Olive {};
}
struct HSV {
float hue;
float saturation;
float value;
};
Vector2 ScreenToViewport(const Vector2& v)
{
// TODO: Implement (CORRECT!!!) matrix transformation
float x = v.x / 600.f;
float y = v.y / 600.f;
return {
x - .5f, y - .5f
};
}
Vector2 ViewportToScreen(const Vector2& v)
{
// 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 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)
{
auto vp_pos = ScreenToViewport(pos);
auto vp_size = ScreenToViewport(size);
glBegin(GL_QUADS);
glColor3f(color.r, color.g, color.b);
glVertex2f(vp_pos.x, vp_pos.y);
glVertex2f(vp_pos.x, vp_pos.y + vp_size.y);
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y + vp_size.y);
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)
{
auto vp_pos = ScreenToViewport(pos);
auto vp_size = ScreenToViewport(size);
glBegin(GL_LINE_LOOP);
glColor3f(color.r, color.g, color.b);
glVertex2f(vp_pos.x, vp_pos.y);
glVertex2f(vp_pos.x, vp_pos.y + vp_size.y);
glVertex2f(vp_pos.x + vp_size.x, vp_pos.y + vp_size.y);
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 GradientFillRect2D ();
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
void DrawMatrixGizmo (const Matrix4x4&);
void DrawAxisAngleGizmo (const AxisAngle&, const Vector3&);
void DrawQuaternionGizmo (const Quaternion&, const Vector3&);
}