- create_gl(sdl_surface, &gl_texture);
- w = sdl_surface->w;
- h = sdl_surface->h;
-}
-
-SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient,
- int _w, int _h)
-{
- sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h);
- create_gl(sdl_surface, &gl_texture);
- w = sdl_surface->w;
- h = sdl_surface->h;
-}
-
-SurfaceOpenGL::~SurfaceOpenGL()
-{
- glDeleteTextures(1, &gl_texture);
-}
-
-void
-SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * 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),
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
- 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
-#else
- conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
- 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);
- }
-
- // We check all the pixels of the surface to figure out which
- // internal format OpenGL should use for storing it, ie. if no alpha
- // is present store in RGB instead of RGBA, this saves a few bytes
- // of memory, but much more importantly it makes the game look
- // *much* better in 16bit color mode
- int internal_format = GL_RGB10_A2;
- bool has_alpha = false;
-
- unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
- for (int y = 0; y < surf->h; ++y)
- for (int x = 0; x < surf->w; ++x)
- {
- if (buf[(conv->pitch*y + x*4) + 3] != 255)
- {
- has_alpha = true;
- break;
- }
- }
-
- if (!has_alpha)
- {
- internal_format = GL_RGB;
- }
-
- glGenTextures(1, &*tex);
- glBindTexture(GL_TEXTURE_2D , *tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
- glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-
- SDL_FreeSurface(conv);
-}
-
-int
-SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
-{
- float pw = power_of_two(w);
- float ph = power_of_two(h);
-
- if(effect & SEMI_TRANSPARENT)
- alpha = 128;
-
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glColor4ub(alpha, alpha, alpha, alpha);
-
- glBindTexture(GL_TEXTURE_2D, gl_texture);
-