diff options
Diffstat (limited to 'glpong.c')
-rw-r--r-- | glpong.c | 36 |
1 files changed, 31 insertions, 5 deletions
@@ -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; |