hud_init(prog);
hud_rescale(width, height);
- hud_add(RESSOURCEPATH "textures/crosshair.png", (v2f) {0.0f, 0.0f}, (v2f) {1.0f, 1.0f});
+ hud_add(RESSOURCEPATH "textures/crosshair.png", (v2f) {0.0f, 0.0f}, (v2f) {1.0f, 1.0f}, HUD_SCALE_TEXTURE);
struct timespec ts, ts_old;
clock_gettime(CLOCK_REALTIME, &ts_old);
static void element_transform(HUDElement *element)
{
mat4x4_translate(element->transform, (1.0f + element->pos.x) / 2.0f * (f32) hud.width, (1.0f + element->pos.y) / 2.0f * (f32) hud.height, 0.0f);
+
+ v2f scale = element->scale;
+
+ switch (element->scale_type) {
+ case HUD_SCALE_TEXTURE:
+ scale.x *= element->texture->width;
+ scale.y *= element->texture->height;
+
+ break;
+
+ case HUD_SCALE_SCREEN:
+ scale.x *= hud.width;
+ scale.y *= hud.height;
+
+ break;
+
+ default:
+ break;
+ }
+
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
- mat4x4_scale_aniso(element->transform, element->transform, element->scale.x, element->scale.y, 1.0f);
+ mat4x4_scale_aniso(element->transform, element->transform, scale.x, scale.y, 1.0f);
#pragma GCC diagnostic pop
}
}
}
-HUDElement *hud_add(char *texture, v2f pos, v2f scale)
+HUDElement *hud_add(char *texture, v2f pos, v2f scale, HUDScaleType scale_type)
{
HUDElement *element = malloc(sizeof(HUDElement));
element->texture = get_texture(texture);
element->visible = true;
element->pos = pos;
-
element->scale = scale;
- element->scale.x *= (f32) element->texture->width;
- element->scale.y *= (f32) element->texture->height;
+ element->scale_type = scale_type;
element_transform(element);
#include "texture.h"
#include "types.h"
+typedef enum
+{
+ HUD_SCALE_TEXTURE,
+ HUD_SCALE_SCREEN,
+ HUD_SCALE_NONE,
+} HUDScaleType;
+
typedef struct
{
Texture *texture;
bool visible;
v2f pos;
v2f scale;
+ HUDScaleType scale_type;
mat4x4 transform;
} HUDElement;
void hud_deinit();
void hud_rescale(int width, int height);
void hud_render();
-HUDElement *hud_add(char *texture, v2f pos, v2f scale);
+HUDElement *hud_add(char *texture, v2f pos, v2f scale, HUDScaleType scale_type);
#endif