summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2006-08-04 22:11:17 +0000
committerMatt Turner <mattst88@gmail.com>2006-08-04 22:11:17 +0000
commitcfb3a61dc358ee8d82294fd28e4090e10252431c (patch)
tree428f1c46625f1d20368de54553fa2da3d0940381
parenta5d8b148782f401357349684954afe670ca45dd6 (diff)
Support for background images :P
git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@10 4dd1920e-271a-0410-bca0-81b404a81564
-rw-r--r--glpong3d.c23
-rw-r--r--glpong3d.h2
2 files changed, 24 insertions, 1 deletions
diff --git a/glpong3d.c b/glpong3d.c
index 26d09d9..b9aee6c 100644
--- a/glpong3d.c
+++ b/glpong3d.c
@@ -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);
diff --git a/glpong3d.h b/glpong3d.h
index 27122ab..dad9526 100644
--- a/glpong3d.h
+++ b/glpong3d.h
@@ -7,6 +7,8 @@
#include "ball.h"
#include "paddle.h"
+GLuint background;
+
typedef struct {
GLfloat x, y;
} Mouse_t;