summaryrefslogtreecommitdiff
path: root/glpong3d.c
diff options
context:
space:
mode:
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);