summaryrefslogtreecommitdiff
path: root/glpong.c
diff options
context:
space:
mode:
Diffstat (limited to 'glpong.c')
-rw-r--r--glpong.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/glpong.c b/glpong.c
index 883d926..b5ad25c 100644
--- a/glpong.c
+++ b/glpong.c
@@ -69,6 +69,8 @@ int main(int argc, char * argv[]) {
/* clean up */
GLPong_BallDeleteAll(GLPong.balls);
+ GLPong_BallDeinit();
+
return 0;
}
@@ -122,9 +124,11 @@ GLPong_Init(GLPong_t * GLPong) {
printf("OpenGL Version: %s\n", glGetString(GL_VERSION));
printf("OpenGL Extensions: %s\n", glGetString(GL_EXTENSIONS));
- ball_texture = SDL_GL_SurfaceToTexture(temp);
+ ball_texture = SDL_GL_NPOTSurfaceToTexture(temp, NULL, NULL);
SDL_FreeSurface(temp);
+ GLPong_BallInit();
+
return 0;
}
@@ -214,8 +218,10 @@ SDL_GL_SurfaceToTexture(SDL_Surface * surface) {
static GLuint
SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * hratio) {
SDL_Surface * pow2 = NULL;
+
unsigned int w = NextPow2(surface->w);
unsigned int h = NextPow2(surface->h);
+
if (wratio) {
*wratio = (GLfloat)surface->w / (GLfloat)h;
}
@@ -223,9 +229,12 @@ SDL_GL_NPOTSurfaceToTexture(SDL_Surface * surface, GLfloat * wratio, GLfloat * h
*hratio = (GLfloat)surface->h/(GLfloat)h;
}
- pow2 = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
- SDL_BlitSurface(surface, NULL, pow2, NULL);
-
- return SDL_GL_SurfaceToTexture(pow2);
+ if ((w != surface->w) || (h != surface->h)) {
+ pow2 = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
+ SDL_BlitSurface(surface, NULL, pow2, NULL);
+ return SDL_GL_SurfaceToTexture(pow2);
+ } else {
+ return SDL_GL_SurfaceToTexture(surface);
+ }
}