diff src/video/SDL_renderer_gl.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 0267b8b1595c
children 0f958e527e5e
line wrap: on
line diff
--- a/src/video/SDL_renderer_gl.c	Fri Dec 18 08:19:18 2009 +0000
+++ b/src/video/SDL_renderer_gl.c	Wed Dec 23 01:55:00 2009 +0000
@@ -96,12 +96,15 @@
 static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
                             int numrects, const SDL_Rect * rects);
-static int GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
-                           int count);
-static int GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
-                          int count);
-static int GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                          int count);
+static int GL_RenderClear(SDL_Renderer * renderer);
+static int GL_RenderDrawPoints(SDL_Renderer * renderer,
+                               const SDL_Point * points, int count);
+static int GL_RenderDrawLines(SDL_Renderer * renderer,
+                              const SDL_Point * points, int count);
+static int GL_RenderDrawRects(SDL_Renderer * renderer,
+                              const SDL_Rect ** rects, int count);
+static int GL_RenderFillRects(SDL_Renderer * renderer,
+                              const SDL_Rect ** rects, int count);
 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
@@ -306,9 +309,11 @@
     renderer->LockTexture = GL_LockTexture;
     renderer->UnlockTexture = GL_UnlockTexture;
     renderer->DirtyTexture = GL_DirtyTexture;
-    renderer->RenderPoints = GL_RenderPoints;
-    renderer->RenderLines = GL_RenderLines;
-    renderer->RenderRects = GL_RenderRects;
+    renderer->RenderClear = GL_RenderClear;
+    renderer->RenderDrawPoints = GL_RenderDrawPoints;
+    renderer->RenderDrawLines = GL_RenderDrawLines;
+    renderer->RenderDrawRects = GL_RenderDrawRects;
+    renderer->RenderFillRects = GL_RenderFillRects;
     renderer->RenderCopy = GL_RenderCopy;
     renderer->RenderReadPixels = GL_RenderReadPixels;
     renderer->RenderWritePixels = GL_RenderWritePixels;
@@ -1114,7 +1119,23 @@
 }
 
 static int
-GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
+GL_RenderClear(SDL_Renderer * renderer)
+{
+    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+
+    data->glClearColor((GLfloat) renderer->r * inv255f,
+                       (GLfloat) renderer->g * inv255f,
+                       (GLfloat) renderer->b * inv255f,
+                       (GLfloat) renderer->a * inv255f);
+
+    data->glClear(GL_COLOR_BUFFER_BIT);
+
+    return 0;
+}
+
+static int
+GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
+                    int count)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     int i;
@@ -1136,7 +1157,8 @@
 }
 
 static int
-GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
+GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
+                   int count)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     int i;
@@ -1199,7 +1221,46 @@
 }
 
 static int
-GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+GL_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+{
+    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+    int i, x, y;
+    SDL_Point points[4];
+
+    GL_SetBlendMode(data, renderer->blendMode, 1);
+
+    data->glColor4f((GLfloat) renderer->r * inv255f,
+                    (GLfloat) renderer->g * inv255f,
+                    (GLfloat) renderer->b * inv255f,
+                    (GLfloat) renderer->a * inv255f);
+
+    data->glBegin(GL_LINE_LOOP);
+    for (i = 0; i < count; ++i) {
+        const SDL_Rect *rect = rects[i];
+
+        x = rect->x;
+        y = rect->y;
+        data->glVertex2f(0.5f + x, 0.5f + y);
+
+        x = rect->x+rect->w-1;
+        y = rect->y;
+        data->glVertex2f(0.5f + x, 0.5f + y);
+
+        x = rect->x+rect->w-1;
+        y = rect->y+rect->h-1;
+        data->glVertex2f(0.5f + x, 0.5f + y);
+
+        x = rect->x;
+        y = rect->y+rect->h-1;
+        data->glVertex2f(0.5f + x, 0.5f + y);
+    }
+    data->glEnd();
+
+    return 0;
+}
+
+static int
+GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     int i;