diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | data/Makefile.am | 2 | ||||
-rw-r--r-- | data/textures/font.png | bin | 0 -> 23985 bytes | |||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/render-text.c | 52 | ||||
-rw-r--r-- | src/render-text.h | 27 | ||||
-rw-r--r-- | src/render.c | 5 | ||||
-rw-r--r-- | src/texture.c | 2 |
8 files changed, 88 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am index cc10a56..d3436d2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -EXTRA_DIST = configure src/game.h src/model.h src/physics.h src/render.h src/texture.h src/types.h src/utils.h src/audio.h data/* +EXTRA_DIST = configure src/game.h src/model.h src/physics.h src/render.h src/texture.h src/types.h src/utils.h src/audio.h src/render-text.h data/* SUBDIRS = src data TESTS = src/glcheck diff --git a/data/Makefile.am b/data/Makefile.am index cbeb059..019eba4 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -6,7 +6,7 @@ shadersdir = $(datadir)/thrust3d/shaders shaders_DATA = shaders/lighting.vert shaders/lighting.frag shaders/swirlytron.vert shaders/swirlytron.frag texturesdir = $(datadir)/thrust3d/textures -textures_DATA = textures/floor1.png textures/tiledwall.png textures/radioactive.png textures/fuel.png +textures_DATA = textures/floor1.png textures/tiledwall.png textures/radioactive.png textures/fuel.png textures/font.png roomsdir = $(datadir)/thrust3d/rooms rooms_DATA = rooms/00-00-00 rooms/00-00-01 rooms/00-00-02 rooms/00-00-03 rooms/00-00-04 rooms/00-01-04 rooms/00-02-04 diff --git a/data/textures/font.png b/data/textures/font.png Binary files differnew file mode 100644 index 0000000..99c06c0 --- /dev/null +++ b/data/textures/font.png diff --git a/src/Makefile.am b/src/Makefile.am index 50dc1d3..6cd8ff0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = thrust3d glcheck -thrust3d_SOURCES = main.c model.c render.c physics.c game.c texture.c utils.c audio.c +thrust3d_SOURCES = main.c model.c render.c physics.c game.c texture.c utils.c audio.c render-text.c thrust3d_LDADD = @LIBS@ glcheck_SOURCES = glcheck.c diff --git a/src/render-text.c b/src/render-text.c new file mode 100644 index 0000000..710837f --- /dev/null +++ b/src/render-text.c @@ -0,0 +1,52 @@ +/* + * render-text.c + * + * Simple text rendering + * + * (c) 2008 Thomas White <taw27@cam.ac.uk> + * + * thrust3d - a silly game + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <png.h> +#include <stdlib.h> +#include <glew.h> + +#include "render.h" +#include "texture.h" + +void render_text_setup(RenderContext *r) { + + texture_load(r, "font"); + +} + +void render_text_write(GLfloat x, GLfloat y, const char *text, RenderContext *r) { + + Texture *texture; + + texture = texture_lookup(r, "font"); + glBindTexture(GL_TEXTURE_2D, texture->texname); + glEnable(GL_TEXTURE_2D); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex2f(x, y); + glTexCoord2f(1.0, 0.0); + glVertex2f(x+0.1, y); + glTexCoord2f(1.0, 1.0); + glVertex2f(x+0.1, y+0.1); + glTexCoord2f(0.0, 1.0); + glVertex2f(x, y+0.1); + glEnd(); + + glDisable(GL_TEXTURE_2D); + +} + diff --git a/src/render-text.h b/src/render-text.h new file mode 100644 index 0000000..243dfb0 --- /dev/null +++ b/src/render-text.h @@ -0,0 +1,27 @@ +/* + * render-text.h + * + * Simple text rendering + * + * (c) 2008 Thomas White <taw27@cam.ac.uk> + * + * thrust3d - a silly game + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifndef RENDERTEXT_H +#define RENDERTEXT_H + +#include "types.h" + +#include <glew.h> + +extern void render_text_setup(RenderContext *r); +extern void render_text_write(GLfloat x, GLfloat y, const char *text, RenderContext *r); + +#endif /* RENDERTEXT_H */ + diff --git a/src/render.c b/src/render.c index 6a638dd..3ba93c8 100644 --- a/src/render.c +++ b/src/render.c @@ -24,6 +24,7 @@ #include "render.h" #include "texture.h" #include "utils.h" +#include "render-text.h" #define PANEL_ALPHA 0.3 @@ -266,6 +267,8 @@ RenderContext *render_setup(int width, int height) { texture_load(r, "radioactive"); texture_load(r, "fuel"); + render_text_setup(r); + return r; } @@ -635,6 +638,8 @@ static void render_draw_2d(RenderContext *r, Game *game) { glVertex2f(0.9, -0.8+(1.8*game->fuel)); /* Top left */ glEnd(); + //render_text_write(-1.0, 0.8, "Hello", r); + } void render_draw(Game *game, Uint32 t) { diff --git a/src/texture.c b/src/texture.c index 36f6a8b..464b057 100644 --- a/src/texture.c +++ b/src/texture.c @@ -15,7 +15,7 @@ #include <png.h> #include <stdlib.h> -#include <gl.h> +#include <glew.h> #include <glu.h> #include "render.h" |