diff options
author | Matt Turner <mattst88@gmail.com> | 2010-01-21 15:55:32 -0500 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2011-04-04 17:14:35 -0400 |
commit | 89c1f661870d210cf4c0971f97a67a1a7c5b7a39 (patch) | |
tree | 7bba802acd43fcb04f050584afdb4d00539722af /glpong3d.c | |
parent | ce7f4caaf9fa41e383efbc4854106558b3ff0e19 (diff) |
Rework GLPong_Draw, use FPS code.
Signed-off-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'glpong3d.c')
-rw-r--r-- | glpong3d.c | 36 |
1 files changed, 17 insertions, 19 deletions
@@ -1,6 +1,5 @@ #include <stdio.h> #include <stdlib.h> -#include <time.h> #include "SDL.h" #include "SDL_opengl.h" @@ -10,6 +9,7 @@ #include "glpong3d.h" #include "text.h" +#include "fps.h" static int GLPong_Init(GLPong_t * GLPong); static int GLPong_HandleEvents(void); @@ -20,7 +20,6 @@ static void GLPong_Move(void); GLuint box; int main(int argc, char * argv[]) { - clock_t start; unsigned int frames = 0; int done = 0; int action; @@ -34,7 +33,7 @@ int main(int argc, char * argv[]) { return -1; } - start = SDL_GetTicks(); + GLPong_FPSInit(); while (!done) { action = GLPong_HandleEvents(); @@ -45,14 +44,22 @@ int main(int argc, char * argv[]) { } GLPong_Move(); + + /* begin drawing */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + GLPong_Draw(); + frames++; - if (frames == 10) { - GLPong.fps = (float) frames / (SDL_GetTicks() - start) * 1000; + if (frames == 30) { frames = 0; - start = SDL_GetTicks(); } -/* printf("frames: %u, fps: %f\n", frames, GLPong.fps);*/ + + GLPong_TextDrawFPS(GLPong_FPSCount()); + + SDL_GL_SwapBuffers(); + /* end drawing */ + SDL_Delay(10); } GLPong_CleanUp(); @@ -116,7 +123,7 @@ GLPong_Init(GLPong_t * GLPong) { 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_DOUBLEBUFFER, 1); if (GLPong_TextInit() < 0) { fprintf(stderr, "Cannot initialize GLC context: %d\n", glcGetError()); @@ -143,7 +150,7 @@ GLPong_Init(GLPong_t * GLPong) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +/* glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);*/ /* disabled since it causes drawing corruption, but necessary to enable transparency */ glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); @@ -265,15 +272,8 @@ void GLPong_Move(void) { } void GLPong_Draw(void) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glLoadIdentity(); - if (background) { - glBindTexture(GL_TEXTURE_2D, background); - glEnable(GL_TEXTURE_2D); - } else { - glColor3f(0.0f, 0.0f, 0.0f); - } + glColor3f(0.0f, 0.0f, 0.0f); glTranslatef(0.0f, 0.0f, -9.0f); glBegin(GL_QUADS); glTexCoord2f(0.875f, 0.0f); glVertex2f( 1.5f, 1.0f); /* Upper Right */ @@ -448,8 +448,6 @@ void GLPong_Draw(void) { glBegin(GL_POINTS); glVertex3f(0.0f, 0.0f, 0.0f); glEnd(); - - SDL_GL_SwapBuffers(); } void GLPong_Collide(Ball_t * ball, const Paddle_t * paddle) { |