Add animation ffi hook
This commit is contained in:
parent
804c2de617
commit
daebe5c665
|
@ -18,6 +18,7 @@
|
|||
#include "stb_image_write.h"
|
||||
|
||||
static uint32_t VBO = 0;
|
||||
static uint32_t VAO = 0;
|
||||
|
||||
unsigned char ttf_buffer[1<<25];
|
||||
|
||||
|
@ -30,6 +31,15 @@ void font_init(struct shader *textshader) {
|
|||
shader_use(shader);
|
||||
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenVertexArrays(1, &VAO);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Default font
|
||||
//font = MakeFont("teenytinypixels.ttf", 30);
|
||||
|
@ -152,7 +162,8 @@ void renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3
|
|||
glBindTexture(GL_TEXTURE_2D, font->texID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, len*16*sizeof(float), NULL, GL_STREAM_DRAW);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
const unsigned char *line, *wordstart;
|
||||
line = (unsigned char*)text;
|
||||
|
|
|
@ -472,6 +472,20 @@ s7_pointer s7_anim(s7_scheme *sc, s7_pointer args) {
|
|||
free_anim(a);
|
||||
}
|
||||
|
||||
s7_pointer s7_anim_cmd(s7_scheme *sc, s7_pointer args) {
|
||||
int cmd = s7_integer(s7_car(args));
|
||||
int body = s7_integer(s7_cadr(args));
|
||||
s7_pointer sym = s7_caddr(args);
|
||||
|
||||
switch (cmd) {
|
||||
case 0:
|
||||
YughInfo("Playing animation called %s.", s7_symbol_name(sym));
|
||||
break;
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
#define S7_FUNC(NAME, ARGS) s7_define_function(s7, #NAME, s7_ ##NAME, ARGS, 0, 0, "")
|
||||
|
||||
void ffi_load() {
|
||||
|
@ -511,5 +525,6 @@ void ffi_load() {
|
|||
S7_FUNC(timer_cmd, 2);
|
||||
|
||||
S7_FUNC(anim, 2);
|
||||
S7_FUNC(anim_cmd, 3);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,11 +108,18 @@ unsigned int incrementAnimFrame(unsigned int interval, struct sprite *sprite)
|
|||
return interval;
|
||||
}
|
||||
|
||||
static uint32_t VAO = 0;
|
||||
|
||||
// TODO: This should be done once for all sprites
|
||||
void sprite_initialize()
|
||||
{
|
||||
glGenBuffers(1, &VBO);
|
||||
glGenVertexArrays(1, &VAO);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
glEnableVertexAttribArray(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,9 +160,11 @@ void tex_draw(struct Texture *tex, float pos[2], float angle, float size[2], flo
|
|||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STREAM_DRAW);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||
|
||||
glBindVertexArray(VAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void sprite_draw(struct sprite *sprite)
|
||||
|
@ -179,31 +188,6 @@ void gui_draw_img(const char *img, float x, float y) {
|
|||
tex_draw(tex, pos, 0.f, size, offset, tex_get_rect(tex));
|
||||
}
|
||||
|
||||
void spriteanim_draw(struct sprite *sprite)
|
||||
{
|
||||
shader_use(animSpriteShader);
|
||||
|
||||
mfloat_t model[16] = { 0.f };
|
||||
memcpy(model, UNITMAT4, sizeof(UNITMAT4));
|
||||
|
||||
mat4_translate_vec2(model, sprite->pos);
|
||||
mfloat_t msize[2] =
|
||||
{ sprite->size[0] * sprite->anim.dimensions[0],
|
||||
sprite->size[1] * sprite->anim.dimensions[1] };
|
||||
mat4_scale_vec2(model, msize);
|
||||
|
||||
shader_setmat4(animSpriteShader, "model", model);
|
||||
shader_setvec3(animSpriteShader, "spriteColor", sprite->color);
|
||||
shader_setfloat(animSpriteShader, "frame", sprite->anim.frame);
|
||||
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, sprite->tex->id);
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
|
||||
void video_draw(struct datastream *stream, mfloat_t position[2], mfloat_t size[2], float rotate, mfloat_t color[3])
|
||||
{
|
||||
shader_use(vid_shader);
|
||||
|
|
|
@ -40,7 +40,6 @@ void sprite_loadanim(struct sprite *sprite, const char *path, struct Anim2D anim
|
|||
void sprite_settex(struct sprite *sprite, struct Texture *tex);
|
||||
void sprite_initialize();
|
||||
void sprite_draw(struct sprite *sprite);
|
||||
void spriteanim_draw(struct sprite *sprite);
|
||||
void video_draw(struct datastream *ds, mfloat_t pos[2], mfloat_t size[2], float rotate, mfloat_t color[3]);
|
||||
void sprite_draw_all();
|
||||
unsigned int incrementAnimFrame(unsigned int interval, struct sprite *sprite);
|
||||
|
|
|
@ -58,6 +58,9 @@
|
|||
(define (sound_stop sound) (sound_cmd sound 2))
|
||||
(define (sound_restart sound) (sound_cmd sound 3))
|
||||
|
||||
(define-macro (anim_play anim)
|
||||
`(anim_cmd 0 body ,anim))
|
||||
|
||||
(define-macro (registertype type . expr)
|
||||
(let ((f (gensym)))
|
||||
`(begin
|
||||
|
|
Loading…
Reference in a new issue