diff options
Diffstat (limited to 'glpong3d.c')
-rw-r--r-- | glpong3d.c | 72 |
1 files changed, 31 insertions, 41 deletions
@@ -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();
-}
|