Cleanup.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m1s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m1s
Preparing for Release-1, J2D lighting is all that's left and then I can work on J3D. Added helper functions to get rid of the constant need to dereference things. Wrote a few functions that were defined but never implemented.
This commit is contained in:
@@ -54,7 +54,6 @@ namespace JGL {
|
||||
/// Provide a list of lights to be used in 2D space. Typically directly after J2D::Begin();
|
||||
/// 8 lights maximum for now. Some kind of light sorting will eventually be needed per j2d element.
|
||||
void LightArray(Light*, size_t size);
|
||||
void LightArray(std::vector<Light> lights);
|
||||
|
||||
/// Plots a single pixel on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
@@ -68,7 +67,7 @@ namespace JGL {
|
||||
/// @param color
|
||||
/// @param points
|
||||
/// @param radius
|
||||
void DrawPoints(const Color4& color, const std::vector<Vector2>& points, float radius = 1.f);
|
||||
void DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius = 1.f);
|
||||
|
||||
/// Plots a line (segment) on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see classes Color3, Color4.
|
||||
@@ -141,8 +140,12 @@ namespace JGL {
|
||||
/// Draws a render target to the screen.
|
||||
void DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const RenderTarget& render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
void DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const RenderTarget& render_target,const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0 , 0),
|
||||
const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
|
||||
/// Draws a sprite to the screen by passing a G̶L̶u̶i̶n̶t̶ JGL Texture that represents a handle to a loaded texture.
|
||||
/// @param texture
|
||||
@@ -155,13 +158,13 @@ namespace JGL {
|
||||
/// @see class Texture
|
||||
void DrawSprite(const Texture& texture, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0,0),
|
||||
const Vector2& scale = Vector2(1,1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const Texture& texture,
|
||||
float positionX, float positionY,
|
||||
float rad_rotation = 0,
|
||||
float originX = 0, float originY = 0,
|
||||
float scaleX = 1, float scaleY = 1,
|
||||
const Color4& color = Colors::White,
|
||||
Direction inversion = Direction::None);
|
||||
void DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation = 0, const Vector2& origin = Vector2(0,0),
|
||||
const Vector2& scale = Vector2(1,1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const Texture& texture, float positionX, float positionY, float rad_rotation = 0, float originX = 0, float originY = 0,
|
||||
float scaleX = 1, float scaleY = 1, const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation = 0,
|
||||
float originX = 0, float originY = 0,float scaleX = 1, float scaleY = 1,
|
||||
const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
|
||||
/// Draws a piece of a sprite to the screen, similar to DrawSprite.
|
||||
/// @param texture
|
||||
@@ -174,8 +177,12 @@ namespace JGL {
|
||||
/// @param inversion
|
||||
void DrawPartialSprite(const Texture& texture, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size, float rad_rotation = 0,
|
||||
const Vector2& origin = Vector2(0,0), const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position, const Vector2& sub_texture_size, float rad_rotation = 0,
|
||||
const Vector2& origin = Vector2(0,0), const Vector2& scale = Vector2(1, 1), const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawPartialSprite(const Texture& texture, float positionX, float positionY, float sub_texture_positionX, float sub_texture_positionY, unsigned int sub_texture_sizeX, unsigned int sub_texture_sizeY,
|
||||
float rad_rotation = 0, float originX = 0, float originY = 0, float scaleX = 1, float scaleY = 1, const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
void DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX, float sub_texture_positionY, unsigned int sub_texture_sizeX, unsigned int sub_texture_sizeY,
|
||||
float rad_rotation = 0, float originX = 0, float originY = 0, float scaleX = 1, float scaleY = 1, const Color4& color = Colors::White, Direction inversion = Direction::None);
|
||||
|
||||
/// To save v-ram, Use if a sprite would be identical if mirrored horizontally, vertically, or both. For example, a circle.
|
||||
/// Assumes the input texture is the top left quadrant. You can use "SoftwareTexture" to invert it correctly so that's the case.
|
||||
@@ -187,7 +194,7 @@ namespace JGL {
|
||||
/// @param scale
|
||||
/// @param color
|
||||
void DrawMirrorSprite(const Texture& texture, const Vector2& position, Direction mirror_axis = Direction::Horizontal | Direction::Vertical, float rad_rotation = 0, const Vector2& origin = Vector2(0,0), const Vector2& scale = Vector2(1,1), const Color4& color = Colors::White);
|
||||
|
||||
void DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis = Direction::Horizontal | Direction::Vertical, float rad_rotation = 0, const Vector2& origin = Vector2(0,0), const Vector2& scale = Vector2(1,1), const Color4& color = Colors::White);
|
||||
/// Draws an outline of a circle on the screen.
|
||||
void OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions = 16, float thickness = 1);
|
||||
|
||||
@@ -212,7 +219,7 @@ namespace JGL {
|
||||
int subdivisions = 10, float thickness = 1);
|
||||
|
||||
/// Draws a series of points where the last point always connects to the first point.
|
||||
void OutlinePolygon(const Color4& color, const std::vector<Vector2>& points, float thickness = 1);
|
||||
void OutlinePolygon(const Color4& color, const Vector2* points, int points_size, float thickness = 1);
|
||||
|
||||
/// Draws a text string on the screen with a given point-size and font.
|
||||
void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font);
|
||||
@@ -224,7 +231,7 @@ namespace JGL {
|
||||
void FillTexturedTriangle();
|
||||
|
||||
/// Draws an Arc (section of a circle) to the screen.
|
||||
void DrawArc(const Color4 &color, const Vector2 ¢er, float radius, float arc_begin, float arc_end,
|
||||
void DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end,
|
||||
unsigned int subdivisions, float thickness);
|
||||
}
|
||||
|
||||
|
15
main.cpp
15
main.cpp
@@ -167,9 +167,9 @@ public:
|
||||
|
||||
J2D::Begin(j2d_render_target, true);
|
||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||
J2D::DrawSprite(*image2, {300, 400}, sprite_radians * 0.10, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawMirrorSprite(*image, {400, 300}, Direction::Horizontal | Direction::Vertical, sprite_radians, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawPartialSprite(*image, {225, 300}, image->GetDimensions() * 0.25, image->GetDimensions() * 0.75, sprite_radians, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawSprite(image2, {300, 400}, sprite_radians * 0.10f, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawMirrorSprite(image, {400, 300}, Direction::Horizontal | Direction::Vertical, sprite_radians, {0.5,0.5}, {1, 1}, Colors::White);
|
||||
J2D::DrawPartialSprite(image, {225, 300}, image->GetDimensions() * 0.25, image->GetDimensions() * 0.75, sprite_radians, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::FillRect(Colors::Pinks::HotPink, {68, 120}, {32, 32});
|
||||
J2D::FillGradientRect(Colors::Red, Colors::Blue, Direction::Diagonal_SWNE, {100,52}, {100,100});
|
||||
J2D::FillRoundedRect(Colors::Red, {200, 52}, {100, 100}, 8, 8);
|
||||
@@ -179,7 +179,7 @@ public:
|
||||
|
||||
J2D::FillChamferRect(Colors::Reds::LightSalmon, {150, 400}, {64, 64}, 5);
|
||||
J2D::OutlineRoundedRect(Colors::Reds::LightCoral, {250, 350}, {128, 128}, 10, 2);
|
||||
|
||||
std::vector<Vector2> points = {{1,1}, {4,4}, {8,8}, {16,16}, {32,32}};
|
||||
J2D::FillGradientTriangle(Color4(Colors::Red), Color4(Colors::Green), Color4(Colors::Blue), {{0, 275}, {0, 375}, {100, 375}});
|
||||
J2D::OutlineTriangle(Colors::Blue, {{100, 275}, {0, 275}, {100, 375}});
|
||||
J2D::DrawGradientLine(Colors::Red, Colors::Blue, {105, 375}, {200, 275}, 2);
|
||||
@@ -190,7 +190,8 @@ public:
|
||||
J2D::DrawString(Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, 16, 1,16, Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, 33, 1,16, Jupiteroid);
|
||||
J2D::DrawString(Colors::White, "Framerate: " + std::to_string((int) fps), 0, 48, 1, 16, Jupiteroid);
|
||||
J2D::OutlinePolygon(Colors::White, {{200, 400}, {220, 420}, {220, 430}, {230, 410}, {200, 400}});
|
||||
std::array<Vector2, 5> polygon = {Vector2(200, 400), {220, 420}, {220, 430}, {230, 410}, {200, 400}};
|
||||
J2D::OutlinePolygon(Colors::White, polygon.data(), polygon.size());
|
||||
//J2D::FillPolygon(Colors::White, {{200, 400}, {220, 420}, {220, 430}, {230, 410}, {200, 400}});
|
||||
J2D::DrawCubicBezierCurve(Colors::Blues::CornflowerBlue,
|
||||
a.position,
|
||||
@@ -209,8 +210,8 @@ public:
|
||||
|
||||
auto image3_render_target = image2_render_target;
|
||||
J2D::Begin();
|
||||
J2D::DrawSprite(*j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawSprite(*image3_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawSprite(j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawSprite(image3_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::End();
|
||||
|
||||
}
|
||||
|
70
src/JGL.cpp
70
src/JGL.cpp
@@ -295,6 +295,52 @@ namespace JGL {
|
||||
J2D::FillCircle(color, {pos.x + size.x - radius, pos.y + size.y - radius}, radius, subdivisions);
|
||||
}
|
||||
|
||||
void J2D::DrawSprite(const Texture* texture, float positionX, float positionY, float rad_rotation,
|
||||
float originX, float originY,float scaleX, float scaleY,
|
||||
const Color4& color, Direction inversion) {
|
||||
DrawSprite(*texture, {positionX, positionY}, rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
||||
}
|
||||
void J2D::DrawSprite(const Texture* texture, const Vector2& position, float rad_rotation, const Vector2& origin,
|
||||
const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
|
||||
DrawSprite(*texture, position, rad_rotation, origin, scale, color, inversion);
|
||||
}
|
||||
|
||||
void J2D::DrawPartialSprite(const Texture* texture, const Vector2& position, const Vector2& sub_texture_position,
|
||||
const Vector2& sub_texture_size, float rad_rotation, const Vector2& origin,
|
||||
const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
DrawPartialSprite(*texture, position, sub_texture_position, sub_texture_size, rad_rotation, origin, scale, color, inversion);
|
||||
|
||||
}
|
||||
|
||||
void J2D::DrawPartialSprite(const Texture* texture, float positionX, float positionY, float sub_texture_positionX,
|
||||
float sub_texture_positionY, unsigned int sub_texture_sizeX,
|
||||
unsigned int sub_texture_sizeY, float rad_rotation, float originX, float originY,
|
||||
float scaleX, float scaleY, const Color4& color, Direction inversion) {
|
||||
DrawPartialSprite(*texture, {positionX, positionY}, {sub_texture_positionX, sub_texture_positionY}, {(float) sub_texture_sizeX, (float) sub_texture_sizeY},
|
||||
rad_rotation, {originX, originY}, {scaleX, scaleY}, color, inversion);
|
||||
}
|
||||
|
||||
void J2D::DrawMirrorSprite(const Texture* texture, const Vector2& position, Direction mirror_axis, float rad_rotation,
|
||||
const Vector2& origin, const Vector2& scale, const Color4& color) {
|
||||
DrawMirrorSprite(*texture, position, mirror_axis, rad_rotation, origin, scale, color);
|
||||
}
|
||||
|
||||
void J2D::DrawSprite(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
||||
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
|
||||
}
|
||||
|
||||
void J2D::DrawRenderTarget(const RenderTarget* render_target, const Vector2& position, float rad_rotation,
|
||||
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
DrawSprite(*render_target, position, rad_rotation, origin, scale, color, inversion);
|
||||
}
|
||||
|
||||
void J2D::DrawRenderTarget(const RenderTarget& render_target, const Vector2& position, float rad_rotation,
|
||||
const Vector2& origin, const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
DrawSprite(render_target, position, rad_rotation, origin, scale, color, inversion);
|
||||
}
|
||||
|
||||
void J2D::DrawSprite(const JGL::RenderTarget& rt, const Vector2& position, float rad_rotation, const Vector2& origin,
|
||||
const Vector2& scale, const Color4& color, Direction inversion) {
|
||||
|
||||
@@ -680,17 +726,17 @@ namespace JGL {
|
||||
DrawLine(color, last, first, thickness);
|
||||
}
|
||||
|
||||
void J2D::OutlinePolygon(const Color4 &color, const std::vector<Vector2>& points, float thickness) {
|
||||
void J2D::OutlinePolygon(const Color4 &color, const Vector2* points, int points_size, float thickness) {
|
||||
if (!inJ2D)
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
if (points.front() != points.back())
|
||||
if (points[0] != points[points_size -1])
|
||||
throw std::runtime_error("J2D::OutlinePolygon: The first point and the last point must connect.");
|
||||
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points.data());
|
||||
glDrawArrays(GL_LINE_LOOP, 0, (int) points.size());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, points_size);
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
@@ -746,8 +792,6 @@ namespace JGL {
|
||||
Vector2 br = pos + size;
|
||||
Vector2 bl = pos + Vector2(0, size.y);
|
||||
|
||||
|
||||
|
||||
// Center-point around which to calculate each 'quarter-circle'.
|
||||
Vector2 anchor_tl = pos + Vector2(radius, radius);
|
||||
Vector2 anchor_tr = pos + Vector2(size.x-radius, radius);
|
||||
@@ -796,9 +840,8 @@ namespace JGL {
|
||||
FillRoundedRect(color, pos, size, radius, 4);
|
||||
}
|
||||
|
||||
void J2D::OutlineChamferRect(const Color4 &color, const Vector2 &pos, const Vector2 &size, float radius,
|
||||
void J2D::OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius,
|
||||
float thickness) {
|
||||
|
||||
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
|
||||
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
|
||||
Vector2 anchor_topright_right = pos + Vector2(size.x, radius);
|
||||
@@ -809,20 +852,25 @@ namespace JGL {
|
||||
Vector2 anchor_topleft_left = pos + Vector2(0, radius);
|
||||
|
||||
Vector2 vertices[] = {anchor_topleft_top, anchor_topright_top, anchor_topright_right, anchor_bottomright_right, anchor_bottomright_bottom, anchor_bottomleft_bottom, anchor_bottomleft_left, anchor_topleft_left};
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 8);
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J2D::DrawPoints(const Color4 &color, const std::vector<Vector2> &points, float radius) {
|
||||
void J2D::DrawPoints(const Color4& color, const Vector2* points, int num_points, float radius) {
|
||||
glPointSize(radius);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points.data());
|
||||
glDrawArrays(GL_POINTS, 0, points.size());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), points);
|
||||
glDrawArrays(GL_POINTS, 0, num_points);
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J2D::FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC) {
|
||||
FillTriangle(color, {triA, triB, triC});
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region J3D
|
||||
|
Reference in New Issue
Block a user