summaryrefslogtreecommitdiff
path: root/glpong3d.c
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 /glpong3d.c
parent2702663dd712037f01d9dd97663d8f63603ea930 (diff)
Begin working on paddles
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@6 4dd1920e-271a-0410-bca0-81b404a81564
Diffstat (limited to 'glpong3d.c')
-rw-r--r--glpong3d.c37
1 files changed, 34 insertions, 3 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) {