summaryrefslogtreecommitdiff
path: root/glpong3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'glpong3d.c')
-rw-r--r--glpong3d.c140
1 files changed, 67 insertions, 73 deletions
diff --git a/glpong3d.c b/glpong3d.c
index c15ba62..f6d270d 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -9,8 +9,9 @@
#include <GL/glc.h>
#include "glpong3d.h"
+#include "text.h"
-static void GLPong_Init(void);
+static int GLPong_Init(GLPong_t * GLPong);
static int GLPong_HandleEvents(void);
static void GLPong_Draw(void);
static void GLPong_CleanUp(void);
@@ -28,7 +29,10 @@ int main(int argc, char * argv[]) {
if (argv) {}
}
- GLPong_Init();
+ if (GLPong_Init(&GLPong) < 0) {
+ fprintf(stderr, "Bailing out.\n");
+ return -1;
+ }
start = SDL_GetTicks();
@@ -56,68 +60,57 @@ int main(int argc, char * argv[]) {
return 0;
}
-void GLPong_Init(void) {
+static int
+GLPong_Init(GLPong_t * GLPong) {
SDL_Surface * temp = NULL;
- int i;
- int count;
-
- GLPong.Ball.w = 0.5f;
- GLPong.Ball.h = 0.5f;
- GLPong.Ball.x = -(GLPong.Ball.w / 2);
- GLPong.Ball.y = -(GLPong.Ball.h / 2);
- GLPong.Ball.z = -3.0f;
- GLPong.Ball.r = 1.0f;
- GLPong.Ball.g = 0.0f;
- GLPong.Ball.b = 0.0f;
- GLPong.Ball.xv = 0.02f;
- GLPong.Ball.yv = 0.01f;
- GLPong.Ball.zv = -0.05f;
-
- GLPong.Front.w = 0.66f;
- GLPong.Front.h = 0.5f;
- GLPong.Front.x = -1.0f;
- GLPong.Front.y = -1.0f;
- GLPong.Front.z = -3.0f;
- GLPong.Front.r = 1.0f;
- GLPong.Front.g = 1.0f;
- GLPong.Front.b = 1.0f;
-
- GLPong.Back.w = 0.66f;
- GLPong.Back.h = 0.5f;
- GLPong.Back.x = -(GLPong.Front.w / 2);
- GLPong.Back.y = -(GLPong.Front.h / 2);
- GLPong.Back.z = -9.0f;
- GLPong.Back.r = 1.0f;
- GLPong.Back.g = 1.0f;
- GLPong.Back.b = 1.0f;
-
- 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", (char *)glcGetListc(GLC_CATALOG_LIST, i));
+ GLPong->Ball.w = 0.5f;
+ GLPong->Ball.h = 0.5f;
+ GLPong->Ball.x = -(GLPong->Ball.w / 2);
+ GLPong->Ball.y = -(GLPong->Ball.h / 2);
+ GLPong->Ball.z = -3.0f;
+ GLPong->Ball.r = 1.0f;
+ GLPong->Ball.g = 0.0f;
+ GLPong->Ball.b = 0.0f;
+ GLPong->Ball.xv = 0.02f;
+ GLPong->Ball.yv = 0.01f;
+ GLPong->Ball.zv = -0.05f;
+
+ GLPong->Front.w = 0.66f;
+ GLPong->Front.h = 0.5f;
+ GLPong->Front.x = -1.0f;
+ GLPong->Front.y = -1.0f;
+ GLPong->Front.z = -3.0f;
+ GLPong->Front.r = 1.0f;
+ GLPong->Front.g = 1.0f;
+ GLPong->Front.b = 1.0f;
+
+ GLPong->Back.w = 0.66f;
+ GLPong->Back.h = 0.5f;
+ GLPong->Back.x = -(GLPong->Front.w / 2);
+ GLPong->Back.y = -(GLPong->Front.h / 2);
+ GLPong->Back.z = -9.0f;
+ GLPong->Back.r = 1.0f;
+ GLPong->Back.g = 1.0f;
+ GLPong->Back.b = 1.0f;
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
+ fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
+ return -1;
}
+ atexit(SDL_Quit);
+
+ SDL_WM_SetCaption("glpong3d", "glpong3d");
+ SDL_ShowCursor(SDL_DISABLE);
- GLPong.GLC.font = glcGenFontID();
- glcNewFontFromFamily(GLPong.GLC.font, "DejaVu Sans");
- glcFontFace(GLPong.GLC.font, "Normal");
- glcRenderStyle(GLC_TEXTURE);
- glcFont(GLPong.GLC.font);
-
- SDLNet_Init();
- atexit(SDLNet_Quit);
+ temp = IMG_Load("ball.png");
+ if (!temp) {
+ fprintf(stderr, "Unable to open ball.png\n");
+ return -1;
+ }
- SDL_WM_SetCaption("glpong3d", "glpong3d");
- /*temp = IMG_Load("ball.png");
SDL_WM_SetIcon(temp, NULL);
- SDL_FreeSurface(temp);*/
-
+
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
@@ -125,7 +118,19 @@ void GLPong_Init(void) {
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);;
- GLPong.Surface = SDL_SetVideoMode(GLPONG_WIDTH, GLPONG_HEIGHT, 32, SDL_OPENGL);
+ if (GLPong_TextInit() < 0) {
+ fprintf(stderr, "Cannot initialize GLC context: %d\n", glcGetError());
+ return -1;
+ }
+ atexit(GLPong_TextDeinit);
+
+ if (SDLNet_Init() < 0) {
+ fprintf(stderr, "Cannot initialize SDL_net: %s\n", SDL_GetError());
+ return -1;
+ }
+ atexit(SDLNet_Quit);
+
+ GLPong->Surface = SDL_SetVideoMode(GLPONG_WIDTH, GLPONG_HEIGHT, 32, SDL_OPENGL);
glViewport(0, 0, GLPONG_WIDTH, GLPONG_HEIGHT);
glMatrixMode(GL_PROJECTION);
@@ -147,12 +152,7 @@ void GLPong_Init(void) {
printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
printf("OpenGL Extensions: %s\n", glGetString(GL_EXTENSIONS));
- temp = IMG_Load("background.jpg");
- if (temp != NULL) {
- background = SDL_GL_SurfaceToTexture(temp);
- SDL_FreeSurface(temp);
- }
- temp = IMG_Load("ball.png");
+ /*temp = IMG_Load("ball.png");*/ /* disabled since it's already loaded for the icon */
ball_texture = SDL_GL_SurfaceToTexture(temp);
SDL_FreeSurface(temp);
temp = IMG_Load("paddle-skyos.png");
@@ -172,6 +172,8 @@ void GLPong_Init(void) {
glEnd();
glEndList();
glPointSize(10.0f);
+
+ return 0;
}
static int
@@ -263,7 +265,6 @@ void GLPong_Move(void) {
}
void GLPong_Draw(void) {
- char buffer[10];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
@@ -448,13 +449,6 @@ void GLPong_Draw(void) {
glVertex3f(0.0f, 0.0f, 0.0f);
glEnd();
- sprintf(buffer, "%.0f FPS", GLPong.fps);
- glLoadIdentity();
- glTranslatef(-1.5f, 1.05f, -3.0f);
- glColor3f(1.0f, 1.0f, 1.0f);
- glScalef(0.2f, 0.2f, 0.0f);
- glcRenderString(buffer);
-
SDL_GL_SwapBuffers();
}