Compare commits
4 Commits
a697fec5d1
...
ae8bbc0077
Author | SHA1 | Date | |
---|---|---|---|
ae8bbc0077 | |||
7f5c6446f7 | |||
e11f54f3a1 | |||
60660f2388 |
4
text_rendering/.gitignore
vendored
Normal file
4
text_rendering/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.png
|
||||||
|
test
|
||||||
|
obj/**
|
||||||
|
objlist
|
@ -1,7 +1,17 @@
|
|||||||
|
CC = gcc
|
||||||
LDFLAGS = -lm -lgrapheme -lSDL2 -lGLEW -lGL
|
LDFLAGS = -lm -lgrapheme -lSDL2 -lGLEW -lGL
|
||||||
CFLAGS = -g -Wall -Wextra -pedantic
|
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
|
|
||||||
|
|
||||||
test: ${HEADER} ${SOURCE}
|
.PHONY: clean all
|
||||||
gcc ${CFLAGS} ${LDFLAGS} ${SOURCE} -o test
|
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
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
43
text_rendering/genmake.sh
Executable file
43
text_rendering/genmake.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/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
|
@ -2,6 +2,7 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <SDL2/SDL_opengl.h>
|
#include <SDL2/SDL_opengl.h>
|
||||||
#include <SDL2/SDL_video.h>
|
#include <SDL2/SDL_video.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <grapheme.h>
|
#include <grapheme.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -451,17 +452,27 @@ int ren_set_scissor(int x, int y, int w, int h)
|
|||||||
// TODO: implement font size
|
// TODO: implement font size
|
||||||
int ren_render_text(const char *str, int x, int y, int w, int h, int size)
|
int ren_render_text(const char *str, int x, int y, int w, int h, int size)
|
||||||
{
|
{
|
||||||
// x4,y4 x3,y3
|
|
||||||
// +-------------+
|
/* x4,y4 x3,y3
|
||||||
// |(x,y) /|
|
* +-------------+
|
||||||
// | / |
|
* |(x,y) /|
|
||||||
// | 2 / |
|
* | / |
|
||||||
// | / |
|
* | 2 / |
|
||||||
// | / |
|
* | / |
|
||||||
// | / 1 |
|
* | / |
|
||||||
// |/ |
|
* | / 1 |
|
||||||
// +-------------+
|
* |/ |
|
||||||
// x1,y1 x2,y2
|
* +-------------+
|
||||||
|
* 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
|
||||||
|
|
||||||
const struct font_glyph *g;
|
const struct font_glyph *g;
|
||||||
struct font_glyph c;
|
struct font_glyph c;
|
||||||
@ -471,6 +482,8 @@ int ren_render_text(const char *str, int x, int y, int w, int h, int size)
|
|||||||
struct v_text v;
|
struct v_text v;
|
||||||
printf("rendering text: %s\n", str);
|
printf("rendering text: %s\n", str);
|
||||||
for (off = 0; (ret = grapheme_decode_utf8(str+off, SIZE_MAX, &cp)) > 0 && cp != 0; off += ret) {
|
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);
|
g = font_get_glyph_texture(ren.font, cp, &updated);
|
||||||
if (!g) REN_RET(-1, REN_FONT);
|
if (!g) REN_RET(-1, REN_FONT);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
@ -522,6 +535,7 @@ 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.a;
|
||||||
//gx += c.w + c.x + 1;
|
//gx += c.w + c.x + 1;
|
||||||
gx += c.x + c.a;
|
gx += c.x + c.a;
|
||||||
|
skip_render:
|
||||||
switch (cp) {
|
switch (cp) {
|
||||||
case '\r':
|
case '\r':
|
||||||
gx = x;
|
gx = x;
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user