summaryrefslogtreecommitdiff
path: root/glpong3d.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-12-12 00:20:26 +0000
committerMatt Turner <mattst88@gmail.com>2006-12-12 00:20:26 +0000
commitc8f218776cfed976f0a1c92807572f255f392577 (patch)
tree07fd94f8baa2fe02c5ac330704d3f99836eb0ad5 /glpong3d.c
parentfb9b032bd8e18e3f99841bf3da5e0cab793b3ca9 (diff)
-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
Diffstat (limited to 'glpong3d.c')
-rw-r--r--glpong3d.c41
1 files changed, 21 insertions, 20 deletions
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);