pgpl/include/pgpl/render/texture.h

73 lines
3.2 KiB
C
Raw Normal View History

2025-10-03 20:16:11 +02:00
#ifndef PGPL_RENDER_TEXTURE_H
#define PGPL_RENDER_TEXTURE_H
#include <pgpl/render/predef.h>
#ifdef __cplusplus
extern "C" {
#endif
/* This enum contains all possible texture filtering methods that textures can
* be created with. */
typedef enum PGPL_TextureFilter {
PGPL_TEXTURE_FILTER_LINEAR,
PGPL_TEXTURE_FILTER_NEAREST
} PGPL_TextureFilter;
/* This enum contains all possible texture formats that textures can be created
* from. */
typedef enum PGPL_TextureFormat {
PGPL_TEXTURE_FORMAT_RGBA,
PGPL_TEXTURE_FORMAT_RGB,
PGPL_TEXTURE_FORMAT_BW
} PGPL_TextureFormat;
/* This creates a texture from an image file stored in memory. The file_data is
* a pointer to it, and len is the lenght of the file_data. See
* pgpl_render_create_texture_file for more info. */
PGPL_Texture *pgpl_render_create_texture_file_memory(PGPL_Renderer *renderer,
const uint8_t *file_data,
uint32_t len,
PGPL_TextureFilter filter);
/* This creates a texture from a file. This supports anything that stb_image
* supports. You can also choose the filtering method to be used. */
PGPL_Texture *pgpl_render_create_texture_file(PGPL_Renderer *renderer,
const char *filename,
PGPL_TextureFilter filter);
/* This creates a texture from raw pixel data. The width and height are used to
* determine the size of the data. Note that RGB images are padded to 4 bytes
* per pixel. */
PGPL_Texture *pgpl_render_create_texture(PGPL_Renderer *renderer,
const uint8_t *data, uint32_t width,
uint32_t height,
PGPL_TextureFilter filter,
PGPL_TextureFormat format);
/* This frees any resources associated with a texture. Note that you can call
* this with renderer being NULL, this however doesn't get rid of any OpenGL
* data (it still gets deleted upon window destruction). Only call this with the
* renderer as NULL if the window it was created on is already destroyed. */
void pgpl_render_destroy_texture(PGPL_Renderer *renderer,
PGPL_Texture *texture);
/* This renders a texture at the given position and with the given size. Note
* that you can ONLY render images on the window they were created on. */
void pgpl_render_texture(PGPL_Renderer *renderer, PGPL_Texture *texture,
double x, double y, double width, double height);
/* This renders a texture with extended settings. The color parameter allows you
* to modulate the color of the texture, the s0, s1, t0 and t1 parameters let
* you specify coordinates on a given texture, so that you only render a part of
* the texture. See pgpl_render_texture for more info. */
void pgpl_render_texture_extended(PGPL_Renderer *renderer,
PGPL_Texture *texture, double x, double y,
double width, double height, PGPL_Color color,
double s0, double t0, double s1, double t1);
#ifdef __cplusplus
}
#endif
#endif