.
This commit is contained in:
parent
8126762901
commit
59c6aed2c8
Binary file not shown.
@ -45,7 +45,7 @@ struct draw_instruction_t
|
|||||||
/* DI_PROGRAM_SWITCH_FONT */
|
/* DI_PROGRAM_SWITCH_FONT */
|
||||||
xoverlay_font_handle_t font;
|
xoverlay_font_handle_t font;
|
||||||
/* */
|
/* */
|
||||||
xoverlay_texture_handle thandle;
|
xoverlay_texture_handle_t thandle;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ void
|
|||||||
dis_program_switch_texture(GLuint texture);
|
dis_program_switch_texture(GLuint texture);
|
||||||
|
|
||||||
void
|
void
|
||||||
dis_textureapi_switch_texture(xoverlay_texture_handle texture);
|
dis_textureapi_switch_texture(xoverlay_texture_handle_t texture);
|
||||||
|
|
||||||
void
|
void
|
||||||
dis_program_switch_font(xoverlay_font_handle_t font);
|
dis_program_switch_font(xoverlay_font_handle_t font);
|
||||||
@ -121,7 +121,7 @@ struct draw_state
|
|||||||
|
|
||||||
GLuint texture;
|
GLuint texture;
|
||||||
xoverlay_font_handle_t font;
|
xoverlay_font_handle_t font;
|
||||||
xoverlay_texture_handle thandle;
|
xoverlay_texture_handle_t thandle;
|
||||||
|
|
||||||
GLuint shader;
|
GLuint shader;
|
||||||
};
|
};
|
||||||
@ -155,7 +155,7 @@ ds_render_next_frame();
|
|||||||
/* To be called by draw functions */
|
/* To be called by draw functions */
|
||||||
|
|
||||||
void
|
void
|
||||||
ds_prepare_texture_handle(xoverlay_texture_handle handle);
|
ds_prepare_texture_handle(xoverlay_texture_handle_t handle);
|
||||||
|
|
||||||
void
|
void
|
||||||
ds_prepare_texture(GLuint texture);
|
ds_prepare_texture(GLuint texture);
|
||||||
@ -173,26 +173,3 @@ ds_use_shader(GLuint shader);
|
|||||||
|
|
||||||
void
|
void
|
||||||
ds_use_font(xoverlay_font_handle_t font);
|
ds_use_font(xoverlay_font_handle_t font);
|
||||||
|
|
||||||
/* Primitive Internal Drawing API */
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_line(vec2 xy, vec2 delta, vec4 color, float thickness);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect(vec2 xy, vec2 hw, vec4 color);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect_outline(vec2 xy, vec2 hw, vec4 color, float thickness);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect_textured(vec2 xy, vec2 hw, vec4 color, xoverlay_texture_handle texture, vec2 t_xy, vec2 t_hw);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string_internal(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, int *out_x, int *out_y);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, int *out_x, int *out_y);
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string_with_outline(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, vec4 outline_color, float outline_width, int adjust_outline_alpha, int *out_x, int *out_y);
|
|
||||||
|
@ -70,12 +70,6 @@ typedef struct xoverlay_vec4_t
|
|||||||
};
|
};
|
||||||
} xoverlay_vec4_t, xoverlay_rgba_t;
|
} xoverlay_vec4_t, xoverlay_rgba_t;
|
||||||
|
|
||||||
typedef struct xoverlay_vec2_t
|
|
||||||
{
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
} xoverlay_vec2_t;
|
|
||||||
|
|
||||||
int xoverlay_init();
|
int xoverlay_init();
|
||||||
void xoverlay_destroy();
|
void xoverlay_destroy();
|
||||||
|
|
||||||
@ -87,22 +81,22 @@ void xoverlay_install_mouse_callback(xoverlay_callback_mousemove callback);
|
|||||||
xoverlay_rgba_t xoverlay_rgba(int r, int g, int b, int a);
|
xoverlay_rgba_t xoverlay_rgba(int r, int g, int b, int a);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_line(xoverlay_vec2_t xy, xoverlay_vec2_t delta, xoverlay_rgba_t color, float thickness);
|
xoverlay_draw_line(float x, float y, float dx, float dy, xoverlay_rgba_t color, float thickness);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_rect(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color);
|
xoverlay_draw_rect(float x, float y, float w, float h, xoverlay_rgba_t color);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_rect_outline(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color, float thickness);
|
xoverlay_draw_rect_outline(float x, float y, float w, float h, xoverlay_rgba_t color, float thickness);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_rect_textured(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color, xoverlay_texture_handle texture, xoverlay_vec2_t t_xy, xoverlay_vec2_t t_hw);
|
xoverlay_draw_rect_textured(float x, float y, float w, float h, xoverlay_rgba_t color, xoverlay_texture_handle_t texture, float tx, float ty, float tw, float th);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_string(xoverlay_vec2_t xy, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, int *out_x, int *out_y);
|
xoverlay_draw_string(float x, float y, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, float *out_x, float *out_y);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_draw_string_with_outline(xoverlay_vec2_t xy, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, xoverlay_vec4_t outline_color, float outline_width, int adjust_outline_alpha, int *out_x, int *out_y);
|
xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, xoverlay_vec4_t outline_color, float outline_width, int adjust_outline_alpha, float *out_x, float *out_y);
|
||||||
|
|
||||||
void xoverlay_poll_events();
|
void xoverlay_poll_events();
|
||||||
void xoverlay_draw_begin();
|
void xoverlay_draw_begin();
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
typedef unsigned xoverlay_texture_handle;
|
typedef unsigned xoverlay_texture_handle_t;
|
||||||
|
|
||||||
xoverlay_texture_handle
|
xoverlay_texture_handle_t
|
||||||
xoverlay_texture_load_png_rgba(const char *path);
|
xoverlay_texture_load_png_rgba(const char *path);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_texture_unload(xoverlay_texture_handle handle);
|
xoverlay_texture_unload(xoverlay_texture_handle_t handle);
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_texture_get_size(xoverlay_texture_handle handle, int *width, int *height);
|
xoverlay_texture_get_size(xoverlay_texture_handle_t handle, int *width, int *height);
|
||||||
|
@ -34,10 +34,10 @@ int
|
|||||||
textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out);
|
textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out);
|
||||||
|
|
||||||
struct textureapi_texture_t *
|
struct textureapi_texture_t *
|
||||||
textureapi_get(xoverlay_texture_handle handle);
|
textureapi_get(xoverlay_texture_handle_t handle);
|
||||||
|
|
||||||
void
|
void
|
||||||
textureapi_bind(xoverlay_texture_handle handle);
|
textureapi_bind(xoverlay_texture_handle_t handle);
|
||||||
|
|
||||||
int
|
int
|
||||||
textureapi_init();
|
textureapi_init();
|
||||||
@ -45,7 +45,7 @@ textureapi_init();
|
|||||||
void
|
void
|
||||||
textureapi_destroy();
|
textureapi_destroy();
|
||||||
|
|
||||||
xoverlay_texture_handle
|
xoverlay_texture_handle_t
|
||||||
textureapi_add_texture(struct textureapi_texture_t font);
|
textureapi_add_texture(struct textureapi_texture_t font);
|
||||||
|
|
||||||
|
|
||||||
|
227
src/drawglx.c
227
src/drawglx.c
@ -5,12 +5,13 @@
|
|||||||
* Author: nullifiedcat
|
* Author: nullifiedcat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "drawglx.h"
|
#include "drawglx_internal.h"
|
||||||
#include "overlay.h"
|
#include "overlay.h"
|
||||||
#include "programs.h"
|
#include "programs.h"
|
||||||
#include "drawglx_internal.h"
|
#include "vertex_structs.h"
|
||||||
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <X11/extensions/shape.h>
|
#include <X11/extensions/shape.h>
|
||||||
@ -187,6 +188,228 @@ int xoverlay_glx_create_window()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xoverlay_draw_line(float x, float y, float dx, float dy, xoverlay_rgba_t color, float thickness)
|
||||||
|
{
|
||||||
|
ds_prepare_program(PROGRAM_TRIANGLES_PLAIN);
|
||||||
|
|
||||||
|
GLuint idx = dstream.next_index;
|
||||||
|
GLuint indices[6] = { idx, idx + 1, idx + 3, idx + 3, idx +2, idx };
|
||||||
|
struct vertex_v2fc4f vertices[4];
|
||||||
|
|
||||||
|
float nx = -dy;
|
||||||
|
float ny = dx;
|
||||||
|
|
||||||
|
float ex = x + dx;
|
||||||
|
float ey = y + dy;
|
||||||
|
|
||||||
|
float length = sqrtf(nx * nx + ny * ny);
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
length /= thickness;
|
||||||
|
nx /= length;
|
||||||
|
ny /= length;
|
||||||
|
|
||||||
|
vertices[0].pos.x = x - nx;
|
||||||
|
vertices[0].pos.y = y - ny;
|
||||||
|
vertices[0].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[1].pos.x = x + nx;
|
||||||
|
vertices[1].pos.y = y + ny;
|
||||||
|
vertices[1].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
|
||||||
|
vertices[2].pos.x = ex - nx;
|
||||||
|
vertices[2].pos.y = ey - ny;
|
||||||
|
vertices[2].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
|
||||||
|
vertices[3].pos.x = ex + ny;
|
||||||
|
vertices[3].pos.y = ey + ny;
|
||||||
|
vertices[3].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
dis_push_vertices(4, sizeof(struct vertex_v2fc4f), vertices);
|
||||||
|
dis_push_indices(6, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xoverlay_draw_rect(float x, float y, float w, float h, xoverlay_rgba_t color)
|
||||||
|
{
|
||||||
|
ds_prepare_program(PROGRAM_TRIANGLES_PLAIN);
|
||||||
|
GLuint idx = dstream.next_index;
|
||||||
|
|
||||||
|
struct vertex_v2fc4f vertices[4];
|
||||||
|
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx };
|
||||||
|
|
||||||
|
vertices[0].pos.x = x;
|
||||||
|
vertices[0].pos.y = y;
|
||||||
|
vertices[0].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[1].pos.x = x;
|
||||||
|
vertices[1].pos.y = y + h;
|
||||||
|
vertices[1].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[2].pos.x = x + w;
|
||||||
|
vertices[2].pos.y = y + h;
|
||||||
|
vertices[2].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[3].pos.x = x + w;
|
||||||
|
vertices[3].pos.y = y;
|
||||||
|
vertices[3].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
dis_push_vertices(4, sizeof(struct vertex_v2fc4f), vertices);
|
||||||
|
dis_push_indices(6, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xoverlay_draw_rect_outline(float x, float y, float w, float h, xoverlay_rgba_t color, float thickness)
|
||||||
|
{
|
||||||
|
xoverlay_draw_line(x, y, w, 0, color, thickness);
|
||||||
|
xoverlay_draw_line(x + w, y, 0, h, color, thickness);
|
||||||
|
xoverlay_draw_line(x + w, y + h, -w, 0, color, thickness);
|
||||||
|
xoverlay_draw_line(x, y + h, 0, -h, color, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xoverlay_draw_rect_textured(float x, float y, float w, float h, xoverlay_rgba_t color, xoverlay_texture_handle_t texture, float tx, float ty, float tw, float th)
|
||||||
|
{
|
||||||
|
struct textureapi_texture_t *tex = textureapi_get(texture);
|
||||||
|
|
||||||
|
if (tex == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ds_prepare_program(PROGRAM_TRIANGLES_TEXTURED);
|
||||||
|
ds_prepare_texture_handle(texture);
|
||||||
|
|
||||||
|
GLuint idx = dstream.next_index;
|
||||||
|
|
||||||
|
struct vertex_v2ft2fc4f vertices[4];
|
||||||
|
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx };
|
||||||
|
|
||||||
|
float s0 = tx / tex->width;
|
||||||
|
float s1 = (tx + tw) / tex->width;
|
||||||
|
float t0 = ty / tex->height;
|
||||||
|
float t1 = (ty + th) / tex->height;
|
||||||
|
|
||||||
|
vertices[0].pos.x = x;
|
||||||
|
vertices[0].pos.y = y;
|
||||||
|
vertices[0].uv.x = s0;
|
||||||
|
vertices[0].uv.y = t1;
|
||||||
|
vertices[0].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[1].pos.x = x;
|
||||||
|
vertices[1].pos.y = y + h;
|
||||||
|
vertices[1].uv.x = s0;
|
||||||
|
vertices[1].uv.y = t0;
|
||||||
|
vertices[1].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[2].pos.x = x + w;
|
||||||
|
vertices[2].pos.y = y + h;
|
||||||
|
vertices[2].uv.x = s1;
|
||||||
|
vertices[2].uv.y = t0;
|
||||||
|
vertices[2].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
vertices[3].pos.x = x + w;
|
||||||
|
vertices[3].pos.y = y;
|
||||||
|
vertices[3].uv.x = s1;
|
||||||
|
vertices[3].uv.y = t1;
|
||||||
|
vertices[3].color = *(vec4*)&color;
|
||||||
|
|
||||||
|
dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices);
|
||||||
|
dis_push_indices(6, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
draw_string_internal(float x, float y, const char *string, texture_font_t *fnt, vec4 color, float *out_x, float *out_y)
|
||||||
|
{
|
||||||
|
float pen_x = x;
|
||||||
|
float pen_y = y;
|
||||||
|
float size_y = 0;
|
||||||
|
|
||||||
|
texture_font_load_glyphs(fnt, string);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < strlen(string); ++i)
|
||||||
|
{
|
||||||
|
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &string[i]);
|
||||||
|
if (glyph == NULL)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
x += texture_glyph_get_kerning(glyph, &string[i - 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
float x0 = (pen_x + glyph->offset_x);
|
||||||
|
float y0 = (pen_y - glyph->offset_y);
|
||||||
|
float x1 = (x0 + glyph->width);
|
||||||
|
float y1 = (y0 + glyph->height);
|
||||||
|
float s0 = glyph->s0;
|
||||||
|
float t0 = glyph->t0;
|
||||||
|
float s1 = glyph->s1;
|
||||||
|
float t1 = glyph->t1;
|
||||||
|
|
||||||
|
GLuint idx = dstream.next_index;
|
||||||
|
GLuint indices[] = { idx, idx + 1, idx + 2,
|
||||||
|
idx + 2, idx + 3, idx };
|
||||||
|
struct vertex_v2ft2fc4f vertices[] = {
|
||||||
|
{ (vec2){ x0, y0 }, (vec2){ s0, t0 }, color },
|
||||||
|
{ (vec2){ x0, y1 }, (vec2){ s0, t1 }, color },
|
||||||
|
{ (vec2){ x1, y1 }, (vec2){ s1, t1 }, color },
|
||||||
|
{ (vec2){ x1, y0 }, (vec2){ s1, t0 }, color }
|
||||||
|
};
|
||||||
|
|
||||||
|
dis_push_indices(6, indices);
|
||||||
|
dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices);
|
||||||
|
|
||||||
|
pen_x += glyph->advance_x;
|
||||||
|
if (glyph->height > size_y)
|
||||||
|
size_y = glyph->height;
|
||||||
|
}
|
||||||
|
if (out_x)
|
||||||
|
*out_x = pen_x - x;
|
||||||
|
if (out_y)
|
||||||
|
*out_y = size_y;
|
||||||
|
}
|
||||||
|
void
|
||||||
|
xoverlay_draw_string(float x, float y, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, float *out_x, float *out_y)
|
||||||
|
{
|
||||||
|
ds_prepare_program(PROGRAM_FREETYPE);
|
||||||
|
ds_prepare_font(font);
|
||||||
|
|
||||||
|
texture_font_t *fnt = fontapi_get(font);
|
||||||
|
|
||||||
|
if (fnt == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fnt->rendermode = RENDER_NORMAL;
|
||||||
|
fnt->outline_thickness = 0.0f;
|
||||||
|
|
||||||
|
draw_string_internal(x, y, string, fnt, *(vec4*)&color, out_x, out_y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xoverlay_draw_string_with_outline(float x, float y, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, xoverlay_vec4_t outline_color, float outline_width, int adjust_outline_alpha, float *out_x, float *out_y)
|
||||||
|
{
|
||||||
|
ds_prepare_program(PROGRAM_FREETYPE);
|
||||||
|
ds_prepare_font(font);
|
||||||
|
|
||||||
|
if (adjust_outline_alpha)
|
||||||
|
outline_color.a = color.a;
|
||||||
|
|
||||||
|
texture_font_t *fnt = fontapi_get(font);
|
||||||
|
|
||||||
|
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
|
||||||
|
fnt->outline_thickness = outline_width;
|
||||||
|
draw_string_internal(x, y, string, fnt, *(vec4*)&outline_color, NULL, NULL);
|
||||||
|
|
||||||
|
fnt->rendermode = RENDER_NORMAL;
|
||||||
|
fnt->outline_thickness = 0.0f;
|
||||||
|
draw_string_internal(x, y, string, fnt, *(vec4*)&color, out_x, out_y);
|
||||||
|
}
|
||||||
|
|
||||||
int xoverlay_glx_destroy()
|
int xoverlay_glx_destroy()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
BIN
src/drawglx.o
BIN
src/drawglx.o
Binary file not shown.
@ -239,7 +239,7 @@ dis_fetch_instruction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
dis_textureapi_switch_texture(xoverlay_texture_handle texture)
|
dis_textureapi_switch_texture(xoverlay_texture_handle_t texture)
|
||||||
{
|
{
|
||||||
struct draw_instruction_t *last = dis_last_pushed_instruction();
|
struct draw_instruction_t *last = dis_last_pushed_instruction();
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ ds_use_font(xoverlay_font_handle_t font)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ds_prepare_texture_handle(xoverlay_texture_handle handle)
|
ds_prepare_texture_handle(xoverlay_texture_handle_t handle)
|
||||||
{
|
{
|
||||||
if (handle != ds.thandle)
|
if (handle != ds.thandle)
|
||||||
{
|
{
|
||||||
@ -467,238 +467,3 @@ ds_prepare_font(xoverlay_font_handle_t font)
|
|||||||
ds.font = font;
|
ds.font = font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
draw_line(vec2 xy, vec2 delta, vec4 color, float thickness)
|
|
||||||
{
|
|
||||||
ds_prepare_program(PROGRAM_TRIANGLES_PLAIN);
|
|
||||||
GLuint idx = dstream.next_index;
|
|
||||||
|
|
||||||
struct vertex_v2fc4f vertices[4];
|
|
||||||
/* A C => ABC, CDB
|
|
||||||
* B D
|
|
||||||
*/
|
|
||||||
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx + 1 };
|
|
||||||
|
|
||||||
vec2 normal = { .x = -delta.y, .y = delta.x };
|
|
||||||
vec2 end = (vec2){ xy.x + delta.x, xy.y + delta.y };
|
|
||||||
float length = sqrtf(normal.x * normal.x + normal.y * normal.y);
|
|
||||||
if (length == 0)
|
|
||||||
return;
|
|
||||||
length /= thickness;
|
|
||||||
normal.x /= length;
|
|
||||||
normal.y /= length;
|
|
||||||
|
|
||||||
vertices[0].pos.x = xy.x - normal.x;
|
|
||||||
vertices[0].pos.y = xy.y - normal.y;
|
|
||||||
vertices[0].color = color;
|
|
||||||
|
|
||||||
vertices[1].pos.x = xy.x + normal.x;
|
|
||||||
vertices[1].pos.y = xy.y + normal.y;
|
|
||||||
vertices[1].color = color;
|
|
||||||
|
|
||||||
vertices[2].pos.x = end.x - normal.x;
|
|
||||||
vertices[2].pos.y = end.y - normal.y;
|
|
||||||
vertices[2].color = color;
|
|
||||||
|
|
||||||
vertices[3].pos.x = end.x + normal.x;
|
|
||||||
vertices[3].pos.y = end.y + normal.y;
|
|
||||||
vertices[3].color = color;
|
|
||||||
|
|
||||||
dis_push_vertices(4, sizeof(struct vertex_v2fc4f), vertices);
|
|
||||||
dis_push_indices(6, indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect(vec2 xy, vec2 hw, vec4 color)
|
|
||||||
{
|
|
||||||
ds_prepare_program(PROGRAM_TRIANGLES_PLAIN);
|
|
||||||
GLuint idx = dstream.next_index;
|
|
||||||
|
|
||||||
struct vertex_v2fc4f vertices[4];
|
|
||||||
/* A D => ABC, CDA
|
|
||||||
* B C
|
|
||||||
*/
|
|
||||||
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx };
|
|
||||||
|
|
||||||
vertices[0].pos.x = xy.x;
|
|
||||||
vertices[0].pos.y = xy.y;
|
|
||||||
vertices[0].color = color;
|
|
||||||
|
|
||||||
vertices[1].pos.x = xy.x;
|
|
||||||
vertices[1].pos.y = xy.y + hw.y;
|
|
||||||
vertices[1].color = color;
|
|
||||||
|
|
||||||
vertices[2].pos.x = xy.x + hw.x;
|
|
||||||
vertices[2].pos.y = xy.y + hw.y;
|
|
||||||
vertices[2].color = color;
|
|
||||||
|
|
||||||
vertices[3].pos.x = xy.x + hw.x;
|
|
||||||
vertices[3].pos.y = xy.y;
|
|
||||||
vertices[3].color = color;
|
|
||||||
|
|
||||||
dis_push_vertices(4, sizeof(struct vertex_v2fc4f), vertices);
|
|
||||||
dis_push_indices(6, indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect_outline(vec2 xy, vec2 hw, vec4 color, float thickness)
|
|
||||||
{
|
|
||||||
vec2 point = xy;
|
|
||||||
vec2 delta = { hw.x, 0 };
|
|
||||||
draw_line(point, delta, color, thickness);
|
|
||||||
point.x += delta.x;
|
|
||||||
delta.x = 0;
|
|
||||||
delta.y = hw.y;
|
|
||||||
draw_line(point, delta, color, thickness);
|
|
||||||
point.y += delta.y;
|
|
||||||
delta.x = -hw.x;
|
|
||||||
delta.y = 0;
|
|
||||||
draw_line(point, delta, color, thickness);
|
|
||||||
point.x += delta.x;
|
|
||||||
delta.x = 0;
|
|
||||||
delta.y = -hw.y;
|
|
||||||
draw_line(point, delta, color, thickness);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_rect_textured(vec2 xy, vec2 hw, vec4 color, xoverlay_texture_handle texture, vec2 t_xy, vec2 t_hw)
|
|
||||||
{
|
|
||||||
struct textureapi_texture_t *tx = textureapi_get(texture);
|
|
||||||
if (tx == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ds_prepare_program(PROGRAM_TRIANGLES_TEXTURED);
|
|
||||||
ds_prepare_texture_handle(texture);
|
|
||||||
|
|
||||||
GLuint idx = dstream.next_index;
|
|
||||||
|
|
||||||
struct vertex_v2ft2fc4f vertices[4];
|
|
||||||
/* A C => ABC, CDB
|
|
||||||
* B D
|
|
||||||
*/
|
|
||||||
GLuint indices[6] = { idx, idx + 1, idx + 2, idx + 2, idx + 3, idx };
|
|
||||||
|
|
||||||
float s0 = t_xy.x / tx->width;
|
|
||||||
float s1 = (t_xy.x + t_hw.x) / tx->width;
|
|
||||||
float t0 = t_xy.y / tx->height;
|
|
||||||
float t1 = (t_xy.y + t_hw.y) / tx->height;
|
|
||||||
|
|
||||||
vertices[0].pos.x = xy.x;
|
|
||||||
vertices[0].pos.y = xy.y;
|
|
||||||
vertices[0].uv = (vec2){ s0, t1 };
|
|
||||||
vertices[0].color = color;
|
|
||||||
|
|
||||||
vertices[1].pos.x = xy.x;
|
|
||||||
vertices[1].pos.y = xy.y + hw.y;
|
|
||||||
vertices[1].uv = (vec2){ s0, t0 };
|
|
||||||
vertices[1].color = color;
|
|
||||||
|
|
||||||
vertices[2].pos.x = xy.x + hw.x;
|
|
||||||
vertices[2].pos.y = xy.y + hw.y;
|
|
||||||
vertices[2].uv = (vec2){ s1, t0 };
|
|
||||||
vertices[2].color = color;
|
|
||||||
|
|
||||||
vertices[3].pos.x = xy.x + hw.x;
|
|
||||||
vertices[3].pos.y = xy.y;
|
|
||||||
vertices[3].uv = (vec2){ s1, t1 };
|
|
||||||
vertices[3].color = color;
|
|
||||||
|
|
||||||
dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices);
|
|
||||||
dis_push_indices(6, indices);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string_internal(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, int *out_x, int *out_y)
|
|
||||||
{
|
|
||||||
ds_prepare_program(PROGRAM_FREETYPE);
|
|
||||||
ds_prepare_font(font);
|
|
||||||
|
|
||||||
texture_font_t *fnt = fontapi_get(font);
|
|
||||||
if (!fnt)
|
|
||||||
return;
|
|
||||||
|
|
||||||
vec2 pen = { xy.x, xy.y };
|
|
||||||
vec2 pen_start = pen;
|
|
||||||
vec2 size = { 0, 0 };
|
|
||||||
texture_font_load_glyphs(fnt, string);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < strlen(string); ++i)
|
|
||||||
{
|
|
||||||
texture_glyph_t *glyph = texture_font_find_glyph(fnt, &string[i]);
|
|
||||||
if (glyph == NULL)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (i > 0)
|
|
||||||
{
|
|
||||||
pen.x += texture_glyph_get_kerning(glyph, &string[i - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
float x0 = (pen.x + glyph->offset_x);
|
|
||||||
float y0 = (pen.y - glyph->offset_y);
|
|
||||||
float x1 = (x0 + glyph->width);
|
|
||||||
float y1 = (y0 + glyph->height);
|
|
||||||
float s0 = glyph->s0;
|
|
||||||
float t0 = glyph->t0;
|
|
||||||
float s1 = glyph->s1;
|
|
||||||
float t1 = glyph->t1;
|
|
||||||
|
|
||||||
GLuint idx = dstream.next_index;
|
|
||||||
GLuint indices[] = { idx, idx + 1, idx + 2,
|
|
||||||
idx + 2, idx + 3, idx };
|
|
||||||
struct vertex_v2ft2fc4f vertices[] = {
|
|
||||||
{ (vec2){ x0, y0 }, (vec2){ s0, t0 }, color },
|
|
||||||
{ (vec2){ x0, y1 }, (vec2){ s0, t1 }, color },
|
|
||||||
{ (vec2){ x1, y1 }, (vec2){ s1, t1 }, color },
|
|
||||||
{ (vec2){ x1, y0 }, (vec2){ s1, t0 }, color }
|
|
||||||
};
|
|
||||||
|
|
||||||
dis_push_indices(6, indices);
|
|
||||||
dis_push_vertices(4, sizeof(struct vertex_v2ft2fc4f), vertices);
|
|
||||||
|
|
||||||
pen.x += glyph->advance_x;
|
|
||||||
if (glyph->height > size.y)
|
|
||||||
size.y = glyph->height;
|
|
||||||
}
|
|
||||||
size.x = pen.x - pen_start.x;
|
|
||||||
if (out_x)
|
|
||||||
*out_x = size.x;
|
|
||||||
if (out_y)
|
|
||||||
*out_y = size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, int *out_x, int *out_y)
|
|
||||||
{
|
|
||||||
ds_prepare_program(PROGRAM_FREETYPE);
|
|
||||||
ds_prepare_font(font);
|
|
||||||
|
|
||||||
texture_font_t *fnt = fontapi_get(font);
|
|
||||||
fnt->rendermode = RENDER_NORMAL;
|
|
||||||
fnt->outline_thickness = 0.0f;
|
|
||||||
|
|
||||||
draw_string_internal(xy, string, font, color, out_x, out_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
draw_string_with_outline(vec2 xy, const char *string, xoverlay_font_handle_t font, vec4 color, vec4 outline_color, float outline_width, int adjust_outline_alpha, int *out_x, int *out_y)
|
|
||||||
{
|
|
||||||
ds_prepare_program(PROGRAM_FREETYPE);
|
|
||||||
ds_prepare_font(font);
|
|
||||||
|
|
||||||
if (adjust_outline_alpha)
|
|
||||||
outline_color.a = color.a;
|
|
||||||
|
|
||||||
texture_font_t *fnt = fontapi_get(font);
|
|
||||||
|
|
||||||
fnt->rendermode = RENDER_OUTLINE_POSITIVE;
|
|
||||||
fnt->outline_thickness = outline_width;
|
|
||||||
draw_string_internal(xy, string, font, outline_color, 0, 0);
|
|
||||||
|
|
||||||
fnt->rendermode = RENDER_NORMAL;
|
|
||||||
fnt->outline_thickness = 0.0f;
|
|
||||||
draw_string_internal(xy, string, font, color, out_x, out_y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Binary file not shown.
@ -91,24 +91,6 @@ xoverlay_rgba_t xoverlay_rgba(int r, int g, int b, int a)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_line(xoverlay_vec2_t xy, xoverlay_vec2_t delta, xoverlay_rgba_t color, float thickness)
|
|
||||||
{
|
|
||||||
draw_line(*(vec2*)&xy, *(vec2*)&delta, *(vec4*)&color, thickness);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_rect(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color)
|
|
||||||
{
|
|
||||||
draw_rect(*(vec2*)&xy, *(vec2*)&hw, *(vec4*)&color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_rect_outline(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color, float thickness)
|
|
||||||
{
|
|
||||||
draw_rect_outline(*(vec2*)&xy, *(vec2*)&hw, *(vec4*)&color, thickness);
|
|
||||||
}
|
|
||||||
|
|
||||||
void xoverlay_install_keyboard_callback(xoverlay_callback_keypress callback)
|
void xoverlay_install_keyboard_callback(xoverlay_callback_keypress callback)
|
||||||
{
|
{
|
||||||
xoverlay_library.cb_keypress = callback;
|
xoverlay_library.cb_keypress = callback;
|
||||||
@ -257,24 +239,6 @@ void xoverlay_poll_events()
|
|||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_string(xoverlay_vec2_t xy, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, int *out_x, int *out_y)
|
|
||||||
{
|
|
||||||
draw_string(*(vec2*)&xy, string, font, *(vec4*)&color, out_x, out_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_string_with_outline(xoverlay_vec2_t xy, const char *string, xoverlay_font_handle_t font, xoverlay_vec4_t color, xoverlay_vec4_t outline_color, float outline_width, int adjust_outline_alpha, int *out_x, int *out_y)
|
|
||||||
{
|
|
||||||
draw_string_with_outline(*(vec2*)&xy, string, font, *(vec4*)&color, *(vec4*)&outline_color, outline_width, adjust_outline_alpha, out_x, out_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
xoverlay_draw_rect_textured(xoverlay_vec2_t xy, xoverlay_vec2_t hw, xoverlay_rgba_t color, xoverlay_texture_handle texture, xoverlay_vec2_t t_xy, xoverlay_vec2_t t_hw)
|
|
||||||
{
|
|
||||||
draw_rect_textured(*(vec2*)&xy, *(vec2*)&hw, *(vec4*)&color, texture, *(vec2*)&t_xy, *(vec2*)&t_hw);
|
|
||||||
}
|
|
||||||
|
|
||||||
void xoverlay_draw_begin()
|
void xoverlay_draw_begin()
|
||||||
{
|
{
|
||||||
if (!xoverlay_library.init) return;
|
if (!xoverlay_library.init) return;
|
||||||
|
BIN
src/overlay.o
BIN
src/overlay.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/programs.o
BIN
src/programs.o
Binary file not shown.
@ -96,7 +96,7 @@ textureapi_load_png_rgba(const char *name, struct textureapi_texture_t *out)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
textureapi_bind(xoverlay_texture_handle handle)
|
textureapi_bind(xoverlay_texture_handle_t handle)
|
||||||
{
|
{
|
||||||
struct textureapi_texture_t *texture = textureapi_get(handle);
|
struct textureapi_texture_t *texture = textureapi_get(handle);
|
||||||
if (texture == NULL || texture->init == 0)
|
if (texture == NULL || texture->init == 0)
|
||||||
@ -117,7 +117,7 @@ textureapi_bind(xoverlay_texture_handle handle)
|
|||||||
ds_bind_texture(texture->texture_id);
|
ds_bind_texture(texture->texture_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
xoverlay_texture_handle
|
xoverlay_texture_handle_t
|
||||||
xoverlay_texture_load_png_rgba(const char *path)
|
xoverlay_texture_load_png_rgba(const char *path)
|
||||||
{
|
{
|
||||||
struct textureapi_texture_t result;
|
struct textureapi_texture_t result;
|
||||||
@ -132,7 +132,7 @@ xoverlay_texture_load_png_rgba(const char *path)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_texture_get_size(xoverlay_texture_handle handle, int *width, int *height)
|
xoverlay_texture_get_size(xoverlay_texture_handle_t handle, int *width, int *height)
|
||||||
{
|
{
|
||||||
struct textureapi_texture_t *tx = textureapi_get(handle);
|
struct textureapi_texture_t *tx = textureapi_get(handle);
|
||||||
if (tx == NULL)
|
if (tx == NULL)
|
||||||
@ -144,7 +144,7 @@ xoverlay_texture_get_size(xoverlay_texture_handle handle, int *width, int *heigh
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct textureapi_texture_t *
|
struct textureapi_texture_t *
|
||||||
textureapi_get(xoverlay_texture_handle handle)
|
textureapi_get(xoverlay_texture_handle_t handle)
|
||||||
{
|
{
|
||||||
if (handle == 0 || handle >= XOVERLAY_TEXTURE_COUNT)
|
if (handle == 0 || handle >= XOVERLAY_TEXTURE_COUNT)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -166,10 +166,10 @@ textureapi_destroy()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xoverlay_texture_handle
|
xoverlay_texture_handle_t
|
||||||
textureapi_add_texture(struct textureapi_texture_t texture)
|
textureapi_add_texture(struct textureapi_texture_t texture)
|
||||||
{
|
{
|
||||||
for (xoverlay_texture_handle i = 0; i < XOVERLAY_TEXTURE_COUNT; ++i)
|
for (xoverlay_texture_handle_t i = 0; i < XOVERLAY_TEXTURE_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if (loaded_textures[i].init == 0)
|
if (loaded_textures[i].init == 0)
|
||||||
{
|
{
|
||||||
@ -182,7 +182,7 @@ textureapi_add_texture(struct textureapi_texture_t texture)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xoverlay_texture_unload(xoverlay_texture_handle handle)
|
xoverlay_texture_unload(xoverlay_texture_handle_t handle)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
BIN
src/textureapi.o
Normal file
BIN
src/textureapi.o
Normal file
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user