From c8f218776cfed976f0a1c92807572f255f392577 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Tue, 12 Dec 2006 00:20:26 +0000 Subject: -Fixed the FPS counter, somewhat. -Compressed the PNGs a little more. git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@15 4dd1920e-271a-0410-bca0-81b404a81564 --- Makefile | 4 ++-- ball.png | Bin 12689 -> 10213 bytes glpong3d.c | 41 +++++++++++++++++++++-------------------- glpong3d.h | 2 +- paddle-skyos.png | Bin 57023 -> 56609 bytes 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index b1b5fe6..c95d7ef 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ WARN=-Wall -W -ansi -pedantic CFLAGS=-Os -pipe -std=c99 ${WARN} LDFLAGS=-Wl,-O1,-s INCLUDES=`sdl-config --cflags` -LIBRARIES=`sdl-config --libs` -lSDL_image -lSDL_net -lGL -lGLU -lglc32 +LIBRARIES=`sdl-config --libs` -lSDL_image -lSDL_net -lGL -lGLU -lGLC EXT=.exe EXE=glpong3d${EXT} @@ -23,4 +23,4 @@ remake: rebuild %.o: %.c ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< - \ No newline at end of file + diff --git a/ball.png b/ball.png index 18cb29c..7ff9bc5 100644 Binary files a/ball.png and b/ball.png differ diff --git a/glpong3d.c b/glpong3d.c index c918f7b..e3b1486 100644 --- a/glpong3d.c +++ b/glpong3d.c @@ -13,27 +13,28 @@ GLuint box; int main(int argc, char * argv[]) { - clock_t now, last = 0; + clock_t start; unsigned int frames = 0; if (argc) { if (argv) {} } - GLPong_Init(); + GLPong_Init(); + + start = SDL_GetTicks(); while ( !GLPong.done ) { GLPong_HandleEvents(); - GLPong_Move(); - now = clock(); - frames++; - if (now - last > CLK_TCK * 2) { - GLPong.fps = (frames * CLK_TCK) / (now - last); - last = now; - frames = 0; - } - printf("now: %ld, last %ld, frames: %u, fps: %u\n", now, last, frames, GLPong.fps); - GLPong_Draw(); - SDL_Delay(10); + GLPong_Move(); + GLPong_Draw(); + frames++; + if (frames == 10) { + GLPong.fps = (float) frames / (SDL_GetTicks() - start) * 1000; + frames = 0; + start = SDL_GetTicks(); + } + printf("frames: %u, fps: %f\n", frames, GLPong.fps); + SDL_Delay(10); } GLPong_CleanUp(); @@ -107,12 +108,12 @@ void GLPong_Init() { SDL_WM_SetIcon(temp, NULL); SDL_FreeSurface(temp);*/ - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); GLPong.Surface = SDL_SetVideoMode(GLPong.w, GLPong.h, 32, SDL_OPENGL); glViewport(0, 0, GLPong.w, GLPong.h); @@ -321,7 +322,7 @@ void GLPong_Draw() { glEnd(); glDisable(GL_TEXTURE_2D); - sprintf(buffer, "%u FPS", GLPong.fps); + sprintf(buffer, "%.0f FPS", GLPong.fps); glLoadIdentity(); glTranslatef(-1.5f, 1.1f, -3.0f); glColor3f(1.0f, 1.0f, 1.0f); diff --git a/glpong3d.h b/glpong3d.h index 9cd2bc9..a993b6e 100644 --- a/glpong3d.h +++ b/glpong3d.h @@ -40,7 +40,7 @@ struct { GLC_t GLC; GLfloat w; GLfloat h; - GLuint fps; + GLfloat fps; Sint8 done; } GLPong; diff --git a/paddle-skyos.png b/paddle-skyos.png index 4af354c..eb80a8d 100644 Binary files a/paddle-skyos.png and b/paddle-skyos.png differ -- cgit v1.2.3