Yay! D3D renderer works!
authorSam Lantinga
Fri, 14 Jul 2006 07:41:16 +0000
changeset 19041a713f9d1f71
parent 1903 f132024010be
child 1905 36d52b1f0504
Yay! D3D renderer works!
src/video/win32/SDL_d3drender.c
test/testsprite2.c
     1.1 --- a/src/video/win32/SDL_d3drender.c	Fri Jul 14 06:40:53 2006 +0000
     1.2 +++ b/src/video/win32/SDL_d3drender.c	Fri Jul 14 07:41:16 2006 +0000
     1.3 @@ -113,7 +113,8 @@
     1.4  typedef struct
     1.5  {
     1.6      float x, y, z;
     1.7 -    float tu, tv;
     1.8 +    float rhw;
     1.9 +    float u, v;
    1.10  } Vertex;
    1.11  
    1.12  static void
    1.13 @@ -330,9 +331,17 @@
    1.14      data->beginScene = SDL_TRUE;
    1.15  
    1.16      /* Set up parameters for rendering */
    1.17 +    IDirect3DDevice9_SetVertexShader(data->device, NULL);
    1.18 +    IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
    1.19      IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
    1.20                                      D3DCULL_NONE);
    1.21 -    IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZ | D3DFVF_TEX1);
    1.22 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
    1.23 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
    1.24 +                                    TRUE);
    1.25 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
    1.26 +                                    D3DBLEND_SRCALPHA);
    1.27 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
    1.28 +                                    D3DBLEND_INVSRCALPHA);
    1.29  
    1.30      return renderer;
    1.31  }
    1.32 @@ -560,7 +569,7 @@
    1.33      SDL_D3D_TextureData *texturedata =
    1.34          (SDL_D3D_TextureData *) texture->driverdata;
    1.35      float minx, miny, maxx, maxy;
    1.36 -    float mintu, maxtu, mintv, maxtv;
    1.37 +    float minu, maxu, minv, maxv;
    1.38      Vertex vertices[4];
    1.39      HRESULT result;
    1.40  
    1.41 @@ -569,36 +578,43 @@
    1.42          data->beginScene = SDL_FALSE;
    1.43      }
    1.44  
    1.45 -    minx = (float) dstrect->x;
    1.46 -    miny = (float) dstrect->y;
    1.47 -    maxx = (float) dstrect->x + dstrect->w;
    1.48 -    maxy = (float) dstrect->y + dstrect->h;
    1.49 +    minx = (float) dstrect->x - 0.5f;
    1.50 +    miny = (float) dstrect->y - 0.5f;
    1.51 +    maxx = (float) dstrect->x + dstrect->w - 0.5f;
    1.52 +    maxy = (float) dstrect->y + dstrect->h - 0.5f;
    1.53  
    1.54 -    mintu = (float) srcrect->x / texture->w;
    1.55 -    maxtu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.56 -    mintv = (float) srcrect->y / texture->h;
    1.57 -    maxtv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.58 +    minu = (float) srcrect->x / texture->w;
    1.59 +    maxu = (float) (srcrect->x + srcrect->w) / texture->w;
    1.60 +    minv = (float) srcrect->y / texture->h;
    1.61 +    maxv = (float) (srcrect->y + srcrect->h) / texture->h;
    1.62  
    1.63      vertices[0].x = minx;
    1.64      vertices[0].y = miny;
    1.65      vertices[0].z = 0.0f;
    1.66 -    vertices[0].tu = mintu;
    1.67 -    vertices[0].tv = mintv;
    1.68 +    vertices[0].rhw = 1.0f;
    1.69 +    vertices[0].u = minu;
    1.70 +    vertices[0].v = minv;
    1.71 +
    1.72      vertices[1].x = maxx;
    1.73      vertices[1].y = miny;
    1.74      vertices[1].z = 0.0f;
    1.75 -    vertices[1].tu = maxtu;
    1.76 -    vertices[1].tv = mintv;
    1.77 +    vertices[1].rhw = 1.0f;
    1.78 +    vertices[1].u = maxu;
    1.79 +    vertices[1].v = minv;
    1.80 +
    1.81      vertices[2].x = maxx;
    1.82      vertices[2].y = maxy;
    1.83      vertices[2].z = 0.0f;
    1.84 -    vertices[2].tu = maxtu;
    1.85 -    vertices[2].tv = maxtv;
    1.86 +    vertices[2].rhw = 1.0f;
    1.87 +    vertices[2].u = maxu;
    1.88 +    vertices[2].v = maxv;
    1.89 +
    1.90      vertices[3].x = minx;
    1.91      vertices[3].y = maxy;
    1.92      vertices[3].z = 0.0f;
    1.93 -    vertices[3].tu = mintu;
    1.94 -    vertices[3].tv = maxtv;
    1.95 +    vertices[3].rhw = 1.0f;
    1.96 +    vertices[3].u = minu;
    1.97 +    vertices[3].v = maxv;
    1.98  
    1.99      result =
   1.100          IDirect3DDevice9_SetTexture(data->device, 0,
     2.1 --- a/test/testsprite2.c	Fri Jul 14 06:40:53 2006 +0000
     2.2 +++ b/test/testsprite2.c	Fri Jul 14 07:41:16 2006 +0000
     2.3 @@ -5,7 +5,7 @@
     2.4  
     2.5  #include "SDL.h"
     2.6  
     2.7 -#define NUM_WINDOWS 1
     2.8 +#define NUM_WINDOWS 4
     2.9  #define WINDOW_W    640
    2.10  #define WINDOW_H    480
    2.11  #define NUM_SPRITES	100
    2.12 @@ -141,22 +141,23 @@
    2.13      num_sprites = NUM_SPRITES;
    2.14      window_w = WINDOW_W;
    2.15      window_h = WINDOW_H;
    2.16 -    while (argc > 1) {
    2.17 -        if (strcmp(argv[argc - 1], "-width") == 0) {
    2.18 -            window_w = atoi(argv[argc]);
    2.19 -            --argc;
    2.20 -        } else if (strcmp(argv[argc - 1], "-height") == 0) {
    2.21 -            window_h = atoi(argv[argc]);
    2.22 -            --argc;
    2.23 -        } else if (strcmp(argv[argc - 1], "-fullscreen") == 0) {
    2.24 +    for (i = 1; i < argc; ++i) {
    2.25 +        if (strcmp(argv[i], "-width") == 0 && (i + 1 < argc)) {
    2.26 +            window_w = atoi(argv[++i]);
    2.27 +        } else if (strcmp(argv[i], "-height") == 0 && (i + 1 < argc)) {
    2.28 +            window_h = atoi(argv[++i]);
    2.29 +        } else if (strcmp(argv[i], "-windows") == 0 && (i + 1 < argc)) {
    2.30 +            num_windows = atoi(argv[++i]);
    2.31 +            window_flags &= ~SDL_WINDOW_FULLSCREEN;
    2.32 +        } else if (strcmp(argv[i], "-fullscreen") == 0) {
    2.33              num_windows = 1;
    2.34              window_flags |= SDL_WINDOW_FULLSCREEN;
    2.35 -            --argc;
    2.36 -        } else if (isdigit(argv[argc][0])) {
    2.37 -            num_sprites = atoi(argv[argc]);
    2.38 +        } else if (isdigit(argv[i][0])) {
    2.39 +            num_sprites = atoi(argv[i]);
    2.40          } else {
    2.41              fprintf(stderr,
    2.42 -                    "Usage: %s [-width] [-height] [numsprites]\n", argv[0]);
    2.43 +                    "Usage: %s [-width N] [-height N] [-windows N] [-fullscreen] [numsprites]\n",
    2.44 +                    argv[0]);
    2.45              quit(1);
    2.46          }
    2.47      }
    2.48 @@ -240,8 +241,7 @@
    2.49                  }
    2.50                  break;
    2.51              case SDL_KEYDOWN:
    2.52 -                ///* Any keypress quits the app... */
    2.53 -                break;
    2.54 +                /* Any keypress quits the app... */
    2.55              case SDL_QUIT:
    2.56                  done = 1;
    2.57                  break;