master
Alessandro Mauri 1 year ago
parent 9136eaa54f
commit 805f633af0
  1. BIN
      text_rendering/atlas.png
  2. 13
      text_rendering/font.c
  3. 53
      text_rendering/ren.c
  4. 61
      text_rendering/stack.h
  5. BIN
      text_rendering/test

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

@ -123,14 +123,19 @@ const struct font_glyph * font_get_glyph_texture(struct font_atlas *atlas, unsig
atlas->priv.scale,
2.0f/glyph_h,
&atlas->priv.ctx);
if (!err)
return NULL;
// msdf_genGlyph returns 0 only when there are no contours, so only for
// whitespace and such, for those insert a zero uv map into the cache
// FIXME: this is a waste of space
if (!err) {
atlas->priv.msdf.width = 0;
atlas->priv.msdf.height = 0;
}
unsigned int spot = cache_get();
unsigned int oy = (glyph_h * spot) / atlas->width;
unsigned int ox = (glyph_h * spot) % atlas->height;
unsigned int w = atlas->width;
unsigned int w = atlas->width;
// sum magic shit
struct {unsigned char r,g,b;} *a = (void *)atlas->atlas;
@ -180,7 +185,7 @@ const struct font_glyph * font_get_glyph_texture(struct font_atlas *atlas, unsig
void font_dump(const struct font_atlas *atlas, const char *path)
{
stbi_write_png(
path,
path,
//atlas->width,
//atlas->height,
128, 128,

@ -0,0 +1,53 @@
#include <SDL2/SDL.h>
#include <GL/glew.h>
#include <SDL2/SDL_opengl.h>
#define GLSL_VERT_SHADER "vertex.glsl"
#define GLSL_FRAG_SHADER "fragment.glsl"
#define PACKED __attribute__((packed))
struct {
SDL_Window *w;
SDL_GLContext *gl;
GLuint gl_vertbuffer;
GLuint gl_program;
GLuint font_texture;
} ren = {0};
typedef struct PACKED {
union { GLint x, u; };
union { GLint y, v; };
} vec2_i;
typedef struct PACKED {
union { GLint x, r; };
union { GLint y, g; };
union { GLint z, b; };
union { GLint w, a; };
} vec4_i;
// textured vertex
struct PACKED v_text {
vec2_i pos;
vec2_i uv;
};
// colored vertex
struct PACKED v_col {
vec2_i pos;
vec2_i col;
};
// different stacks
#define _STACK_NAME vtstack
#define _STACK_TYPE struct v_text
#include "stack.h"
#undef _STACK_NAME
#undef _STACK_TYPE
#define _STACK_NAME vcstack
#define _STACK_TYPE struct v_col
#include "stack.h"

@ -0,0 +1,61 @@
#ifdef _STACK_TYPE
#ifdef _STACK_NAME
#ifndef _STACK_REALLOC
#define _STACK_REALLOC(p, s) realloc(p,s)
#endif
#ifndef _STACK_MEMSET
#define _STACK_MEMSET(p, c, s) memset(p,c,s)
#endif
#ifndef _STACK_STEP
#define _STACK_STEP 8
#endif
#ifndef _STACK_CAT
#define _STACK_CAT_I(a,b) a ## b
#define _STACK_CAT(a,b) _STACK_CAT_I(a,b)
#endif
// TODO: add a rolling hash
struct _STACK_NAME {
_STACK_TYPE *items;
int size, idx;
};
int _STACK_CAT(stack_grow_,_STACK_NAME)(struct _STACK_NAME *stack, int step)
{
if (!stack)
return -1;
stack->items = _STACK_REALLOC(stack->items, (stack->size+step)*sizeof(_STACK_TYPE));
if(!stack->items)
return -1;
_STACK_MEMSET(&(stack->items[stack->size]), 0, step*sizeof(*(stack->items)));
stack->size += step;
return 0;
}
int _STACK_CAT(stack_push_,_STACK_NAME)(struct _STACK_NAME *stack, _STACK_TYPE *e)
{
if (!stack || !e)
return -1;
if (stack->idx >= stack->size)
if (_STACK_CAT(stack_grow_,_STACK_NAME)(stack, _STACK_STEP))
return -1;
stack->items[stack->idx++] = *e;
return 0;
}
int _STACK_CAT(stack_clear_,_STACK_NAME)(struct _STACK_NAME *stack)
{
if (!stack)
return -1;
stack->idx = 0;
}
#endif
#endif

Binary file not shown.
Loading…
Cancel
Save