37 lines
820 B
C
37 lines
820 B
C
/*
|
|
* DESCRIPTION:
|
|
* Texture atlas functions.
|
|
*/
|
|
|
|
#include "atlas.h"
|
|
|
|
/* Initializes an atlas. */
|
|
void
|
|
atlas_init(struct Atlas* self, struct Texture texture, s32 frameW, s32 frameH, s32 rows, s32 cols)
|
|
{
|
|
self->texture = texture;
|
|
self->frameW = frameW;
|
|
self->frameH = frameH;
|
|
self->rows = rows;
|
|
self->cols = cols;
|
|
|
|
self->index = 0;
|
|
}
|
|
|
|
/* Obtains the texture coordinates for an atlas frame. */
|
|
void
|
|
atlas_uv_get(struct Atlas* self, vec2 uvMin, vec2 uvMax)
|
|
{
|
|
vec2 pos;
|
|
s32 col;
|
|
s32 row;
|
|
|
|
pos[0] = (f32)(self->index / self->rows) * self->frameW;
|
|
pos[1] = (f32)(self->index % self->rows) * self->frameH;
|
|
|
|
uvMin[0] = (f32)pos[0] / self->texture.w;
|
|
uvMin[1] = (f32)pos[1] / self->texture.h;
|
|
uvMax[0] = (f32)(pos[0] + self->frameW) / self->texture.w;
|
|
uvMax[1] = (f32)(pos[1] + self->frameH) / self->texture.h;
|
|
}
|