Implement OutlineRect2D
This commit is contained in:
@@ -47,7 +47,7 @@ namespace JGL {
|
|||||||
|
|
||||||
Vector2 ScreenToViewport(const Vector2& v)
|
Vector2 ScreenToViewport(const Vector2& v)
|
||||||
{
|
{
|
||||||
// TODO: Implement matrix transformation
|
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||||
float x = v.x / 600.f;
|
float x = v.x / 600.f;
|
||||||
float y = v.y / 600.f;
|
float y = v.y / 600.f;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ namespace JGL {
|
|||||||
}
|
}
|
||||||
Vector2 ViewportToScreen(const Vector2& v)
|
Vector2 ViewportToScreen(const Vector2& v)
|
||||||
{
|
{
|
||||||
// TODO: Implement matrix transformation
|
// TODO: Implement (CORRECT!!!) matrix transformation
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawPixel2D(const Color3 &, int x, int y);
|
void DrawPixel2D(const Color3 &, int x, int y);
|
||||||
@@ -88,7 +88,18 @@ 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 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 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 OutlineRoundedRect2D(const Vector2& pos, const Vector2& size, const Color3& color, float radius, float thickness = 1);
|
||||||
void OutlinePolygon2D ();
|
void OutlinePolygon2D ();
|
||||||
|
3
main.cpp
3
main.cpp
@@ -42,7 +42,8 @@ void display() {
|
|||||||
glVertex2f(-0.9f, -0.3f);
|
glVertex2f(-0.9f, -0.3f);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
JGL::FillRect2D({64, 64}, {128, 128}, JGL::Colors::White);
|
JGL::FillRect2D({0, 0}, {128, 128}, JGL::Colors::White);
|
||||||
|
JGL::OutlineRect2D({0, 0}, {128, 128}, JGL::Colors::BrightRed);
|
||||||
|
|
||||||
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