summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-05-14 16:26:15 +0000
committerMatt Turner <mattst88@gmail.com>2008-05-14 16:26:15 +0000
commit15e2da75f4a8550b445a4ba8cb3d21c20beb007f (patch)
tree7e2708a75653b85e468523c08629f870f174b07e
parenta8921d2baf7fe632839ec4c1a6f55db9c78f1c1c (diff)
Make quesoglc work. Still need to sort out why GLC_TRIANGLE works but GLC_TEXTURE doesn't.
git-svn-id: svn://mattst88.com/svn/glpong/trunk@15 449aeecc-241a-0410-943f-e2f883e2d7a2
-rw-r--r--Makefile4
-rw-r--r--ball.h4
-rw-r--r--fps.c11
-rw-r--r--fps.h3
-rw-r--r--glpong.c21
-rw-r--r--text.c33
6 files changed, 51 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 4259e2c..5de936c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
CC=gcc
STRIP=strip
WARN=-Wall -W -ansi -pedantic
-DEFINES=-DINLINE=inline
-CFLAGS=-Os -pipe -std=c99 -g ${DEFINES} -Wall #${WARN}
+DEFINES=-DINLINE=__inline__ -DDEBUG=1
+CFLAGS=-Os -pipe -std=c99 -g ${DEFINES} ${WARN}
LDFLAGS=-Wl,-O1
INCLUDES=`sdl-config --cflags`
LIBRARIES=`sdl-config --libs` -lSDL_image -lGL -lGLC
diff --git a/ball.h b/ball.h
index 4618b46..db3ee12 100644
--- a/ball.h
+++ b/ball.h
@@ -22,5 +22,9 @@ int GLPong_BallCollide(const Ball_t * a, const Ball_t * b);
void GLPong_BallMoveAll(Ball_t ** balls);
void GLPong_BallDrawAll(Ball_t * balls);
+#ifdef DEBUG
+int length(Ball_t * balls);
+#endif
+
#endif
diff --git a/fps.c b/fps.c
index 4379e38..ca2787a 100644
--- a/fps.c
+++ b/fps.c
@@ -14,14 +14,11 @@ GLPong_FPSInit() {
start = SDL_GetTicks();
}
-void
+INLINE GLfloat
GLPong_FPSCount() {
- // 10.0f is the number of frames we let draw before calculating FPS
- fps = 10.0f / (SDL_GetTicks() - start) * 1000; // 1 sec / 1 millisec == 1000
+ /* 10.0f is the number of frames we let draw before calculating FPS */
+ fps = 10.0f / (SDL_GetTicks() - start) * 1000; /* 1 sec / 1 millisec == 1000 */
start = SDL_GetTicks();
+ return fps;
}
-void
-GLPong_FPSPrint() {
- printf("%.2f frames per second\n", fps);
-}
diff --git a/fps.h b/fps.h
index 4b965b9..ef16ed8 100644
--- a/fps.h
+++ b/fps.h
@@ -2,8 +2,7 @@
#define FPS_H
void GLPong_FPSInit();
-void GLPong_FPSCount();
-void GLPong_FPSPrint();
+INLINE GLfloat GLPong_FPSCount();
#endif
diff --git a/glpong.c b/glpong.c
index a1d9b53..a7c7c7e 100644
--- a/glpong.c
+++ b/glpong.c
@@ -14,7 +14,7 @@
static int GLPong_Init(GLPong_t * GLPong);
static void GLPong_Deinit(GLPong_t * GLPong);
static int GLPong_HandleEvents();
-
+static INLINE unsigned int NextPow2(unsigned int value);
static GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface);
static GLuint SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * hratio);
@@ -67,15 +67,16 @@ int main(int argc, char * argv[]) {
GLPong_BallDrawAll(GLPong.balls);
- SDL_GL_SwapBuffers();
- /* end drawing */
-
frames++;
- if (frames == 10) {
- GLPong_FPSCount();
+ if (frames == 30) {
frames = 0;
- GLPong_FPSPrint();
}
+ GLPong_TextDrawFPS(GLPong_FPSCount());
+
+ SDL_GL_SwapBuffers();
+ /* end drawing */
+
+
SDL_Delay(10);
}
@@ -194,7 +195,7 @@ GLPong_HandleEvents() {
static INLINE unsigned int
NextPow2(unsigned int value) {
-#if (defined __i386__ || defined __amd64__ || defined __x86_64__) \
+#if (defined __i386__ || defined __x86_64__) \
&& (defined __GNUC__)
unsigned int x;
__asm(
@@ -253,8 +254,8 @@ static GLuint
SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * hratio) {
SDL_Surface * pow2 = NULL;
- unsigned int w = NextPow2(surface->w);
- unsigned int h = NextPow2(surface->h);
+ int w = NextPow2(surface->w);
+ int h = NextPow2(surface->h);
if (wratio) {
*wratio = (GLfloat)surface->w / (GLfloat)h;
diff --git a/text.c b/text.c
index 2694e4b..06254c3 100644
--- a/text.c
+++ b/text.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
#include <GL/glc.h>
#include "text.h"
@@ -6,6 +8,9 @@ static GLuint font;
int
GLPong_TextInit() {
+#ifdef DEBUG
+ int count, i;
+#endif
GLuint context = glcGenContext();
glcContext(context);
@@ -13,6 +18,7 @@ GLPong_TextInit() {
if (!glcIsContext(context)) {
return -1;
}
+ glcAppendCatalog("/usr/share/fonts/dejavu/");
#ifdef DEBUG
count = glcGeti(GLC_CATALOG_COUNT);
@@ -22,10 +28,15 @@ GLPong_TextInit() {
#endif
font = glcGenFontID();
- glcNewFontFromFamily(font, "Ar");
+ glcNewFontFromFamily(font, "Deja Vu Sans");
glcFontFace(font, "Normal");
- glcRenderStyle(GLC_TEXTURE);
- glcFont(font);
+/* glcRenderStyle(GLC_TEXTURE);*/
+ glcRenderStyle(GLC_TRIANGLE);
+ if (glcIsFont(font)) {
+ glcFont(font);
+ } else {
+ return -1;
+ }
return 0;
}
@@ -36,4 +47,18 @@ GLPong_TextDeinit() {
}
void
-GLPong_TextDrawFPS(GLfloat fps) { }
+GLPong_TextDrawFPS(GLfloat fps) {
+ char buffer[10];
+
+ sprintf(buffer, "%.0f FPS", fps);
+#ifdef DEBUG
+ printf("%s frames per second\n", buffer);
+#endif
+
+ glLoadIdentity();
+ glTranslatef(40.0f, 400.0f, 0.0f);
+ glScalef(25.0f, 25.0f, 0.0f);
+ glColor3f(1.0f, 0.0f, 0.0f);
+ glcRenderString(buffer);
+}
+