From 8490c68f5d3fbb4d3e0030467dd785beca10c3f1 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sat, 1 Mar 2008 18:04:19 +0000 Subject: Begin adding text rendering support using QuesoGLC. Minor clean ups. Begin working on FPS counter. git-svn-id: svn://mattst88.com/svn/glpong/trunk@13 449aeecc-241a-0410-943f-e2f883e2d7a2 --- Makefile | 4 ++-- ball.c | 8 ++++---- glpong.c | 36 +++++++++++++++++++++++++++++++----- glpong.h | 4 ++-- text.c | 40 ++++++++++++++++++++++++++++++++++++++++ text.h | 11 +++++++++++ 6 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 text.c create mode 100644 text.h diff --git a/Makefile b/Makefile index 69f36fb..94d9c57 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,12 @@ DEFINES=-DINLINE=inline CFLAGS=-Os -pipe -std=c99 -g ${DEFINES} -Wall #${WARN} LDFLAGS=-Wl,-O1 INCLUDES=`sdl-config --cflags` -LIBRARIES=`sdl-config --libs` -lSDL_image -lGL +LIBRARIES=`sdl-config --libs` -lSDL_image -lGL -lGLC EXT=.exe EXE=glpong${EXT} -OBJS=glpong.o ball.o #paddle.o +OBJS=glpong.o ball.o text.o #paddle.o all: ${OBJS} ${CC} ${LDFLAGS} ${OBJS} -o ${EXE} ${LIBRARIES} diff --git a/ball.c b/ball.c index a1c3b9e..914804c 100644 --- a/ball.c +++ b/ball.c @@ -23,8 +23,8 @@ length(Ball_t * balls) { void GLPong_BallInit() { - ball_width = GLPONG_WIDTH / 32.0f; /* FIXME: magic numbers */ - ball_height = GLPONG_HEIGHT / 24.0f; + ball_width = 20.0f; + ball_height = 20.0f; ball = glGenLists(1); glNewList(ball, GL_COMPILE); @@ -55,8 +55,8 @@ GLPong_BallAdd(Ball_t ** balls) { newball->x = 100.0f; newball->y = 100.0f; - newball->xv = GLPONG_WIDTH / (GLfloat)320; /* FIXME: magic numbers */ - newball->yv = GLPONG_HEIGHT / (GLfloat)240; + newball->xv = 2.0f; + newball->yv = 2.0f; newball->r = rand() % 255; newball->g = rand() % 255; newball->b = rand() % 255; diff --git a/glpong.c b/glpong.c index 6e87e26..cca1238 100644 --- a/glpong.c +++ b/glpong.c @@ -7,8 +7,10 @@ #include "SDL_image.h" #include "glpong.h" +#include "text.h" static int GLPong_Init(GLPong_t * GLPong); +static void GLPong_Deinit(GLPong_t * GLPong); static int GLPong_HandleEvents(); static GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface); @@ -23,13 +25,16 @@ int main(int argc, char * argv[]) { GLPONG_HEIGHT }; + clock_t start; + GLfloat fps; + unsigned int frames = 0; int action; int done = 0; if (argc) { if (argv) {} } - + if (GLPong_Init(&GLPong) < 0) { fprintf(stderr, "Bailing out.\n"); return -1; @@ -42,6 +47,8 @@ int main(int argc, char * argv[]) { #ifdef DEBUG printf("%d balls\n", length(GLPong.balls)); #endif + + start = SDL_GetTicks(); while ( !done ) { action = GLPong_HandleEvents(); @@ -59,17 +66,22 @@ int main(int argc, char * argv[]) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLPong_BallDrawAll(GLPong.balls); - + SDL_GL_SwapBuffers(); /* end drawing */ + frames++; + if (frames == 10) { + fps = (GLfloat) frames / (SDL_GetTicks() - start) * 1000; + frames = 0; + start = SDL_GetTicks(); + //printf("%.2f frames per second\n", GLPong.fps); + } SDL_Delay(10); } /* clean up */ - GLPong_BallDeleteAll(GLPong.balls); - - GLPong_BallDeinit(); + GLPong_Deinit(&GLPong); return 0; } @@ -109,6 +121,11 @@ GLPong_Init(GLPong_t * GLPong) { fprintf(stderr, "Cannot SetVideoMode: %s\n", SDL_GetError()); return -1; } + + if (GLPong_TextInit() == -1) { + fprintf(stderr, "Cannot initialize GLC context: %d\n", glcGetError()); + return -1; + } glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -132,6 +149,15 @@ GLPong_Init(GLPong_t * GLPong) { return 0; } +static void +GLPong_Deinit(GLPong_t * GLPong) { + GLPong_BallDeleteAll(GLPong->balls); + + GLPong_BallDeinit(); + + GLPong_TextDeinit(); +} + static int GLPong_HandleEvents() { SDL_Event Event; diff --git a/glpong.h b/glpong.h index 43ee592..6bbde04 100644 --- a/glpong.h +++ b/glpong.h @@ -7,8 +7,8 @@ #include "ball.h" /*#include "paddle.h"*/ -#define GLPONG_WIDTH 640 -#define GLPONG_HEIGHT 480 +#define GLPONG_WIDTH 640.0f +#define GLPONG_HEIGHT 480.0f #define GLPONG_NOACTION 0 #define GLPONG_EXIT 1 diff --git a/text.c b/text.c new file mode 100644 index 0000000..cd90efe --- /dev/null +++ b/text.c @@ -0,0 +1,40 @@ + +#include + +#include "text.h" + +static GLuint font; + +int +GLPong_TextInit() { + GLuint context = glcGenContext(); + glcContext(context); + + + if (!glcIsContext(context)) { + return -1; + } + +#ifdef DEBUG + count = glcGeti(GLC_CATALOG_COUNT); + for (i = 0; i < count; i++) { + printf("%s\n", (char *)glcGetListc(GLC_CATALOG_LIST, i)); + } +#endif + + font = glcGenFontID(); + glcNewFontFromFamily(font, "Ar"); + glcFontFace(font, "Normal"); + glcRenderStyle(GLC_TEXTURE); + glcFont(font); + + return 0; +} + +void +GLPong_TextDeinit() { + glcDeleteFont(font); +} + +void +GLPong_TextDrawFPS(GLfloat fps) { } diff --git a/text.h b/text.h new file mode 100644 index 0000000..dfc3458 --- /dev/null +++ b/text.h @@ -0,0 +1,11 @@ +#ifndef TEXT_H +#define TEXT_H + +#include + +int GLPong_TextInit(); +void GLPong_TextDeinit(); +void GLPong_TextDrawFPS(GLfloat fps); + +#endif + -- cgit v1.2.3