comparison src/video/win32/SDL_d3drender.c @ 1904:1a713f9d1f71

Yay! D3D renderer works!
author Sam Lantinga <slouken@libsdl.org>
date Fri, 14 Jul 2006 07:41:16 +0000
parents f132024010be
children 36d52b1f0504
comparison
equal deleted inserted replaced
1903:f132024010be 1904:1a713f9d1f71
111 } SDL_D3D_TextureData; 111 } SDL_D3D_TextureData;
112 112
113 typedef struct 113 typedef struct
114 { 114 {
115 float x, y, z; 115 float x, y, z;
116 float tu, tv; 116 float rhw;
117 float u, v;
117 } Vertex; 118 } Vertex;
118 119
119 static void 120 static void
120 D3D_SetError(const char *prefix, HRESULT result) 121 D3D_SetError(const char *prefix, HRESULT result)
121 { 122 {
328 return NULL; 329 return NULL;
329 } 330 }
330 data->beginScene = SDL_TRUE; 331 data->beginScene = SDL_TRUE;
331 332
332 /* Set up parameters for rendering */ 333 /* Set up parameters for rendering */
334 IDirect3DDevice9_SetVertexShader(data->device, NULL);
335 IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1);
333 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, 336 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
334 D3DCULL_NONE); 337 D3DCULL_NONE);
335 IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZ | D3DFVF_TEX1); 338 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
339 IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
340 TRUE);
341 IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
342 D3DBLEND_SRCALPHA);
343 IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
344 D3DBLEND_INVSRCALPHA);
336 345
337 return renderer; 346 return renderer;
338 } 347 }
339 348
340 static int 349 static int
558 { 567 {
559 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata; 568 SDL_D3D_RenderData *data = (SDL_D3D_RenderData *) renderer->driverdata;
560 SDL_D3D_TextureData *texturedata = 569 SDL_D3D_TextureData *texturedata =
561 (SDL_D3D_TextureData *) texture->driverdata; 570 (SDL_D3D_TextureData *) texture->driverdata;
562 float minx, miny, maxx, maxy; 571 float minx, miny, maxx, maxy;
563 float mintu, maxtu, mintv, maxtv; 572 float minu, maxu, minv, maxv;
564 Vertex vertices[4]; 573 Vertex vertices[4];
565 HRESULT result; 574 HRESULT result;
566 575
567 if (data->beginScene) { 576 if (data->beginScene) {
568 IDirect3DDevice9_BeginScene(data->device); 577 IDirect3DDevice9_BeginScene(data->device);
569 data->beginScene = SDL_FALSE; 578 data->beginScene = SDL_FALSE;
570 } 579 }
571 580
572 minx = (float) dstrect->x; 581 minx = (float) dstrect->x - 0.5f;
573 miny = (float) dstrect->y; 582 miny = (float) dstrect->y - 0.5f;
574 maxx = (float) dstrect->x + dstrect->w; 583 maxx = (float) dstrect->x + dstrect->w - 0.5f;
575 maxy = (float) dstrect->y + dstrect->h; 584 maxy = (float) dstrect->y + dstrect->h - 0.5f;
576 585
577 mintu = (float) srcrect->x / texture->w; 586 minu = (float) srcrect->x / texture->w;
578 maxtu = (float) (srcrect->x + srcrect->w) / texture->w; 587 maxu = (float) (srcrect->x + srcrect->w) / texture->w;
579 mintv = (float) srcrect->y / texture->h; 588 minv = (float) srcrect->y / texture->h;
580 maxtv = (float) (srcrect->y + srcrect->h) / texture->h; 589 maxv = (float) (srcrect->y + srcrect->h) / texture->h;
581 590
582 vertices[0].x = minx; 591 vertices[0].x = minx;
583 vertices[0].y = miny; 592 vertices[0].y = miny;
584 vertices[0].z = 0.0f; 593 vertices[0].z = 0.0f;
585 vertices[0].tu = mintu; 594 vertices[0].rhw = 1.0f;
586 vertices[0].tv = mintv; 595 vertices[0].u = minu;
596 vertices[0].v = minv;
597
587 vertices[1].x = maxx; 598 vertices[1].x = maxx;
588 vertices[1].y = miny; 599 vertices[1].y = miny;
589 vertices[1].z = 0.0f; 600 vertices[1].z = 0.0f;
590 vertices[1].tu = maxtu; 601 vertices[1].rhw = 1.0f;
591 vertices[1].tv = mintv; 602 vertices[1].u = maxu;
603 vertices[1].v = minv;
604
592 vertices[2].x = maxx; 605 vertices[2].x = maxx;
593 vertices[2].y = maxy; 606 vertices[2].y = maxy;
594 vertices[2].z = 0.0f; 607 vertices[2].z = 0.0f;
595 vertices[2].tu = maxtu; 608 vertices[2].rhw = 1.0f;
596 vertices[2].tv = maxtv; 609 vertices[2].u = maxu;
610 vertices[2].v = maxv;
611
597 vertices[3].x = minx; 612 vertices[3].x = minx;
598 vertices[3].y = maxy; 613 vertices[3].y = maxy;
599 vertices[3].z = 0.0f; 614 vertices[3].z = 0.0f;
600 vertices[3].tu = mintu; 615 vertices[3].rhw = 1.0f;
601 vertices[3].tv = maxtv; 616 vertices[3].u = minu;
617 vertices[3].v = maxv;
602 618
603 result = 619 result =
604 IDirect3DDevice9_SetTexture(data->device, 0, 620 IDirect3DDevice9_SetTexture(data->device, 0,
605 (IDirect3DBaseTexture9 *) texturedata-> 621 (IDirect3DBaseTexture9 *) texturedata->
606 texture); 622 texture);