summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-08-06 18:06:33 +0000
committerMatt Turner <mattst88@gmail.com>2006-08-06 18:06:33 +0000
commit9b186bbaba1913b65ce01c570878b98346b35c71 (patch)
tree141efc9b602c36de6dab41bc3ff1eb6d1f096d5a
parentfaa75e3a202b773d5f90cd99bc076ca9635440bf (diff)
Added FPS counter. Cleaned up GLC code.
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@12 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--glpong3d.c43
-rw-r--r--glpong3d.h7
2 files changed, 33 insertions, 17 deletions
diff --git a/glpong3d.c b/glpong3d.c
index 2203f39..0296b35 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -11,10 +11,10 @@
#include "glpong3d.h"
GLuint box;
-GLuint font;
-GLuint ctx;
int main(int argc, char * argv[]) {
+ clock_t now, last = 0;
+ unsigned int frames = 0;
if (argc) {
if (argv) {}
}
@@ -24,6 +24,14 @@ int main(int argc, char * argv[]) {
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);
}
@@ -63,24 +71,24 @@ void GLPong_Init() {
GLPong.Back.y = -(GLPong.Front.h / 2);
GLPong.Back.z = -9.0f;
- ctx = glcGenContext();
- glcContext(ctx);
+ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
+ atexit(SDL_Quit);
+
+ GLPong.GLC.context = glcGenContext();
+ glcContext(GLPong.GLC.context);
#ifdef _WIN32
glcAppendCatalog("C:\\WINDOWS\\Fonts");
#endif
count = glcGeti(GLC_CATALOG_COUNT);
for (i = 0; i < count; i++) {
- printf("%s\n", glcGetListc(GLC_CATALOG_LIST, i));
+ printf("%s\n", (char *)glcGetListc(GLC_CATALOG_LIST, i));
}
- font = glcGenFontID();
- glcNewFontFromFamily(font, "DejaVu Sans");
- glcFontFace(font, "Normal");
+ GLPong.GLC.font = glcGenFontID();
+ glcNewFontFromFamily(GLPong.GLC.font, "DejaVu Sans");
+ glcFontFace(GLPong.GLC.font, "Normal");
glcRenderStyle(GLC_TEXTURE);
- glcFont(font);
-
- SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
- atexit(SDL_Quit);
+ glcFont(GLPong.GLC.font);
SDLNet_Init();
atexit(SDLNet_Quit);
@@ -188,10 +196,11 @@ void GLPong_HandleEvents() {
GLPong.Mouse.y = -1.0 + (GLPong.Front.h / 2);
else if (GLPong.Mouse.y >= 1.0 - (GLPong.Front.h / 2))
GLPong.Mouse.y = 1.0 - (GLPong.Front.h / 2);
- printf("SDL x,y: %d,%d; OpenGL x,y: %f,%f\n", x, y, GLPong.Mouse.x, GLPong.Mouse.y);
+ /*printf("SDL x,y: %d,%d; OpenGL x,y: %f,%f\n", x, y, GLPong.Mouse.x, GLPong.Mouse.y);*/
}
void GLPong_Draw() {
+ char buffer[10];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
@@ -303,12 +312,12 @@ void GLPong_Draw() {
glEnd();
glDisable(GL_TEXTURE_2D);
+ sprintf(buffer, "%u FPS", GLPong.fps);
glLoadIdentity();
- glTranslatef(0.0f, 1.1f, -3.0f);
- glColor3f(0.0f, 0.0f, 1.0f);
+ glTranslatef(-1.5f, 1.1f, -3.0f);
+ glColor3f(1.0f, 1.0f, 1.0f);
glScalef(0.1f, 0.1f, 0.0f);
- glcRenderString("Hello, GLC");
- glDisable2D();
+ glcRenderString(buffer);
SDL_GL_SwapBuffers();
}
diff --git a/glpong3d.h b/glpong3d.h
index a248b7c..dfe6cab 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -13,6 +13,11 @@ typedef struct {
GLfloat x, y;
} Mouse_t;
+typedef struct {
+ GLuint context;
+ GLuint font;
+} GLC_t;
+
struct {
SDL_Event Event;
SDL_Surface * Surface;
@@ -20,8 +25,10 @@ struct {
Paddle_t Front;
Paddle_t Back;
Mouse_t Mouse;
+ GLC_t GLC;
GLfloat w;
GLfloat h;
+ GLuint fps;
Sint8 done;
} GLPong;