diff options
-rw-r--r-- | glpong3d.c | 37 | ||||
-rw-r--r-- | glpong3d.h | 7 | ||||
-rw-r--r-- | paddle-skyos.png | bin | 0 -> 11998 bytes | |||
-rw-r--r-- | paddle.h | 7 |
4 files changed, 47 insertions, 4 deletions
@@ -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) {
@@ -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 Binary files differnew file mode 100644 index 0000000..2bb6972 --- /dev/null +++ b/paddle-skyos.png @@ -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
|