Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Updated to compile on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Dec 24, 2009
1 parent 43a8dbf commit 5512c2e
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/video/SDL_renderer_gl.c
Expand Up @@ -1225,7 +1225,6 @@ 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);

Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_renderer_sw.c
Expand Up @@ -698,6 +698,7 @@ SW_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
}

for (i = 0; i < count; ++i) {
/* FIXME: We don't want to draw clipped edges */
if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
/* Nothing to draw */
continue;
Expand Down
2 changes: 2 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -2673,6 +2673,7 @@ SDL_RenderFillRects(const SDL_Rect ** rects, int count)
return renderer->RenderFillRects(renderer, rects, count);
}

#if 0
int
SDL_RenderDrawCircle(int x, int y, int radius)
{
Expand Down Expand Up @@ -2714,6 +2715,7 @@ int SDL_RenderFillEllipse(int x, int y, int w, int h)
}
return renderer->RenderFillEllipse(renderer, x, y, w, h);
}
#endif // 0

int
SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect,
Expand Down
94 changes: 82 additions & 12 deletions src/video/win32/SDL_d3drender.c
Expand Up @@ -118,12 +118,14 @@ static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects);
static int D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count);
static int D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
int count);
static int D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count);
static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int D3D_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int D3D_RenderDrawRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int D3D_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Expand Down Expand Up @@ -462,9 +464,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->LockTexture = D3D_LockTexture;
renderer->UnlockTexture = D3D_UnlockTexture;
renderer->DirtyTexture = D3D_DirtyTexture;
renderer->RenderPoints = D3D_RenderPoints;
renderer->RenderLines = D3D_RenderLines;
renderer->RenderRects = D3D_RenderRects;
renderer->RenderDrawPoints = D3D_RenderDrawPoints;
renderer->RenderDrawLines = D3D_RenderDrawLines;
renderer->RenderDrawRects = D3D_RenderDrawRects;
renderer->RenderCopy = D3D_RenderCopy;
renderer->RenderReadPixels = D3D_RenderReadPixels;
renderer->RenderWritePixels = D3D_RenderWritePixels;
Expand Down Expand Up @@ -1021,7 +1023,8 @@ D3D_SetBlendMode(D3D_RenderData * data, int blendMode)
}

static int
D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
Expand Down Expand Up @@ -1068,7 +1071,8 @@ D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
}

static int
D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
Expand Down Expand Up @@ -1124,7 +1128,73 @@ D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
}

static int
D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
D3D_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
int i;
Vertex vertices[5];
HRESULT result;

if (data->beginScene) {
IDirect3DDevice9_BeginScene(data->device);
data->beginScene = SDL_FALSE;
}

D3D_SetBlendMode(data, renderer->blendMode);

result =
IDirect3DDevice9_SetTexture(data->device, 0,
(IDirect3DBaseTexture9 *) 0);
if (FAILED(result)) {
D3D_SetError("SetTexture()", result);
return -1;
}

color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);

for (i = 0; i < SDL_arraysize(vertices); ++i) {
vertices[i].z = 0.0f;
vertices[i].rhw = 1.0f;
vertices[i].color = color;
vertices[i].u = 0.0f;
vertices[i].v = 0.0f;
}

for (i = 0; i < count; ++i) {
const SDL_Rect *rect = rects[i];

vertices[0].x = (float) rect->x;
vertices[0].y = (float) rect->y;

vertices[1].x = (float) rect->x+rect->w-1;
vertices[1].y = (float) rect->y;

vertices[2].x = (float) rect->x+rect->w-1;
vertices[2].y = (float) rect->y+rect->h-1;

vertices[3].x = (float) rect->x;
vertices[3].y = (float) rect->y+rect->h-1;

vertices[4].x = (float) rect->x;
vertices[4].y = (float) rect->y;

result =
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, 4,
vertices, sizeof(*vertices));

if (FAILED(result)) {
D3D_SetError("DrawPrimitiveUP()", result);
return -1;
}
}
return 0;
}

static int
D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
Expand Down
87 changes: 75 additions & 12 deletions src/video/win32/SDL_gdirender.c
Expand Up @@ -61,12 +61,14 @@ static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch);
static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GDI_SetDrawBlendMode(SDL_Renderer * renderer);
static int GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count);
static int GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
int count);
static int GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count);
static int GDI_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int GDI_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points, int count);
static int GDI_RenderDrawRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int GDI_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rects, int count);
static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Expand Down Expand Up @@ -194,9 +196,10 @@ GDI_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->LockTexture = GDI_LockTexture;
renderer->UnlockTexture = GDI_UnlockTexture;
renderer->SetDrawBlendMode = GDI_SetDrawBlendMode;
renderer->RenderPoints = GDI_RenderPoints;
renderer->RenderLines = GDI_RenderLines;
renderer->RenderRects = GDI_RenderRects;
renderer->RenderDrawPoints = GDI_RenderDrawPoints;
renderer->RenderDrawLines = GDI_RenderDrawLines;
renderer->RenderDrawRects = GDI_RenderDrawRects;
renderer->RenderFillRects = GDI_RenderFillRects;
renderer->RenderCopy = GDI_RenderCopy;
renderer->RenderReadPixels = GDI_RenderReadPixels;
renderer->RenderWritePixels = GDI_RenderWritePixels;
Expand Down Expand Up @@ -687,7 +690,8 @@ GDI_SetDrawBlendMode(SDL_Renderer * renderer)
}

static int
GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
GDI_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
int i;
Expand Down Expand Up @@ -719,7 +723,8 @@ GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
}

static int
GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
GDI_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
int count)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
HPEN pen;
Expand Down Expand Up @@ -773,7 +778,65 @@ GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
}

static int
GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
GDI_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
HPEN pen;
POINT vertices[5];
int i, status = 1;

if (data->makedirty) {
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_Rect clip, rect;

clip.x = 0;
clip.y = 0;
clip.w = window->w;
clip.h = window->h;

for (i = 0; i < count; ++i) {
if (SDL_IntersectRect(rects[i], &clip, &rect)) {
SDL_AddDirtyRect(&data->dirty, &rect);
}
}
}

/* Should we cache the pen? .. it looks like GDI does for us. :) */
pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b));
SelectObject(data->current_hdc, pen);
for (i = 0; i < count; ++i) {
const SDL_Rect *rect = rects[i];

vertices[0].x = rect->x;
vertices[0].y = rect->y;

vertices[1].x = rect->x+rect->w-1;
vertices[1].y = rect->y;

vertices[2].x = rect->x+rect->w-1;
vertices[2].y = rect->y+rect->h-1;

vertices[3].x = rect->x;
vertices[3].y = rect->y+rect->h-1;

vertices[4].x = rect->x;
vertices[4].y = rect->y;

status &= Polyline(data->current_hdc, vertices, 5);
}
DeleteObject(pen);

if (!status) {
WIN_SetError("Polyline()");
return -1;
}
return 0;
}

static int
GDI_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
int count)
{
GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata;
RECT rc;
Expand Down

0 comments on commit 5512c2e

Please sign in to comment.