Code
This commit is contained in:
@@ -45,51 +45,17 @@ namespace JGL {
|
||||
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 ScreenToViewport(const Vector2& v);
|
||||
Vector2 ViewportToScreen(const Vector2& v)
|
||||
{
|
||||
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||
}
|
||||
|
||||
|
||||
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 DrawPixel2D(const Color3& color, const Vector2 &coordinates);
|
||||
void DrawPixel2D(const Color3& color, float x, float y);
|
||||
void DrawLine2D(const Color3& color, const Vector2 &A, const Vector2 &B, float thickness = 1);
|
||||
void DrawLine2D(const Color3& color, float x, float y, float w, float h, float thickness = 1);
|
||||
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);
|
||||
@@ -104,31 +70,8 @@ namespace JGL {
|
||||
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);
|
||||
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 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);
|
||||
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 FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size);
|
||||
void OutlineRect2D ( const Color3& color, const Vector2& pos, const Vector2& size, float thickness = 1);
|
||||
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);
|
||||
|
@@ -1,3 +1,74 @@
|
||||
//
|
||||
// Created by dawsh on 1/17/24.
|
||||
//
|
||||
#include <JGL/JGL.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
namespace JGL
|
||||
{
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
void FillRect2D(const Color3 &color, const Vector2 &pos, const Vector2 &size) {
|
||||
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 Color3 &color, const Vector2 &pos, const Vector2 &size, float thickness) {
|
||||
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);
|
||||
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 DrawLine2D(const Color3 &color, const Vector2 &A, const Vector2 &B, float thickness) {
|
||||
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) {
|
||||
DrawLine2D(color, {x, y}, {w, h}, thickness);
|
||||
}
|
||||
|
||||
void JGL::DrawPixel2D(const Color3 &color, float x, float y) {
|
||||
DrawPixel2D(color, {x, y});
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user