diff options
author | Matt Turner <mattst88@gmail.com> | 2008-03-01 18:04:19 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-03-01 18:04:19 +0000 |
commit | 8490c68f5d3fbb4d3e0030467dd785beca10c3f1 (patch) | |
tree | ca375e1605a94d44bf23d3b8e80084ec65371da2 | |
parent | 83723eb5558383537968bee22b2342372ad9a40d (diff) |
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
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | ball.c | 8 | ||||
-rw-r--r-- | glpong.c | 36 | ||||
-rw-r--r-- | glpong.h | 4 | ||||
-rw-r--r-- | text.c | 40 | ||||
-rw-r--r-- | text.h | 11 |
6 files changed, 90 insertions, 13 deletions
@@ -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} @@ -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; @@ -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; @@ -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 @@ -0,0 +1,40 @@ + +#include <GL/glc.h> + +#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) { } @@ -0,0 +1,11 @@ +#ifndef TEXT_H +#define TEXT_H + +#include <GL/glc.h> + +int GLPong_TextInit(); +void GLPong_TextDeinit(); +void GLPong_TextDrawFPS(GLfloat fps); + +#endif + |