From cfb3a61dc358ee8d82294fd28e4090e10252431c Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Fri, 4 Aug 2006 22:11:17 +0000 Subject: Support for background images :P git-svn-id: svn://mattst88.com/svn/glpong3d/trunk@10 4dd1920e-271a-0410-bca0-81b404a81564 --- glpong3d.c | 23 ++++++++++++++++++++++- glpong3d.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) 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; -- cgit v1.2.3