From: Tobias Gläßer Date: Mon, 2 Feb 2004 16:42:06 +0000 (+0000) Subject: Got rid of the TEXTURE_RECTANGLE NVIDIA extension for the OpenGl mode. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cf0b64c4246eebd618e345660e1ffcb3d660fbd2;p=supertux.git Got rid of the TEXTURE_RECTANGLE NVIDIA extension for the OpenGl mode. SVN-Revision: 110 --- diff --git a/src/intro.c b/src/intro.c index a8ccb237f..7df97b23f 100644 --- a/src/intro.c +++ b/src/intro.c @@ -146,7 +146,7 @@ int intro(void) ++scene; /* Helicopter begins to fly in: */ - erasecenteredtext(intro_text[0], 456, bkgd.sdl_surface, NO_UPDATE, 1); + erasecenteredtext(intro_text[0], 456, &bkgd, NO_UPDATE, 1); text_drawf(&blue_text, intro_text[1], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } @@ -200,7 +200,7 @@ int intro(void) texture_draw(&tux_upset, 270, 400, UPDATE); - erasecenteredtext(intro_text[1], 456, bkgd.sdl_surface, UPDATE, 1); + erasecenteredtext(intro_text[1], 456, &bkgd, UPDATE, 1); text_drawf(&blue_text, intro_text[2], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } @@ -254,7 +254,7 @@ int intro(void) texture_draw(&tux_mad, 270, 400, UPDATE); - erasecenteredtext(intro_text[2], 456, bkgd.sdl_surface, UPDATE, 1); + erasecenteredtext(intro_text[2], 456, &bkgd, UPDATE, 1); text_drawf(&blue_text, intro_text[3], 0,-8, A_HMIDDLE, A_BOTTOM, 0, NO_UPDATE); } diff --git a/src/screen.c b/src/screen.c index b5bd3f893..bbd2c60e8 100644 --- a/src/screen.c +++ b/src/screen.c @@ -146,7 +146,7 @@ SDL_UpdateRect(scr, x, y, w, h); /* --- ERASE TEXT: --- */ -void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize) +void erasetext(char * text, int x, int y, texture_type * ptexture, int update, int shadowsize) { SDL_Rect dest; @@ -159,7 +159,7 @@ void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int sh if (dest.w > screen->w) dest.w = screen->w; - SDL_BlitSurface(surf, &dest, screen, &dest); + texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update); if (update == UPDATE) update_rect(screen, dest.x, dest.y, dest.w, dest.h); @@ -168,7 +168,7 @@ void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int sh /* --- ERASE CENTERED TEXT: --- */ -void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize) +void erasecenteredtext(char * text, int y, texture_type * ptexture, int update, int shadowsize) { - erasetext(text, screen->w / 2 - (strlen(text) * 8), y, surf, update, shadowsize); + erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize); } diff --git a/src/screen.h b/src/screen.h index 78f633650..7eb8bf8bf 100644 --- a/src/screen.h +++ b/src/screen.h @@ -16,14 +16,8 @@ #include #ifndef NOOPENGL #include - -#ifndef GL_NV_texture_rectangle -#define GL_TEXTURE_RECTANGLE_NV 0x84F5 -#define GL_TEXTURE_BINDING_RECTANGLE_NV 0x84F6 -#define GL_PROXY_TEXTURE_RECTANGLE_NV 0x84F7 -#define GL_MAX_RECTANGLE_TEXTURE_SIZE_NV 0x84F8 -#endif #endif +#include "texture.h" #define NO_UPDATE 0 #define UPDATE 1 @@ -36,8 +30,8 @@ void fillrect(float x, float y, float w, float h, float r, float g, float b); void updatescreen(void); void flipscreen(void); SDL_Surface * load_image(char * file, int use_alpha); -void erasetext(char * text, int x, int y, SDL_Surface * surf, int update, int shadowsize); -void erasecenteredtext(char * text, int y, SDL_Surface * surf, int update, int shadowsize); +void erasetext(char * text, int x, int y, texture_type * surf, int update, int shadowsize); +void erasecenteredtext(char * text, int y, texture_type * surf, int update, int shadowsize); void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h); #endif /*SUPERTUX_SCREEN_H*/ diff --git a/src/texture.c b/src/texture.c index a3b093076..90ccd5959 100644 --- a/src/texture.c +++ b/src/texture.c @@ -62,6 +62,71 @@ void texture_load_part_gl(texture_type* ptexture, char * file, int x, int y, int texture_create_gl(ptexture->sdl_surface,&ptexture->gl_texture); } +/* Quick utility function for texture creation */ +static int power_of_two(int input) +{ + int value = 1; + + while ( value < input ) { + value <<= 1; + } + return value; +} + +void texture_create_gl(SDL_Surface * surf, GLint * tex) +{ + Uint32 saved_flags; + Uint8 saved_alpha; + int w, h; + SDL_Surface *conv; + + w = power_of_two(surf->w); + h = power_of_two(surf->h), + conv = SDL_CreateRGBSurface(surf->flags, w, h, surf->format->BitsPerPixel, +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); +#else + + 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); +#endif + + /* Save the alpha blending attributes */ + saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); + saved_alpha = surf->format->alpha; + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, 0, 0); + } + + SDL_BlitSurface(surf, 0, conv, 0); + + /* Restore the alpha blending attributes */ + if ( (saved_flags & SDL_SRCALPHA) + == SDL_SRCALPHA ) + { + SDL_SetAlpha(surf, saved_flags, saved_alpha); + } + + + glGenTextures(1, &*tex); + + glBindTexture(GL_TEXTURE_2D , *tex); + glEnable(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + SDL_FreeSurface(conv); +} + +void texture_free_gl(texture_type* ptexture) +{ + SDL_FreeSurface(ptexture->sdl_surface); + glDeleteTextures(1, &ptexture->gl_texture); +} + void texture_draw_gl(texture_type* ptexture, float x, float y, int update) { @@ -71,16 +136,15 @@ void texture_draw_gl(texture_type* ptexture, float x, float y, int update) glColor4ub(255, 255, 255,255); - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(x, y); - glTexCoord2f((float)ptexture->w, 0); + glTexCoord2f((float)ptexture->w / (float)power_of_two(ptexture->w), 0); glVertex2f((float)ptexture->w+x, y); - glTexCoord2f((float)ptexture->w, (float)ptexture->h); - glVertex2f((float)ptexture->w+x, (float)ptexture->h+y); - glTexCoord2f(0, (float)ptexture->h); + glTexCoord2f((float)ptexture->w / (float)power_of_two(ptexture->w), (float)ptexture->h / (float)power_of_two(ptexture->h)); glVertex2f((float)ptexture->w+x, (float)ptexture->h+y); + glTexCoord2f(0, (float)ptexture->h / (float)power_of_two(ptexture->h)); glVertex2f(x, (float)ptexture->h+y); glEnd(); @@ -91,99 +155,49 @@ void texture_draw_bg_gl(texture_type* ptexture, int update) { glColor3ub(255, 255, 255); - glEnable(GL_TEXTURE_RECTANGLE_NV); - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture); glBegin(GL_QUADS); glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f((float)ptexture->w, 0); + glTexCoord2f((float)ptexture->w / (float)power_of_two(ptexture->w), 0); glVertex2f(screen->w, 0); - glTexCoord2f((float)ptexture->w, (float)ptexture->h); + glTexCoord2f((float)ptexture->w / (float)power_of_two(ptexture->w), (float)ptexture->h / power_of_two(ptexture->h)); glVertex2f(screen->w, screen->h); - glTexCoord2f(0, (float)ptexture->h); + glTexCoord2f(0, (float)ptexture->h / (float)power_of_two(ptexture->h)); glVertex2f(0, screen->h); glEnd(); } void texture_draw_part_gl(texture_type* ptexture,float sx, float sy, float x, float y, float w, float h, int update) { +/*FIXME: The texture isn't drawn to the correct x,y positions.*/ - glBindTexture(GL_TEXTURE_RECTANGLE_NV, ptexture->gl_texture); + glBindTexture(GL_TEXTURE_2D, ptexture->gl_texture); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255, 255, 255,255); - glEnable(GL_TEXTURE_RECTANGLE_NV); + glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); - glTexCoord2f(x, y); - glVertex2f(x, y); - glTexCoord2f(x+w, y); - glVertex2f(w+x, y); - glTexCoord2f(x+w, y+h); - glVertex2f(w+x, h+y); - glTexCoord2f(x, y+h); - glVertex2f(x, h+y); + glTexCoord2f(sx / (float)power_of_two(ptexture->w), sy / (float)power_of_two(ptexture->h)); + glVertex2f(sx, sy); + glTexCoord2f((float)(sx + w) / (float)power_of_two(ptexture->w), sy / (float)power_of_two(ptexture->h)); + glVertex2f(w+sx, sy); + glTexCoord2f((sx+w) / (float)power_of_two(ptexture->w), (sy+h) / (float)power_of_two(ptexture->h)); + glVertex2f(w +sx, h+sy); + glTexCoord2f(sx / (float)power_of_two(ptexture->w), (float)(sy+h) / (float)power_of_two(ptexture->h)); + glVertex2f(sx, h+sy); glEnd(); glDisable(GL_BLEND); } - -void texture_create_gl(SDL_Surface * surf, GLint * tex) -{ - Uint32 saved_flags; - Uint8 saved_alpha; - - SDL_Surface *conv; - conv = SDL_CreateRGBSurface(surf->flags, surf->w, surf->h, surf->format->BitsPerPixel, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); -#else - - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); -#endif - - /* Save the alpha blending attributes */ - saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); - saved_alpha = surf->format->alpha; - if ( (saved_flags & SDL_SRCALPHA) - == SDL_SRCALPHA ) - { - SDL_SetAlpha(surf, 0, 0); - } - - SDL_BlitSurface(surf, 0, conv, 0); - - /* Restore the alpha blending attributes */ - if ( (saved_flags & SDL_SRCALPHA) - == SDL_SRCALPHA ) - { - SDL_SetAlpha(surf, saved_flags, saved_alpha); - } - - - glGenTextures(1, &*tex); - - glBindTexture(GL_TEXTURE_RECTANGLE_NV , *tex); - glEnable(GL_TEXTURE_RECTANGLE_NV); - glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel); - glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB10_A2, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - SDL_FreeSurface(conv); -} - -void texture_free_gl(texture_type* ptexture) -{ - SDL_FreeSurface(ptexture->sdl_surface); - glDeleteTextures(1, &ptexture->gl_texture); -} #endif void texture_load_sdl(texture_type* ptexture, char * file, int use_alpha)