comparison src/video/win32/SDL_d3drender.c @ 1987:36a08379b3f2

Implemented color modulation in the D3D renderer. FIXME: Why doesn't alpha modulation appear to work?
author Sam Lantinga <slouken@libsdl.org>
date Mon, 28 Aug 2006 04:03:32 +0000
parents 8055185ae4ed
children 1ee02169bbb0
comparison
equal deleted inserted replaced
1986:f4c65e3bfaed 1987:36a08379b3f2
111 111
112 typedef struct 112 typedef struct
113 { 113 {
114 float x, y, z; 114 float x, y, z;
115 float rhw; 115 float rhw;
116 DWORD color;
116 float u, v; 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)
377 renderer->info.max_texture_width = caps.MaxTextureWidth; 378 renderer->info.max_texture_width = caps.MaxTextureWidth;
378 renderer->info.max_texture_height = caps.MaxTextureHeight; 379 renderer->info.max_texture_height = caps.MaxTextureHeight;
379 380
380 /* Set up parameters for rendering */ 381 /* Set up parameters for rendering */
381 IDirect3DDevice9_SetVertexShader(data->device, NULL); 382 IDirect3DDevice9_SetVertexShader(data->device, NULL);
382 IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1); 383 IDirect3DDevice9_SetFVF(data->device,
384 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
383 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, 385 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
384 D3DCULL_NONE); 386 D3DCULL_NONE);
385 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); 387 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
386 388
387 return renderer; 389 return renderer;
402 D3D_SetError("Reset()", result); 404 D3D_SetError("Reset()", result);
403 return -1; 405 return -1;
404 } 406 }
405 } 407 }
406 IDirect3DDevice9_SetVertexShader(data->device, NULL); 408 IDirect3DDevice9_SetVertexShader(data->device, NULL);
407 IDirect3DDevice9_SetFVF(data->device, D3DFVF_XYZRHW | D3DFVF_TEX1); 409 IDirect3DDevice9_SetFVF(data->device,
410 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
408 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE, 411 IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
409 D3DCULL_NONE); 412 D3DCULL_NONE);
410 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE); 413 IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
411 return 0; 414 return 0;
412 } 415 }
491 } 494 }
492 495
493 static int 496 static int
494 D3D_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) 497 D3D_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
495 { 498 {
496 /* FIXME: implement vertex coloring */ 499 return 0;
497 return -1;
498 } 500 }
499 501
500 static int 502 static int
501 D3D_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) 503 D3D_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
502 { 504 {
503 /* FIXME: implement vertex coloring */ 505 return 0;
504 return -1;
505 } 506 }
506 507
507 static int 508 static int
508 D3D_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) 509 D3D_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
509 { 510 {
691 { 692 {
692 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; 693 D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
693 D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata; 694 D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
694 float minx, miny, maxx, maxy; 695 float minx, miny, maxx, maxy;
695 float minu, maxu, minv, maxv; 696 float minu, maxu, minv, maxv;
697 DWORD color;
696 Vertex vertices[4]; 698 Vertex vertices[4];
697 HRESULT result; 699 HRESULT result;
698 700
699 if (data->beginScene) { 701 if (data->beginScene) {
700 IDirect3DDevice9_BeginScene(data->device); 702 IDirect3DDevice9_BeginScene(data->device);
709 minu = (float) srcrect->x / texture->w; 711 minu = (float) srcrect->x / texture->w;
710 maxu = (float) (srcrect->x + srcrect->w) / texture->w; 712 maxu = (float) (srcrect->x + srcrect->w) / texture->w;
711 minv = (float) srcrect->y / texture->h; 713 minv = (float) srcrect->y / texture->h;
712 maxv = (float) (srcrect->y + srcrect->h) / texture->h; 714 maxv = (float) (srcrect->y + srcrect->h) / texture->h;
713 715
716 color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
717
714 vertices[0].x = minx; 718 vertices[0].x = minx;
715 vertices[0].y = miny; 719 vertices[0].y = miny;
716 vertices[0].z = 0.0f; 720 vertices[0].z = 0.0f;
717 vertices[0].rhw = 1.0f; 721 vertices[0].rhw = 1.0f;
722 vertices[0].color = color;
718 vertices[0].u = minu; 723 vertices[0].u = minu;
719 vertices[0].v = minv; 724 vertices[0].v = minv;
720 725
721 vertices[1].x = maxx; 726 vertices[1].x = maxx;
722 vertices[1].y = miny; 727 vertices[1].y = miny;
723 vertices[1].z = 0.0f; 728 vertices[1].z = 0.0f;
724 vertices[1].rhw = 1.0f; 729 vertices[1].rhw = 1.0f;
730 vertices[1].color = color;
725 vertices[1].u = maxu; 731 vertices[1].u = maxu;
726 vertices[1].v = minv; 732 vertices[1].v = minv;
727 733
728 vertices[2].x = maxx; 734 vertices[2].x = maxx;
729 vertices[2].y = maxy; 735 vertices[2].y = maxy;
730 vertices[2].z = 0.0f; 736 vertices[2].z = 0.0f;
731 vertices[2].rhw = 1.0f; 737 vertices[2].rhw = 1.0f;
738 vertices[2].color = color;
732 vertices[2].u = maxu; 739 vertices[2].u = maxu;
733 vertices[2].v = maxv; 740 vertices[2].v = maxv;
734 741
735 vertices[3].x = minx; 742 vertices[3].x = minx;
736 vertices[3].y = maxy; 743 vertices[3].y = maxy;
737 vertices[3].z = 0.0f; 744 vertices[3].z = 0.0f;
738 vertices[3].rhw = 1.0f; 745 vertices[3].rhw = 1.0f;
746 vertices[3].color = color;
739 vertices[3].u = minu; 747 vertices[3].u = minu;
740 vertices[3].v = maxv; 748 vertices[3].v = maxv;
741 749
742 switch (texture->blendMode) { 750 switch (texture->blendMode) {
743 case SDL_TEXTUREBLENDMODE_NONE: 751 case SDL_TEXTUREBLENDMODE_NONE: