Removed a few things from svn:ignore that are no longer needed to to switch to Cmake
[supertux.git] / src / video / gl_renderer.cpp
index 6fb6480..3654a49 100644 (file)
 #include "obstack/obstackpp.hpp"
 #define LIGHTMAP_DIV 5
 
-namespace
+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);
+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);
+  if (angle == 0.0f)
+    { // unrotated blit
+      glBlendFunc(blend.sfactor, blend.dfactor);
+      glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
+      glBegin(GL_QUADS);
+      glTexCoord2f(uv_left, uv_top);
+      glVertex2f(left, top);
+
+      glTexCoord2f(uv_right, uv_top);
+      glVertex2f(right, top);
+
+      glTexCoord2f(uv_right, uv_bottom);
+      glVertex2f(right, bottom);
+
+      glTexCoord2f(uv_left, uv_bottom);
+      glVertex2f(left, bottom);
+      glEnd();
+    }
+  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;
+
+      glBlendFunc(blend.sfactor, blend.dfactor);
+      glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
+      glBegin(GL_QUADS);
+      glTexCoord2f(uv_left, uv_top);
+      glVertex2f(left*ca - top*sa + center_x,
+                 left*sa + top*ca + center_y);
+
+      glTexCoord2f(uv_right, uv_top);
+      glVertex2f(right*ca - top*sa + center_x,
+                 right*sa + top*ca + center_y);
+
+      glTexCoord2f(uv_right, uv_bottom);
+      glVertex2f(right*ca - bottom*sa + center_x,
+                 right*sa + bottom*ca + center_y);
+
+      glTexCoord2f(uv_left, uv_bottom);
+      glVertex2f(left*ca - bottom*sa + center_x,
+                 left*sa + bottom*ca + center_y);
+      glEnd();
     }
 
-    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;
-
-    glBlendFunc(blend.sfactor, blend.dfactor);
-    glColor4f(color.red, color.green, color.blue, color.alpha * alpha);
-    glBegin(GL_QUADS);
-    glTexCoord2f(uv_left, uv_top);
-    glVertex2f(left*ca - top*sa + center_x,
-               left*sa + top*ca + center_y);
-
-    glTexCoord2f(uv_right, uv_top);
-    glVertex2f(right*ca - top*sa + center_x,
-               right*sa + top*ca + center_y);
-
-    glTexCoord2f(uv_right, uv_bottom);
-    glVertex2f(right*ca - bottom*sa + center_x,
-               right*sa + bottom*ca + center_y);
-
-    glTexCoord2f(uv_left, uv_bottom);
-    glVertex2f(left*ca - bottom*sa + center_x,
-               left*sa + bottom*ca + center_y);
-    glEnd();
-
-    // 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);
-  }
+  // 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 GL
@@ -236,37 +257,73 @@ namespace GL
   }
 
   void
-  Renderer::draw_text(const DrawingRequest& request)
-  {
-    const TextRequest* textrequest = (TextRequest*) request.request_data;
-
-    textrequest->font->draw(this, textrequest->text, request.pos,
-        textrequest->alignment, request.drawing_effect, request.alpha);
-  }
-
-  void
   Renderer::draw_filled_rect(const DrawingRequest& request)
   {
     const FillRectRequest* fillrectrequest
       = (FillRectRequest*) request.request_data;
 
-    float x = request.pos.x;
-    float y = request.pos.y;
-    float w = fillrectrequest->size.x;
-    float h = fillrectrequest->size.y;
-
-    glDisable(GL_TEXTURE_2D);
-    glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
-              fillrectrequest->color.blue, fillrectrequest->color.alpha);
-
-    glBegin(GL_QUADS);
-    glVertex2f(x, y);
-    glVertex2f(x+w, y);
-    glVertex2f(x+w, y+h);
-    glVertex2f(x, y+h);
-    glEnd();
-    glEnable(GL_TEXTURE_2D);
-    glColor4f(1, 1, 1, 1);
+    if (fillrectrequest->radius != 0.0f)
+      {
+        // draw round rect
+        // Keep radius in the limits, so that we get a circle instead of
+        // just graphic junk
+        float radius = std::min(fillrectrequest->radius,
+                                std::min(fillrectrequest->size.x/2,
+                                         fillrectrequest->size.y/2));
+
+        // inner rectangle
+        Rect irect(request.pos.x    + radius,
+                   request.pos.y    + radius,
+                   request.pos.x + fillrectrequest->size.x - radius,
+                   request.pos.y + fillrectrequest->size.y - radius);
+
+        glDisable(GL_TEXTURE_2D);
+        glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
+                  fillrectrequest->color.blue, fillrectrequest->color.alpha);
+
+
+        int n = 8;
+        glBegin(GL_QUAD_STRIP);
+        for(int i = 0; i <= n; ++i)
+          {
+            float x = sinf(i * (M_PI/2) / n) * radius;
+            float y = cosf(i * (M_PI/2) / n) * radius;
+
+            glVertex2f(irect.get_left()  - x, irect.get_top() - y);
+            glVertex2f(irect.get_right() + x, irect.get_top() - y);
+          }
+        for(int i = 0; i <= n; ++i)
+          {
+            float x = cosf(i * (M_PI/2) / n) * radius;
+            float y = sinf(i * (M_PI/2) / n) * radius;
+
+            glVertex2f(irect.get_left()  - x, irect.get_bottom() + y);
+            glVertex2f(irect.get_right() + x, irect.get_bottom() + y);
+          }
+        glEnd();
+        glEnable(GL_TEXTURE_2D);
+        glColor4f(1, 1, 1, 1);
+      }
+    else
+      {
+        float x = request.pos.x;
+        float y = request.pos.y;
+        float w = fillrectrequest->size.x;
+        float h = fillrectrequest->size.y;
+
+        glDisable(GL_TEXTURE_2D);
+        glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
+                  fillrectrequest->color.blue, fillrectrequest->color.alpha);
+
+        glBegin(GL_QUADS);
+        glVertex2f(x, y);
+        glVertex2f(x+w, y);
+        glVertex2f(x+w, y+h);
+        glVertex2f(x, y+h);
+        glEnd();
+        glEnable(GL_TEXTURE_2D);
+        glColor4f(1, 1, 1, 1);
+      }
   }
 
   void