diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | ball.h | 4 | ||||
-rw-r--r-- | fps.c | 11 | ||||
-rw-r--r-- | fps.h | 3 | ||||
-rw-r--r-- | glpong.c | 21 | ||||
-rw-r--r-- | text.c | 33 |
6 files changed, 51 insertions, 25 deletions
@@ -1,8 +1,8 @@ CC=gcc STRIP=strip WARN=-Wall -W -ansi -pedantic -DEFINES=-DINLINE=inline -CFLAGS=-Os -pipe -std=c99 -g ${DEFINES} -Wall #${WARN} +DEFINES=-DINLINE=__inline__ -DDEBUG=1 +CFLAGS=-Os -pipe -std=c99 -g ${DEFINES} ${WARN} LDFLAGS=-Wl,-O1 INCLUDES=`sdl-config --cflags` LIBRARIES=`sdl-config --libs` -lSDL_image -lGL -lGLC @@ -22,5 +22,9 @@ int GLPong_BallCollide(const Ball_t * a, const Ball_t * b); void GLPong_BallMoveAll(Ball_t ** balls); void GLPong_BallDrawAll(Ball_t * balls); +#ifdef DEBUG +int length(Ball_t * balls); +#endif + #endif @@ -14,14 +14,11 @@ GLPong_FPSInit() { start = SDL_GetTicks(); } -void +INLINE GLfloat GLPong_FPSCount() { - // 10.0f is the number of frames we let draw before calculating FPS - fps = 10.0f / (SDL_GetTicks() - start) * 1000; // 1 sec / 1 millisec == 1000 + /* 10.0f is the number of frames we let draw before calculating FPS */ + fps = 10.0f / (SDL_GetTicks() - start) * 1000; /* 1 sec / 1 millisec == 1000 */ start = SDL_GetTicks(); + return fps; } -void -GLPong_FPSPrint() { - printf("%.2f frames per second\n", fps); -} @@ -2,8 +2,7 @@ #define FPS_H void GLPong_FPSInit(); -void GLPong_FPSCount(); -void GLPong_FPSPrint(); +INLINE GLfloat GLPong_FPSCount(); #endif @@ -14,7 +14,7 @@ static int GLPong_Init(GLPong_t * GLPong); static void GLPong_Deinit(GLPong_t * GLPong); static int GLPong_HandleEvents(); - +static INLINE unsigned int NextPow2(unsigned int value); static GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface); static GLuint SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * hratio); @@ -67,15 +67,16 @@ int main(int argc, char * argv[]) { GLPong_BallDrawAll(GLPong.balls); - SDL_GL_SwapBuffers(); - /* end drawing */ - frames++; - if (frames == 10) { - GLPong_FPSCount(); + if (frames == 30) { frames = 0; - GLPong_FPSPrint(); } + GLPong_TextDrawFPS(GLPong_FPSCount()); + + SDL_GL_SwapBuffers(); + /* end drawing */ + + SDL_Delay(10); } @@ -194,7 +195,7 @@ GLPong_HandleEvents() { static INLINE unsigned int NextPow2(unsigned int value) { -#if (defined __i386__ || defined __amd64__ || defined __x86_64__) \ +#if (defined __i386__ || defined __x86_64__) \ && (defined __GNUC__) unsigned int x; __asm( @@ -253,8 +254,8 @@ static GLuint SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * hratio) { SDL_Surface * pow2 = NULL; - unsigned int w = NextPow2(surface->w); - unsigned int h = NextPow2(surface->h); + int w = NextPow2(surface->w); + int h = NextPow2(surface->h); if (wratio) { *wratio = (GLfloat)surface->w / (GLfloat)h; @@ -1,3 +1,5 @@ +#include <stdio.h> + #include <GL/glc.h> #include "text.h" @@ -6,6 +8,9 @@ static GLuint font; int GLPong_TextInit() { +#ifdef DEBUG + int count, i; +#endif GLuint context = glcGenContext(); glcContext(context); @@ -13,6 +18,7 @@ GLPong_TextInit() { if (!glcIsContext(context)) { return -1; } + glcAppendCatalog("/usr/share/fonts/dejavu/"); #ifdef DEBUG count = glcGeti(GLC_CATALOG_COUNT); @@ -22,10 +28,15 @@ GLPong_TextInit() { #endif font = glcGenFontID(); - glcNewFontFromFamily(font, "Ar"); + glcNewFontFromFamily(font, "Deja Vu Sans"); glcFontFace(font, "Normal"); - glcRenderStyle(GLC_TEXTURE); - glcFont(font); +/* glcRenderStyle(GLC_TEXTURE);*/ + glcRenderStyle(GLC_TRIANGLE); + if (glcIsFont(font)) { + glcFont(font); + } else { + return -1; + } return 0; } @@ -36,4 +47,18 @@ GLPong_TextDeinit() { } void -GLPong_TextDrawFPS(GLfloat fps) { } +GLPong_TextDrawFPS(GLfloat fps) { + char buffer[10]; + + sprintf(buffer, "%.0f FPS", fps); +#ifdef DEBUG + printf("%s frames per second\n", buffer); +#endif + + glLoadIdentity(); + glTranslatef(40.0f, 400.0f, 0.0f); + glScalef(25.0f, 25.0f, 0.0f); + glColor3f(1.0f, 0.0f, 0.0f); + glcRenderString(buffer); +} + |