summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-08-09 03:04:24 +0000
committerMatt Turner <mattst88@gmail.com>2006-08-09 03:04:24 +0000
commita61afd2ec1baa53361fa763430c5c0abfe6647df (patch)
tree1b0fd7cc0dc8ea165b54bc1b7d2f903a9be4c6a2
parent9b186bbaba1913b65ce01c570878b98346b35c71 (diff)
New ball image. Fixes, code clean up. Removal of unused functions.
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@13 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--128x128.pngbin15898 -> 0 bytes
-rw-r--r--Makefile2
-rw-r--r--ball.c6
-rw-r--r--ball.h13
-rw-r--r--ball.pngbin0 -> 12689 bytes
-rw-r--r--glpong3d.c72
-rw-r--r--glpong3d.h20
-rw-r--r--paddle.c6
-rw-r--r--paddle.h12
9 files changed, 47 insertions, 84 deletions
diff --git a/128x128.png b/128x128.png
deleted file mode 100644
index 7094b27..0000000
--- a/128x128.png
+++ /dev/null
Binary files differ
diff --git a/Makefile b/Makefile
index 0dee9ba..79011fa 100644
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ EXT=.exe
EXE=glpong3d${EXT}
-OBJS=glpong3d.o ball.o paddle.o
+OBJS=glpong3d.o # ball.o paddle.o
all: ${OBJS}
${CC} ${LDFLAGS} ${OBJS} -o ${EXE} ${LIBRARIES}
diff --git a/ball.c b/ball.c
deleted file mode 100644
index 36f33e7..0000000
--- a/ball.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "SDL.h"
-#include "SDL_opengl.h"
-
-#include "glpong3d.h"
-#include "ball.h"
-#include "paddle.h"
diff --git a/ball.h b/ball.h
deleted file mode 100644
index 48c8f14..0000000
--- a/ball.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef BALL_H
-#define BALL_H
-
-GLuint ball_texture;
-
-typedef struct {
- GLfloat w, h, x, y, z;
- GLfloat r, g, b, a;
- GLfloat xv, yv, zv;
- GLfloat rotate;
-} Ball_t;
-
-#endif
diff --git a/ball.png b/ball.png
new file mode 100644
index 0000000..18cb29c
--- /dev/null
+++ b/ball.png
Binary files differ
diff --git a/glpong3d.c b/glpong3d.c
index 0296b35..1bc1d02 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -31,7 +31,7 @@ int main(int argc, char * argv[]) {
last = now;
frames = 0;
}
- printf("now: %ld, last %ld, frames: %u, fps: %u\n", now, last, frames, GLPong.fps);
+ /*printf("now: %ld, last %ld, frames: %u, fps: %u\n", now, last, frames, GLPong.fps);*/
GLPong_Draw();
SDL_Delay(10);
}
@@ -55,6 +55,9 @@ void GLPong_Init() {
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 = 1.0f;
+ GLPong.Ball.b = 1.0f;
GLPong.Ball.xv = 0.02f;
GLPong.Ball.yv = 0.01f;
GLPong.Ball.zv = -0.03f;
@@ -64,12 +67,18 @@ void GLPong_Init() {
GLPong.Front.x = -(GLPong.Front.w / 2);
GLPong.Front.y = -(GLPong.Front.h / 2);
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);
@@ -97,6 +106,7 @@ void GLPong_Init() {
temp = IMG_Load("ball.png");
SDL_WM_SetIcon(temp, NULL);
SDL_FreeSurface(temp);
+ temp = NULL;
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
@@ -132,9 +142,9 @@ void GLPong_Init() {
temp = IMG_Load("background.jpg");
if (temp != NULL) {
background = SDL_GL_SurfaceToTexture(temp);
+ SDL_FreeSurface(temp);
}
- SDL_FreeSurface(temp);
- temp = IMG_Load("128x128.png");
+ temp = IMG_Load("ball-blur.png");
ball_texture = SDL_GL_SurfaceToTexture(temp);
SDL_FreeSurface(temp);
temp = IMG_Load("paddle-skyos.png");
@@ -199,6 +209,21 @@ void GLPong_HandleEvents() {
/*printf("SDL x,y: %d,%d; OpenGL x,y: %f,%f\n", x, y, GLPong.Mouse.x, GLPong.Mouse.y);*/
}
+void GLPong_Move() {
+ GLPong.Ball.x += GLPong.Ball.xv;
+ GLPong.Ball.y += GLPong.Ball.yv;
+ GLPong.Ball.z += GLPong.Ball.zv;
+ if ((GLPong.Ball.x > 1.0f) || (GLPong.Ball.x + GLPong.Ball.w < -1.0f)) {
+ GLPong.Ball.xv = -GLPong.Ball.xv;
+ }
+ if ((GLPong.Ball.y > 0.5f) || (GLPong.Ball.y + GLPong.Ball.h < -0.5f)) {
+ GLPong.Ball.yv = -GLPong.Ball.yv;
+ }
+ if ((GLPong.Ball.z < -9.0f) || (GLPong.Ball.z > -3.0f)) {
+ GLPong.Ball.zv = -GLPong.Ball.zv;
+ }
+}
+
void GLPong_Draw() {
char buffer[10];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -274,7 +299,7 @@ void GLPong_Draw() {
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, paddle_texture);
glEnable(GL_TEXTURE_2D);
- glColor3f(1.0f, 1.0f, 1.0f);
+ glColor3f(GLPong.Back.r, GLPong.Back.g, GLPong.Back.b);
glTranslatef(0.0f, 0.0f, GLPong.Back.z);
glBegin(GL_QUADS);
glTexCoord2f(0.832f, 1.0f); glVertex2f(GLPong.Back.w / 2, GLPong.Back.h / 2); /* Upper Right */
@@ -287,6 +312,7 @@ void GLPong_Draw() {
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, ball_texture);
glEnable(GL_TEXTURE_2D);
+ glColor3f(GLPong.Ball.r, GLPong.Ball.g, GLPong.Ball.b);
glTranslatef(GLPong.Ball.x, GLPong.Ball.y, GLPong.Ball.z);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(GLPong.Ball.w, GLPong.Ball.h); /* Lower Left */
@@ -303,6 +329,7 @@ void GLPong_Draw() {
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, paddle_texture);
glEnable(GL_TEXTURE_2D);
+ glColor3f(GLPong.Front.r, GLPong.Front.g, GLPong.Front.b);
glTranslatef(GLPong.Mouse.x, -GLPong.Mouse.y, GLPong.Front.z);
glBegin(GL_QUADS);
glTexCoord2f(0.168f, 1.0f); glVertex2f(GLPong.Front.w / 2, GLPong.Front.h / 2); /* Upper Right */
@@ -326,21 +353,6 @@ void GLPong_CleanUp() {
}
-void GLPong_Move() {
- GLPong.Ball.x += GLPong.Ball.xv;
- GLPong.Ball.y += GLPong.Ball.yv;
- GLPong.Ball.z += GLPong.Ball.zv;
- if ((GLPong.Ball.x > 1.0f) || (GLPong.Ball.x + GLPong.Ball.w < -1.0f)) {
- GLPong.Ball.xv = -GLPong.Ball.xv;
- }
- if ((GLPong.Ball.y > 0.5f) || (GLPong.Ball.y + GLPong.Ball.h < -0.5f)) {
- GLPong.Ball.yv = -GLPong.Ball.yv;
- }
- if ((GLPong.Ball.z < -9.0f) || (GLPong.Ball.z > -3.0f)) {
- GLPong.Ball.zv = -GLPong.Ball.zv;
- }
-}
-
__inline__ unsigned int NextPow2(unsigned int value) {
unsigned int x;
__asm("dec %1\n\t"
@@ -394,25 +406,3 @@ GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface) {
return texture;
}
-
-void glEnable2D() {
- int vPort[4];
-
- glGetIntegerv(GL_VIEWPORT, vPort);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- glOrtho(0, vPort[2], vPort[3], 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-}
-
-void glDisable2D() {
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-}
diff --git a/glpong3d.h b/glpong3d.h
index dfe6cab..9cd2bc9 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -4,11 +4,23 @@
#include "SDL.h"
#include "SDL_opengl.h"
-#include "ball.h"
-#include "paddle.h"
-
GLuint background;
+GLuint paddle_texture;
+GLuint ball_texture;
+
+typedef struct {
+ GLfloat w, h, x, y, z;
+ GLfloat r, g, b;
+} Paddle_t;
+
+typedef struct {
+ GLfloat w, h, x, y, z;
+ GLfloat r, g, b;
+ GLfloat xv, yv, zv;
+ GLfloat rotate;
+} Ball_t;
+
typedef struct {
GLfloat x, y;
} Mouse_t;
@@ -40,7 +52,5 @@ void GLPong_Move();
GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface);
__inline__ unsigned int NextPow2(unsigned int value);
-void glEnable2D();
-void glDisable2D();
#endif
diff --git a/paddle.c b/paddle.c
deleted file mode 100644
index 36f33e7..0000000
--- a/paddle.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "SDL.h"
-#include "SDL_opengl.h"
-
-#include "glpong3d.h"
-#include "ball.h"
-#include "paddle.h"
diff --git a/paddle.h b/paddle.h
deleted file mode 100644
index c0c8b0c..0000000
--- a/paddle.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef PADDLE_H
-#define PADDLE_H
-
-GLuint paddle_texture;
-GLuint paddle_hit_texture;
-
-typedef struct {
- GLfloat w, h, x, y, z;
- GLfloat r, g, b, a;
-} Paddle_t;
-
-#endif