Commit 6da163ab authored by Sam Lantinga's avatar Sam Lantinga

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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404346
parent d45158ea
...@@ -295,7 +295,9 @@ extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); ...@@ -295,7 +295,9 @@ extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval);
extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval);
extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable);
#define SDL_RenderFill SDL_RenderRect #define SDL_RenderPoint SDL_RenderDrawPoint
#define SDL_RenderLine SDL_RenderDrawLine
#define SDL_RenderFill(X) (X) ? SDL_RenderFillRect(X) : SDL_RenderClear()
extern DECLSPEC int SDLCALL SDL_putenv(const char *variable); extern DECLSPEC int SDLCALL SDL_putenv(const char *variable);
......
...@@ -411,12 +411,9 @@ extern DECLSPEC int SDLCALL SDL_DrawPoints ...@@ -411,12 +411,9 @@ extern DECLSPEC int SDLCALL SDL_DrawPoints
/** /**
* Blends a point with an RGBA value. * Blends a point with an RGBA value.
* *
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error. * \return 0 on success, or -1 on error.
*/ */
extern DECLSPEC int SDLCALL SDL_BlendDrawPoint extern DECLSPEC int SDLCALL SDL_BlendPoint
(SDL_Surface * dst, int x, int y, (SDL_Surface * dst, int x, int y,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern DECLSPEC int SDLCALL SDL_BlendPoints extern DECLSPEC int SDLCALL SDL_BlendPoints
...@@ -464,9 +461,9 @@ extern DECLSPEC int SDLCALL SDL_DrawRects ...@@ -464,9 +461,9 @@ extern DECLSPEC int SDLCALL SDL_DrawRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color); (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
/** /**
* Blends the given rectangle with \c color. * Blends an RGBA value into the outline of the given rectangle.
* *
* If \c rect is NULL, the whole surface will have a blended outline of \c color. * If \c rect is NULL, the whole surface will have a blended outline.
* *
* \return 0 on success, or -1 on error. * \return 0 on success, or -1 on error.
*/ */
...@@ -495,7 +492,7 @@ extern DECLSPEC int SDLCALL SDL_FillRects ...@@ -495,7 +492,7 @@ extern DECLSPEC int SDLCALL SDL_FillRects
/** /**
* Blends an RGBA value into the given rectangle. * Blends an RGBA value into the given rectangle.
* *
* If \c rect is NULL, the whole surface will be blended with \c color. * If \c rect is NULL, the whole surface will be blended with the color.
* *
* \return This function returns 0 on success, or -1 on error. * \return This function returns 0 on success, or -1 on error.
*/ */
...@@ -506,6 +503,88 @@ extern DECLSPEC int SDLCALL SDL_BlendFillRects ...@@ -506,6 +503,88 @@ extern DECLSPEC int SDLCALL SDL_BlendFillRects
(SDL_Surface * dst, const SDL_Rect ** rects, int count, (SDL_Surface * dst, const SDL_Rect ** rects, int count,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#if 0
/**
* Draws the given circle with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawCircle
(SDL_Surface * dst, int x, int y, int radius, Uint32 color);
/**
* Blends an RGBA value into the outline of the given circle.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendCircle
(SDL_Surface * dst, int x, int y, int radius,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Fills the given circle with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_FillCircle
(SDL_Surface * dst, int x, int y, int radius, Uint32 color);
/**
* Blends an RGBA value into the given circle.
*
* \return This function returns 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendFillCircle
(SDL_Surface * dst, int x, int y, int radius,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Draws the given ellipse with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_DrawEllipse
(SDL_Surface * dst, int x, int y, int w, int h, Uint32 color);
/**
* Blends an RGBA value into the outline of the given ellipse.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendEllipse
(SDL_Surface * dst, int x, int y, int w, int h,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/**
* Fills the given ellipse with \c color.
*
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.
*
* \return 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_FillEllipse
(SDL_Surface * dst, int x, int y, int w, int h, Uint32 color);
/**
* Blends an RGBA value into the given ellipse.
*
* \return This function returns 0 on success, or -1 on error.
*/
extern DECLSPEC int SDLCALL SDL_BlendFillEllipse
(SDL_Surface * dst, int x, int y, int w, int h,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif // 0
/** /**
* Performs a fast blit from the source surface to the destination surface. * Performs a fast blit from the source surface to the destination surface.
* *
......
...@@ -1137,6 +1137,11 @@ extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode); ...@@ -1137,6 +1137,11 @@ extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode);
*/ */
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode); extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
/**
* \brief Clear the current rendering target with the drawing color
*/
extern DECLSPEC int SDLCALL SDL_RenderClear();
/** /**
* \brief Draw a point on the current rendering target. * \brief Draw a point on the current rendering target.
* *
...@@ -1145,7 +1150,7 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode); ...@@ -1145,7 +1150,7 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y); extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(int x, int y);
/** /**
* \brief Draw some number of points on the current rendering target. * \brief Draw some number of points on the current rendering target.
...@@ -1155,7 +1160,7 @@ extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y); ...@@ -1155,7 +1160,7 @@ extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y);
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderPoints(const SDL_Point * points, extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points,
int count); int count);
/** /**
...@@ -1168,7 +1173,7 @@ extern DECLSPEC int SDLCALL SDL_RenderPoints(const SDL_Point * points, ...@@ -1168,7 +1173,7 @@ extern DECLSPEC int SDLCALL SDL_RenderPoints(const SDL_Point * points,
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2); extern DECLSPEC int SDLCALL SDL_RenderDrawLine(int x1, int y1, int x2, int y2);
/** /**
* \brief Draw a series of connected lines on the current rendering target. * \brief Draw a series of connected lines on the current rendering target.
...@@ -1178,18 +1183,37 @@ extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2); ...@@ -1178,18 +1183,37 @@ extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2);
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderLines(const SDL_Point * points, extern DECLSPEC int SDLCALL SDL_RenderDrawLines(const SDL_Point * points,
int count); int count);
/** /**
* \brief Fill the current rendering target with the drawing color. * \brief Draw a rectangle on the current rendering target with the drawing color.
*
* \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawRect(const SDL_Rect * rect);
/**
* \brief Draw some number of rectangles in the current rendering target with the drawing color.
*
* \param rects A pointer to an array of destination rectangles.
* \param count The number of rectangles.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawRects(const SDL_Rect ** rect, int count);
/**
* \brief Fill a rectangle on the current rendering target with the drawing color.
* *
* \param rect A pointer to the destination rectangle, or NULL for the entire * \param rect A pointer to the destination rectangle, or NULL for the entire
* rendering target. * rendering target.
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderRect(const SDL_Rect * rect); extern DECLSPEC int SDLCALL SDL_RenderFillRect(const SDL_Rect * rect);
/** /**
* \brief Fill some number of rectangles in the current rendering target with the drawing color. * \brief Fill some number of rectangles in the current rendering target with the drawing color.
...@@ -1199,7 +1223,37 @@ extern DECLSPEC int SDLCALL SDL_RenderRect(const SDL_Rect * rect); ...@@ -1199,7 +1223,37 @@ extern DECLSPEC int SDLCALL SDL_RenderRect(const SDL_Rect * rect);
* *
* \return 0 on success, or -1 if there is no rendering context current. * \return 0 on success, or -1 if there is no rendering context current.
*/ */
extern DECLSPEC int SDLCALL SDL_RenderRects(const SDL_Rect ** rect, int count); extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int count);
#if 0
/**
* \brief Draw a circle on the current rendering target with the drawing color.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawCircle(int x, int y, int radius);
/**
* \brief Fill a circle on the current rendering target with the drawing color.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderFillCircle(int x, int y, int radius);
/**
* \brief Draw an ellipse on the current rendering target with the drawing color.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawEllipse(int x, int y, int w, int h);
/**
* \brief Fill an ellipse on the current rendering target with the drawing color.
*
* \return 0 on success, or -1 if there is no rendering context current.
*/
extern DECLSPEC int SDLCALL SDL_RenderFillEllipse(int x, int y, int w, int h);
#endif // 0
/** /**
* \brief Copy a portion of the texture to the current rendering target. * \brief Copy a portion of the texture to the current rendering target.
......
...@@ -23,306 +23,734 @@ ...@@ -23,306 +23,734 @@
#include "SDL_draw.h" #include "SDL_draw.h"
static int
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2, static void
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
unsigned inva = 0xff - a; const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555, draw_end); HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555, draw_end); HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555, draw_end); HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555, draw_end); HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
draw_end);
break;
}
}
} }
static int static void
SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
unsigned inva = 0xff - a; const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565, draw_end); HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565, draw_end); HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565, draw_end); HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565, draw_end); HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break;
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
break;
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
draw_end);
break;
}
}
} }
static int static void
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
unsigned inva = 0xff - a; const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888, draw_end); HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888, draw_end); HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888, draw_end); HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888, draw_end); HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break;
default:
VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
break;
default:
DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
draw_end);
break;
}
}
} }
static int static void
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
unsigned inva = 0xff - a; const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end); HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888, draw_end); HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888, draw_end); HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888, draw_end); HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
default:
VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
break;
default:
DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
draw_end);
break;
}
}
} }
static int static void
SDL_BlendLine_RGB(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
SDL_PixelFormat *fmt = dst->format; const SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a; unsigned r, g, b, a, inva;
switch (fmt->BytesPerPixel) { if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
case 2: r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB, draw_end); HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB, draw_end); HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB, draw_end); HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB, draw_end); HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
case 4:
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB, draw_end); VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB, draw_end); VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB, draw_end); VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB, draw_end); VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
break; break;
} }
return 0; } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
break;
default: default:
SDL_Unsupported(); DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
return -1; break;
}
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
draw_end);
break;
}
} }
} }
static int static void
SDL_BlendLine_RGBA(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a, int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end) SDL_bool draw_end)
{ {
SDL_PixelFormat *fmt = dst->format; const SDL_PixelFormat *fmt = dst->format;
unsigned inva = 0xff - a; unsigned r, g, b, a, inva;
switch (fmt->BytesPerPixel) { if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
case 4: r = DRAW_MUL(_r, _a);
g = DRAW_MUL(_g, _a);
b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
}
inva = (a ^ 0xff);
if (y1 == y2) {
switch (blendMode) { switch (blendMode) {
case SDL_BLENDMODE_BLEND: case SDL_BLENDMODE_BLEND:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA, draw_end); HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
break; break;
case SDL_BLENDMODE_ADD: case SDL_BLENDMODE_ADD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA, draw_end); HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
break; break;
case SDL_BLENDMODE_MOD: case SDL_BLENDMODE_MOD:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA, draw_end); HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break; break;
default: default:
DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA, draw_end); HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
break; break;
} }
return 0; } else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break;
default: default:
SDL_Unsupported(); VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
return -1; break;
} }
} } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
int case SDL_BLENDMODE_BLEND:
SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) break;
{ case SDL_BLENDMODE_ADD:
/* This function doesn't work on surfaces < 8 bpp */ DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
if (dst->format->BitsPerPixel < 8) { break;
SDL_SetError("SDL_BlendLine(): Unsupported surface format"); case SDL_BLENDMODE_MOD:
return (-1); DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
break;
default:
DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
break;
} }
} else {
/* Perform clipping */ switch (blendMode) {
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { case SDL_BLENDMODE_BLEND:
return (0); AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
draw_end);
break;
default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
draw_end);
break;
} }
}
}
static void
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
SDL_bool draw_end)
{
const SDL_PixelFormat *fmt = dst->format;
unsigned r, g, b, a, inva;
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
r = DRAW_MUL(r, a); r = DRAW_MUL(_r, _a);
g = DRAW_MUL(g, a); g = DRAW_MUL(_g, _a);
b = DRAW_MUL(b, a); b = DRAW_MUL(_b, _a);
a = _a;
} else {
r = _r;
g = _g;
b = _b;
a = _a;
} }
inva = (a ^ 0xff);
switch (dst->format->BitsPerPixel) { if (y1 == y2) {
case 15: switch (blendMode) {
switch (dst->format->Rmask) { case SDL_BLENDMODE_BLEND:
case 0x7C00: HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g, break;
b, a, SDL_TRUE); case SDL_BLENDMODE_ADD:
} HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_MOD:
HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
default:
HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break; break;
case 16:
switch (dst->format->Rmask) {
case 0xF800:
return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g,
b, a, SDL_TRUE);
} }
} else if (x1 == x2) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_ADD:
VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_MOD:
VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
default:
VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break; break;
case 32:
switch (dst->format->Rmask) {
case 0x00FF0000:
if (!dst->format->Amask) {
return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r,
g, b, a, SDL_TRUE);
} else {
return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode,
r, g, b, a, SDL_TRUE);
} }
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_ADD:
DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
break;
case SDL_BLENDMODE_MOD:
DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
break;
default:
DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
break; break;
} }
} else {
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
draw_end);
break;
case SDL_BLENDMODE_ADD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
draw_end);
break;
case SDL_BLENDMODE_MOD:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
draw_end);
break; break;
default: default:
AALINE(x1, y1, x2, y2,
DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
draw_end);
break; break;
} }
}
}
if (!dst->format->Amask) { typedef void (*BlendLineFunc) (SDL_Surface * dst,
return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, int x1, int y1, int x2, int y2,
r, g, b, a, SDL_TRUE); int blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end);
static BlendLineFunc
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
{
switch (fmt->BytesPerPixel) {
case 2:
if (fmt->Rmask == 0x7C00) {
return SDL_BlendLine_RGB555;
} else if (fmt->Rmask == 0xF800) {
return SDL_BlendLine_RGB565;
} else {
return SDL_BlendLine_RGB2;
}
break;
case 4:
if (fmt->Rmask == 0x00FF0000) {
if (fmt->Amask) {
return SDL_BlendLine_ARGB8888;
} else {
return SDL_BlendLine_RGB888;
}
} else { } else {
return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, if (fmt->Amask) {
r, g, b, a, SDL_TRUE); return SDL_BlendLine_RGBA4;
} else {
return SDL_BlendLine_RGB4;
}
}
} }
return NULL;
} }
int int
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{ {
int i; BlendLineFunc func;
int x1, y1;
int x2, y2;
int (*func)(SDL_Surface * dst, int x1, int y1, int x2, int y2,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
SDL_bool draw_end) = NULL;
int status = 0;
if (!dst) { if (!dst) {
SDL_SetError("Passed NULL destination surface"); SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
return -1; return -1;
} }
/* This function doesn't work on surfaces < 8 bpp */ func = SDL_CalculateBlendLineFunc(dst->format);
if (dst->format->BitsPerPixel < 8) { if (!func) {
SDL_SetError("SDL_BlendLines(): Unsupported surface format"); SDL_SetError("SDL_BlendLine(): Unsupported surface format");
return -1; return -1;
} }
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { /* Perform clipping */
r = DRAW_MUL(r, a); /* FIXME: We don't actually want to clip, as it may change line slope */
g = DRAW_MUL(g, a); if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
b = DRAW_MUL(b, a); return 0;
} }
/* FIXME: Does this function pointer slow things down significantly? */ func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
switch (dst->format->BitsPerPixel) { return 0;
case 15: }
switch (dst->format->Rmask) {
case 0x7C00: int
func = SDL_BlendLine_RGB555; SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
} int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
break; {
case 16: int i;
switch (dst->format->Rmask) { int x1, y1;
case 0xF800: int x2, y2;
func = SDL_BlendLine_RGB565; SDL_bool draw_end;
} BlendLineFunc func;
break;
case 32: if (!dst) {
switch (dst->format->Rmask) { SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
case 0x00FF0000: return -1;
if (!dst->format->Amask) {
func = SDL_BlendLine_RGB888;
} else {
func = SDL_BlendLine_ARGB8888;
}
break;
}
default:
break;
} }
func = SDL_CalculateBlendLineFunc(dst->format);
if (!func) { if (!func) {
if (!dst->format->Amask) { SDL_SetError("SDL_BlendLines(): Unsupported surface format");
func = SDL_BlendLine_RGB; return -1;
} else {
func = SDL_BlendLine_RGBA;
}
} }
for (i = 1; i < count; ++i) { for (i = 1; i < count; ++i) {
...@@ -337,12 +765,16 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, ...@@ -337,12 +765,16 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
continue; continue;
} }
status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_FALSE); /* Draw the end if it was clipped */
draw_end = (x2 != points[i].x || y2 != points[i].y);
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
} }
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, r, g, b, a); SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
blendMode, r, g, b, a);
} }
return status; return 0;
} }
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */
...@@ -29,12 +29,20 @@ ...@@ -29,12 +29,20 @@
#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255) #define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
#define DRAW_FASTSETPIXEL(x, y, type, bpp, color) \ #define DRAW_FASTSETPIXEL(type) \
*(type *)((Uint8 *)dst->pixels + y * dst->pitch + x * bpp) = (type) color *pixel = (type) color
#define DRAW_FASTSETPIXEL1(x, y) DRAW_FASTSETPIXEL(x, y, Uint8, 1, color); #define DRAW_FASTSETPIXEL1 DRAW_FASTSETPIXEL(Uint8)
#define DRAW_FASTSETPIXEL2(x, y) DRAW_FASTSETPIXEL(x, y, Uint16, 2, color); #define DRAW_FASTSETPIXEL2 DRAW_FASTSETPIXEL(Uint16)
#define DRAW_FASTSETPIXEL4(x, y) DRAW_FASTSETPIXEL(x, y, Uint32, 4, color); #define DRAW_FASTSETPIXEL4 DRAW_FASTSETPIXEL(Uint32)
#define DRAW_FASTSETPIXELXY(x, y, type, bpp, color) \
*(type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ (x) * bpp) = (type) color
#define DRAW_FASTSETPIXELXY1(x, y) DRAW_FASTSETPIXELXY(x, y, Uint8, 1, color)
#define DRAW_FASTSETPIXELXY2(x, y) DRAW_FASTSETPIXELXY(x, y, Uint16, 2, color)
#define DRAW_FASTSETPIXELXY4(x, y) DRAW_FASTSETPIXELXY(x, y, Uint32, 4, color)
#define DRAW_SETPIXEL(setpixel) \ #define DRAW_SETPIXEL(setpixel) \
do { \ do { \
...@@ -74,7 +82,8 @@ do { \ ...@@ -74,7 +82,8 @@ do { \
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \ #define DRAW_SETPIXELXY(x, y, type, bpp, op) \
do { \ do { \
type *pixel = (type *)((Uint8 *)dst->pixels + y * dst->pitch + x * bpp); \ type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
+ (x) * bpp); \
op; \ op; \
} while (0) } while (0)
...@@ -283,7 +292,87 @@ do { \ ...@@ -283,7 +292,87 @@ do { \
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
#define BRESENHAM(x1, y1, x2, y2, op, draw_end) \ /* Horizontal line */
#define HLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (x1 <= x2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (x2-x1+1) : (x2-x1); \
} else { \
pixel = (type *)dst->pixels + y1 * pitch + x2; \
if (!draw_end) { \
++pixel; \
} \
length = draw_end ? (x1-x2+1) : (x1-x2); \
} \
while (length--) { \
op; \
++pixel; \
} \
}
/* Vertical line */
#define VLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
length = draw_end ? (y2-y1+1) : (y2-y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x1; \
if (!draw_end) { \
pixel += pitch; \
} \
length = draw_end ? (y1-y2+1) : (y1-y2); \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Diagonal line */
#define DLINE(type, op, draw_end) \
{ \
int length; \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \
type *pixel; \
if (y1 <= y2) { \
pixel = (type *)dst->pixels + y1 * pitch + x1; \
if (x1 <= x2) { \
++pitch; \
} else { \
--pitch; \
} \
length = (y2-y1); \
} else { \
pixel = (type *)dst->pixels + y2 * pitch + x2; \
if (x2 <= x1) { \
++pitch; \
} else { \
--pitch; \
} \
if (!draw_end) { \
pixel += pitch; \
} \
length = (y1-y2); \
} \
if (draw_end) { \
++length; \
} \
while (length--) { \
op; \
pixel += pitch; \
} \
}
/* Bresenham's line algorithm */
#define BLINE(x1, y1, x2, y2, op, draw_end) \
{ \ { \
int i, deltax, deltay, numpixels; \ int i, deltax, deltay, numpixels; \
int d, dinc1, dinc2; \ int d, dinc1, dinc2; \
...@@ -341,45 +430,123 @@ do { \ ...@@ -341,45 +430,123 @@ do { \
} \ } \
} \ } \
} }
#define DRAWLINE BRESENHAM
/* /* Xiaolin Wu's line algorithm, based on Michael Abrash's implementation */
* Define draw rect macro #define WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
* (not tested, this level of optimization not needed ... yet?) { \
*/ Uint16 ErrorAdj, ErrorAcc; \
#define DRAWRECT(type, op) \ Uint16 ErrorAccTemp, Weighting; \
do { \ int DeltaX, DeltaY, Temp, XDir; \
int width = rect->w; \ unsigned r, g, b, a, inva; \
int height = rect->h; \ \
int pitch = (dst->pitch / dst->format->BytesPerPixel); \ /* Draw the initial pixel, which is always exactly intersected by \
int skip = pitch - width; \ the line and so needs no weighting */ \
type *pixel; \ opaque_op(x1, y1); \
pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ \
{ int n = (width+3)/4; \ /* Draw the final pixel, which is always exactly intersected by the line \
switch (width & 3) { \ and so needs no weighting */ \
case 0: do { op; pixel++; \ if (draw_end) { \
case 3: op; pixel++; \ opaque_op(x2, y2); \
case 2: op; pixel++; \
case 1: op; pixel++; \
} while ( --n > 0 ); \
} \ } \
\
/* Make sure the line runs top to bottom */ \
if (y1 > y2) { \
Temp = y1; y1 = y2; y2 = Temp; \
Temp = x1; x1 = x2; x2 = Temp; \
} \ } \
pixel += skip; \ DeltaY = y2 - y1; \
width -= 1; \ \
height -= 2; \ if ((DeltaX = x2 - x1) >= 0) { \
while (height--) { \ XDir = 1; \
op; pixel += width; op; pixel += skip; \ } else { \
XDir = -1; \
DeltaX = -DeltaX; /* make DeltaX positive */ \
} \ } \
{ int n = (width+3)/4; \ \
switch (width & 3) { \ /* line is not horizontal, diagonal, or vertical */ \
case 0: do { op; pixel++; \ ErrorAcc = 0; /* initialize the line error accumulator to 0 */ \
case 3: op; pixel++; \ \
case 2: op; pixel++; \ /* Is this an X-major or Y-major line? */ \
case 1: op; pixel++; \ if (DeltaY > DeltaX) { \
} while ( --n > 0 ); \ /* Y-major line; calculate 16-bit fixed-point fractional part of a \
pixel that X advances each time Y advances 1 pixel, truncating the \
result so that we won't overrun the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaX << 16) / (unsigned long) DeltaY; \
/* Draw all pixels other than the first and last */ \
while (--DeltaY) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the X coord */ \
x1 += XDir; \
} \ } \
y1++; /* Y-major, so always advance Y */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \ } \
} while (0) { \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1 + XDir, y1); \
} \
} \
} else { \
/* X-major line; calculate 16-bit fixed-point fractional part of a \
pixel that Y advances each time X advances 1 pixel, truncating the \
result to avoid overrunning the endpoint along the X axis */ \
ErrorAdj = ((unsigned long) DeltaY << 16) / (unsigned long) DeltaX; \
/* Draw all pixels other than the first and last */ \
while (--DeltaX) { \
ErrorAccTemp = ErrorAcc; /* remember currrent accumulated error */ \
ErrorAcc += ErrorAdj; /* calculate error for next pixel */ \
if (ErrorAcc <= ErrorAccTemp) { \
/* The error accumulator turned over, so advance the Y coord */ \
y1++; \
} \
x1 += XDir; /* X-major, so always advance X */ \
/* The IntensityBits most significant bits of ErrorAcc give us the \
intensity weighting for this pixel, and the complement of the \
weighting for the paired pixel */ \
Weighting = ErrorAcc >> 8; \
{ \
a = DRAW_MUL(_a, (Weighting ^ 255)); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1); \
} \
{ \
a = DRAW_MUL(_a, Weighting); \
r = DRAW_MUL(_r, a); \
g = DRAW_MUL(_g, a); \
b = DRAW_MUL(_b, a); \
inva = (a ^ 0xFF); \
blend_op(x1, y1 + 1); \
} \
} \
} \
}
#ifdef AA_LINES
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
WULINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end)
#else
#define AALINE(x1, y1, x2, y2, opaque_op, blend_op, draw_end) \
BLINE(x1, y1, x2, y2, opaque_op, draw_end)
#endif
/* /*
* Define fill rect macro * Define fill rect macro
......
...@@ -23,17 +23,116 @@ ...@@ -23,17 +23,116 @@
#include "SDL_draw.h" #include "SDL_draw.h"
static void
SDL_DrawLine1(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
HLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
} else if (x1 == x2) {
VLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
DLINE(Uint8, DRAW_FASTSETPIXEL1, draw_end);
} else {
BLINE(x1, y1, x2, y2, DRAW_FASTSETPIXELXY1, draw_end);
}
}
static void
SDL_DrawLine2(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
HLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else if (x1 == x2) {
VLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
DLINE(Uint16, DRAW_FASTSETPIXEL2, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat * fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x7C00) {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB555,
draw_end);
} else if (fmt->Rmask == 0xF800) {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY_BLEND_RGB565,
draw_end);
} else {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY2, DRAW_SETPIXELXY2_BLEND_RGB,
draw_end);
}
}
}
static void
SDL_DrawLine4(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color,
SDL_bool draw_end)
{
if (y1 == y2) {
HLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else if (x1 == x2) {
VLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else if (ABS(x1 - x2) == ABS(y1 - y2)) {
DLINE(Uint32, DRAW_FASTSETPIXEL4, draw_end);
} else {
Uint8 _r, _g, _b, _a;
const SDL_PixelFormat * fmt = dst->format;
SDL_GetRGBA(color, fmt, &_r, &_g, &_b, &_a);
if (fmt->Rmask == 0x00FF0000) {
if (!fmt->Amask) {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_RGB888,
draw_end);
} else {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY_BLEND_ARGB8888,
draw_end);
}
} else {
AALINE(x1, y1, x2, y2,
DRAW_FASTSETPIXELXY4, DRAW_SETPIXELXY4_BLEND_RGB,
draw_end);
}
}
}
typedef void (*DrawLineFunc) (SDL_Surface * dst,
int x1, int y1, int x2, int y2,
Uint32 color, SDL_bool draw_end);
static DrawLineFunc
SDL_CalculateDrawLineFunc(const SDL_PixelFormat * fmt)
{
switch (fmt->BytesPerPixel) {
case 1:
if (fmt->BitsPerPixel < 8) {
break;
}
return SDL_DrawLine1;
case 2:
return SDL_DrawLine2;
case 4:
return SDL_DrawLine4;
}
return NULL;
}
int int
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
{ {
DrawLineFunc func;
if (!dst) { if (!dst) {
SDL_SetError("Passed NULL destination surface"); SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
return -1; return -1;
} }
/* This function doesn't work on surfaces < 8 bpp */ func = SDL_CalculateDrawLineFunc(dst->format);
if (dst->format->BitsPerPixel < 8) { if (!func) {
SDL_SetError("SDL_DrawLine(): Unsupported surface format"); SDL_SetError("SDL_DrawLine(): Unsupported surface format");
return -1; return -1;
} }
...@@ -41,23 +140,10 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) ...@@ -41,23 +140,10 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
/* Perform clipping */ /* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */ /* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
return (0); return 0;
} }
switch (dst->format->BytesPerPixel) { func(dst, x1, y1, x2, y2, color, SDL_TRUE);
case 1:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
break;
case 2:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
break;
}
return 0; return 0;
} }
...@@ -66,27 +152,27 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, ...@@ -66,27 +152,27 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
Uint32 color) Uint32 color)
{ {
int i; int i;
int x1, y1;
int x2, y2;
SDL_bool draw_end;
DrawLineFunc func;
if (!dst) { if (!dst) {
SDL_SetError("Passed NULL destination surface"); SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
return -1; return -1;
} }
/* This function doesn't work on surfaces < 8 bpp */ func = SDL_CalculateDrawLineFunc(dst->format);
if (dst->format->BitsPerPixel < 8) { if (!func) {
SDL_SetError("SDL_DrawLine(): Unsupported surface format"); SDL_SetError("SDL_DrawLines(): Unsupported surface format");
return -1; return -1;
} }
if (count < 2) {
return 0;
}
for (i = 1; i < count; ++i) { for (i = 1; i < count; ++i) {
int x1 = points[i-1].x; x1 = points[i-1].x;
int y1 = points[i-1].y; y1 = points[i-1].y;
int x2 = points[i].x; x2 = points[i].x;
int y2 = points[i].y; y2 = points[i].y;
/* Perform clipping */ /* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */ /* FIXME: We don't actually want to clip, as it may change line slope */
...@@ -94,20 +180,13 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, ...@@ -94,20 +180,13 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
continue; continue;
} }
switch (dst->format->BytesPerPixel) { /* Draw the end if it was clipped */
case 1: draw_end = (x2 != points[i].x || y2 != points[i].y);
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
break; func(dst, x1, y1, x2, y2, color, draw_end);
case 2:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
break;
} }
if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
SDL_DrawPoint(dst, points[count-1].x, points[count-1].y, color);
} }
return 0; return 0;
} }
......
...@@ -47,16 +47,16 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) ...@@ -47,16 +47,16 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
switch (dst->format->BytesPerPixel) { switch (dst->format->BytesPerPixel) {
case 1: case 1:
DRAW_FASTSETPIXEL1(x, y); DRAW_FASTSETPIXELXY1(x, y);
break; break;
case 2: case 2:
DRAW_FASTSETPIXEL2(x, y); DRAW_FASTSETPIXELXY2(x, y);
break; break;
case 3: case 3:
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
case 4: case 4:
DRAW_FASTSETPIXEL4(x, y); DRAW_FASTSETPIXELXY4(x, y);
break; break;
} }
return 0; return 0;
...@@ -97,16 +97,16 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, ...@@ -97,16 +97,16 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
switch (dst->format->BytesPerPixel) { switch (dst->format->BytesPerPixel) {
case 1: case 1:
DRAW_FASTSETPIXEL1(x, y); DRAW_FASTSETPIXELXY1(x, y);
break; break;
case 2: case 2:
DRAW_FASTSETPIXEL2(x, y); DRAW_FASTSETPIXELXY2(x, y);
break; break;
case 3: case 3:
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
case 4: case 4:
DRAW_FASTSETPIXEL4(x, y); DRAW_FASTSETPIXELXY4(x, y);
break; break;
} }
} }
......
...@@ -96,12 +96,15 @@ static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -96,12 +96,15 @@ static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects); int numrects, const SDL_Rect * rects);
static int GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, static int GL_RenderClear(SDL_Renderer * renderer);
int count); static int GL_RenderDrawPoints(SDL_Renderer * renderer,
static int GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, const SDL_Point * points, int count);
int count); static int GL_RenderDrawLines(SDL_Renderer * renderer,
static int GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, const SDL_Point * points, int count);
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, static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect); const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
...@@ -306,9 +309,11 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -306,9 +309,11 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->LockTexture = GL_LockTexture; renderer->LockTexture = GL_LockTexture;
renderer->UnlockTexture = GL_UnlockTexture; renderer->UnlockTexture = GL_UnlockTexture;
renderer->DirtyTexture = GL_DirtyTexture; renderer->DirtyTexture = GL_DirtyTexture;
renderer->RenderPoints = GL_RenderPoints; renderer->RenderClear = GL_RenderClear;
renderer->RenderLines = GL_RenderLines; renderer->RenderDrawPoints = GL_RenderDrawPoints;
renderer->RenderRects = GL_RenderRects; renderer->RenderDrawLines = GL_RenderDrawLines;
renderer->RenderDrawRects = GL_RenderDrawRects;
renderer->RenderFillRects = GL_RenderFillRects;
renderer->RenderCopy = GL_RenderCopy; renderer->RenderCopy = GL_RenderCopy;
renderer->RenderReadPixels = GL_RenderReadPixels; renderer->RenderReadPixels = GL_RenderReadPixels;
renderer->RenderWritePixels = GL_RenderWritePixels; renderer->RenderWritePixels = GL_RenderWritePixels;
...@@ -1114,7 +1119,23 @@ GL_SetBlendMode(GL_RenderData * data, int blendMode, int isprimitive) ...@@ -1114,7 +1119,23 @@ GL_SetBlendMode(GL_RenderData * data, int blendMode, int isprimitive)
} }
static int 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; GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
int i; int i;
...@@ -1136,7 +1157,8 @@ GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -1136,7 +1157,8 @@ GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int 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; GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
int i; int i;
...@@ -1199,7 +1221,46 @@ GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -1199,7 +1221,46 @@ GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int 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; GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
int i; int i;
......
...@@ -59,12 +59,14 @@ static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -59,12 +59,14 @@ static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels, const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch); int *pitch);
static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, static int SW_RenderDrawPoints(SDL_Renderer * renderer,
int count); const SDL_Point * points, int count);
static int SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, static int SW_RenderDrawLines(SDL_Renderer * renderer,
int count); const SDL_Point * points, int count);
static int SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, static int SW_RenderDrawRects(SDL_Renderer * renderer,
int count); const SDL_Rect ** rects, int count);
static int SW_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect); const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
...@@ -230,9 +232,10 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -230,9 +232,10 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->ActivateRenderer = SW_ActivateRenderer; renderer->ActivateRenderer = SW_ActivateRenderer;
renderer->DisplayModeChanged = SW_DisplayModeChanged; renderer->DisplayModeChanged = SW_DisplayModeChanged;
renderer->RenderPoints = SW_RenderPoints; renderer->RenderDrawPoints = SW_RenderDrawPoints;
renderer->RenderLines = SW_RenderLines; renderer->RenderDrawLines = SW_RenderDrawLines;
renderer->RenderRects = SW_RenderRects; renderer->RenderDrawRects = SW_RenderDrawRects;
renderer->RenderFillRects = SW_RenderFillRects;
renderer->RenderCopy = SW_RenderCopy; renderer->RenderCopy = SW_RenderCopy;
renderer->RenderReadPixels = SW_RenderReadPixels; renderer->RenderReadPixels = SW_RenderReadPixels;
renderer->RenderWritePixels = SW_RenderWritePixels; renderer->RenderWritePixels = SW_RenderWritePixels;
...@@ -539,7 +542,8 @@ SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -539,7 +542,8 @@ SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
} }
static int static int
SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{ {
SW_RenderData *data = (SW_RenderData *) renderer->driverdata; SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Texture *texture = data->texture[data->current_texture]; SDL_Texture *texture = data->texture[data->current_texture];
...@@ -602,7 +606,8 @@ SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -602,7 +606,8 @@ SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int static int
SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{ {
SW_RenderData *data = (SW_RenderData *) renderer->driverdata; SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Texture *texture = data->texture[data->current_texture]; SDL_Texture *texture = data->texture[data->current_texture];
...@@ -670,7 +675,8 @@ SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -670,7 +675,8 @@ SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int static int
SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) SW_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{ {
SW_RenderData *data = (SW_RenderData *) renderer->driverdata; SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Texture *texture = data->texture[data->current_texture]; SDL_Texture *texture = data->texture[data->current_texture];
...@@ -712,7 +718,7 @@ SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -712,7 +718,7 @@ SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
if (renderer->blendMode == SDL_BLENDMODE_NONE || if (renderer->blendMode == SDL_BLENDMODE_NONE ||
renderer->blendMode == SDL_BLENDMODE_MASK) { renderer->blendMode == SDL_BLENDMODE_MASK) {
status = SDL_FillRect(&data->surface, NULL, color); status = SDL_DrawRect(&data->surface, NULL, color);
} else { } else {
status = SDL_BlendRect(&data->surface, NULL, status = SDL_BlendRect(&data->surface, NULL,
renderer->blendMode, renderer->blendMode,
...@@ -725,6 +731,63 @@ SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) ...@@ -725,6 +731,63 @@ SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
return status; return status;
} }
static int
SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
SDL_Texture *texture = data->texture[data->current_texture];
SDL_Rect clip, rect;
Uint32 color = 0;
int i;
int status = 0;
clip.x = 0;
clip.y = 0;
clip.w = texture->w;
clip.h = texture->h;
if (renderer->blendMode == SDL_BLENDMODE_NONE ||
renderer->blendMode == SDL_BLENDMODE_MASK) {
color = SDL_MapRGBA(data->surface.format,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
for (i = 0; i < count; ++i) {
if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
/* Nothing to draw */
continue;
}
if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
SDL_AddDirtyRect(&data->dirty, &rect);
}
if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
&data->surface.pixels,
&data->surface.pitch) < 0) {
return -1;
}
data->surface.clip_rect.w = data->surface.w = rect.w;
data->surface.clip_rect.h = data->surface.h = rect.h;
if (renderer->blendMode == SDL_BLENDMODE_NONE ||
renderer->blendMode == SDL_BLENDMODE_MASK) {
status = SDL_FillRect(&data->surface, NULL, color);
} else {
status = SDL_BlendFillRect(&data->surface, NULL,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
data->renderer->UnlockTexture(data->renderer, texture);
}
return status;
}
static int static int
SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect) const SDL_Rect * srcrect, const SDL_Rect * dstrect)
......
...@@ -90,12 +90,19 @@ struct SDL_Renderer ...@@ -90,12 +90,19 @@ struct SDL_Renderer
int numrects, const SDL_Rect * rects); int numrects, const SDL_Rect * rects);
int (*SetDrawColor) (SDL_Renderer * renderer); int (*SetDrawColor) (SDL_Renderer * renderer);
int (*SetDrawBlendMode) (SDL_Renderer * renderer); int (*SetDrawBlendMode) (SDL_Renderer * renderer);
int (*RenderPoints) (SDL_Renderer * renderer, const SDL_Point * points, int (*RenderClear) (SDL_Renderer * renderer);
int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points,
int count); int count);
int (*RenderLines) (SDL_Renderer * renderer, const SDL_Point * points, int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
int count); int count);
int (*RenderRects) (SDL_Renderer * renderer, const SDL_Rect ** rects, int (*RenderDrawRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
int count); int count);
int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
int count);
int (*RenderDrawEllipse) (SDL_Renderer * renderer, int x, int y,
int w, int h);
int (*RenderFillEllipse) (SDL_Renderer * renderer, int x, int y,
int w, int h);
int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture, int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect); const SDL_Rect * srcrect, const SDL_Rect * dstrect);
int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect, int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
......
...@@ -2483,22 +2483,49 @@ SDL_GetRenderDrawBlendMode(int *blendMode) ...@@ -2483,22 +2483,49 @@ SDL_GetRenderDrawBlendMode(int *blendMode)
} }
int int
SDL_RenderPoint(int x, int y) SDL_RenderClear()
{
SDL_Renderer *renderer;
renderer = SDL_GetCurrentRenderer(SDL_TRUE);
if (!renderer) {
return -1;
}
if (!renderer->RenderClear) {
int blendMode = renderer->blendMode;
int status;
if (blendMode >= SDL_BLENDMODE_BLEND) {
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
}
status = SDL_RenderFillRect(NULL);
if (blendMode >= SDL_BLENDMODE_BLEND) {
SDL_SetRenderDrawBlendMode(blendMode);
}
return status;
}
return renderer->RenderClear(renderer);
}
int
SDL_RenderDrawPoint(int x, int y)
{ {
SDL_Point point; SDL_Point point;
point.x = x; point.x = x;
point.y = y; point.y = y;
return SDL_RenderPoints(&point, 1); return SDL_RenderDrawPoints(&point, 1);
} }
int int
SDL_RenderPoints(const SDL_Point * points, int count) SDL_RenderDrawPoints(const SDL_Point * points, int count)
{ {
SDL_Renderer *renderer; SDL_Renderer *renderer;
if (!points) { if (!points) {
SDL_SetError("SDL_RenderPoints(): Passed NULL points"); SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
return -1; return -1;
} }
...@@ -2506,18 +2533,18 @@ SDL_RenderPoints(const SDL_Point * points, int count) ...@@ -2506,18 +2533,18 @@ SDL_RenderPoints(const SDL_Point * points, int count)
if (!renderer) { if (!renderer) {
return -1; return -1;
} }
if (!renderer->RenderPoints) { if (!renderer->RenderDrawPoints) {
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
} }
if (count < 1) { if (count < 1) {
return 0; return 0;
} }
return renderer->RenderPoints(renderer, points, count); return renderer->RenderDrawPoints(renderer, points, count);
} }
int int
SDL_RenderLine(int x1, int y1, int x2, int y2) SDL_RenderDrawLine(int x1, int y1, int x2, int y2)
{ {
SDL_Point points[2]; SDL_Point points[2];
...@@ -2525,16 +2552,16 @@ SDL_RenderLine(int x1, int y1, int x2, int y2) ...@@ -2525,16 +2552,16 @@ SDL_RenderLine(int x1, int y1, int x2, int y2)
points[0].y = y1; points[0].y = y1;
points[1].x = x2; points[1].x = x2;
points[1].y = y2; points[1].y = y2;
return SDL_RenderLines(points, 2); return SDL_RenderDrawLines(points, 2);
} }
int int
SDL_RenderLines(const SDL_Point * points, int count) SDL_RenderDrawLines(const SDL_Point * points, int count)
{ {
SDL_Renderer *renderer; SDL_Renderer *renderer;
if (!points) { if (!points) {
SDL_SetError("SDL_RenderLines(): Passed NULL points"); SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
return -1; return -1;
} }
...@@ -2542,30 +2569,30 @@ SDL_RenderLines(const SDL_Point * points, int count) ...@@ -2542,30 +2569,30 @@ SDL_RenderLines(const SDL_Point * points, int count)
if (!renderer) { if (!renderer) {
return -1; return -1;
} }
if (!renderer->RenderLines) { if (!renderer->RenderDrawLines) {
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
} }
if (count < 2) { if (count < 2) {
return 0; return 0;
} }
return renderer->RenderLines(renderer, points, count); return renderer->RenderDrawLines(renderer, points, count);
} }
int int
SDL_RenderRect(const SDL_Rect * rect) SDL_RenderDrawRect(const SDL_Rect * rect)
{ {
return SDL_RenderRects(&rect, 1); return SDL_RenderDrawRects(&rect, 1);
} }
int int
SDL_RenderRects(const SDL_Rect ** rects, int count) SDL_RenderDrawRects(const SDL_Rect ** rects, int count)
{ {
SDL_Renderer *renderer; SDL_Renderer *renderer;
int i; int i;
if (!rects) { if (!rects) {
SDL_SetError("SDL_RenderRects(): Passed NULL rects"); SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
return -1; return -1;
} }
...@@ -2573,7 +2600,7 @@ SDL_RenderRects(const SDL_Rect ** rects, int count) ...@@ -2573,7 +2600,7 @@ SDL_RenderRects(const SDL_Rect ** rects, int count)
if (!renderer) { if (!renderer) {
return -1; return -1;
} }
if (!renderer->RenderRects) { if (!renderer->RenderDrawRects) {
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
} }
...@@ -2593,10 +2620,99 @@ SDL_RenderRects(const SDL_Rect ** rects, int count) ...@@ -2593,10 +2620,99 @@ SDL_RenderRects(const SDL_Rect ** rects, int count)
full_rect.w = window->w; full_rect.w = window->w;
full_rect.h = window->h; full_rect.h = window->h;
rect = &full_rect; rect = &full_rect;
return renderer->RenderRects(renderer, &rect, 1); return renderer->RenderDrawRects(renderer, &rect, 1);
}
} }
return renderer->RenderDrawRects(renderer, rects, count);
}
int
SDL_RenderFillRect(const SDL_Rect * rect)
{
return SDL_RenderFillRects(&rect, 1);
}
int
SDL_RenderFillRects(const SDL_Rect ** rects, int count)
{
SDL_Renderer *renderer;
int i;
if (!rects) {
SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
return -1;
}
renderer = SDL_GetCurrentRenderer(SDL_TRUE);
if (!renderer) {
return -1;
}
if (!renderer->RenderFillRects) {
SDL_Unsupported();
return -1;
}
if (count < 1) {
return 0;
}
/* Check for NULL rect, which means fill entire window */
for (i = 0; i < count; ++i) {
if (rects[i] == NULL) {
SDL_Window *window;
SDL_Rect full_rect;
const SDL_Rect *rect;
window = SDL_GetWindowFromID(renderer->window);
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = window->w;
full_rect.h = window->h;
rect = &full_rect;
return renderer->RenderFillRects(renderer, &rect, 1);
}
}
return renderer->RenderFillRects(renderer, rects, count);
}
int
SDL_RenderDrawCircle(int x, int y, int radius)
{
return SDL_RenderDrawEllipse(x, y, 2*radius, 2*radius);
}
int
SDL_RenderFillCircle(int x, int y, int radius)
{
return SDL_RenderFillEllipse(x, y, 2*radius, 2*radius);
}
int SDL_RenderDrawEllipse(int x, int y, int w, int h)
{
SDL_Renderer *renderer;
renderer = SDL_GetCurrentRenderer(SDL_TRUE);
if (!renderer) {
return -1;
}
if (!renderer->RenderDrawEllipse) {
SDL_Unsupported();
return -1;
}
return renderer->RenderDrawEllipse(renderer, x, y, w, h);
}
int SDL_RenderFillEllipse(int x, int y, int w, int h)
{
SDL_Renderer *renderer;
renderer = SDL_GetCurrentRenderer(SDL_TRUE);
if (!renderer) {
return -1;
}
if (!renderer->RenderFillEllipse) {
SDL_Unsupported();
return -1;
} }
return renderer->RenderRects(renderer, rects, count); return renderer->RenderFillEllipse(renderer, x, y, w, h);
} }
int int
......
...@@ -31,11 +31,13 @@ ...@@ -31,11 +31,13 @@
static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
Uint32 flags); Uint32 flags);
static int SDL_DUMMY_RenderPoints(SDL_Renderer * renderer, static int SDL_DUMMY_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count); const SDL_Point * points, int count);
static int SDL_DUMMY_RenderLines(SDL_Renderer * renderer, static int SDL_DUMMY_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count); const SDL_Point * points, int count);
static int SDL_DUMMY_RenderRects(SDL_Renderer * renderer, static int SDL_DUMMY_RenderDrawRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int SDL_DUMMY_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count); const SDL_Rect ** rects, int count);
static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Texture * texture,
...@@ -100,9 +102,10 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -100,9 +102,10 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
} }
SDL_zerop(data); SDL_zerop(data);
renderer->RenderPoints = SDL_DUMMY_RenderPoints; renderer->RenderDrawPoints = SDL_DUMMY_RenderDrawPoints;
renderer->RenderLines = SDL_DUMMY_RenderLines; renderer->RenderDrawLines = SDL_DUMMY_RenderDrawLines;
renderer->RenderRects = SDL_DUMMY_RenderRects; renderer->RenderDrawRects = SDL_DUMMY_RenderDrawRects;
renderer->RenderFillRects = SDL_DUMMY_RenderFillRects;
renderer->RenderCopy = SDL_DUMMY_RenderCopy; renderer->RenderCopy = SDL_DUMMY_RenderCopy;
renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels; renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels; renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels;
...@@ -140,7 +143,7 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -140,7 +143,7 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
} }
static int static int
SDL_DUMMY_RenderPoints(SDL_Renderer * renderer, SDL_DUMMY_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count) const SDL_Point * points, int count)
{ {
SDL_DUMMY_RenderData *data = SDL_DUMMY_RenderData *data =
...@@ -162,7 +165,7 @@ SDL_DUMMY_RenderPoints(SDL_Renderer * renderer, ...@@ -162,7 +165,7 @@ SDL_DUMMY_RenderPoints(SDL_Renderer * renderer,
} }
static int static int
SDL_DUMMY_RenderLines(SDL_Renderer * renderer, SDL_DUMMY_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count) const SDL_Point * points, int count)
{ {
SDL_DUMMY_RenderData *data = SDL_DUMMY_RenderData *data =
...@@ -184,7 +187,7 @@ SDL_DUMMY_RenderLines(SDL_Renderer * renderer, ...@@ -184,7 +187,7 @@ SDL_DUMMY_RenderLines(SDL_Renderer * renderer,
} }
static int static int
SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, SDL_DUMMY_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count) int count)
{ {
SDL_DUMMY_RenderData *data = SDL_DUMMY_RenderData *data =
...@@ -197,7 +200,7 @@ SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, ...@@ -197,7 +200,7 @@ SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
renderer->r, renderer->g, renderer->b, renderer->r, renderer->g, renderer->b,
renderer->a); renderer->a);
return SDL_FillRects(target, rects, count, color); return SDL_DrawRects(target, rects, count, color);
} else { } else {
return SDL_BlendRects(target, rects, count, return SDL_BlendRects(target, rects, count,
renderer->blendMode, renderer->blendMode,
...@@ -206,6 +209,29 @@ SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, ...@@ -206,6 +209,29 @@ SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
} }
} }
static int
SDL_DUMMY_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
SDL_DUMMY_RenderData *data =
(SDL_DUMMY_RenderData *) renderer->driverdata;
SDL_Surface *target = data->screens[data->current_screen];
if (renderer->blendMode == SDL_BLENDMODE_NONE ||
renderer->blendMode == SDL_BLENDMODE_MASK) {
Uint32 color = SDL_MapRGBA(target->format,
renderer->r, renderer->g, renderer->b,
renderer->a);
return SDL_FillRects(target, rects, count, color);
} else {
return SDL_BlendFillRects(target, rects, count,
renderer->blendMode,
renderer->r, renderer->g, renderer->b,
renderer->a);
}
}
static int static int
SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect) const SDL_Rect * srcrect, const SDL_Rect * dstrect)
......
...@@ -503,8 +503,9 @@ SDL_PS3_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) ...@@ -503,8 +503,9 @@ SDL_PS3_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
status = SDL_FillRect(target, &real_rect, color); status = SDL_FillRect(target, &real_rect, color);
} else { } else {
status = status =
SDL_BlendRect(target, &real_rect, renderer->blendMode, SDL_BlendFillRect(target, &real_rect, renderer->blendMode,
renderer->r, renderer->g, renderer->b, renderer->a); renderer->r, renderer->g, renderer->b,
renderer->a);
} }
return status; return status;
} }
......
...@@ -50,12 +50,14 @@ static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -50,12 +50,14 @@ static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch); void **pixels, int *pitch);
static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int X11_SetDrawBlendMode(SDL_Renderer * renderer); static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
static int X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, static int X11_RenderDrawPoints(SDL_Renderer * renderer,
int count); const SDL_Point * points, int count);
static int X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, static int X11_RenderDrawLines(SDL_Renderer * renderer,
int count); const SDL_Point * points, int count);
static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, static int X11_RenderDrawRects(SDL_Renderer * renderer,
int count); const SDL_Rect ** rects, int count);
static int X11_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect); const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
...@@ -208,9 +210,10 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -208,9 +210,10 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->LockTexture = X11_LockTexture; renderer->LockTexture = X11_LockTexture;
renderer->UnlockTexture = X11_UnlockTexture; renderer->UnlockTexture = X11_UnlockTexture;
renderer->SetDrawBlendMode = X11_SetDrawBlendMode; renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
renderer->RenderPoints = X11_RenderPoints; renderer->RenderDrawPoints = X11_RenderDrawPoints;
renderer->RenderLines = X11_RenderLines; renderer->RenderDrawLines = X11_RenderDrawLines;
renderer->RenderRects = X11_RenderRects; renderer->RenderDrawRects = X11_RenderDrawRects;
renderer->RenderFillRects = X11_RenderFillRects;
renderer->RenderCopy = X11_RenderCopy; renderer->RenderCopy = X11_RenderCopy;
renderer->RenderReadPixels = X11_RenderReadPixels; renderer->RenderReadPixels = X11_RenderReadPixels;
renderer->RenderWritePixels = X11_RenderWritePixels; renderer->RenderWritePixels = X11_RenderWritePixels;
...@@ -600,7 +603,8 @@ renderdrawcolor(SDL_Renderer * renderer, int premult) ...@@ -600,7 +603,8 @@ renderdrawcolor(SDL_Renderer * renderer, int premult)
} }
static int static int
X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{ {
X11_RenderData *data = (X11_RenderData *) renderer->driverdata; X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
...@@ -649,7 +653,8 @@ X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -649,7 +653,8 @@ X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int static int
X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{ {
X11_RenderData *data = (X11_RenderData *) renderer->driverdata; X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
...@@ -787,7 +792,52 @@ X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) ...@@ -787,7 +792,52 @@ X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
} }
static int static int
X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{
X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_Rect clip, rect;
unsigned long foreground;
XRectangle *xrects, *xrect;
int i, xcount;
clip.x = 0;
clip.y = 0;
clip.w = window->w;
clip.h = window->h;
foreground = renderdrawcolor(renderer, 1);
XSetForeground(data->display, data->gc, foreground);
xrect = xrects = SDL_stack_alloc(XRectangle, count);
xcount = 0;
for (i = 0; i < count; ++i) {
if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
continue;
}
xrect->x = (short)rect.x;
xrect->y = (short)rect.y;
xrect->width = (unsigned short)rect.w;
xrect->height = (unsigned short)rect.h;
++xrect;
++xcount;
if (data->makedirty) {
SDL_AddDirtyRect(&data->dirty, &rect);
}
}
if (xcount > 0) {
XDrawRectangles(data->display, data->drawable, data->gc,
xrects, xcount);
}
SDL_stack_free(xpoints);
return 0;
}
static int
X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
{ {
X11_RenderData *data = (X11_RenderData *) renderer->driverdata; X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
......
...@@ -50,6 +50,10 @@ SDL_X11_SYM(int,XDefineCursor,(Display* a,Window b,Cursor c),(a,b,c),return) ...@@ -50,6 +50,10 @@ SDL_X11_SYM(int,XDefineCursor,(Display* a,Window b,Cursor c),(a,b,c),return)
SDL_X11_SYM(int,XDeleteProperty,(Display* a,Window b,Atom c),(a,b,c),return) SDL_X11_SYM(int,XDeleteProperty,(Display* a,Window b,Atom c),(a,b,c),return)
SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return) SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return)
SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return) SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return)
SDL_X11_SYM(int,XDrawLines,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XDrawPoint,(Display* a, Drawable b, GC c, int d, int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XDrawPoints,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XDrawRectangles,(Display* a,Drawable b,GC c,XRectangle* d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XFillRectangles,(Display* a,Drawable b,GC c,XRectangle* d,int e),(a,b,c,d,e),return) SDL_X11_SYM(int,XFillRectangles,(Display* a,Drawable b,GC c,XRectangle* d,int e),(a,b,c,d,e),return)
SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return) SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return)
SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return) SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return)
...@@ -95,9 +99,6 @@ SDL_X11_SYM(Display*,XOpenDisplay,(_Xconst char* a),(a),return) ...@@ -95,9 +99,6 @@ SDL_X11_SYM(Display*,XOpenDisplay,(_Xconst char* a),(a),return)
SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b),(a,b),return) SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b),(a,b),return)
SDL_X11_SYM(int,XPending,(Display* a),(a),return) SDL_X11_SYM(int,XPending,(Display* a),(a),return)
SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j),(a,b,c,d,e,f,g,h,i,j),return) SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j),(a,b,c,d,e,f,g,h,i,j),return)
SDL_X11_SYM(int,XDrawLines,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XDrawPoint,(Display* a, Drawable b, GC c, int d, int e),(a,b,c,d,e),return)
SDL_X11_SYM(int,XDrawPoints,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
SDL_X11_SYM(int,XQueryColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return) SDL_X11_SYM(int,XQueryColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return)
SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return) SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return)
SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return) SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return)
......
CFLAGS := -W -Wall -Wextra -g `sdl-config --cflags` CFLAGS := -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
LDFLAGS := `sdl-config --libs` LDFLAGS := `sdl-config --libs`
# If it doesn't pick up defaults # If it doesn't pick up defaults
......
...@@ -341,9 +341,9 @@ static int render_clearScreen (void) ...@@ -341,9 +341,9 @@ static int render_clearScreen (void)
*/ */
/* Clear screen. */ /* Clear screen. */
ret = SDL_RenderRect( NULL ); ret = SDL_RenderFillRect( NULL );
/* /*
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
*/ */
...@@ -413,8 +413,8 @@ static int render_testPrimitives (void) ...@@ -413,8 +413,8 @@ static int render_testPrimitives (void)
ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( &rect ); ret = SDL_RenderFillRect( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
/* Draw a rectangle. */ /* Draw a rectangle. */
...@@ -425,8 +425,8 @@ static int render_testPrimitives (void) ...@@ -425,8 +425,8 @@ static int render_testPrimitives (void)
ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( &rect ); ret = SDL_RenderFillRect( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
/* Draw some points like so: /* Draw some points like so:
...@@ -439,8 +439,8 @@ static int render_testPrimitives (void) ...@@ -439,8 +439,8 @@ static int render_testPrimitives (void)
ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderPoint( x, y ); ret = SDL_RenderDrawPoint( x, y );
if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0))
return -1; return -1;
} }
} }
...@@ -449,29 +449,29 @@ static int render_testPrimitives (void) ...@@ -449,29 +449,29 @@ static int render_testPrimitives (void)
ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 0, 30, 80, 30 ); ret = SDL_RenderDrawLine( 0, 30, 80, 30 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 40, 30, 40, 60 ); ret = SDL_RenderDrawLine( 40, 30, 40, 60 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 0, 0, 29, 29 ); ret = SDL_RenderDrawLine( 0, 0, 29, 29 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 29, 30, 0, 59 ); ret = SDL_RenderDrawLine( 29, 30, 0, 59 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 79, 0, 50, 29 ); ret = SDL_RenderDrawLine( 79, 0, 50, 29 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 79, 59, 50, 30 ); ret = SDL_RenderDrawLine( 79, 59, 50, 30 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
/* See if it's the same. */ /* See if it's the same. */
...@@ -506,8 +506,8 @@ static int render_testPrimitivesBlend (void) ...@@ -506,8 +506,8 @@ static int render_testPrimitivesBlend (void)
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( NULL ); ret = SDL_RenderFillRect( NULL );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
rect.x = 10; rect.x = 10;
rect.y = 25; rect.y = 25;
...@@ -519,8 +519,8 @@ static int render_testPrimitivesBlend (void) ...@@ -519,8 +519,8 @@ static int render_testPrimitivesBlend (void)
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( &rect ); ret = SDL_RenderFillRect( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
rect.x = 30; rect.x = 30;
rect.y = 40; rect.y = 40;
...@@ -532,8 +532,8 @@ static int render_testPrimitivesBlend (void) ...@@ -532,8 +532,8 @@ static int render_testPrimitivesBlend (void)
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( &rect ); ret = SDL_RenderFillRect( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
rect.x = 25; rect.x = 25;
rect.y = 25; rect.y = 25;
...@@ -545,8 +545,8 @@ static int render_testPrimitivesBlend (void) ...@@ -545,8 +545,8 @@ static int render_testPrimitivesBlend (void)
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderRect( &rect ); ret = SDL_RenderFillRect( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0)) if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
return -1; return -1;
/* Draw blended lines, lines for everyone. */ /* Draw blended lines, lines for everyone. */
...@@ -558,8 +558,8 @@ static int render_testPrimitivesBlend (void) ...@@ -558,8 +558,8 @@ static int render_testPrimitivesBlend (void)
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 0, 0, i, 59 ); ret = SDL_RenderDrawLine( 0, 0, i, 59 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
} }
for (i=0; i<SCREEN_H; i+=2) { for (i=0; i<SCREEN_H; i+=2) {
...@@ -570,8 +570,8 @@ static int render_testPrimitivesBlend (void) ...@@ -570,8 +570,8 @@ static int render_testPrimitivesBlend (void)
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderLine( 0, 0, 79, i ); ret = SDL_RenderDrawLine( 0, 0, 79, i );
if (SDL_ATassert( "SDL_RenderLine", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
return -1; return -1;
} }
...@@ -585,8 +585,8 @@ static int render_testPrimitivesBlend (void) ...@@ -585,8 +585,8 @@ static int render_testPrimitivesBlend (void)
((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1; return -1;
ret = SDL_RenderPoint( i, j ); ret = SDL_RenderDrawPoint( i, j );
if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0))
return -1; return -1;
} }
} }
......
...@@ -56,8 +56,7 @@ static void surface_testLoad( SDL_Surface *testsur ) ...@@ -56,8 +56,7 @@ static void surface_testLoad( SDL_Surface *testsur )
/* Set transparent pixel as the pixel at (0,0) */ /* Set transparent pixel as the pixel at (0,0) */
if (face->format->palette) { if (face->format->palette) {
ret = SDL_SetColorKey(face, (SDL_SRCCOLORKEY | SDL_RLEACCEL), ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
*(Uint8 *) face->pixels);
if (SDL_ATassert( "SDL_SetColorKey", ret == 0)) if (SDL_ATassert( "SDL_SetColorKey", ret == 0))
return; return;
} }
...@@ -184,29 +183,29 @@ static void surface_testPrimitivesBlend( SDL_Surface *testsur ) ...@@ -184,29 +183,29 @@ static void surface_testPrimitivesBlend( SDL_Surface *testsur )
return; return;
/* Create some rectangles for each blend mode. */ /* Create some rectangles for each blend mode. */
ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 ); ret = SDL_BlendFillRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
if (SDL_ATassert( "SDL_BlendRect", ret == 0)) if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return; return;
rect.x = 10; rect.x = 10;
rect.y = 25; rect.y = 25;
rect.w = 40; rect.w = 40;
rect.h = 25; rect.h = 25;
ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 ); ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
if (SDL_ATassert( "SDL_BlendRect", ret == 0)) if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return; return;
rect.x = 30; rect.x = 30;
rect.y = 40; rect.y = 40;
rect.w = 45; rect.w = 45;
rect.h = 15; rect.h = 15;
ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 ); ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
if (SDL_ATassert( "SDL_BlendRect", ret == 0)) if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return; return;
rect.x = 25; rect.x = 25;
rect.y = 25; rect.y = 25;
rect.w = 25; rect.w = 25;
rect.h = 25; rect.h = 25;
ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 ); ret = SDL_BlendFillRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 );
if (SDL_ATassert( "SDL_BlendRect", ret == 0)) if (SDL_ATassert( "SDL_BlendFillRect", ret == 0))
return; return;
/* Draw blended lines, lines for everyone. */ /* Draw blended lines, lines for everyone. */
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
* Released under Public Domain. * Released under Public Domain.
*/ */
#include "SDL.h" #include "SDL.h"
#include "SDL_at.h" #include "SDL_at.h"
......
...@@ -58,7 +58,7 @@ DrawPoints(SDL_WindowID window) ...@@ -58,7 +58,7 @@ DrawPoints(SDL_WindowID window)
x = rand() % window_w; x = rand() % window_w;
y = rand() % window_h; y = rand() % window_h;
SDL_RenderPoint(x, y); SDL_RenderDrawPoint(x, y);
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
} }
...@@ -102,16 +102,16 @@ DrawLines(SDL_WindowID window) ...@@ -102,16 +102,16 @@ DrawLines(SDL_WindowID window)
(Uint8) current_color, (Uint8) current_alpha); (Uint8) current_color, (Uint8) current_alpha);
if (i == 0) { if (i == 0) {
SDL_RenderLine(0, 0, window_w - 1, window_h - 1); SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
SDL_RenderLine(0, window_h - 1, window_w - 1, 0); SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2); SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1); SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
} else { } else {
x1 = (rand() % (window_w*2)) - window_w; x1 = (rand() % (window_w*2)) - window_w;
x2 = (rand() % (window_w*2)) - window_w; x2 = (rand() % (window_w*2)) - window_w;
y1 = (rand() % (window_h*2)) - window_h; y1 = (rand() % (window_h*2)) - window_h;
y2 = (rand() % (window_h*2)) - window_h; y2 = (rand() % (window_h*2)) - window_h;
SDL_RenderLine(x1, y1, x2, y2); SDL_RenderDrawLine(x1, y1, x2, y2);
} }
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
...@@ -159,7 +159,7 @@ DrawRects(SDL_WindowID window) ...@@ -159,7 +159,7 @@ DrawRects(SDL_WindowID window)
rect.h = rand() % (window_h / 2); rect.h = rand() % (window_h / 2);
rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2); rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2); rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
SDL_RenderRect(&rect); SDL_RenderFillRect(&rect);
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
} }
...@@ -231,7 +231,7 @@ main(int argc, char *argv[]) ...@@ -231,7 +231,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_SelectRenderer(state->windows[i]); SDL_SelectRenderer(state->windows[i]);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
} }
srand(time(NULL)); srand(time(NULL));
...@@ -251,7 +251,7 @@ main(int argc, char *argv[]) ...@@ -251,7 +251,7 @@ main(int argc, char *argv[])
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_SelectRenderer(event.window.windowID); SDL_SelectRenderer(event.window.windowID);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
break; break;
} }
break; break;
...@@ -262,7 +262,7 @@ main(int argc, char *argv[]) ...@@ -262,7 +262,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_SelectRenderer(state->windows[i]); SDL_SelectRenderer(state->windows[i]);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
DrawRects(state->windows[i]); DrawRects(state->windows[i]);
DrawLines(state->windows[i]); DrawLines(state->windows[i]);
......
...@@ -59,7 +59,7 @@ DrawPoints(SDL_WindowID window) ...@@ -59,7 +59,7 @@ DrawPoints(SDL_WindowID window)
x = rand() % window_w; x = rand() % window_w;
y = rand() % window_h; y = rand() % window_h;
SDL_RenderPoint(x, y); SDL_RenderDrawPoint(x, y);
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
} }
...@@ -100,12 +100,12 @@ DrawLines(SDL_WindowID window) ...@@ -100,12 +100,12 @@ DrawLines(SDL_WindowID window)
SDL_SetRenderDrawColor(255, 255, 255, 255); SDL_SetRenderDrawColor(255, 255, 255, 255);
if (i == -1) { if (i == -1) {
SDL_RenderLine(0, 0, window_w - 1, window_h - 1); SDL_RenderDrawLine(0, 0, window_w - 1, window_h - 1);
SDL_RenderLine(0, window_h - 1, window_w - 1, 0); SDL_RenderDrawLine(0, window_h - 1, window_w - 1, 0);
SDL_RenderLine(0, window_h / 2, window_w - 1, window_h / 2); SDL_RenderDrawLine(0, window_h / 2, window_w - 1, window_h / 2);
SDL_RenderLine(window_w / 2, 0, window_w / 2, window_h - 1); SDL_RenderDrawLine(window_w / 2, 0, window_w / 2, window_h - 1);
} else { } else {
SDL_RenderLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h); SDL_RenderDrawLine(lines[i].x, lines[i].y, lines[i].w, lines[i].h);
} }
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
...@@ -150,7 +150,7 @@ DrawRects(SDL_WindowID window) ...@@ -150,7 +150,7 @@ DrawRects(SDL_WindowID window)
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
for (i = 0; i < num_rects; ++i) { for (i = 0; i < num_rects; ++i) {
SDL_SetRenderDrawColor(255, 127, 0, 255); SDL_SetRenderDrawColor(255, 127, 0, 255);
SDL_RenderRect(&rects[i]); SDL_RenderFillRect(&rects[i]);
} }
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
} }
...@@ -178,7 +178,7 @@ DrawRectLineIntersections(SDL_WindowID window) ...@@ -178,7 +178,7 @@ DrawRectLineIntersections(SDL_WindowID window)
if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) { if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
SDL_SetRenderDrawColor(0, 255, 55, 255); SDL_SetRenderDrawColor(0, 255, 55, 255);
SDL_RenderLine(x1, y1, x2, y2); SDL_RenderDrawLine(x1, y1, x2, y2);
} }
} }
...@@ -197,7 +197,7 @@ DrawRectRectIntersections(SDL_WindowID window) ...@@ -197,7 +197,7 @@ DrawRectRectIntersections(SDL_WindowID window)
SDL_Rect r; SDL_Rect r;
if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
SDL_SetRenderDrawColor(255, 200, 0, 255); SDL_SetRenderDrawColor(255, 200, 0, 255);
SDL_RenderRect(&r); SDL_RenderFillRect(&r);
} }
} }
...@@ -272,7 +272,7 @@ main(int argc, char *argv[]) ...@@ -272,7 +272,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_SelectRenderer(state->windows[i]); SDL_SelectRenderer(state->windows[i]);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
} }
srand(time(NULL)); srand(time(NULL));
...@@ -326,7 +326,7 @@ main(int argc, char *argv[]) ...@@ -326,7 +326,7 @@ main(int argc, char *argv[])
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_SelectRenderer(event.window.windowID); SDL_SelectRenderer(event.window.windowID);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
break; break;
} }
break; break;
...@@ -337,7 +337,7 @@ main(int argc, char *argv[]) ...@@ -337,7 +337,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_SelectRenderer(state->windows[i]); SDL_SelectRenderer(state->windows[i]);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
DrawRects(state->windows[i]); DrawRects(state->windows[i]);
DrawPoints(state->windows[i]); DrawPoints(state->windows[i]);
......
...@@ -83,7 +83,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -83,7 +83,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
/* Move the sprite, bounce at the wall, and draw */ /* Move the sprite, bounce at the wall, and draw */
n = 0; n = 0;
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
for (i = 0; i < NUM_SPRITES; ++i) { for (i = 0; i < NUM_SPRITES; ++i) {
position = &positions[i]; position = &positions[i];
velocity = &velocities[i]; velocity = &velocities[i];
...@@ -158,7 +158,7 @@ main(int argc, char *argv[]) ...@@ -158,7 +158,7 @@ main(int argc, char *argv[])
/* Clear the window, load the sprite and go! */ /* Clear the window, load the sprite and go! */
SDL_SelectRenderer(window); SDL_SelectRenderer(window);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
sprite = LoadSprite(window, "icon.bmp"); sprite = LoadSprite(window, "icon.bmp");
if (!sprite) { if (!sprite) {
...@@ -199,7 +199,7 @@ main(int argc, char *argv[]) ...@@ -199,7 +199,7 @@ main(int argc, char *argv[])
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_SelectRenderer(event.window.windowID); SDL_SelectRenderer(event.window.windowID);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
break; break;
} }
break; break;
......
...@@ -139,21 +139,21 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -139,21 +139,21 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
/* Draw a gray background */ /* Draw a gray background */
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
/* Test points */ /* Test points */
SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF); SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF);
SDL_RenderPoint(0, 0); SDL_RenderDrawPoint(0, 0);
SDL_RenderPoint(window_w-1, 0); SDL_RenderDrawPoint(window_w-1, 0);
SDL_RenderPoint(0, window_h-1); SDL_RenderDrawPoint(0, window_h-1);
SDL_RenderPoint(window_w-1, window_h-1); SDL_RenderDrawPoint(window_w-1, window_h-1);
/* Test horizontal and vertical lines */ /* Test horizontal and vertical lines */
SDL_SetRenderDrawColor(0x00, 0xFF, 0x00, 0xFF); SDL_SetRenderDrawColor(0x00, 0xFF, 0x00, 0xFF);
SDL_RenderLine(1, 0, window_w-2, 0); SDL_RenderDrawLine(1, 0, window_w-2, 0);
SDL_RenderLine(1, window_h-1, window_w-2, window_h-1); SDL_RenderDrawLine(1, window_h-1, window_w-2, window_h-1);
SDL_RenderLine(0, 1, 0, window_h-2); SDL_RenderDrawLine(0, 1, 0, window_h-2);
SDL_RenderLine(window_w-1, 1, window_w-1, window_h-2); SDL_RenderDrawLine(window_w-1, 1, window_w-1, window_h-2);
/* Test fill and copy */ /* Test fill and copy */
SDL_SetRenderDrawColor(0xFF, 0xFF, 0xFF, 0xFF); SDL_SetRenderDrawColor(0xFF, 0xFF, 0xFF, 0xFF);
...@@ -161,32 +161,32 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -161,32 +161,32 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
temp.y = 1; temp.y = 1;
temp.w = sprite_w; temp.w = sprite_w;
temp.h = sprite_h; temp.h = sprite_h;
SDL_RenderRect(&temp); SDL_RenderFillRect(&temp);
SDL_RenderCopy(sprite, NULL, &temp); SDL_RenderCopy(sprite, NULL, &temp);
temp.x = window_w-sprite_w-1; temp.x = window_w-sprite_w-1;
temp.y = 1; temp.y = 1;
temp.w = sprite_w; temp.w = sprite_w;
temp.h = sprite_h; temp.h = sprite_h;
SDL_RenderRect(&temp); SDL_RenderFillRect(&temp);
SDL_RenderCopy(sprite, NULL, &temp); SDL_RenderCopy(sprite, NULL, &temp);
temp.x = 1; temp.x = 1;
temp.y = window_h-sprite_h-1; temp.y = window_h-sprite_h-1;
temp.w = sprite_w; temp.w = sprite_w;
temp.h = sprite_h; temp.h = sprite_h;
SDL_RenderRect(&temp); SDL_RenderFillRect(&temp);
SDL_RenderCopy(sprite, NULL, &temp); SDL_RenderCopy(sprite, NULL, &temp);
temp.x = window_w-sprite_w-1; temp.x = window_w-sprite_w-1;
temp.y = window_h-sprite_h-1; temp.y = window_h-sprite_h-1;
temp.w = sprite_w; temp.w = sprite_w;
temp.h = sprite_h; temp.h = sprite_h;
SDL_RenderRect(&temp); SDL_RenderFillRect(&temp);
SDL_RenderCopy(sprite, NULL, &temp); SDL_RenderCopy(sprite, NULL, &temp);
/* Test diagonal lines */ /* Test diagonal lines */
SDL_SetRenderDrawColor(0x00, 0xFF, 0x00, 0xFF); SDL_SetRenderDrawColor(0x00, 0xFF, 0x00, 0xFF);
SDL_RenderLine(sprite_w, sprite_h, SDL_RenderDrawLine(sprite_w, sprite_h,
window_w-sprite_w-2, window_h-sprite_h-2); window_w-sprite_w-2, window_h-sprite_h-2);
SDL_RenderLine(window_w-sprite_w-2, sprite_h, SDL_RenderDrawLine(window_w-sprite_w-2, sprite_h,
sprite_w, window_h-sprite_h-2); sprite_w, window_h-sprite_h-2);
/* Move the sprite, bounce at the wall, and draw */ /* Move the sprite, bounce at the wall, and draw */
...@@ -302,7 +302,7 @@ main(int argc, char *argv[]) ...@@ -302,7 +302,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
SDL_SelectRenderer(state->windows[i]); SDL_SelectRenderer(state->windows[i]);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
} }
if (LoadSprite("icon.bmp") < 0) { if (LoadSprite("icon.bmp") < 0) {
quit(2); quit(2);
...@@ -348,7 +348,7 @@ main(int argc, char *argv[]) ...@@ -348,7 +348,7 @@ main(int argc, char *argv[])
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
SDL_SelectRenderer(event.window.windowID); SDL_SelectRenderer(event.window.windowID);
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
break; break;
} }
break; break;
......
...@@ -87,7 +87,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) ...@@ -87,7 +87,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite)
/* Draw a gray background */ /* Draw a gray background */
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderRect(NULL); SDL_RenderClear();
/* Move the sprite, bounce at the wall, and draw */ /* Move the sprite, bounce at the wall, and draw */
for (i = 0; i < NUM_SPRITES; ++i) { for (i = 0; i < NUM_SPRITES; ++i) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment