summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2010-01-21 15:55:32 -0500
committerMatt Turner <mattst88@gmail.com>2011-04-04 17:14:35 -0400
commit89c1f661870d210cf4c0971f97a67a1a7c5b7a39 (patch)
tree7bba802acd43fcb04f050584afdb4d00539722af
parentce7f4caaf9fa41e383efbc4854106558b3ff0e19 (diff)
Rework GLPong_Draw, use FPS code.
Signed-off-by: Matt Turner <mattst88@gmail.com>
-rw-r--r--glpong3d.c36
-rw-r--r--glpong3d.h2
-rw-r--r--text.c2
3 files changed, 18 insertions, 22 deletions
diff --git a/glpong3d.c b/glpong3d.c
index f6d270d..1c76beb 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -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) {
diff --git a/glpong3d.h b/glpong3d.h
index 80d6cb0..55bab80 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -22,8 +22,6 @@
#define AMASK 0xff000000
#endif
-GLuint background;
-
GLuint paddle_texture;
GLuint paddle_texture_hit;
GLuint ball_texture;
diff --git a/text.c b/text.c
index 60d6e4c..a7aff5e 100644
--- a/text.c
+++ b/text.c
@@ -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 */
}