28 enum class LoadType : uint8_t {
64 Sprite(
const uint8_t* bytes,
size_t width,
size_t height,
bool mipmap =
false);
128 operator
bool() const;
137 std::
string filename;
223 [[deprecated(
"Scale the modelview matrix instead using jngl::Mat3::scale")]]
228 [[deprecated(
"Use new drawClipped(Vec2, Vec2) method instead")]]
void
229 drawClipped(
float xstart,
float xend,
float ystart,
float yend)
const;
267 void setBytes(
const unsigned char*);
277 void setPos(
double x,
double y);
278 template <
class Vect>
void setPos(Vect p) {
283 void setCenter(
double x,
double y);
284 template <
class Vect>
void setCenter(Vect c) {
288 double getLeft()
const;
289 void setLeft(
double x);
291 double getTop()
const;
292 void setTop(
double y);
294 double getRight()
const;
295 void setRight(
double x);
297 double getBottom()
const;
298 void setBottom(
double y);
306 Vec2 getSize()
const;
308 float getWidth()
const;
310 float getHeight()
const;
312 void drawBoundingBox()
const;
317 void enableMipmaps();
319 void loadTexture(
int scaledWidth,
int scaledHeight,
const std::string& filename,
bool halfLoad,
320 unsigned int format,
const unsigned char*
const* rowPointers,
321 const unsigned char* data =
nullptr,
bool mipmap =
false);
322 Finally LoadPNG(
const std::string& filename, FILE* fp,
bool halfLoad,
bool mipmap);
324 unsigned int dataOffset;
325 unsigned int headerSize;
328 unsigned short planes;
330 unsigned int compression;
331 unsigned int dataSize;
333 Finally LoadBMP(
const std::string& filename, FILE* fp,
bool halfLoad,
bool mipmap);
335 Finally LoadWebP(
const std::string& filename, FILE* file,
bool halfLoad,
bool mipmap);
350template <
class Vect>
void draw(
const std::string& filename, Vect pos) {
351 draw(filename, pos.x, pos.y);
364 float xend,
float ystart,
float yend);
366void setSpriteColor(
unsigned char red,
unsigned char green,
unsigned char blue,
367 unsigned char alpha);
369void setSpriteColor(
unsigned char red,
unsigned char green,
unsigned char blue);
377void setSpriteAlpha(
unsigned char alpha);
379void pushSpriteAlpha(
unsigned char alpha = 255);
381void popSpriteAlpha();
387#if __cplusplus >= 201703L
392Finally drawOnlyIntoAlphaChannel();
412#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::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 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 ...
@ Premultiplied
For colours that already have their alpha multiplied in, 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.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.