29 enum class LoadType : uint8_t {
65 Sprite(
const uint8_t* bytes,
size_t width,
size_t height,
bool mipmap =
false);
129 operator
bool() const;
138 std::
string filename;
224 [[deprecated(
"Scale the modelview matrix instead using jngl::Mat3::scale")]]
229 [[deprecated(
"Use new drawClipped(Vec2, Vec2) method instead")]]
void
230 drawClipped(
float xstart,
float xend,
float ystart,
float yend)
const;
268 void setBytes(
const unsigned char*);
278 void setPos(
double x,
double y);
279 template <
class Vect>
void setPos(Vect p) {
284 void setCenter(
double x,
double y);
285 template <
class Vect>
void setCenter(Vect c) {
289 double getLeft()
const;
290 void setLeft(
double x);
292 double getTop()
const;
293 void setTop(
double y);
295 double getRight()
const;
296 void setRight(
double x);
298 double getBottom()
const;
299 void setBottom(
double y);
307 Vec2 getSize()
const;
309 float getWidth()
const;
311 float getHeight()
const;
313 void drawBoundingBox()
const;
323 void enableMipmaps();
325 void loadTexture(
int scaledWidth,
int scaledHeight,
const std::string& filename,
bool halfLoad,
326 unsigned int format,
const unsigned char*
const* rowPointers,
327 const unsigned char* data =
nullptr,
bool mipmap =
false);
330 unsigned int dataOffset;
331 unsigned int headerSize;
334 unsigned short planes;
336 unsigned int compression;
337 unsigned int dataSize;
341 Finally LoadWebP(
const std::string& filename, FILE* file,
bool halfLoad,
bool mipmap);
356template <
class Vect>
void draw(
const std::string& filename, Vect pos) {
357 draw(filename, pos.x, pos.y);
370 float xend,
float ystart,
float yend);
372void setSpriteColor(
unsigned char red,
unsigned char green,
unsigned char blue,
373 unsigned char alpha);
375void setSpriteColor(
unsigned char red,
unsigned char green,
unsigned char blue);
383void setSpriteAlpha(
unsigned char alpha);
385void pushSpriteAlpha(
unsigned char alpha = 255);
387void popSpriteAlpha();
393#if __cplusplus >= 201703L
398Finally drawOnlyIntoAlphaChannel();
431#if __cplusplus >= 201703L
Contains jngl::Drawable class.
Contains jngl::Finally class.
Contains jngl::Rgb class.
Contains jngl::Rgba class.
Contains jngl::ShaderProgram class.
Contains jngl::TextureFilter.
Contains jngl::Vec2 class.
Object representing only the Alpha Channel in an RGBA color, 0 meaning invisible, 1 fully visible.
Helper class which calls a function when being destroyed.
Containing the pixel data of an image file.
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
Object representing a RGBA color.
Linked vertex and fragment shaders.
Fragment or vertex GLSL shader.
While this object is alive, don't do any other draw calls. Should never outlive its Sprite.
void draw(Mat3 modelview) const
Draws the Sprite which created this Batch centered using modelview.
Use this class to load a Sprite asynchronously.
Loader(std::string filename, bool mipmap=false) noexcept
Starts a thread to load filename and returns instantly.
std::shared_ptr< Sprite > shared() const
Blocks until the Sprite has been loaded and returns a non-nullptr std::shared_ptr.
Higher-level representation of an image.
void setTextureFilter(TextureFilter minification, TextureFilter magnification)
Sets how the texture is sampled when the sprite is drawn smaller than its pixel size (minification) a...
void drawClipped(Vec2 start, Vec2 end) const
Draw a cutout of the sprite. drawClipped({0, 0}, {1, 1}) would draw it normally.
void draw() const
Draws the Sprite, centered by default.
Batch batch(const ShaderProgram *shaderProgram=nullptr) const
Allows to draw the Sprite multiple times at different locations in an efficient way.
void drawScaled(float xfactor, float yfactor, const ShaderProgram *shaderProgram=nullptr) const
Draws the image scaled by xfactor and yfactor
Sprite(const std::string &filename, LoadType loadType=LoadType::NORMAL, bool mipmap=false)
std::shared_ptr< Finally > loader
Function which actually loads the sprite.
void drawClipped(float xstart, float xend, float ystart, float yend) const
void drawMesh(const std::vector< Vertex > &vertexes, const ShaderProgram *=nullptr) const
Draws a list of triangles with the sprite's texture on it using the global modelview from jngl::model...
Sprite(const std::string &filename, bool mipmap)
Sprite(const ImageData &, double scale, std::optional< std::string_view > filename=std::nullopt, bool mipmap=false)
Creates a Sprite from ImageData and scales it by scale.
static const Shader & vertexShader()
Returns a reference to JNGL's default vertex shader used to draw textures.
Sprite(const uint8_t *bytes, size_t width, size_t height, bool mipmap=false)
The sprite data is stored as packed RGBA bytes in an array, where the size of the array needs to be c...
void drawLerped(Mat3 modelview, Rgb color, float red, float green, float blue, Alpha) const
Draws the Sprite with each color channel linearly interpolated towards color.
void drawMesh(const Mat3 &modelview, const std::vector< Vertex > &vertexes, const ShaderProgram *shaderProgram=nullptr) const
Draws a list of triangles with the sprite's texture on it, ignores the Sprite's position.
BlendMode
How what's drawn is blended with what's already there, see setBlendMode()
@ Composite
Colours are blended by their alpha as usual, but alpha is composited too, rather than added up as it ...
@ PremultipliedAdditive
BlendMode::Additive for colors that already have their alpha multiplied in.
@ Screen
The opposite of Multiply: lightens what's there by the colors.
@ Premultiplied
For colours that already have their alpha multiplied in, e.g.
@ Additive
Adds the colors, by their alpha, to what's there, e.g. for something that glows.
@ Multiply
Multiplies what's there with the colors, darkening it, e.g.
Finally setBlendMode(BlendMode)
Sets how what's drawn is blended with what's already there, until the returned Finally object is dest...
void scale(double factor)
Multiplies the global ModelView matrix by a scaling matrix.
Finally load(const std::string &filename)
Starts a thread to load filename and returns a Finally which will join it.
TextureFilter
How a texture is sampled when it's drawn bigger or smaller than its pixel size.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.