summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-08-04 17:01:27 +0000
committerMatt Turner <mattst88@gmail.com>2006-08-04 17:01:27 +0000
commit30783e44cac2b4a32eedff9ee5052ba61dde0a6c (patch)
treef7fa76a061b9d86bda7e155d9b8149c498e620b5
parent2702663dd712037f01d9dd97663d8f63603ea930 (diff)
Begin working on paddles
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@6 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--glpong3d.c37
-rw-r--r--glpong3d.h7
-rw-r--r--paddle-skyos.pngbin0 -> 11998 bytes
-rw-r--r--paddle.h7
4 files changed, 47 insertions, 4 deletions
diff --git a/glpong3d.c b/glpong3d.c
index a41537c..43798ce 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -45,6 +45,12 @@ void GLPong_Init() {
GLPong.Ball.yv = 0.01f;
GLPong.Ball.zv = -0.01f;
+ GLPong.Front.w = 0.66f;
+ GLPong.Front.h = 0.5f;
+ GLPong.Front.x = -(GLPong.Front.w / 2);
+ GLPong.Front.y = -(GLPong.Front.h / 2);
+ GLPong.Front.z = -3.0f;
+
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
atexit(SDL_Quit);
@@ -88,6 +94,9 @@ void GLPong_Init() {
temp = IMG_Load("128x128.png");
ball_texture = SDL_GL_SurfaceToTexture(temp);
SDL_FreeSurface(temp);
+ temp = IMG_Load("paddle-skyos.png");
+ paddle_texture = SDL_GL_SurfaceToTexture(temp);
+ SDL_FreeSurface(temp);
box = glGenLists(1);
glNewList(box, GL_COMPILE);
@@ -98,9 +107,11 @@ void GLPong_Init() {
glVertex3f(-1.5f, 1.0f, 0.0f); /* Upper Left */
glEnd();
glEndList();
- }
+}
void GLPong_HandleEvents() {
+ Uint8 * key;
+ int x = 0, y = 0;
if (SDL_PollEvent(&GLPong.Event) != 0) {
if (GLPong.Event.type == SDL_QUIT) {
GLPong.done = 1;
@@ -130,6 +141,11 @@ void GLPong_HandleEvents() {
}
}
}
+ key = SDL_GetKeyState(NULL);
+ SDL_GetMouseState(&x, &y);
+ GLPong.Mouse.x = ((float) x / GLPong.w) * 3.3f - 1.65f;
+ GLPong.Mouse.y = ((float) y / GLPong.h) * 2.5f - 1.25f;
+ printf("SDL x,y: %d,%d; OpenGL x,y: %f,%f\n", x, y, GLPong.Mouse.x, GLPong.Mouse.y);
}
void GLPong_Draw() {
@@ -192,7 +208,7 @@ void GLPong_Draw() {
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 1.0f, 1.0f);
glTranslatef(GLPong.Ball.x, GLPong.Ball.y, GLPong.Ball.z);
- glRotatef(GLPong.Ball.rotate, 0.0f, 0.0f, 1.0f);
+ /*glRotatef(GLPong.Ball.rotate, 0.0f, 0.0f, 1.0f);*/
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2f(GLPong.Ball.w, GLPong.Ball.h); /* Lower Left */
glTexCoord2f(1.0f, 1.0f); glVertex2f(0.0f, GLPong.Ball.h); /* Lower Right */
@@ -205,6 +221,18 @@ void GLPong_Draw() {
glTranslatef(0.0f, 0.0f, GLPong.Ball.z);
glCallList(box);
+ glLoadIdentity();
+ glBindTexture(GL_TEXTURE_2D, paddle_texture);
+ glEnable(GL_TEXTURE_2D);
+ 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 */
+ glTexCoord2f(0.832f, 1.0f); glVertex2f(-GLPong.Front.w / 2, GLPong.Front.h / 2); /* Upper Left */
+ glTexCoord2f(0.832f, 0.0f); glVertex2f(-GLPong.Front.w / 2, -GLPong.Front.h / 2); /* Lower Left */
+ glTexCoord2f(0.168f, 0.0f); glVertex2f(GLPong.Front.w / 2, -GLPong.Front.h / 2); /* Lower Right */
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+
SDL_GL_SwapBuffers();
}
@@ -225,7 +253,10 @@ void GLPong_Move() {
if ((GLPong.Ball.z < -9.0f) || (GLPong.Ball.z > -3.0f)) {
GLPong.Ball.zv = -GLPong.Ball.zv;
}
- GLPong.Ball.rotate += 0.0f;
+ /*GLPong.Ball.rotate += 2.0f;
+ if (GLPong.Ball.rotate >= 360.f) {
+ GLPong.Ball.rotate -= 360.0f;
+ }*/
}
__inline__ unsigned int NextPow2(unsigned int value) {
diff --git a/glpong3d.h b/glpong3d.h
index edc6394..76fb8e5 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -7,11 +7,16 @@
#include "ball.h"
#include "paddle.h"
+typedef struct {
+ GLfloat x, y;
+} Mouse_t;
+
struct {
SDL_Event Event;
SDL_Surface * Surface;
Ball_t Ball;
- /*Paddle_t Front, Back;*/
+ Paddle_t Front;
+ Mouse_t Mouse;
GLfloat w;
GLfloat h;
Sint8 done;
diff --git a/paddle-skyos.png b/paddle-skyos.png
new file mode 100644
index 0000000..2bb6972
--- /dev/null
+++ b/paddle-skyos.png
Binary files differ
diff --git a/paddle.h b/paddle.h
index 754cdbf..c9c23a3 100644
--- a/paddle.h
+++ b/paddle.h
@@ -1,4 +1,11 @@
#ifndef PADDLE_H
#define PADDLE_H
+GLuint paddle_texture;
+
+typedef struct {
+ GLfloat w, h, x, y, z;
+ GLfloat r, g, b, a;
+} Paddle_t;
+
#endif