Commit e920af3d authored by Sam Lantinga's avatar Sam Lantinga

Yay! D3D renderer works!

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401949
parent 58770212
...@@ -113,7 +113,8 @@ typedef struct ...@@ -113,7 +113,8 @@ typedef struct
typedef struct typedef struct
{ {
float x, y, z; float x, y, z;
float tu, tv; float rhw;
float u, v;
} Vertex; } Vertex;
static void static void
...@@ -330,9 +331,17 @@ SDL_D3D_CreateRenderer(SDL_Window * window, Uint32 flags) ...@@ -330,9 +331,17 @@ SDL_D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
data->beginScene = SDL_TRUE; data->beginScene = SDL_TRUE;
/* Set up parameters for rendering */ /* Set up parameters for rendering */
IDirect3DDevice9_SetVertexShader(data->device, NULL);
IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
D3DCULL_NONE); D3DCULL_NONE);
IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZ | D3DFVF_TEX1); IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
TRUE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
D3DBLEND_SRCALPHA);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
D3DBLEND_INVSRCALPHA);
return renderer; return renderer;
} }
...@@ -560,7 +569,7 @@ SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -560,7 +569,7 @@ SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_D3D_TextureData *texturedata = SDL_D3D_TextureData *texturedata =
(SDL_D3D_TextureData *) texture->driverdata; (SDL_D3D_TextureData *) texture->driverdata;
float minx, miny, maxx, maxy; float minx, miny, maxx, maxy;
float mintu, maxtu, mintv, maxtv; float minu, maxu, minv, maxv;
Vertex vertices[4]; Vertex vertices[4];
HRESULT result; HRESULT result;
...@@ -569,36 +578,43 @@ SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -569,36 +578,43 @@ SDL_D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
data->beginScene = SDL_FALSE; data->beginScene = SDL_FALSE;
} }
minx = (float) dstrect->x; minx = (float) dstrect->x - 0.5f;
miny = (float) dstrect->y; miny = (float) dstrect->y - 0.5f;
maxx = (float) dstrect->x + dstrect->w; maxx = (float) dstrect->x + dstrect->w - 0.5f;
maxy = (float) dstrect->y + dstrect->h; maxy = (float) dstrect->y + dstrect->h - 0.5f;
mintu = (float) srcrect->x / texture->w; minu = (float) srcrect->x / texture->w;
maxtu = (float) (srcrect->x + srcrect->w) / texture->w; maxu = (float) (srcrect->x + srcrect->w) / texture->w;
mintv = (float) srcrect->y / texture->h; minv = (float) srcrect->y / texture->h;
maxtv = (float) (srcrect->y + srcrect->h) / texture->h; maxv = (float) (srcrect->y + srcrect->h) / texture->h;
vertices[0].x = minx; vertices[0].x = minx;
vertices[0].y = miny; vertices[0].y = miny;
vertices[0].z = 0.0f; vertices[0].z = 0.0f;
vertices[0].tu = mintu; vertices[0].rhw = 1.0f;
vertices[0].tv = mintv; vertices[0].u = minu;
vertices[0].v = minv;
vertices[1].x = maxx; vertices[1].x = maxx;
vertices[1].y = miny; vertices[1].y = miny;
vertices[1].z = 0.0f; vertices[1].z = 0.0f;
vertices[1].tu = maxtu; vertices[1].rhw = 1.0f;
vertices[1].tv = mintv; vertices[1].u = maxu;
vertices[1].v = minv;
vertices[2].x = maxx; vertices[2].x = maxx;
vertices[2].y = maxy; vertices[2].y = maxy;
vertices[2].z = 0.0f; vertices[2].z = 0.0f;
vertices[2].tu = maxtu; vertices[2].rhw = 1.0f;
vertices[2].tv = maxtv; vertices[2].u = maxu;
vertices[2].v = maxv;
vertices[3].x = minx; vertices[3].x = minx;
vertices[3].y = maxy; vertices[3].y = maxy;
vertices[3].z = 0.0f; vertices[3].z = 0.0f;
vertices[3].tu = mintu; vertices[3].rhw = 1.0f;
vertices[3].tv = maxtv; vertices[3].u = minu;
vertices[3].v = maxv;
result = result =
IDirect3DDevice9_SetTexture(data->device, 0, IDirect3DDevice9_SetTexture(data->device, 0,
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "SDL.h" #include "SDL.h"
#define NUM_WINDOWS 1 #define NUM_WINDOWS 4
#define WINDOW_W 640 #define WINDOW_W 640
#define WINDOW_H 480 #define WINDOW_H 480
#define NUM_SPRITES 100 #define NUM_SPRITES 100
...@@ -141,22 +141,23 @@ main(int argc, char *argv[]) ...@@ -141,22 +141,23 @@ main(int argc, char *argv[])
num_sprites = NUM_SPRITES; num_sprites = NUM_SPRITES;
window_w = WINDOW_W; window_w = WINDOW_W;
window_h = WINDOW_H; window_h = WINDOW_H;
while (argc > 1) { for (i = 1; i < argc; ++i) {
if (strcmp(argv[argc - 1], "-width") == 0) { if (strcmp(argv[i], "-width") == 0 && (i + 1 < argc)) {
window_w = atoi(argv[argc]); window_w = atoi(argv[++i]);
--argc; } else if (strcmp(argv[i], "-height") == 0 && (i + 1 < argc)) {
} else if (strcmp(argv[argc - 1], "-height") == 0) { window_h = atoi(argv[++i]);
window_h = atoi(argv[argc]); } else if (strcmp(argv[i], "-windows") == 0 && (i + 1 < argc)) {
--argc; num_windows = atoi(argv[++i]);
} else if (strcmp(argv[argc - 1], "-fullscreen") == 0) { window_flags &= ~SDL_WINDOW_FULLSCREEN;
} else if (strcmp(argv[i], "-fullscreen") == 0) {
num_windows = 1; num_windows = 1;
window_flags |= SDL_WINDOW_FULLSCREEN; window_flags |= SDL_WINDOW_FULLSCREEN;
--argc; } else if (isdigit(argv[i][0])) {
} else if (isdigit(argv[argc][0])) { num_sprites = atoi(argv[i]);
num_sprites = atoi(argv[argc]);
} else { } else {
fprintf(stderr, fprintf(stderr,
"Usage: %s [-width] [-height] [numsprites]\n", argv[0]); "Usage: %s [-width N] [-height N] [-windows N] [-fullscreen] [numsprites]\n",
argv[0]);
quit(1); quit(1);
} }
} }
...@@ -240,8 +241,7 @@ main(int argc, char *argv[]) ...@@ -240,8 +241,7 @@ main(int argc, char *argv[])
} }
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
///* Any keypress quits the app... */ /* Any keypress quits the app... */
break;
case SDL_QUIT: case SDL_QUIT:
done = 1; done = 1;
break; break;
......
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