diff options
-rw-r--r-- | glpong3d.c | 23 | ||||
-rw-r--r-- | glpong3d.h | 2 |
2 files changed, 24 insertions, 1 deletions
@@ -96,6 +96,11 @@ void GLPong_Init() { printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
printf("OpenGL Extensions: %s\n", glGetString(GL_EXTENSIONS));
+ temp = IMG_Load("background.jpg");
+ if (temp != NULL) {
+ background = SDL_GL_SurfaceToTexture(temp);
+ }
+ SDL_FreeSurface(temp);
temp = IMG_Load("128x128.png");
ball_texture = SDL_GL_SurfaceToTexture(temp);
SDL_FreeSurface(temp);
@@ -163,7 +168,23 @@ void GLPong_HandleEvents() { void GLPong_Draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
+
+ glLoadIdentity();
+ if (background) {
+ glBindTexture(GL_TEXTURE_2D, background);
+ glEnable(GL_TEXTURE_2D);
+ } else {
+ glColor3f(0.0f, 0.0f, 0.0f);
+ }
+ glTranslatef(0.0f, 0.0f, -9.0f);
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.875f, 0.0f); glVertex2f( 1.5f, 1.0f); /* Upper Right */
+ glTexCoord2f(0.125f, 0.0f); glVertex2f(-1.5f, 1.0f); /* Upper Left */
+ glTexCoord2f(0.125f, 1.0f); glVertex2f(-1.5f, -1.0f); /* Lower Left */
+ glTexCoord2f(0.875f, 1.0f); glVertex2f( 1.5f, -1.0f); /* Lower Right */
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+
glLoadIdentity();
glColor3f(0.0f, 1.0f, 0.0f);
@@ -7,6 +7,8 @@ #include "ball.h"
#include "paddle.h"
+GLuint background;
+
typedef struct {
GLfloat x, y;
} Mouse_t;
|