Compare commits

..

No commits in common. "ae8bbc007716caa9b5f3fbe83fb7291619e2304b" and "a697fec5d14ec8a32cd414efd013b1f6fa0fcc38" have entirely different histories.

6 changed files with 16 additions and 87 deletions

View File

@ -1,4 +0,0 @@
*.png
test
obj/**
objlist

View File

@ -1,17 +1,7 @@
CC = gcc
LDFLAGS = -lm -lgrapheme -lSDL2 -lGLEW -lGL
CFLAGS = -g -Wall -Wextra -pedantic
SOURCE = main.c font.c cache.c hash.c util.c ren.c
HEADER = font.h hash.h cache.h util.h ren.h
.PHONY: clean all
all: test
cache.o: cache.c cache.h hash.h font.h util.h
font.o: font.c font.h stb_truetype.h stb_image_write.h util.h cache.h
hash.o: hash.c hash.h util.h
main.o: main.c ren.h util.h
ren.o: ren.c util.h font.h ren.h stack.h
util.o: util.c util.h
test: cache.o font.o hash.o main.o ren.o util.o
${CC} ${LDFLAGS} -o test cache.o font.o hash.o main.o ren.o util.o
clean:
rm -f cache.o font.o hash.o main.o ren.o util.o
test: ${HEADER} ${SOURCE}
gcc ${CFLAGS} ${LDFLAGS} ${SOURCE} -o test

BIN
text_rendering/atlas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -1,43 +0,0 @@
#!/bin/sh
genobj() {
#echo "$1" | sed -e 's/^/obj\//' -e 's/\.c/\.o/'
echo "$1" | sed -e 's/\.c/\.o/'
}
genrule() {
#gcc -MM "$1" | sed 's/^/obj\//'
gcc -MM "$1"
}
rm -f objlist
cat > Makefile << EOF
CC = gcc
LDFLAGS = -lm -lgrapheme -lSDL2 -lGLEW -lGL
CFLAGS = -g -Wall -Wextra -pedantic
.PHONY: clean all
all: test
EOF
for f in *.c; do
genrule $f >> Makefile
genobj $f >> objlist
done
mainrule='test: '
linkcmd=' ${CC} ${LDFLAGS} -o test '
cleanrule='clean:
rm -f '
while IFS="" read -r line; do
mainrule="$mainrule $line"
linkcmd="$linkcmd $line"
cleanrule="$cleanrule $line"
done < objlist
echo "$mainrule" >> Makefile
echo "$linkcmd" >> Makefile
echo "$cleanrule" >> Makefile

View File

@ -2,7 +2,6 @@
#include <GL/glew.h>
#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_video.h>
#include <ctype.h>
#include <grapheme.h>
#include <stdio.h>
@ -452,27 +451,17 @@ int ren_set_scissor(int x, int y, int w, int h)
// TODO: implement font size
int ren_render_text(const char *str, int x, int y, int w, int h, int size)
{
/* x4,y4 x3,y3
* +-------------+
* |(x,y) /|
* | / |
* | 2 / |
* | / |
* | / |
* | / 1 |
* |/ |
* +-------------+
* x1,y1 x2,y2 */
// TODO: stop drawing when outside the bounding box
// TODO: check size, if the current font is not of the same size then load
// load a new font and use that texture instead, this implies making
// a system to store and use different fonts, like:
// struct font_atlas * font_by_size(int size);
// FIXME: the bounding box (scissor) logic does not work
// TODO: create a method for calculating the total bounding box of a string
// given the box size
// x4,y4 x3,y3
// +-------------+
// |(x,y) /|
// | / |
// | 2 / |
// | / |
// | / |
// | / 1 |
// |/ |
// +-------------+
// x1,y1 x2,y2
const struct font_glyph *g;
struct font_glyph c;
@ -482,8 +471,6 @@ int ren_render_text(const char *str, int x, int y, int w, int h, int size)
struct v_text v;
printf("rendering text: %s\n", str);
for (off = 0; (ret = grapheme_decode_utf8(str+off, SIZE_MAX, &cp)) > 0 && cp != 0; off += ret) {
// skip special characters that render a box (not present in font)
if (iscntrl(cp)) goto skip_render;
g = font_get_glyph_texture(ren.font, cp, &updated);
if (!g) REN_RET(-1, REN_FONT);
if (updated) {
@ -535,7 +522,6 @@ int ren_render_text(const char *str, int x, int y, int w, int h, int size)
//gx += c.w + c.a;
//gx += c.w + c.x + 1;
gx += c.x + c.a;
skip_render:
switch (cp) {
case '\r':
gx = x;

BIN
text_rendering/test Executable file

Binary file not shown.