2021-11-30 21:29:18 -06:00
|
|
|
#ifndef TEXTURE_H
|
|
|
|
#define TEXTURE_H
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#include "timer.h"
|
|
|
|
|
|
|
|
#define TEX_SPEC 0
|
|
|
|
#define TEX_NORM 1
|
|
|
|
#define TEX_HEIGHT 2
|
|
|
|
#define TEX_DIFF 3
|
|
|
|
|
2022-12-30 13:31:06 -06:00
|
|
|
/* Normalized S,T coordinates for rendering */
|
|
|
|
struct glrect {
|
|
|
|
float s0;
|
|
|
|
float s1;
|
|
|
|
float t0;
|
|
|
|
float t1;
|
|
|
|
};
|
|
|
|
|
|
|
|
float st_s_w(struct glrect st);
|
|
|
|
float st_s_h(struct glrect st);
|
|
|
|
|
|
|
|
#define ST_UNIT (struct glrect) { 0.f, 1.f, 0.f, 1.f }
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-30 13:31:06 -06:00
|
|
|
/* Pixel U,V coordiantes */
|
|
|
|
struct uvrect {
|
|
|
|
int u0;
|
|
|
|
int u1;
|
|
|
|
int v0;
|
|
|
|
int v1;
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
2022-12-30 13:31:06 -06:00
|
|
|
/* Tracks a playing animation */
|
2023-01-16 02:16:39 -06:00
|
|
|
/* Objects should keep this, and simple change what TexAnim they are pointing to */
|
2023-01-15 09:53:50 -06:00
|
|
|
struct anim2d {
|
2021-11-30 21:29:18 -06:00
|
|
|
int frame;
|
|
|
|
int playing;
|
|
|
|
int pausetime;
|
2022-02-06 10:14:57 -06:00
|
|
|
struct timer *timer;
|
2023-01-02 07:55:26 -06:00
|
|
|
struct TexAnim *anim;
|
2023-01-16 02:16:39 -06:00
|
|
|
float size[2]; /* Current size of animation in pixels*/
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
2022-12-30 13:31:06 -06:00
|
|
|
/* Describes an animation on a particular texture */
|
2021-11-30 21:29:18 -06:00
|
|
|
struct TexAnim {
|
2023-01-02 07:55:26 -06:00
|
|
|
struct glrect *st_frames; /* Dynamic array of frames of animation */
|
2021-11-30 21:29:18 -06:00
|
|
|
int ms;
|
2023-01-02 07:55:26 -06:00
|
|
|
struct Texture *tex;
|
2023-01-15 09:53:50 -06:00
|
|
|
int loop;
|
2021-11-30 21:29:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TextureOptions {
|
|
|
|
int sprite;
|
2023-01-13 22:08:39 -06:00
|
|
|
int mips;
|
2021-11-30 21:29:18 -06:00
|
|
|
unsigned int gamma:1;
|
|
|
|
int animation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Texture {
|
2023-01-02 07:55:26 -06:00
|
|
|
unsigned int id; /* ID reference for the GPU memory location of the texture */
|
2022-01-19 16:43:21 -06:00
|
|
|
int width;
|
|
|
|
int height;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
struct TextureOptions opts;
|
|
|
|
struct TexAnim anim;
|
|
|
|
};
|
|
|
|
|
2022-08-25 15:48:15 -05:00
|
|
|
struct Texture *texture_pullfromfile(const char *path); // Create texture from image
|
|
|
|
struct Texture *texture_loadfromfile(const char *path); // Create texture & load to gpu
|
|
|
|
void tex_gpu_reload(struct Texture *tex); // gpu_free then gpu_load
|
|
|
|
void tex_gpu_free(struct Texture *tex); // Remove texture data from gpu
|
|
|
|
void tex_bind(struct Texture *tex); // Bind to gl context
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-08-25 15:48:15 -05:00
|
|
|
char * tex_get_path(struct Texture *tex); // Get image path for texture
|
2022-08-24 12:24:21 -05:00
|
|
|
|
2023-01-16 02:16:39 -06:00
|
|
|
void anim_load(struct anim2d *anim, const char *path); /* Load and start new animation */
|
|
|
|
void texanim_fromframes(struct TexAnim *anim, int frames);
|
|
|
|
void anim_calc(struct anim2d *anim);
|
2023-01-15 09:53:50 -06:00
|
|
|
void anim_play(struct anim2d *anim);
|
|
|
|
void anim_setframe(struct anim2d *anim, int frame);
|
|
|
|
void anim_stop(struct anim2d *anim);
|
|
|
|
void anim_pause(struct anim2d *anim);
|
|
|
|
void anim_fwd(struct anim2d *anim);
|
|
|
|
void anim_bkwd(struct anim2d *anim);
|
|
|
|
void anim_incr(struct anim2d *anim);
|
|
|
|
void anim_decr(struct anim2d *anim);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-29 11:27:41 -06:00
|
|
|
struct glrect tex_get_rect(struct Texture *tex);
|
2023-01-15 09:53:50 -06:00
|
|
|
struct glrect anim_get_rect(struct anim2d *anim);
|
2022-12-24 13:18:06 -06:00
|
|
|
|
2023-01-02 07:55:26 -06:00
|
|
|
int anim_frames(struct TexAnim *a);
|
2022-12-24 13:18:06 -06:00
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
#endif
|