diff options
-rw-r--r-- | glpong3d.c | 36 | ||||
-rw-r--r-- | glpong3d.h | 2 | ||||
-rw-r--r-- | text.c | 2 |
3 files changed, 18 insertions, 22 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) { @@ -22,8 +22,6 @@ #define AMASK 0xff000000 #endif -GLuint background; - GLuint paddle_texture; GLuint paddle_texture_hit; GLuint ball_texture; @@ -59,6 +59,6 @@ GLPong_TextDrawFPS(GLfloat fps) { glTranslatef(40.0f, 400.0f, 0.0f); glScalef(25.0f, 25.0f, 0.0f); glColor3f(1.0f, 0.0f, 0.0f); - glcRenderString(buffer); + /*glcRenderString(buffer);*/ /* XXX: something causes this to segfault */ } |