Make it build with -DCOMPILE_AMALGATION=ON. Still not certain how intern_draw/next_po...
[supertux.git] / src / video / gl / gl_renderer.cpp
index b578977..81d8743 100644 (file)
@@ -18,7 +18,6 @@
 
 #include <iomanip>
 #include <iostream>
-#include <math.h>
 #include <physfs.h>
 
 #include "supertux/gameconfig.hpp"
 #  define glOrtho glOrthof
 #endif
 
-namespace {
-
-inline void intern_draw(float left, float top, float right, float bottom,
-                        float uv_left, float uv_top,
-                        float uv_right, float uv_bottom,
-                        float angle, float alpha,
-                        const Color& color,
-                        const Blend& blend,
-                        DrawingEffect effect)
-{
-  if(effect & HORIZONTAL_FLIP)
-    std::swap(uv_left, uv_right);
-  if(effect & VERTICAL_FLIP) 
-    std::swap(uv_top, uv_bottom);
-
-  // unrotated blit
-  glBlendFunc(blend.sfactor, blend.dfactor);
-  glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
-  if (angle == 0.0f) {
-    float vertices[] = {
-      left, top,
-      right, top,
-      right, bottom,
-      left, bottom,
-    };
-    glVertexPointer(2, GL_FLOAT, 0, vertices);
-
-    float uvs[] = {
-      uv_left, uv_top,
-      uv_right, uv_top,
-      uv_right, uv_bottom,
-      uv_left, uv_bottom,
-    };
-    glTexCoordPointer(2, GL_FLOAT, 0, uvs);
-
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-  } else {
-    // rotated blit
-    float center_x = (left + right) / 2;
-    float center_y = (top + bottom) / 2;
-
-    float sa = sinf(angle/180.0f*M_PI);
-    float ca = cosf(angle/180.0f*M_PI);
-
-    left  -= center_x;
-    right -= center_x;
-
-    top    -= center_y;
-    bottom -= center_y;
-
-    float vertices[] = {
-      left*ca - top*sa + center_x, left*sa + top*ca + center_y,
-      right*ca - top*sa + center_x, right*sa + top*ca + center_y,
-      right*ca - bottom*sa + center_x, right*sa + bottom*ca + center_y,
-      left*ca - bottom*sa + center_x, left*sa + bottom*ca + center_y
-    };
-    glVertexPointer(2, GL_FLOAT, 0, vertices);
-
-    float uvs[] = {
-      uv_left, uv_top,
-      uv_right, uv_top,
-      uv_right, uv_bottom,
-      uv_left, uv_bottom,
-    };
-    glTexCoordPointer(2, GL_FLOAT, 0, uvs);
-
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-  }
-
-  // FIXME: find a better way to restore the blend mode
-  glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-} // namespace
-
 GLRenderer::GLRenderer() :
   desktop_size(-1, -1),
   screen_size(-1, -1),
@@ -180,7 +101,7 @@ GLRenderer::GLRenderer() :
     throw std::runtime_error(out.str());
   }
   log_info << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
-  log_info << "GL_ARB_texture_non_power_of_two: " << GL_ARB_texture_non_power_of_two << std::endl;
+  log_info << "GLEW_ARB_texture_non_power_of_two: " << static_cast<int>(GLEW_ARB_texture_non_power_of_two) << std::endl;
 #endif
 }
 
@@ -192,7 +113,7 @@ void
 GLRenderer::draw_surface(const DrawingRequest& request)
 {
   const Surface* surface = (const Surface*) request.request_data;
-  GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
+  boost::shared_ptr<GLTexture> gltexture = boost::dynamic_pointer_cast<GLTexture>(surface->get_texture());
   GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());
 
   glBindTexture(GL_TEXTURE_2D, gltexture->get_handle());
@@ -215,8 +136,8 @@ GLRenderer::draw_surface_part(const DrawingRequest& request)
 {
   const SurfacePartRequest* surfacepartrequest
     = (SurfacePartRequest*) request.request_data;
-  const Surface *surface = surfacepartrequest->surface;
-  GLTexture *gltexture = dynamic_cast<GLTexture *>(surface->get_texture());
+  const Surfacesurface = surfacepartrequest->surface;
+  boost::shared_ptr<GLTexture> gltexture = boost::dynamic_pointer_cast<GLTexture>(surface->get_texture());
   GLSurfaceData *surface_data = reinterpret_cast<GLSurfaceData *>(surface->get_surface_data());
 
   float uv_width = surface_data->get_uv_right() - surface_data->get_uv_left();
@@ -520,7 +441,7 @@ GLRenderer::resize(int w, int h)
 {
   // This causes the screen to go black, which is annoying, but seems
   // unavoidable with SDL at the moment
-  SDL_SetVideoMode(w, h, 0, SDL_OPENGL /*| SDL_RESIZABLE*/);
+  SDL_SetVideoMode(w, h, 0, SDL_OPENGL | SDL_RESIZABLE);
 
   g_config->window_size = Size(w, h);
 
@@ -530,15 +451,15 @@ GLRenderer::resize(int w, int h)
 void
 GLRenderer::apply_config()
 {    
-  if (1)
+  if (false)
   {
-    std::cout << "Applying Config:" 
-              << "\n  Desktop: " << desktop_size.width << "x" << desktop_size.height
-              << "\n  Window:  " << g_config->window_size
-              << "\n  FullRes: " << g_config->fullscreen_size
-              << "\n  Aspect:  " << g_config->aspect_size
-              << "\n  Magnif:  " << g_config->magnification
-              << std::endl;
+    log_info << "Applying Config:" 
+             << "\n  Desktop: " << desktop_size.width << "x" << desktop_size.height
+             << "\n  Window:  " << g_config->window_size
+             << "\n  FullRes: " << g_config->fullscreen_size
+             << "\n  Aspect:  " << g_config->aspect_size
+             << "\n  Magnif:  " << g_config->magnification
+             << std::endl;
   }
 
   float target_aspect = static_cast<float>(desktop_size.width) / static_cast<float>(desktop_size.height);