Compare commits
14 Commits
Prerelease
...
Prerelease
Author | SHA1 | Date | |
---|---|---|---|
68e98e6c43 | |||
4e9645436e | |||
ea99a96e64 | |||
6866ba828b | |||
4893233301 | |||
7b5ef6045b | |||
5998bec833 | |||
0f4ada563e | |||
b9bae43cf3 | |||
7f1794e48f | |||
cc504c65ec | |||
bb4a80e36d | |||
5d981e64fc | |||
5b19d26b79 |
@@ -32,8 +32,10 @@ namespace JGL {
|
||||
using namespace J3ML::LinearAlgebra;
|
||||
using namespace J3ML::Geometry;
|
||||
|
||||
|
||||
/// @param window_size
|
||||
void Update(const Vector2& window_size);
|
||||
inline void PurgeFontCache() { fontCache.purgeCache(); }
|
||||
inline void PurgeFontCache() { JGL::fontCache.purgeCache(); }
|
||||
std::array<GLfloat, 16> OpenGLPerspectiveProjectionRH(float fovY, float aspect, float z_near, float z_far);
|
||||
/// Returns true if the graphics driver meets the requirements (GL Version & Extensions).
|
||||
bool MeetsRequirements();
|
||||
@@ -43,6 +45,8 @@ namespace JGL {
|
||||
/// @note This call may not strictly be necessary on some setups, but is provided to keep the API constant.
|
||||
/// It is recommended to always open a JGL 2D context to render your content, then close when completed.
|
||||
/// This keeps our code from, say, clobbering the OpenGL rendering context driving 3D content in between our calls.
|
||||
/// @param render_target
|
||||
/// @param clear_buffers
|
||||
void Begin(RenderTarget* render_target = nullptr, bool clear_buffers = false);
|
||||
/// Closes a 2-D rendering context with the underlying graphics system (In this case& by default OpenGL).
|
||||
/// @see Begin().
|
||||
@@ -55,9 +59,17 @@ namespace JGL {
|
||||
/// Plots a single pixel on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param coordinates The pixel-point on-screen at which to plot the pixel.
|
||||
/// @param radius The size of the point to plot. By default, a single pixel.
|
||||
void DrawPoint(const Color4& color, const Vector2& coordinates, float radius = 1.f);
|
||||
void DrawPoint(const Color4& color, float x, float y, float radius = 1.f);
|
||||
|
||||
/// Plots a series of pixel-points on the screen, in a batch.
|
||||
/// @note This is more performant for multiple points than plotting them individually.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param points A set of x,y points to render.
|
||||
/// @param radius The size of the point to plot. By default, a single pixel.
|
||||
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.
|
||||
/// @param A The starting point of the line segment.
|
||||
@@ -66,105 +78,229 @@ namespace JGL {
|
||||
void DrawLine(const Color4& color, const Vector2& A, const Vector2& B, float thickness = 1);
|
||||
void DrawLine(const Color4& color, float x1, float y1, float x2, float y2, float thickness = 1);
|
||||
|
||||
///Draws a line with a gradient that transitions across it.
|
||||
/// Draws a line with a color gradient that transitions across it.
|
||||
/// @param color_a A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param color_b A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param A The starting point of the line segment.
|
||||
/// @param B The end point of the line segment.
|
||||
/// @param thickness The width at which to render the line.
|
||||
void DrawGradientLine(const Color4& color_a, const Color4& color_b, const Vector2& A, const Vector2& B, float thickness = 1);
|
||||
void DrawGradientLine(const Color4& color_a, const Color4& color_b, float x, float y, float w, float h, float thickness = 1);
|
||||
|
||||
/// Draws an outline of a rectangle on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @param thickness The width at which to render the lines.
|
||||
void OutlineRect(const Color4& color, const Vector2& pos, const Vector2& size, float thickness = 1);
|
||||
|
||||
/// Draws an outline of a rectangle with rounded corners onto the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @param radius The corner-rounding radius (in radians).
|
||||
/// @param thickness The width at which to render the lines.
|
||||
void OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, float thickness = 1);
|
||||
|
||||
/// Draws an outline of a rectangle with chamfered corners onto the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @param radius The corner-rounding radius (in radians).
|
||||
/// @param thickness The width at which to render the lines.
|
||||
void OutlineChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, float thickness = 1);
|
||||
|
||||
/// Draws a filled rectangle on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @see FillRoundedRect, FillGradientRect, FillChamferRect.
|
||||
void FillRect(const Color4& color, const Vector2& pos, const Vector2& size);
|
||||
|
||||
/// Draws a filled rectangle where the color transitions across it.
|
||||
/// @param color1 A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param color2 A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param gradient See enum Direction
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
void FillGradientRect(const Color4& color1, const Color4& color2, const Direction& gradient, const Vector2& pos, const Vector2& size);
|
||||
|
||||
/// Draws a filled rectangle with rounded corners on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @param radius The corner-rounding radius (in radians).
|
||||
/// @param subdivisions The amount of sub-divisions (and calculations) to be performed per-arc rounding corner.
|
||||
void FillRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, unsigned int subdivisions = 8);
|
||||
|
||||
/// Draws a render target to the screen.
|
||||
/// Draws a filled rectangle with chamfered (beveled) corners on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param pos The top-left corner of the rectangle.
|
||||
/// @param size The width and height of the rectangle.
|
||||
/// @param radius The corner-rounding radius (in radians).
|
||||
void FillChamferRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5);
|
||||
|
||||
|
||||
|
||||
/// Draws a render-target (runtime-modifiable texture) to the screen.
|
||||
/// @param render_target A RenderTarget instance to be displayed.
|
||||
/// @param position The position at which to render this object from it's center-point, defined by the origin parameter.
|
||||
/// @param rad_rotation The amount of radians to rotate this render-target about it's center-point.
|
||||
/// @param origin The center-point in the image to use for rendering, rotation, and scaling. Top-left is {0,0} and bottom right is {1, 1}.
|
||||
/// @param scale The amount (in both x, and y axis) to scale the image, with {1,1} being default scaling.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param inversion @see Direction
|
||||
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 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);
|
||||
|
||||
|
||||
/// Draws a sprite (technically, actually a render target) to the screen.
|
||||
/// @note This similar overload exists because we expect someone will be an idiot and turn all of their sprites into RenderTargets. ~william
|
||||
/// @param render_target A RenderTarget instance to be displayed.
|
||||
/// @param position The position at which to render this object from it's center-point, defined by the origin parameter.
|
||||
/// @param rad_rotation The amount of radians to rotate this render-target about it's center-point.
|
||||
/// @param origin The center-point in the image to use for rendering, rotation, and scaling. Top-left is {0,0} and bottom right is {1, 1}.
|
||||
/// @param scale The amount (in both x, and y axis) to scale the image, with {1,1} being default scaling.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param inversion @see Direction
|
||||
/// @see DrawSprite
|
||||
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
|
||||
/// @param position
|
||||
/// @param texture A texture instance to be displayed.
|
||||
/// @param position The point at which to draw the sprite (from the top-left down).
|
||||
/// @param origin The center point around which the image should have all transformations applied to it.
|
||||
/// @param scale The scale transformation for the image. X and Y axis are independently-scalable.
|
||||
/// @param rad_rotation A float representing the rotation of the sprite where 0 is no rotation and 1 is the maximum rotation (would look the same as 0).
|
||||
/// @param color A 32-bit RGBA value represented as four unsigned 8-bit integers.
|
||||
/// @param inversion inverts the texture only.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param inversion @see Direction
|
||||
/// @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
|
||||
/// @param position
|
||||
/// @param texture A texture instance to be displayed.
|
||||
/// @param position The point at which to draw the sprite (from the top-left down).
|
||||
/// @param sub_texture_position The top left corner of the sub-texture to be drawn.
|
||||
/// @param sub_texture_size The size of the sub-texture in px.
|
||||
/// @param origin
|
||||
/// @param scale
|
||||
/// @param color
|
||||
/// @param inversion
|
||||
/// @param origin The center point around which the image should have all transformations applied to it.
|
||||
/// @param scale The scale transformation for the image. X and Y axis are independently-scalable.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param inversion @see Direction
|
||||
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.
|
||||
/// @param texture
|
||||
/// @param position
|
||||
/// @param texture A texture instance to be displayed.
|
||||
/// @param position The point at which to draw the sprite (from the top-left down).
|
||||
/// @param mirror_axis The axes to mirror across, Vertical and Horizontal or both only.
|
||||
/// @param rad_rotation The rotation of the final result.
|
||||
/// @param origin The point at which transformations are done about.
|
||||
/// @param scale
|
||||
/// @param color
|
||||
/// @param scale The scale transformation for the image. X and Y axis are independently-scalable.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
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.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param center The point in cartesian space at which to draw the circle. This will by-definition be the centroid of this circle.
|
||||
/// @param radius The radius of the circle to be drawn. AKA Half the diameter.
|
||||
/// @param subdivisions The accuracy of the approximation of the circle, measured in iteration steps taken.
|
||||
/// @param thickness The line-width of the circle to be rendered at.
|
||||
void OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions = 16, float thickness = 1);
|
||||
|
||||
/// Draws a filled circle on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param center The point in cartesian space at which to draw the circle. This will by-definition be the centroid of this circle.
|
||||
/// @param radius The radius of the circle to be drawn. AKA Half the diameter.
|
||||
/// @param subdivisions The accuracy of the approximation of the circle, measured in iteration steps taken.
|
||||
void FillCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions = 8);
|
||||
|
||||
/// Draws an outline of a triangle on the screen.
|
||||
/// @param color
|
||||
/// @param tri
|
||||
/// @param thickness
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param tri The triangle structure / set of 3 points in cartesian space used to draw the triangle.
|
||||
/// @param thickness The line-width of the triangle to be rendered at.
|
||||
void OutlineTriangle(const Color4& color, const Triangle2D& tri, float thickness = 1);
|
||||
void OutlineTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC, float thickness = 1);
|
||||
|
||||
/// Draws a filled triangle on the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param tri The triangle structure / set of 3 points in cartesian space used to draw the triangle.
|
||||
void FillTriangle(const Color4& color, const Triangle2D& tri);
|
||||
void FIllTriangle(const Color4& color, const Vector2& triA, const Vector2& triB, const Vector2& triC);
|
||||
|
||||
/// Draws a triangle where each corner is defined by a given color, Smoothly transitioning between them.
|
||||
/// @param a_color
|
||||
/// @param b_color
|
||||
/// @param c_color
|
||||
/// @param tri
|
||||
void FillGradientTriangle(const Color4& a_color, const Color4& b_color, const Color4& c_color, const Triangle2D& tri);
|
||||
|
||||
/// Draws a smooth, curved line segment between two control points, with the curve controlled by the two inner points.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param controlA The first control point, which can be considered the start of the line.
|
||||
/// @param pointA The first inner point, which controls the contour of the curve.
|
||||
/// @param pointB The second inner point, which controls the contour of the curve.
|
||||
/// @param controlB The second control point, which can be considered the end of the line.
|
||||
/// @see J3ML::Algorithm::Bezier
|
||||
void DrawCubicBezierCurve(const Color4& color, const Vector2& controlA, const Vector2& pointA, const Vector2& pointB, const Vector2& controlB,
|
||||
int subdivisions = 10, float thickness = 1);
|
||||
|
||||
|
||||
// TODO: Implement OutlinePolygon overload which takes a std::vector of points as well.
|
||||
|
||||
/// 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);
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param points The array of vector2's to draw as a polygon.
|
||||
/// @param points_size The length of the array of vector2's.
|
||||
/// @param thickness The line-width of the polygon
|
||||
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.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param text The text to be rendered.
|
||||
/// @param x The position on the screen at which to draw the text, from the top-left.
|
||||
/// @param y The position on the screen at which to draw the text, from the top-left.
|
||||
/// @param scale The value (in both axes) to scale the text by. Defaults to {1,1}.
|
||||
/// @param size The point-size at which to render the font out. Re-using the same point-size allows efficient glyph caching.
|
||||
/// @param font The font to use for rendering. @see Font.
|
||||
void DrawString(const Color4& color, const std::string& text, float x, float y, float scale, u32 size, const Font& font);
|
||||
|
||||
|
||||
/// Draws an Arc (section of a circle) to the screen.
|
||||
/// @param color A 3-or-4 channel color value. @see class Color3, class Color4
|
||||
/// @param center The point in cartesian space at which to draw the arc. This will by-definition be the centroid of this partial circle.
|
||||
/// @param radius The radius of the partial circle to be drawn. AKA Half the diameter.
|
||||
/// @param arc_begin The point (0 - 2pi) around a unit-circle of which to start the arc.
|
||||
/// @param arc_end The point (0 - 2pi) around a unit-circle of which to start the arc.
|
||||
/// @param subdivisions The accuracy of the approximation of the circle, measured in iteration steps taken.
|
||||
/// @param thickness The line-width to draw the arc with.
|
||||
void DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end,
|
||||
unsigned int subdivisions, float thickness);
|
||||
|
||||
|
||||
/// TODO Implement the following. These ones are going to be extremely annoying.
|
||||
void FillPolygon(const Color4& color, const std::vector<Vector2>& points);
|
||||
void FillTexturedPolygon();
|
||||
void OutlineRoundedRect(const Color4& color, const Vector2& pos, const Vector2& size, float radius = 5, float thickness = 1);
|
||||
void FillTexturedTriangle();
|
||||
}
|
||||
|
||||
@@ -185,7 +321,24 @@ namespace JGL {
|
||||
void WireframeCapsule(const Color3& color, const Capsule& cap, float thickness = 1);
|
||||
void FillTriangleMesh(const Color3& color, const TriangleMesh& mesh);
|
||||
void WireframeTriangleMesh(const Color3& color, const TriangleMesh& mesh, float thickness = 1);
|
||||
|
||||
/// Draws a string of text in 3D space, with an arbitrary rotation.
|
||||
/// @param color
|
||||
/// @param text
|
||||
/// @param pos
|
||||
/// @param scale
|
||||
/// @param size
|
||||
/// @param font
|
||||
/// @param angle
|
||||
/// @param draw_back_face
|
||||
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle = {0, 0, 0}, bool draw_back_face = false);
|
||||
|
||||
/// Draws a string of text in 3D space that is always facing the exact direction of the camera projection.
|
||||
void DrawBillboardString();
|
||||
|
||||
/// Draws a texture sprite in 3D space that is always facing the exact direction of the camera projection.
|
||||
void DrawBillboardSprite();
|
||||
|
||||
void DrawSprite();
|
||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||
void DrawMatrixGizmo (const Matrix4x4&);
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
//CachedGlyph(GLuint texture_id, char c);
|
||||
CachedGlyph(char c, std::array<GLfloat, 12> texcoords, float x2o, float y2o, float w, float h, float advX, float advY);
|
||||
char getCharacter();
|
||||
char getCharacter() const;
|
||||
[[nodiscard]] std::array<GLfloat, 12> getTexCoords() const;
|
||||
};
|
||||
|
||||
@@ -38,16 +38,19 @@ private:
|
||||
GLsizei texture_width = 0, texture_height = 0;
|
||||
unsigned int font_size = 0;
|
||||
unsigned int font_index = 0;
|
||||
void Erase();
|
||||
public:
|
||||
void appendGlyph(CachedGlyph* glyph);
|
||||
unsigned int getFontSize();
|
||||
unsigned int getFontIndex();
|
||||
unsigned int getFontSize() const;
|
||||
unsigned int getFontIndex() const;
|
||||
CachedGlyph* getGlyph(char c);
|
||||
std::unordered_map<char, CachedGlyph*> getGlyphs();
|
||||
const GLuint* getTexture();
|
||||
const GLuint* getTextureHandle();
|
||||
[[nodiscard]] GLsizei getTextureWidth() const;
|
||||
[[nodiscard]] GLsizei getTextureHeight() const;
|
||||
public:
|
||||
CachedFont(GLuint texture_id, GLsizei texture_width, GLsizei texture_height, unsigned int font_size, unsigned int font_index);
|
||||
~CachedFont();
|
||||
};
|
||||
|
||||
class JGL::FontCache {
|
||||
|
@@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
#include <JGL/types/Texture.h>
|
||||
#include <Color4.hpp>
|
||||
#include <Colors.hpp>
|
||||
#include <JGL/types/Enums.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
|
||||
namespace JGL {
|
||||
class RenderTarget;
|
||||
class Texture; // Forward declare.
|
||||
}
|
||||
|
||||
//TODO copy constructor for this. Copying this as it is and then that copy going out of scope will crash the program as it sits.
|
||||
//If you do copy it you're doing it wrong. But still.
|
||||
|
||||
class JGL::RenderTarget {
|
||||
private:
|
||||
Color4 clear_color{0,0,0,0};
|
||||
@@ -21,7 +19,7 @@ private:
|
||||
bool texture_created_by_us = false;
|
||||
GLuint framebuffer_object = 0;
|
||||
GLuint depth_buffer = 0;
|
||||
Texture* texture = nullptr;
|
||||
const Texture* texture = nullptr;
|
||||
MSAA_SAMPLE_RATE msaa_sample_rate = MSAA_SAMPLE_RATE::MSAA_NONE;
|
||||
GLuint msaa_framebuffer_object = 0;
|
||||
GLuint msaa_depth_buffer = 0;
|
||||
@@ -39,6 +37,9 @@ public:
|
||||
/// Blits the MSAA FBO onto the regular FBO if MSAA is enabled and or If you're rendering to a texture which uses mipmaps,
|
||||
/// It regenerates them so what you drew doesn't disappear at a distance. Otherwise it does nothing.
|
||||
void Blit() const;
|
||||
|
||||
/// Blit a render target onto another. Will break if they're not the same size.
|
||||
static void Blit(const RenderTarget& source, RenderTarget* destination);
|
||||
[[nodiscard]] bool TextureCreatedByRenderTarget() const;
|
||||
public:
|
||||
[[nodiscard]] Vector2 GetDimensions() const;
|
||||
@@ -47,7 +48,7 @@ public:
|
||||
/// You need to run "Blit()" after rendering to your FBO before you show it.
|
||||
/// @note Also, If the texture wasn't made by the RenderTarget you don't want this. It would destroy the texture.
|
||||
[[nodiscard]] bool MSAAEnabled() const;
|
||||
[[nodiscard]] Texture* GetJGLTexture() const;
|
||||
[[nodiscard]] const Texture* GetJGLTexture() const;
|
||||
[[nodiscard]] GLuint GetGLTextureHandle() const;
|
||||
[[nodiscard]] GLuint GetGLFramebufferObjectHandle() const;
|
||||
[[nodiscard]] GLuint GetGLDepthBufferHandle() const;
|
||||
@@ -55,8 +56,10 @@ public:
|
||||
/// Get the data back from the FBO. This is *not* async friendly.
|
||||
[[nodiscard]] std::vector<GLfloat> GetData() const;
|
||||
public:
|
||||
/// Copy constructor. Will always set "texture_created_by_us" to true and use our own texture to avoid memleaks.
|
||||
RenderTarget(const RenderTarget& rhs);
|
||||
/// Create a render target for a texture that already exists. For adding to an existing texture.
|
||||
explicit RenderTarget(Texture* texture, const Color4& clear_color = Colors::Black);
|
||||
explicit RenderTarget(const Texture* texture, const Color4& clear_color = Colors::Black);
|
||||
/// Create a Render Target with a brand new texture. Want to render JGL elements onto a texture and display it as a sprite?
|
||||
explicit RenderTarget(const Vector2& size, const Color4& clear_color = Colors::Black, bool use_depth = false, MSAA_SAMPLE_RATE sample_rate = MSAA_SAMPLE_RATE::MSAA_NONE);
|
||||
~RenderTarget();
|
||||
|
@@ -52,8 +52,6 @@ namespace JGL {
|
||||
[[nodiscard]] TextureFlag GetFlags() const;
|
||||
[[nodiscard]] TextureFormat GetFormat() const;
|
||||
[[nodiscard]] std::vector<Color4> GetPixelData() const;
|
||||
void SetTextureHandle(GLuint handle);
|
||||
void SetFlags(const TextureFlag& flags);
|
||||
};
|
||||
|
||||
}
|
28
main.cpp
28
main.cpp
@@ -1,4 +1,3 @@
|
||||
|
||||
#include <JGL/JGL.h>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <Colors.hpp>
|
||||
@@ -39,6 +38,8 @@ public:
|
||||
}
|
||||
|
||||
void Draw() {
|
||||
|
||||
|
||||
if (dragging)
|
||||
J2D::DrawPoint(Colors::White, position, 4.f);
|
||||
else if (hovered)
|
||||
@@ -47,6 +48,8 @@ public:
|
||||
J2D::DrawPoint(Colors::Reds::Salmon, position, 3.f);
|
||||
|
||||
J2D::DrawString(Colors::White, std::format("{:.1f},{:.1f}", position.x, position.y), position.x, position.y, 1.f, 10, FreeSans);
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -118,13 +121,13 @@ public:
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
image = new Texture("assets/sprites/Re3D.png", TextureFilteringMode::BILINEAR);
|
||||
j2d_render_target = new RenderTarget({540, 540}, {0,0,0,0}, false, MSAA_SAMPLE_RATE::MSAA_8X);
|
||||
image2 = new Texture("assets/sprites/Re3D.png",TextureFilteringMode::BILINEAR);
|
||||
j2d_render_target = new RenderTarget({540, 540}, {0,0,0,0}, false, MSAA_SAMPLE_RATE::MSAA_NONE);
|
||||
image2 = image;
|
||||
image2_render_target = new RenderTarget(image2);
|
||||
|
||||
J2D::Begin(image2_render_target);
|
||||
J2D::FillRect(Colors::Red, {0,0}, {4,4});
|
||||
J2D::DrawString(Colors::Red, "TEST", 0, 16, 1, 16, FreeSans);
|
||||
J2D::FillRect(Colors::Blue, {0,0}, {4,4});
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
@@ -162,12 +165,11 @@ public:
|
||||
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle, true);
|
||||
J3D::End();
|
||||
|
||||
|
||||
J2D::Begin(j2d_render_target, true);
|
||||
J2D::FillRect(Colors::Blue, {0,52}, {100,100});
|
||||
J2D::DrawSprite(*image2, {300, 300}, 0, {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);
|
||||
@@ -175,6 +177,9 @@ public:
|
||||
J2D::FillCircle(Colors::White, {52, 204}, 50, 24);
|
||||
J2D::OutlineCircle(Colors::White, {153, 204}, 50, 24);
|
||||
|
||||
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);
|
||||
@@ -185,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,
|
||||
@@ -203,8 +209,8 @@ public:
|
||||
//Draw the Render Target that we just drew all that stuff onto.
|
||||
|
||||
J2D::Begin();
|
||||
J2D::DrawSprite(*j2d_render_target, {0, 0}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::DrawSprite(*image2_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(image2_render_target, {300, 500}, 0, {0.5, 0.5}, {1,1}, Colors::White);
|
||||
J2D::End();
|
||||
|
||||
}
|
||||
|
312
src/JGL.cpp
312
src/JGL.cpp
@@ -18,6 +18,7 @@ bool inJ2D = false;
|
||||
bool inJ3D = false;
|
||||
bool wasTexture2DEnabled = false;
|
||||
bool wasTextureCoordArrayEnabled = false;
|
||||
|
||||
bool wasDepthTestEnabled = false;
|
||||
bool wasVertexArraysEnabled = false;
|
||||
bool wasCullFaceEnabled = false;
|
||||
@@ -105,17 +106,13 @@ namespace JGL {
|
||||
else
|
||||
wasBlendEnabled = true;
|
||||
|
||||
if (!glIsEnabled(GL_TEXTURE_2D))
|
||||
wasTexture2DEnabled = false,
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
else
|
||||
wasTexture2DEnabled = true;
|
||||
if (glIsEnabled(GL_TEXTURE_2D))
|
||||
wasTexture2DEnabled = true,
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY))
|
||||
wasTextureCoordArrayEnabled = false,
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
else
|
||||
if (glIsEnabled(GL_TEXTURE_COORD_ARRAY))
|
||||
wasTextureCoordArrayEnabled = true;
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
if (glIsEnabled(GL_COLOR_ARRAY))
|
||||
wasColorArrayEnabled = true,
|
||||
@@ -152,11 +149,11 @@ namespace JGL {
|
||||
if (!wasBlendEnabled)
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
if (!wasTexture2DEnabled)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
if (wasTexture2DEnabled)
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if (!wasTextureCoordArrayEnabled)
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (wasTextureCoordArrayEnabled)
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
if (wasColorArrayEnabled)
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
@@ -298,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) {
|
||||
|
||||
@@ -373,13 +416,17 @@ namespace JGL {
|
||||
std::swap(textureCoordinates[0], textureCoordinates[3]),
|
||||
std::swap(textureCoordinates[1], textureCoordinates[2]);
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4ubv(color.ptr());
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
@@ -458,17 +505,20 @@ namespace JGL {
|
||||
(v.x - pos2.x - offset.x * scale.x) * sin_theta + (v.y - pos2.y - offset.y * scale.y) * cos_theta +
|
||||
pos2.y + offset.y * scale.y};
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4ubv(color.ptr());
|
||||
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void
|
||||
J2D::DrawPartialSprite(const JGL::Texture& texture, float positionX, float positionY, float sub_texture_positionX,
|
||||
void J2D::DrawPartialSprite(const JGL::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 originX, float originY, float rad_rotation,
|
||||
float scaleX, float scaleY, const Color4& color, JGL::Direction inversion) {
|
||||
@@ -538,24 +588,27 @@ namespace JGL {
|
||||
(v.x - pos2.x - offset.x * scale.x) * sin_theta + (v.y - pos2.y - offset.y * scale.y) * cos_theta + pos2.y + offset.y * scale.y
|
||||
};
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(Vector2), textureCoordinates.data());
|
||||
glDrawArrays(GL_QUADS, 0, 4);
|
||||
|
||||
//Reset the wrapping mode.
|
||||
if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_EDGE)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
else if (texture.GetWrappingMode() == TextureWrappingMode::REPEAT)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
else if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_BORDER)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
//Reset the wrapping mode.
|
||||
if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_EDGE)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
else if (texture.GetWrappingMode() == TextureWrappingMode::REPEAT)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
else if (texture.GetWrappingMode() == TextureWrappingMode::CLAMP_TO_BORDER)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER),
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4fv(baseColor);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void J2D::OutlineCircle(const Color4& color, const Vector2& center, float radius, unsigned int subdivisions, float thickness) {
|
||||
@@ -673,20 +726,157 @@ 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);
|
||||
}
|
||||
|
||||
void J2D::DrawGradientLine(const Color4 &color_a, const Color4 &color_b, float x, float y, float w, float h,
|
||||
float thickness) {
|
||||
DrawGradientLine(color_a, color_b, {x, y}, {w, h}, thickness);
|
||||
}
|
||||
|
||||
void J2D::DrawArc(const Color4& color, const Vector2& center, float radius, float arc_begin, float arc_end, unsigned int subdivisions, float thickness)
|
||||
{
|
||||
if (!inJ2D)
|
||||
Logger::Error("Drawing J2D element before J2D begin.");
|
||||
|
||||
if (arc_begin == arc_end)
|
||||
Logger::Error("WTF are you even drawing???");
|
||||
|
||||
if ( J3ML::Math::Mod(J3ML::Math::Abs(arc_begin-arc_end), J3ML::Math::Pi*2.f) == 0)
|
||||
Logger::Error("Use OutlineCircle instead!!");
|
||||
|
||||
float step = Math::Abs(arc_end-arc_begin) / (float) subdivisions;
|
||||
std::vector<Vector2> vertices(subdivisions);
|
||||
GLfloat angle, x, y;
|
||||
|
||||
int i = 0;
|
||||
for (angle = arc_begin; angle <= arc_end; angle += step) {
|
||||
x = center.x + (radius * std::cos(angle));
|
||||
y = center.y + (radius * std::sin(angle));
|
||||
if (i < subdivisions)
|
||||
vertices[i] = {x, y};
|
||||
else
|
||||
vertices.emplace_back(x, y);
|
||||
i++;
|
||||
}
|
||||
|
||||
glLineWidth(thickness);
|
||||
glColor4ubv(color.ptr());
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(Vector2), vertices.data());
|
||||
glDrawArrays(GL_LINE_STRIP, 0, (int) vertices.size());
|
||||
glColor4fv(baseColor);
|
||||
}
|
||||
|
||||
void J2D::OutlineRoundedRect(const Color4 &color, const Vector2 &pos, const Vector2 &size, float radius, float thickness)
|
||||
{
|
||||
// A rounded rectangle of size 2a x 2b with rounding radius r is given by
|
||||
// f(x; a, r) + f(y; b, r) = 1
|
||||
// where
|
||||
// f(x; a, r) = {
|
||||
// if |x| >= a - r: (|x| - (a-r) / r )^2
|
||||
// otherwise: 0
|
||||
// }
|
||||
|
||||
//std::vector<Vector2> vertices;
|
||||
|
||||
|
||||
// TODO: Calculate vertices for top-left quarter-circle.
|
||||
|
||||
Vector2 tl = pos;
|
||||
Vector2 tr = pos + Vector2(size.x, 0);
|
||||
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);
|
||||
Vector2 anchor_br = pos + size - Vector2(radius, radius);
|
||||
Vector2 anchor_bl = pos + Vector2(radius, size.y - radius);
|
||||
|
||||
//J2D::Begin();
|
||||
//J2D::DrawPoints(Colors::Red, {tl, tr, br, bl}, 2);
|
||||
//J2D::DrawPoints(Colors::Blue, {anchor_tl, anchor_tr, anchor_br, anchor_bl}, 2);
|
||||
//J2D::End();
|
||||
|
||||
Vector2 anchor_topleft_top = pos + Vector2(radius, 0);
|
||||
Vector2 anchor_topright_top = pos + Vector2(size.x - radius, 0);
|
||||
// TODO: Calculate vertices for top-right quarter-circle.
|
||||
Vector2 anchor_topright_right = pos + Vector2(size.x, radius);
|
||||
Vector2 anchor_bottomright_right = pos + Vector2(size.x, size.y - radius);
|
||||
// TODO: Calculate vertices for bottom-right quarter-circle.
|
||||
Vector2 anchor_bottomright_bottom = pos + Vector2(size.x - radius, size.y);
|
||||
Vector2 anchor_bottomleft_bottom = pos + Vector2(radius, size.y);
|
||||
// TODO: Calculate vertices for bottom-left quarter-circle.
|
||||
Vector2 anchor_bottomleft_left = pos + Vector2(0, size.y - radius);
|
||||
Vector2 anchor_topleft_left = pos + Vector2(0, radius);
|
||||
|
||||
//J2D::Begin();
|
||||
|
||||
// The 3.01f, etc is a tiny-bit of overshoot to compensate for the fact that
|
||||
// this is not being plotted as a continuous line-loop.
|
||||
// Once i'm done working this out I expect bill will want to make it such.
|
||||
|
||||
unsigned int subdivisions = 9;
|
||||
|
||||
J2D::DrawArc(color, anchor_tl, radius, Math::Pi, 3.01f*Math::Pi/2.f, subdivisions, thickness);
|
||||
J2D::DrawLine(color, anchor_topleft_top, anchor_topright_top, thickness);
|
||||
J2D::DrawArc(color, anchor_tr, radius, 3.f*Math::Pi/2.f, 2.02*Math::Pi, subdivisions, thickness);
|
||||
J2D::DrawLine(color, anchor_topright_right, anchor_bottomright_right, thickness);
|
||||
J2D::DrawArc(color, anchor_br, radius, 0.0f, 1.01f*Math::Pi/2, subdivisions, thickness);
|
||||
J2D::DrawLine(color, anchor_bottomright_bottom, anchor_bottomleft_bottom, thickness);
|
||||
J2D::DrawArc(color, anchor_bl, radius, Math::Pi/2, Math::Pi*1.01f, subdivisions, thickness);
|
||||
J2D::DrawLine(color, anchor_bottomleft_left, anchor_topleft_left, thickness);
|
||||
//J2D::End();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void J2D::FillChamferRect(const Color4 &color, const Vector2 &pos, const Vector2 &size, float radius) {
|
||||
FillRoundedRect(color, pos, size, radius, 4);
|
||||
}
|
||||
|
||||
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);
|
||||
Vector2 anchor_bottomright_right = pos + Vector2(size.x, size.y - radius);
|
||||
Vector2 anchor_bottomright_bottom = pos + Vector2(size.x - radius, size.y);
|
||||
Vector2 anchor_bottomleft_bottom = pos + Vector2(radius, size.y);
|
||||
Vector2 anchor_bottomleft_left = pos + Vector2(0, size.y - radius);
|
||||
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 Vector2* points, int num_points, float radius) {
|
||||
glPointSize(radius);
|
||||
glColor4ubv(color.ptr());
|
||||
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
|
||||
@@ -744,17 +934,13 @@ namespace JGL {
|
||||
wasVertexArraysEnabled = false,
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY))
|
||||
wasTextureCoordArrayEnabled = false,
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
else
|
||||
wasTextureCoordArrayEnabled = true;
|
||||
if (glIsEnabled(GL_TEXTURE_COORD_ARRAY))
|
||||
wasTextureCoordArrayEnabled = true,
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
|
||||
wasTexture2DEnabled = true;
|
||||
if (!glIsEnabled(GL_TEXTURE_2D))
|
||||
wasTexture2DEnabled = false,
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
if (glIsEnabled(GL_TEXTURE_2D))
|
||||
wasTexture2DEnabled = true,
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
wasCullFaceEnabled = false;
|
||||
if (glIsEnabled(GL_CULL_FACE))
|
||||
@@ -782,7 +968,7 @@ namespace JGL {
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (wasTexture2DEnabled)
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if (!wasBlendEnabled)
|
||||
glDisable(GL_BLEND);
|
||||
@@ -790,8 +976,8 @@ namespace JGL {
|
||||
if (wasCullFaceEnabled)
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
if (!wasTextureCoordArrayEnabled)
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (wasTextureCoordArrayEnabled)
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
//Put the draw color back how it was before.
|
||||
glColor4fv(oldColor);
|
||||
|
@@ -15,13 +15,15 @@
|
||||
|
||||
#include <JGL/types/Font.h>
|
||||
#include <JGL/types/FontCache.h>
|
||||
#include "JGL/logger/logger.h"
|
||||
#include <JGL/logger/logger.h>
|
||||
|
||||
namespace JGL {
|
||||
CachedFont* CacheFont(const Font& font, u32 size) {
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
CachedFont* cachedFont;
|
||||
FT_Set_Pixel_Sizes(font.face, 0, size);
|
||||
jlog::Debug("Caching font data...");
|
||||
Logger::Debug("Caching font data...");
|
||||
GLuint texture_id;
|
||||
glGenTextures(1, &texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
@@ -88,6 +90,7 @@ namespace JGL {
|
||||
xoffset += g->bitmap.width;
|
||||
charcode = FT_Get_Next_Char(font.face, charcode, &gindex);
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
return cachedFont;
|
||||
}
|
||||
|
||||
@@ -95,18 +98,30 @@ namespace JGL {
|
||||
// Offset by height to render at "correct" location.
|
||||
y += size;
|
||||
|
||||
bool round_text_coords_for_crisp_rendering = true;
|
||||
|
||||
// TODO: This currently does not account for non-integer scale factors.
|
||||
if (round_text_coords_for_crisp_rendering)
|
||||
{
|
||||
x = J3ML::Math::Floor(x);
|
||||
y = J3ML::Math::Floor(y);
|
||||
}
|
||||
|
||||
CachedFont* cachedFont = fontCache.getFont(size, font.index);
|
||||
|
||||
if (font.face == nullptr)
|
||||
jlog::Fatal("Drawing a string with an uninitialized font?");
|
||||
Logger::Fatal("Drawing a string with an uninitialized font?");
|
||||
|
||||
//If the font doesn't exist in the cache yet.
|
||||
if (!cachedFont)
|
||||
cachedFont = CacheFont(font, size);
|
||||
|
||||
glColor4ubv(color.ptr());
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
//Texture parameters are restored when the texture_handle is bound
|
||||
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
|
||||
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTextureHandle());
|
||||
|
||||
std::vector<std::array<GLfloat, 12>> vertices(text.size());
|
||||
std::vector<std::array<GLfloat, 12>> texcoords(text.size());
|
||||
@@ -143,16 +158,32 @@ namespace JGL {
|
||||
glDrawArrays(GL_TRIANGLES, 0, (int) vertices.size() * 6);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle, bool draw_back_face) {
|
||||
// TODO: Determine the proper scale factor mathematically
|
||||
// This number was arrived at holistically.
|
||||
scale = scale * 0.002f;
|
||||
scale = -scale;
|
||||
float x = pos.x;
|
||||
float y = pos.y;
|
||||
float z = pos.z;
|
||||
|
||||
// TODO: this is broken because it causes the text to be shifted downwards.
|
||||
/*
|
||||
bool round_text_coords_for_crisp_rendering = true;
|
||||
|
||||
// TODO: This currently does not account for non-integer scale factors.
|
||||
if (round_text_coords_for_crisp_rendering)
|
||||
{
|
||||
x = J3ML::Math::Floor(x);
|
||||
y = J3ML::Math::Floor(y);
|
||||
z = J3ML::Math::Floor(z);
|
||||
}
|
||||
*/
|
||||
|
||||
CachedFont* cachedFont = fontCache.getFont(size, font.index);
|
||||
if (font.face == nullptr)
|
||||
jlog::Fatal("Drawing a string with an uninitialized font?");
|
||||
@@ -160,8 +191,10 @@ namespace JGL {
|
||||
if (!cachedFont)
|
||||
cachedFont = CacheFont(font, size);
|
||||
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glColor4ubv(color.ptr());
|
||||
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTexture());
|
||||
glBindTexture(GL_TEXTURE_2D, *cachedFont->getTextureHandle());
|
||||
|
||||
std::vector<std::array<GLfloat, 18>> vertices(text.size());
|
||||
std::vector<std::array<GLfloat, 12>> texcoords(text.size());
|
||||
@@ -211,6 +244,8 @@ namespace JGL {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4f(1, 1, 1, 1);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
@@ -82,8 +82,7 @@ namespace JGL
|
||||
//return newIndex;
|
||||
}
|
||||
|
||||
Font::~Font()
|
||||
{
|
||||
Font::~Font() {
|
||||
//Detail::UnloadFont(this->index);
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace JGL;
|
||||
|
||||
char CachedGlyph::getCharacter() {
|
||||
char CachedGlyph::getCharacter() const {
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ void JGL::CachedFont::appendGlyph(JGL::CachedGlyph* glyph) {
|
||||
glyphs.emplace(glyph->getCharacter(), glyph);
|
||||
}
|
||||
|
||||
unsigned int JGL::CachedFont::getFontSize() {
|
||||
unsigned int JGL::CachedFont::getFontSize() const {
|
||||
return font_size;
|
||||
}
|
||||
|
||||
unsigned int JGL::CachedFont::getFontIndex() {
|
||||
unsigned int JGL::CachedFont::getFontIndex() const {
|
||||
return font_index;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ std::unordered_map<char, CachedGlyph*> CachedFont::getGlyphs() {
|
||||
return glyphs;
|
||||
}
|
||||
|
||||
const GLuint* CachedFont::getTexture() {
|
||||
const GLuint* CachedFont::getTextureHandle() {
|
||||
return &texture;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,15 @@ GLsizei CachedFont::getTextureHeight() const {
|
||||
return texture_height;
|
||||
}
|
||||
|
||||
void CachedFont::Erase() {
|
||||
if (texture != 0)
|
||||
glDeleteTextures(1, &texture);
|
||||
}
|
||||
|
||||
CachedFont::~CachedFont() {
|
||||
Erase();
|
||||
}
|
||||
|
||||
void FontCache::appendFont(CachedFont* font) {
|
||||
cachedFonts.push_back(font);
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
#include <JGL/types/RenderTarget.h>
|
||||
#include <JGL/types/Texture.h>
|
||||
#include <JGL/logger/logger.h>
|
||||
#include <stdexcept>
|
||||
|
||||
JGL::Texture* JGL::RenderTarget::GetJGLTexture() const {
|
||||
const JGL::Texture* JGL::RenderTarget::GetJGLTexture() const {
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ Color4 JGL::RenderTarget::GetClearColor() const {
|
||||
}
|
||||
|
||||
/// Idk why you'd ever want to clear it out if you're rendering onto a texture you passed in :shrug:.
|
||||
JGL::RenderTarget::RenderTarget(JGL::Texture* texture, const Color4& clear_color) {
|
||||
JGL::RenderTarget::RenderTarget(const JGL::Texture* texture, const Color4& clear_color) {
|
||||
GLuint current_fbo = GetActiveGLFramebufferHandle();
|
||||
GLint viewport[4] = {0, 0, 0, 0};
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
@@ -112,7 +113,6 @@ JGL::RenderTarget::RenderTarget(const Vector2& size, const Color4& clear_color,
|
||||
this->clear_color = clear_color;
|
||||
this->size = size;
|
||||
texture_created_by_us = true;
|
||||
this->texture->SetFlags(INVERT_Y);
|
||||
|
||||
if (sample_rate != MSAA_SAMPLE_RATE::MSAA_NONE)
|
||||
SetMSAAEnabled(sample_rate);
|
||||
@@ -301,3 +301,44 @@ void JGL::RenderTarget::Blit() const {
|
||||
glBindTexture(GL_TEXTURE_2D, current_texture);
|
||||
}
|
||||
}
|
||||
|
||||
void JGL::RenderTarget::Blit(const JGL::RenderTarget& source, JGL::RenderTarget* destination) {
|
||||
if (source.size != destination->size)
|
||||
Logger::Warning("Blitting a render target but they're not the same size?");
|
||||
|
||||
// Save the GL state.
|
||||
GLuint current_fbo = GetActiveGLFramebufferHandle();
|
||||
GLint current_draw_fbo = 0;
|
||||
GLint current_read_fbo = 0;
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, ¤t_read_fbo);
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_draw_fbo);
|
||||
|
||||
// Draw the contents of one into the other.
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, source.framebuffer_object);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, destination->framebuffer_object);
|
||||
glBlitFramebuffer(0, 0, source.size.x, source.size.y, 0, 0, source.size.x, source.size.y, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
// Put the GL state back.
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, current_read_fbo);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, current_draw_fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo);
|
||||
}
|
||||
|
||||
JGL::RenderTarget::RenderTarget(const JGL::RenderTarget& rhs) {
|
||||
auto* this_render_target = new RenderTarget(rhs.size, rhs.clear_color, rhs.using_depth, rhs.msaa_sample_rate);
|
||||
RenderTarget::Blit(rhs, this_render_target);
|
||||
|
||||
this->clear_color = this_render_target->clear_color;
|
||||
this->size = this_render_target->size;
|
||||
this->using_depth = this_render_target->using_depth;
|
||||
this->texture_created_by_us = true;
|
||||
this->texture = this_render_target->texture;
|
||||
this->framebuffer_object = this_render_target->framebuffer_object;
|
||||
this->depth_buffer = this_render_target->depth_buffer;
|
||||
this->msaa_sample_rate = this_render_target->msaa_sample_rate;
|
||||
this->msaa_framebuffer_object = this_render_target->msaa_framebuffer_object;
|
||||
this->msaa_depth_buffer = this_render_target->msaa_depth_buffer;
|
||||
this->msaa_render_buffer = this_render_target->msaa_render_buffer;
|
||||
|
||||
operator delete(this_render_target);
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include <JGL/types/Texture.h>
|
||||
#include <iostream>
|
||||
#include <JGL/types/RenderTarget.h>
|
||||
|
||||
using namespace ReImage;
|
||||
|
||||
@@ -36,9 +37,11 @@ namespace JGL
|
||||
texture_size = size;
|
||||
texture_filtering_mode = TextureFilteringMode::NEAREST;
|
||||
texture_wrapping_mode = TextureWrappingMode::CLAMP_TO_EDGE;
|
||||
texture_flags = TextureFlag::NONE;
|
||||
// Because in vram it'll be right side up.
|
||||
texture_flags = TextureFlag::INVERT_Y;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, previous_texture);
|
||||
|
||||
}
|
||||
|
||||
void Texture::load(Image* software_texture, const Vector2& size, const TextureFormat& format,
|
||||
@@ -155,10 +158,6 @@ namespace JGL
|
||||
return texture_filtering_mode;
|
||||
}
|
||||
|
||||
void Texture::SetTextureHandle(GLuint handle) {
|
||||
texture_handle = handle;
|
||||
}
|
||||
|
||||
TextureWrappingMode Texture::GetWrappingMode() const {
|
||||
return texture_wrapping_mode;
|
||||
}
|
||||
@@ -173,13 +172,21 @@ namespace JGL
|
||||
}
|
||||
|
||||
Texture::Texture(const Texture& rhs) {
|
||||
auto pixels = rhs.GetPixelData();
|
||||
auto image = Image(pixels.data(), pixels.size(), rhs.GetDimensions().x, rhs.GetDimensions().y);
|
||||
this->load(&image, rhs.GetDimensions(), rhs.texture_format, rhs.texture_filtering_mode, rhs.texture_wrapping_mode);
|
||||
this->texture_flags = rhs.texture_flags;
|
||||
}
|
||||
auto* this_texture = new Texture(rhs.GetDimensions());
|
||||
auto this_render_target = RenderTarget(this);
|
||||
auto rhs_render_target = RenderTarget(&rhs);
|
||||
|
||||
void Texture::SetFlags(const TextureFlag &flags) {
|
||||
this->texture_flags = flags;
|
||||
RenderTarget::Blit(rhs_render_target, &this_render_target);
|
||||
|
||||
this->texture_handle = this_texture->texture_handle;
|
||||
this->texture_size = this_texture->texture_size;
|
||||
this->texture_flags = this_texture->texture_flags;
|
||||
this->texture_format = this_texture->texture_format;
|
||||
this->texture_filtering_mode = this_texture->texture_filtering_mode;
|
||||
this->texture_wrapping_mode = this_texture->texture_wrapping_mode;
|
||||
|
||||
// Free the memory of "this_texture" without calling the destructor.
|
||||
// In 99% of cases you wouldn't want this. But in this scenario we do.
|
||||
operator delete(this_texture);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user