summaryrefslogtreecommitdiff
path: root/glpong3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'glpong3d.c')
-rw-r--r--glpong3d.c60
1 files changed, 12 insertions, 48 deletions
diff --git a/glpong3d.c b/glpong3d.c
index ff1d064..dbd67a2 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -19,6 +19,7 @@ static void GLPong_Draw(void);
static void GLPong_CleanUp(void);
static void GLPong_Move(void);
static void SDL_GL_GetMouseState(Paddle_t * paddle);
+static GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface);
int main(int argc, char * argv[]) {
unsigned int frames = 0;
@@ -73,18 +74,7 @@ static int
GLPong_Init(GLPong_t * GLPong) {
SDL_Surface * Surface = NULL;
SDL_Surface * temp = NULL;
-
- GLPong->Ball.w = 0.5f;
- GLPong->Ball.h = 0.5f;
- GLPong->Ball.coord.x = -(GLPong->Ball.w / 2);
- GLPong->Ball.coord.y = -(GLPong->Ball.h / 2);
- GLPong->Ball.coord.z = GLPONG_FRONT_Z;
- 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;
+ GLuint texture;
GLPong->Front.w = 0.66f;
GLPong->Front.h = 0.5f;
@@ -163,8 +153,10 @@ GLPong_Init(GLPong_t * GLPong) {
printf("OpenGL Extensions: %s\n", glGetString(GL_EXTENSIONS));
/*temp = IMG_Load("ball.png");*/ /* disabled since it's already loaded for the icon */
- ball_texture = SDL_GL_SurfaceToTexture(temp);
- SDL_FreeSurface(temp);
+ texture = SDL_GL_SurfaceToTexture(temp);
+ GLPong_BallInit(texture);
+ SDL_FreeSurface(temp);
+
temp = IMG_Load("paddle-skyos.png");
paddle_texture = SDL_GL_SurfaceToTexture(temp);
SDL_FreeSurface(temp);
@@ -221,38 +213,7 @@ GLPong_HandleEvents(void) {
static void
GLPong_Move(void) {
- GLPong.Ball.coord.x += GLPong.Ball.xv;
- if (GLPong.Ball.coord.x > 1.0f) {
- GLPong.Ball.coord.x = 1.0f;
- GLPong.Ball.xv = -GLPong.Ball.xv;
- } else if (GLPong.Ball.coord.x + GLPong.Ball.w < -1.0f) {
- GLPong.Ball.coord.x = -1.0f - GLPong.Ball.w;
- GLPong.Ball.xv = -GLPong.Ball.xv;
- }
-
- GLPong.Ball.coord.y += GLPong.Ball.yv;
- if (GLPong.Ball.coord.y > 0.5f) {
- GLPong.Ball.coord.y = 0.5f;
- GLPong.Ball.yv = -GLPong.Ball.yv;
- } else if (GLPong.Ball.coord.y + GLPong.Ball.h < -0.5f) {
- GLPong.Ball.coord.y = -0.5f - GLPong.Ball.h;
- GLPong.Ball.yv = -GLPong.Ball.yv;
- }
-
- GLPong.Ball.coord.z += GLPong.Ball.zv;
- if (GLPong.Ball.coord.z < GLPONG_BACK_Z) {
- GLPong.Ball.coord.z = GLPONG_BACK_Z;
- GLPong.Ball.zv = -GLPong.Ball.zv;
- } else if (GLPong.Ball.coord.z > GLPONG_FRONT_Z) {
- GLPong.Ball.coord.z = GLPONG_FRONT_Z;
- GLPong.Ball.zv = -GLPong.Ball.zv;
- }
-
-#ifdef DEBUG
- GLPong.Back.coord.x = GLPong.Ball.coord.x;
- GLPong.Back.coord.y = GLPong.Ball.coord.y;
-#endif
- GLPong_Collide(&GLPong.Ball, &GLPong.Front);
+ GLPong_BallMove();
}
void GLPong_Draw(void) {
@@ -289,11 +250,12 @@ void GLPong_Draw(void) {
GLPong_PaddleDrawBack(&GLPong.Back);
- GLPong_BallDraw(&GLPong.Ball);
+ GLPong_BallDraw();
GLPong_PaddleDrawFront(&GLPong.Front);
}
+#if 0
void GLPong_Collide(Ball_t * ball, const Paddle_t * paddle) {
if (ball->coord.z == paddle->coord.z) {
if (ball->coord.x + ball->w < paddle->coord.x) return; /* if ball is left of paddle */
@@ -308,6 +270,7 @@ void GLPong_Collide(Ball_t * ball, const Paddle_t * paddle) {
printf("x: %.3f, y: %.2f, z: %.2f\n", ball->coord.x, ball->coord.y, ball->coord.z);
}
}
+#endif
void GLPong_CleanUp(void) {
@@ -337,7 +300,8 @@ NextPow2(unsigned int value) {
return x;
}
-GLuint SDL_GL_SurfaceToTexture(SDL_Surface * surface) {
+static GLuint
+SDL_GL_SurfaceToTexture(SDL_Surface * surface) {
GLuint texture;
GLenum format = GL_RGB;