Added RenderPiont() API
Merged the drawing tests into a single test program --HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403363
This commit is contained in:
parent
4f84ec9b5e
commit
f055f6a189
16 changed files with 671 additions and 264 deletions
|
@ -365,6 +365,25 @@ extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
|
|||
extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface
|
||||
(SDL_Surface * src, SDL_PixelFormat * fmt, Uint32 flags);
|
||||
|
||||
/*
|
||||
* This function draws a point with 'color'
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
* can be generated by the SDL_MapRGB() function.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_DrawPoint
|
||||
(SDL_Surface * dst, int x, int y, Uint32 color);
|
||||
|
||||
/*
|
||||
* This function 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.
|
||||
* This function returns 0 on success, or -1 on error.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_BlendPoint
|
||||
(SDL_Surface * dst, int x, int y, int blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
/*
|
||||
* This function draws a line with 'color'
|
||||
* The color should be a pixel of the format used by the surface, and
|
||||
|
|
|
@ -1196,6 +1196,18 @@ extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode);
|
|||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
|
||||
|
||||
/**
|
||||
* \fn int SDL_RenderPoint(int x, int y)
|
||||
*
|
||||
* \brief Draw a point on the current rendering target.
|
||||
*
|
||||
* \param x The x coordinate of the point
|
||||
* \param y The y coordinate of the point
|
||||
*
|
||||
* \return 0 on success, or -1 if there is no rendering context current
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y);
|
||||
|
||||
/**
|
||||
* \fn int SDL_RenderLine(int x1, int y1, int x2, int y2)
|
||||
*
|
||||
|
@ -1208,7 +1220,6 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);
|
|||
*
|
||||
* \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);
|
||||
|
||||
/**
|
||||
|
|
256
src/video/SDL_blendpoint.c
Normal file
256
src/video/SDL_blendpoint.c
Normal file
|
@ -0,0 +1,256 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL_draw.h"
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY_BLEND_RGB555(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY_ADD_RGB555(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB555(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB555(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY_BLEND_RGB565(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY_ADD_RGB565(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB565(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB565(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY_BLEND_RGB888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY_ADD_RGB888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB888(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB888(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, int blendMode,
|
||||
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY_BLEND_ARGB8888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY_ADD_ARGB8888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_ARGB8888(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_ARGB8888(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (fmt->BytesPerPixel) {
|
||||
case 2:
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY2_BLEND_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY2_ADD_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY2_MOD_RGB(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY2_RGB(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
case 4:
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY4_BLEND_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY4_ADD_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY4_MOD_RGB(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY4_RGB(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
unsigned inva = 0xff - a;
|
||||
|
||||
switch (fmt->BytesPerPixel) {
|
||||
case 4:
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
DRAW_SETPIXELXY4_BLEND_RGBA(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
DRAW_SETPIXELXY4_ADD_RGBA(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY4_MOD_RGBA(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY4_RGBA(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r,
|
||||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
SDL_PixelFormat *fmt = dst->format;
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
if (dst->format->BitsPerPixel < 8) {
|
||||
SDL_SetError("SDL_BlendPoint(): Unsupported surface format");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Perform clipping */
|
||||
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
|
||||
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
|
||||
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((blendMode == SDL_BLENDMODE_BLEND)
|
||||
|| (blendMode == SDL_BLENDMODE_ADD)) {
|
||||
r = DRAW_MUL(r, a);
|
||||
g = DRAW_MUL(g, a);
|
||||
b = DRAW_MUL(b, a);
|
||||
}
|
||||
|
||||
switch (fmt->BitsPerPixel) {
|
||||
case 15:
|
||||
switch (fmt->Rmask) {
|
||||
case 0x7C00:
|
||||
return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a);
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
switch (fmt->Rmask) {
|
||||
case 0xF800:
|
||||
return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a);
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
switch (fmt->Rmask) {
|
||||
case 0x00FF0000:
|
||||
if (!fmt->Amask) {
|
||||
return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b,
|
||||
a);
|
||||
} else {
|
||||
return SDL_BlendPoint_ARGB8888(dst, x, y, blendMode, r, g, b,
|
||||
a);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!fmt->Amask) {
|
||||
return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a);
|
||||
} else {
|
||||
return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -29,6 +29,13 @@
|
|||
|
||||
#define DRAW_MUL(_a, _b) (((unsigned)(_a)*(_b))/255)
|
||||
|
||||
#define DRAW_FASTSETPIXEL(x, y, type, bpp, color) \
|
||||
*(type *)(dst->pixels + y * dst->pitch + x * bpp) = (type) color
|
||||
|
||||
#define DRAW_FASTSETPIXEL1(x, y) DRAW_FASTSETPIXEL(x, y, Uint8, 1, color);
|
||||
#define DRAW_FASTSETPIXEL2(x, y) DRAW_FASTSETPIXEL(x, y, Uint16, 2, color);
|
||||
#define DRAW_FASTSETPIXEL4(x, y) DRAW_FASTSETPIXEL(x, y, Uint32, 4, color);
|
||||
|
||||
#define DRAW_SETPIXEL(setpixel) \
|
||||
do { \
|
||||
unsigned sr = r, sg = g, sb = b, sa = a; \
|
||||
|
|
|
@ -23,13 +23,8 @@
|
|||
|
||||
#include "SDL_draw.h"
|
||||
|
||||
#define SETPIXEL(x, y, type, bpp, color) \
|
||||
*(type *)(dst->pixels + y * dst->pitch + x * bpp) = (type) color
|
||||
|
||||
#define SETPIXEL1(x, y) SETPIXEL(x, y, Uint8, 1, color);
|
||||
#define SETPIXEL2(x, y) SETPIXEL(x, y, Uint16, 2, color);
|
||||
#define SETPIXEL4(x, y) SETPIXEL(x, y, Uint32, 4, color);
|
||||
|
||||
int
|
||||
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
||||
{
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
@ -47,16 +42,16 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
|||
|
||||
switch (dst->format->BytesPerPixel) {
|
||||
case 1:
|
||||
DRAWLINE(x1, y1, x2, y2, SETPIXEL1);
|
||||
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
|
||||
break;
|
||||
case 2:
|
||||
DRAWLINE(x1, y1, x2, y2, SETPIXEL2);
|
||||
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
|
||||
break;
|
||||
case 3:
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
case 4:
|
||||
DRAWLINE(x1, y1, x2, y2, SETPIXEL4);
|
||||
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
60
src/video/SDL_drawpoint.c
Normal file
60
src/video/SDL_drawpoint.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
SDL - Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2009 Sam Lantinga
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Sam Lantinga
|
||||
slouken@libsdl.org
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL_draw.h"
|
||||
|
||||
|
||||
int
|
||||
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
||||
{
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
if (dst->format->BitsPerPixel < 8) {
|
||||
SDL_SetError("SDL_DrawLine(): Unsupported surface format");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Perform clipping */
|
||||
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
|
||||
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
|
||||
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (dst->format->BytesPerPixel) {
|
||||
case 1:
|
||||
DRAW_FASTSETPIXEL1(x, y);
|
||||
break;
|
||||
case 2:
|
||||
DRAW_FASTSETPIXEL2(x, y);
|
||||
break;
|
||||
case 3:
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
case 4:
|
||||
DRAW_FASTSETPIXEL4(x, y);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -98,6 +98,7 @@ static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
int numrects, const SDL_Rect * rects);
|
||||
static int GL_SetDrawColor(SDL_Renderer * renderer);
|
||||
static int GL_SetDrawBlendMode(SDL_Renderer * renderer);
|
||||
static int GL_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
||||
static int GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
|
||||
int y2);
|
||||
static int GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
|
||||
|
@ -313,6 +314,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->DirtyTexture = GL_DirtyTexture;
|
||||
renderer->SetDrawColor = GL_SetDrawColor;
|
||||
renderer->SetDrawBlendMode = GL_SetDrawBlendMode;
|
||||
renderer->RenderPoint = GL_RenderPoint;
|
||||
renderer->RenderLine = GL_RenderLine;
|
||||
renderer->RenderFill = GL_RenderFill;
|
||||
renderer->RenderCopy = GL_RenderCopy;
|
||||
|
@ -1097,11 +1099,9 @@ GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
|
|||
}
|
||||
|
||||
static int
|
||||
GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
GL_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
||||
{
|
||||
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
||||
//data->glLineWidth(1.0);
|
||||
//data->glPointSize(1.0);
|
||||
|
||||
SetBlendMode(data, renderer->blendMode);
|
||||
|
||||
|
@ -1110,16 +1110,30 @@ GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
|||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
data->glBegin(GL_POINTS);
|
||||
data->glVertex2i(x1, y1);
|
||||
data->glVertex2i(x, y);
|
||||
data->glEnd();
|
||||
} else {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
||||
|
||||
SetBlendMode(data, renderer->blendMode);
|
||||
|
||||
data->glColor4f((GLfloat) renderer->r * inv255f,
|
||||
(GLfloat) renderer->g * inv255f,
|
||||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
|
||||
data->glBegin(GL_LINES);
|
||||
data->glVertex2i(x1, y1);
|
||||
data->glVertex2i(x2, y2);
|
||||
data->glEnd();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
static int SW_SetDrawColor(SDL_Renderer * renderer);
|
||||
static int SW_SetDrawBlendMode(SDL_Renderer * renderer);
|
||||
static int SW_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
||||
static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
|
||||
int y2);
|
||||
static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
|
||||
|
@ -227,6 +228,7 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
renderer->SetDrawColor = SW_SetDrawColor;
|
||||
renderer->SetDrawBlendMode = SW_SetDrawBlendMode;
|
||||
renderer->RenderPoint = SW_RenderPoint;
|
||||
renderer->RenderLine = SW_RenderLine;
|
||||
renderer->RenderFill = SW_RenderFill;
|
||||
renderer->RenderCopy = SW_RenderCopy;
|
||||
|
@ -537,6 +539,49 @@ SW_SetDrawBlendMode(SDL_Renderer * renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
||||
{
|
||||
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
|
||||
int status;
|
||||
|
||||
if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
|
||||
SDL_Rect rect;
|
||||
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.w = 1;
|
||||
rect.h = 1;
|
||||
SDL_AddDirtyRect(&data->dirty, &rect);
|
||||
}
|
||||
|
||||
if (data->renderer->LockTexture(data->renderer,
|
||||
data->texture[data->current_texture],
|
||||
&data->surface.clip_rect, 1,
|
||||
&data->surface.pixels,
|
||||
&data->surface.pitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (renderer->blendMode == SDL_BLENDMODE_NONE ||
|
||||
renderer->blendMode == SDL_BLENDMODE_MASK) {
|
||||
Uint32 color =
|
||||
SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
|
||||
renderer->b, renderer->a);
|
||||
|
||||
status = SDL_DrawPoint(&data->surface, x, y, color);
|
||||
} else {
|
||||
status =
|
||||
SDL_BlendPoint(&data->surface, x, y, renderer->blendMode,
|
||||
renderer->r, renderer->g, renderer->b,
|
||||
renderer->a);
|
||||
}
|
||||
|
||||
data->renderer->UnlockTexture(data->renderer,
|
||||
data->texture[data->current_texture]);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
|
@ -571,7 +616,8 @@ SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
|
||||
if (renderer->blendMode == SDL_BLENDMODE_NONE ||
|
||||
renderer->blendMode == SDL_BLENDMODE_MASK) {
|
||||
Uint32 color =
|
||||
SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
|
||||
renderer->b, renderer->a);
|
||||
|
|
|
@ -90,6 +90,7 @@ struct SDL_Renderer
|
|||
int numrects, const SDL_Rect * rects);
|
||||
int (*SetDrawColor) (SDL_Renderer * renderer);
|
||||
int (*SetDrawBlendMode) (SDL_Renderer * renderer);
|
||||
int (*RenderPoint) (SDL_Renderer * renderer, int x, int y);
|
||||
int (*RenderLine) (SDL_Renderer * renderer, int x1, int y1, int x2,
|
||||
int y2);
|
||||
int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect);
|
||||
|
|
|
@ -2070,6 +2070,70 @@ SDL_GetRenderDrawBlendMode(int *blendMode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_RenderPoint(int x, int y)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Window *window;
|
||||
SDL_Rect real_rect;
|
||||
|
||||
if (!_this) {
|
||||
SDL_UninitializedVideo();
|
||||
return -1;
|
||||
}
|
||||
renderer = SDL_CurrentDisplay.current_renderer;
|
||||
if (!renderer) {
|
||||
return -1;
|
||||
}
|
||||
if (!renderer->RenderPoint) {
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
}
|
||||
window = SDL_GetWindowFromID(renderer->window);
|
||||
if (x < 0 || y < 0 || x >= window->w || y >= window->h) {
|
||||
return 0;
|
||||
}
|
||||
return renderer->RenderPoint(renderer, x, y);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_RenderLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Window *window;
|
||||
SDL_Rect real_rect;
|
||||
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
return SDL_RenderPoint(x1, y1);
|
||||
}
|
||||
|
||||
if (!_this) {
|
||||
SDL_UninitializedVideo();
|
||||
return -1;
|
||||
}
|
||||
renderer = SDL_CurrentDisplay.current_renderer;
|
||||
if (!renderer) {
|
||||
return -1;
|
||||
}
|
||||
if (!renderer->RenderLine) {
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
//FIXME: Need line intersect routine
|
||||
window = SDL_GetWindowFromID(renderer->window);
|
||||
real_rect.x = 0;
|
||||
real_rect.y = 0;
|
||||
real_rect.w = window->w;
|
||||
real_rect.h = window->h;
|
||||
if (rect) {
|
||||
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return renderer->RenderLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_RenderFill(const SDL_Rect * rect)
|
||||
|
@ -2103,41 +2167,6 @@ SDL_RenderFill(const SDL_Rect * rect)
|
|||
return renderer->RenderFill(renderer, &real_rect);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_RenderLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Window *window;
|
||||
SDL_Rect real_rect;
|
||||
|
||||
if (!_this) {
|
||||
SDL_UninitializedVideo();
|
||||
return -1;
|
||||
}
|
||||
renderer = SDL_CurrentDisplay.current_renderer;
|
||||
if (!renderer) {
|
||||
return -1;
|
||||
}
|
||||
if (!renderer->RenderLine) {
|
||||
SDL_Unsupported();
|
||||
return -1;
|
||||
}
|
||||
#if 0
|
||||
//FIXME: Need line intersect routine
|
||||
window = SDL_GetWindowFromID(renderer->window);
|
||||
real_rect.x = 0;
|
||||
real_rect.y = 0;
|
||||
real_rect.w = window->w;
|
||||
real_rect.h = window->h;
|
||||
if (rect) {
|
||||
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return renderer->RenderLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
|
||||
const SDL_Rect * dstrect)
|
||||
|
|
|
@ -73,6 +73,7 @@ static void DirectFB_DirtyTexture(SDL_Renderer * renderer,
|
|||
const SDL_Rect * rects);
|
||||
static int DirectFB_SetDrawColor(SDL_Renderer * renderer);
|
||||
static int DirectFB_SetDrawBlendMode(SDL_Renderer * renderer);
|
||||
static int DirectFB_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
||||
static int DirectFB_RenderLine(SDL_Renderer * renderer, int x1, int y1,
|
||||
int x2, int y2);
|
||||
static int DirectFB_RenderFill(SDL_Renderer * renderer,
|
||||
|
@ -295,6 +296,7 @@ DirectFB_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->DirtyTexture = DirectFB_DirtyTexture;
|
||||
renderer->SetDrawColor = DirectFB_SetDrawColor;
|
||||
renderer->SetDrawBlendMode = DirectFB_SetDrawBlendMode;
|
||||
renderer->RenderPoint = DirectFB_RenderPoint;
|
||||
renderer->RenderLine = DirectFB_RenderLine;
|
||||
renderer->RenderFill = DirectFB_RenderFill;
|
||||
renderer->RenderCopy = DirectFB_RenderCopy;
|
||||
|
@ -843,6 +845,19 @@ PrepareDraw(SDL_Renderer * renderer)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
DirectFB_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
||||
{
|
||||
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
|
||||
DFBResult ret;
|
||||
|
||||
PrepareDraw(renderer);
|
||||
SDL_DFB_CHECKERR(data->surface->DrawPoint(data->surface, x, y));
|
||||
return 0;
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
DirectFB_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
|
|
|
@ -33,6 +33,7 @@ static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window,
|
|||
Uint32 flags);
|
||||
static int SDL_DUMMY_SetDrawColor(SDL_Renderer * renderer);
|
||||
static int SDL_DUMMY_SetDrawBlendMode(SDL_Renderer * renderer);
|
||||
static int SDL_DUMMY_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
||||
static int SDL_DUMMY_RenderLine(SDL_Renderer * renderer, int x1, int y1,
|
||||
int x2, int y2);
|
||||
static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer,
|
||||
|
@ -94,6 +95,7 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
renderer->SetDrawColor = SDL_DUMMY_SetDrawColor;
|
||||
renderer->SetDrawBlendMode = SDL_DUMMY_SetDrawBlendMode;
|
||||
renderer->RenderPoint = SDL_DUMMY_RenderPoint;
|
||||
renderer->RenderLine = SDL_DUMMY_RenderLine;
|
||||
renderer->RenderFill = SDL_DUMMY_RenderFill;
|
||||
renderer->RenderCopy = SDL_DUMMY_RenderCopy;
|
||||
|
@ -142,6 +144,29 @@ SDL_DUMMY_SetDrawBlendMode(SDL_Renderer * renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_DUMMY_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
||||
{
|
||||
SDL_DUMMY_RenderData *data =
|
||||
(SDL_DUMMY_RenderData *) renderer->driverdata;
|
||||
SDL_Surface *target = data->screens[data->current_screen];
|
||||
int status;
|
||||
|
||||
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);
|
||||
|
||||
status = SDL_DrawPoint(target, x, y, color);
|
||||
} else {
|
||||
status =
|
||||
SDL_BlendPoint(target, x, y, renderer->blendMode, renderer->r,
|
||||
renderer->g, renderer->b, renderer->a);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_DUMMY_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
|
@ -150,7 +175,8 @@ SDL_DUMMY_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
|||
SDL_Surface *target = data->screens[data->current_screen];
|
||||
int status;
|
||||
|
||||
if (renderer->blendMode == SDL_BLENDMODE_NONE) {
|
||||
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);
|
||||
|
|
|
@ -49,6 +49,7 @@ static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
static int X11_SetDrawColor(SDL_Renderer * renderer);
|
||||
static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
|
||||
static int X11_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
||||
static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
|
||||
int y2);
|
||||
static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
|
||||
|
@ -196,6 +197,7 @@ X11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UnlockTexture = X11_UnlockTexture;
|
||||
renderer->SetDrawColor = X11_SetDrawColor;
|
||||
renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
|
||||
renderer->RenderPoint = X11_RenderPoint;
|
||||
renderer->RenderLine = X11_RenderLine;
|
||||
renderer->RenderFill = X11_RenderFill;
|
||||
renderer->RenderCopy = X11_RenderCopy;
|
||||
|
@ -592,6 +594,28 @@ renderdrawcolor(SDL_Renderer * renderer, int premult)
|
|||
return SDL_MapRGBA(data->format, r, g, b, a);
|
||||
}
|
||||
|
||||
static int
|
||||
X11_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
||||
{
|
||||
X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
|
||||
unsigned long foreground;
|
||||
|
||||
if (data->makedirty) {
|
||||
SDL_Rect rect;
|
||||
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
rect.w = 1;
|
||||
rect.h = 1;
|
||||
SDL_AddDirtyRect(&data->dirty, &rect);
|
||||
}
|
||||
|
||||
foreground = renderdrawcolor(renderer, 1);
|
||||
XSetForeground(data->display, data->gc, foreground);
|
||||
XDrawPoint(data->display, data->drawable, data->gc, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
|
|
|
@ -96,6 +96,7 @@ 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,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,XDrawLine,(Display* a, Drawable b, GC c, int d, int e, int f, int g),(a,b,c,d,e,f,g),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,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(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)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
/* Simple program: draw as many random lines on the screen as possible */
|
||||
/* Simple program: draw as many random objects on the screen as possible */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -7,10 +7,10 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
#define NUM_LINES 100
|
||||
#define NUM_OBJECTS 100
|
||||
|
||||
static CommonState *state;
|
||||
static int num_lines;
|
||||
static int num_objects;
|
||||
static SDL_bool cycle_color;
|
||||
static SDL_bool cycle_alpha;
|
||||
static int cycle_direction = 1;
|
||||
|
@ -19,24 +19,62 @@ static int current_color = 255;
|
|||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
void
|
||||
DrawLines(SDL_WindowID window)
|
||||
DrawPoints(SDL_WindowID window)
|
||||
{
|
||||
int i, n;
|
||||
int x1, y1, x2, y2;
|
||||
int i;
|
||||
int x, y;
|
||||
int window_w, window_h;
|
||||
|
||||
SDL_SelectRenderer(window);
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
|
||||
/* Move the sprite, bounce at the wall, and draw */
|
||||
n = 0;
|
||||
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderFill(NULL);
|
||||
SDL_SetRenderDrawBlendMode(blendMode);
|
||||
for (i = 0; i < num_objects; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
|
||||
x = rand() % window_w;
|
||||
y = rand() % window_h;
|
||||
SDL_RenderPoint(x, y);
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
|
||||
}
|
||||
|
||||
void
|
||||
DrawLines(SDL_WindowID window)
|
||||
{
|
||||
int i;
|
||||
int x1, y1, x2, y2;
|
||||
int window_w, window_h;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(blendMode);
|
||||
for (i = 0; i < num_lines; ++i) {
|
||||
for (i = 0; i < num_objects; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
|
@ -77,9 +115,53 @@ DrawLines(SDL_WindowID window)
|
|||
}
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
|
||||
}
|
||||
|
||||
/* Update the screen! */
|
||||
SDL_RenderPresent();
|
||||
void
|
||||
DrawRects(SDL_WindowID window)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect rect;
|
||||
int window_w, window_h;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(blendMode);
|
||||
for (i = 0; i < num_objects/4; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
|
||||
rect.w = rand() % (window_h / 2);
|
||||
rect.h = rand() % (window_h / 2);
|
||||
rect.x = (rand() % window_w) - (rect.w / 2);
|
||||
rect.y = (rand() % window_w) - (rect.h / 2);
|
||||
SDL_RenderFill(&rect);
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -90,7 +172,7 @@ main(int argc, char *argv[])
|
|||
Uint32 then, now, frames;
|
||||
|
||||
/* Initialize parameters */
|
||||
num_lines = NUM_LINES;
|
||||
num_objects = NUM_OBJECTS;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
|
@ -129,7 +211,7 @@ main(int argc, char *argv[])
|
|||
cycle_alpha = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_isdigit(*argv[i])) {
|
||||
num_lines = SDL_atoi(argv[i]);
|
||||
num_objects = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +260,15 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_SelectRenderer(state->windows[i]);
|
||||
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderFill(NULL);
|
||||
|
||||
DrawRects(state->windows[i]);
|
||||
DrawLines(state->windows[i]);
|
||||
DrawPoints(state->windows[i]);
|
||||
|
||||
SDL_RenderPresent();
|
||||
}
|
||||
}
|
||||
|
187
test/testfill2.c
187
test/testfill2.c
|
@ -1,187 +0,0 @@
|
|||
|
||||
/* Simple program: draw as many random rectangles on the screen as possible */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define NUM_RECTS 100
|
||||
|
||||
static CommonState *state;
|
||||
static int num_rects;
|
||||
static SDL_bool cycle_color;
|
||||
static SDL_bool cycle_alpha;
|
||||
static int cycle_direction = 1;
|
||||
static int current_alpha = 255;
|
||||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
void
|
||||
DrawRects(SDL_WindowID window)
|
||||
{
|
||||
int i, n;
|
||||
SDL_Rect rect;
|
||||
int window_w, window_h;
|
||||
|
||||
SDL_SelectRenderer(window);
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
|
||||
/* Move the sprite, bounce at the wall, and draw */
|
||||
n = 0;
|
||||
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderFill(NULL);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(blendMode);
|
||||
for (i = 0; i < num_rects; ++i) {
|
||||
/* Cycle the color and alpha, if desired */
|
||||
if (cycle_color) {
|
||||
current_color += cycle_direction;
|
||||
if (current_color < 0) {
|
||||
current_color = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_color > 255) {
|
||||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
if (current_alpha < 0) {
|
||||
current_alpha = 0;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
if (current_alpha > 255) {
|
||||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
|
||||
rect.w = rand() % (window_h / 2);
|
||||
rect.h = rand() % (window_h / 2);
|
||||
rect.x = (rand() % window_w) - (rect.w / 2);
|
||||
rect.y = (rand() % window_w) - (rect.h / 2);
|
||||
SDL_RenderFill(&rect);
|
||||
}
|
||||
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
|
||||
|
||||
/* Update the screen! */
|
||||
SDL_RenderPresent();
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Initialize parameters */
|
||||
num_rects = NUM_RECTS;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_strcasecmp(argv[i], "--blend") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
|
||||
blendMode = SDL_BLENDMODE_NONE;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mask") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MASK;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
|
||||
cycle_color = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
|
||||
cycle_alpha = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_isdigit(*argv[i])) {
|
||||
num_rects = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s %s [--blend none|mask|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
|
||||
argv[0], CommonUsage(state));
|
||||
return 1;
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!CommonInit(state)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Create the windows and initialize the renderers */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_SelectRenderer(state->windows[i]);
|
||||
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderFill(NULL);
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
CommonEvent(state, &event, &done);
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
SDL_SelectRenderer(event.window.windowID);
|
||||
SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderFill(NULL);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
DrawRects(state->windows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
printf("%2.2f frames per second\n", fps);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Add table
Add a link
Reference in a new issue