DXGL r267 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r266‎ | r267 | r268 >
Date:18:40, 7 October 2012
Author:admin
Status:new
Tags:
Comment:
Add more controls to Vertex Shader demo.
Add detailed mesh to Vertex Shader demo. This new method is used in all demos but is adjustable in the Vertex Shader demo.
Add ambient, emissive, material ambient, material diffuse, and material specular colors to Vertex Shader demo.
Add toggling lights and vertex colors in Vertex Shader demo.
Use special FVF vertex format for Vertex Shader demo, which stores both colors and vertex normals.
Eliminate resource leaks from Texture Shader and Vertex Shader demos.
Modified paths:
  • /dxgltest/Resource.h (modified) (history)
  • /dxgltest/Tests3D.cpp (modified) (history)
  • /dxgltest/dxgltest.rc (modified) (history)

Diff [purge]

Index: dxgltest/Resource.h
@@ -35,6 +35,7 @@
3636 #define IDC_RESIZABLE 1001
3737 #define IDC_SPINALPHAREF 1001
3838 #define IDC_DDTYPE 1002
 39+#define IDC_SPINDETAIL 1002
3940 #define IDC_SPINLINEREPEAT 1002
4041 #define IDC_TABS 1002
4142 #define IDC_TESTHEADER 1002
@@ -43,6 +44,7 @@
4445 #define IDC_TESTLIST 1004
4546 #define IDC_FILLMODE 1005
4647 #define IDC_ALPHABLEND 1006
 48+#define IDC_DIFFUSESOURCE 1006
4749 #define IDC_BGCOLOR 1007
4850 #define IDC_SHADEMODE 1008
4951 #define IDC_WINDOWED 1008
@@ -50,14 +52,22 @@
5153 #define IDC_CULLMODE 1010
5254 #define IDC_FOGENABLE 1011
5355 #define IDC_APIVER 1012
 56+#define IDC_MATDIFFUSESELECT 1012
 57+#define IDC_MATDIFFUSE 1013
5458 #define IDC_SPINAPI 1013
5559 #define IDC_ENABLELIGHT 1014
5660 #define IDC_ENABLESPECULAR 1015
5761 #define IDC_VSYNC 1015
 62+#define IDC_DETAIL 1016
5863 #define IDC_AMBIENT 1017
5964 #define IDC_BUFFERS 1017
 65+#define IDC_SPECULARSOURCE 1018
6066 #define IDC_SPINBACK 1019
 67+#define IDC_MATSPECULARSELECT 1020
 68+#define IDC_MATSPECULAR 1021
 69+#define IDC_AMBIENTSOURCE 1022
6170 #define IDC_FRAMERATE 1023
 71+#define IDC_EMISSIVESOURCE 1024
6272 #define IDC_SPINFRAME 1024
6373 #define IDC_FSAA 1026
6474 #define IDC_FILTERLABEL 1027
@@ -132,7 +142,7 @@
133143 #define IDC_MATAMBIENTSELECT 1116
134144 #define IDC_POWER 1118
135145 #define IDC_LIGHTNUMBER 1120
136 -#define IDC_SPIN1 1121
 146+#define IDC_SPINLIGHT 1121
137147 #define IDC_LIGHTTYPE 1123
138148 #define IDC_LIGHTDIFFUSE 1126
139149 #define IDC_LIGHTDIFFUSESELECT 1127
Index: dxgltest/Tests3D.cpp
@@ -37,6 +37,7 @@
3838 static MultiDirectDrawSurface *textures[8];
3939 static IDirect3D7 *d3d7;
4040 static IDirect3DDevice7 *d3d7dev;
 41+D3DMATERIAL7 material;
4142 static LPDIRECTDRAWCLIPPER ddclipper;
4243 static int width,height,bpp,refresh,backbuffers;
4344 static double fps;
@@ -46,14 +47,40 @@
4748 static unsigned int randnum;
4849 static int testtypes[] = {0,0,0};
4950
50 -static D3DVECTOR points[256];
51 -static D3DVECTOR normals[256];
52 -static D3DVERTEX vertices[256];
53 -static D3DLVERTEX litvertices[256];
54 -static WORD mesh[256];
55 -static WORD cube_mesh[] = {0,1,2, 2,1,3, 4,5,6, 6,5,7, 8,9,10, 10,9,11, 12,13,14, 14,13,15, 16,17,18,
56 - 18,17,19, 20,21,22, 22,21,23 };
 51+#define FVF_COLORVERTEX (D3DFVF_VERTEX | D3DFVF_DIFFUSE | D3DFVF_SPECULAR)
 52+struct COLORVERTEX
 53+{
 54+ D3DVALUE x;
 55+ D3DVALUE y;
 56+ D3DVALUE z;
 57+ D3DVALUE nx;
 58+ D3DVALUE ny;
 59+ D3DVALUE nz;
 60+ D3DCOLOR color;
 61+ D3DCOLOR specular;
 62+ D3DVALUE tu;
 63+ D3DVALUE tv;
 64+public:
 65+ COLORVERTEX() {};
 66+ COLORVERTEX(const D3DVECTOR& v, const D3DVECTOR& n, D3DCOLOR _color,
 67+ D3DCOLOR _specular, D3DVALUE _tu, D3DVALUE _tv)
 68+ {
 69+ x = v.x; y = v.y; z = v.z;
 70+ nx = n.x; ny = n.y; nz = n.z;
 71+ color = _color; specular = _specular;
 72+ tu = _tu; tv = _tv;
 73+ }
 74+
 75+};
 76+
 77+static int numpoints = 0;
 78+static int numindices = 0;
 79+static D3DVERTEX *vertices = NULL;
 80+static D3DLVERTEX *litvertices = NULL;
 81+static COLORVERTEX *colorvertices = NULL;
 82+static WORD *mesh = NULL;
5783 static D3DLIGHT7 lights[8];
 84+static BOOL lightenable[8];
5885 static DWORD bgcolor = 0;
5986
6087 typedef struct
@@ -201,6 +228,26 @@
202229 ddinterface->Release();
203230 ddinterface = NULL;
204231 }
 232+ if(mesh)
 233+ {
 234+ free(mesh);
 235+ mesh = NULL;
 236+ }
 237+ if(vertices)
 238+ {
 239+ free(vertices);
 240+ vertices = NULL;
 241+ }
 242+ if(litvertices)
 243+ {
 244+ free(litvertices);
 245+ litvertices = NULL;
 246+ }
 247+ if(colorvertices)
 248+ {
 249+ free(colorvertices);
 250+ colorvertices = NULL;
 251+ }
205252 PostQuitMessage(0);
206253 break;
207254 case WM_KEYDOWN:
@@ -466,82 +513,182 @@
467514 StopTimer();
468515 }
469516
470 -void MakeCube3D()
 517+void MakeCube3D(float size, int detail)
471518 {
472 - points[0] = D3DVECTOR(-2.5f,-2.5f,-2.5f);
473 - points[1] = D3DVECTOR(-2.5f,2.5f,-2.5f);
474 - points[2] = D3DVECTOR(2.5f,-2.5f,-2.5f);
475 - points[3] = D3DVECTOR(2.5f,2.5f,-2.5f);
476 - points[4] = D3DVECTOR(2.5f,-2.5f,2.5f);
477 - points[5] = D3DVECTOR(2.5f,2.5f,2.5f);
478 - points[6] = D3DVECTOR(-2.5f,-2.5f,2.5f);
479 - points[7] = D3DVECTOR(-2.5f,2.5f,2.5f);
 519+ if(detail < 2) return;
 520+ D3DVECTOR normals[6];
480521 normals[0] = D3DVECTOR(0.0f,0.0f,-1.0f);
481522 normals[1] = D3DVECTOR(1.0f,0.0f,0.0f);
482523 normals[2] = D3DVECTOR(0.0f,0.0f,1.0f);
483524 normals[3] = D3DVECTOR(-1.0f,0.0f,0.0f);
484525 normals[4] = D3DVECTOR(0.0f,1.0f,0.0f);
485 - normals[5] = D3DVECTOR(0.0f,-10.0f,0.0f);
486 - vertices[0] = D3DVERTEX(points[0],normals[0],0,1);
487 - vertices[1] = D3DVERTEX(points[1],normals[0],0,0);
488 - vertices[2] = D3DVERTEX(points[2],normals[0],1,1);
489 - vertices[3] = D3DVERTEX(points[3],normals[0],1,0);
490 - vertices[4] = D3DVERTEX(points[2],normals[1],0,1);
491 - vertices[5] = D3DVERTEX(points[3],normals[1],0,0);
492 - vertices[6] = D3DVERTEX(points[4],normals[1],1,1);
493 - vertices[7] = D3DVERTEX(points[5],normals[1],1,0);
494 - vertices[8] = D3DVERTEX(points[4],normals[2],0,1);
495 - vertices[9] = D3DVERTEX(points[5],normals[2],0,0);
496 - vertices[10] = D3DVERTEX(points[6],normals[2],1,1);
497 - vertices[11] = D3DVERTEX(points[7],normals[2],1,0);
498 - vertices[12] = D3DVERTEX(points[6],normals[3],0,1);
499 - vertices[13] = D3DVERTEX(points[7],normals[3],0,0);
500 - vertices[14] = D3DVERTEX(points[0],normals[3],1,1);
501 - vertices[15] = D3DVERTEX(points[1],normals[3],1,0);
502 - vertices[16] = D3DVERTEX(points[1],normals[4],0,1);
503 - vertices[17] = D3DVERTEX(points[7],normals[4],0,0);
504 - vertices[18] = D3DVERTEX(points[3],normals[4],1,1);
505 - vertices[19] = D3DVERTEX(points[5],normals[4],1,0);
506 - vertices[20] = D3DVERTEX(points[6],normals[5],0,1);
507 - vertices[21] = D3DVERTEX(points[0],normals[5],0,0);
508 - vertices[22] = D3DVERTEX(points[4],normals[5],1,1);
509 - vertices[23] = D3DVERTEX(points[2],normals[5],1,0);
510 - litvertices[0] = D3DLVERTEX(points[0],0xFFFFFFFF,0,0,1);
511 - litvertices[1] = D3DLVERTEX(points[1],0xFFFFFFFF,0,0,0);
512 - litvertices[2] = D3DLVERTEX(points[2],0xFFFFFFFF,0,1,1);
513 - litvertices[3] = D3DLVERTEX(points[3],0xFFFFFFFF,0,1,0);
514 - litvertices[4] = D3DLVERTEX(points[2],0xFFFFFFFF,0,0,1);
515 - litvertices[5] = D3DLVERTEX(points[3],0xFFFFFFFF,0,0,0);
516 - litvertices[6] = D3DLVERTEX(points[4],0xFFFFFFFF,0,1,1);
517 - litvertices[7] = D3DLVERTEX(points[5],0xFFFFFFFF,0,1,0);
518 - litvertices[8] = D3DLVERTEX(points[4],0xFFFFFFFF,0,0,1);
519 - litvertices[9] = D3DLVERTEX(points[5],0xFFFFFFFF,0,0,0);
520 - litvertices[10] = D3DLVERTEX(points[6],0xFFFFFFFF,0,1,1);
521 - litvertices[11] = D3DLVERTEX(points[7],0xFFFFFFFF,0,1,0);
522 - litvertices[12] = D3DLVERTEX(points[6],0xFFFFFFFF,0,0,1);
523 - litvertices[13] = D3DLVERTEX(points[7],0xFFFFFFFF,0,0,0);
524 - litvertices[14] = D3DLVERTEX(points[0],0xFFFFFFFF,0,1,1);
525 - litvertices[15] = D3DLVERTEX(points[1],0xFFFFFFFF,0,1,0);
526 - litvertices[16] = D3DLVERTEX(points[1],0xFFFFFFFF,0,0,1);
527 - litvertices[17] = D3DLVERTEX(points[7],0xFFFFFFFF,0,0,0);
528 - litvertices[18] = D3DLVERTEX(points[3],0xFFFFFFFF,0,1,1);
529 - litvertices[19] = D3DLVERTEX(points[5],0xFFFFFFFF,0,1,0);
530 - litvertices[20] = D3DLVERTEX(points[6],0xFFFFFFFF,0,0,1);
531 - litvertices[21] = D3DLVERTEX(points[0],0xFFFFFFFF,0,0,0);
532 - litvertices[22] = D3DLVERTEX(points[4],0xFFFFFFFF,0,1,1);
533 - litvertices[23] = D3DLVERTEX(points[2],0xFFFFFFFF,0,1,0);
 526+ normals[5] = D3DVECTOR(0.0f,-1.0f,0.0f);
 527+ int numfacevertices = detail*detail;
 528+ D3DVECTOR *face = (D3DVECTOR*)malloc(numfacevertices*sizeof(D3DVECTOR));
 529+ int numfaceindices = ((detail-1)*(detail-1))*6;
 530+ WORD *faceindex = (WORD*)malloc(numfaceindices*sizeof(WORD));
 531+ int ptr = 0;
 532+ float fx,fy;
 533+ // Generate points
 534+ for(int y = 0; y < detail; y++)
 535+ {
 536+ fy = (((float)(y / (float)(detail-1)))-.5f)*size;
 537+ for(int x = 0; x < detail; x++)
 538+ {
 539+ fx = (((float)(x / (float)(detail-1)))-.5f)*size;
 540+ face[ptr] = D3DVECTOR(fx,fy,0);
 541+ ptr++;
 542+ }
 543+ }
 544+ // Generate triangle indices
 545+ ptr = 0;
 546+ for(int y = 0; y < (detail-1); y++)
 547+ {
 548+ for(int x = 0; x < (detail-1); x++)
 549+ {
 550+ faceindex[ptr++] = x + (detail*y);
 551+ faceindex[ptr++] = x + (detail*(y+1));
 552+ faceindex[ptr++] = (x+1) + (detail*y);
 553+ faceindex[ptr++] = (x+1) + (detail*y);
 554+ faceindex[ptr++] = x + (detail*(y+1));
 555+ faceindex[ptr++] = (x+1) + (detail*(y+1));
 556+ }
 557+ }
 558+ numpoints = (detail*detail)*6;
 559+ numindices = ((detail-1)*(detail-1))*36;
 560+ if(vertices) free(vertices);
 561+ if(litvertices) free(litvertices);
 562+ if(colorvertices) free(colorvertices);
 563+ if(mesh) free(mesh);
 564+ vertices = (D3DVERTEX*)malloc(numpoints*sizeof(D3DVERTEX));
 565+ litvertices = (D3DLVERTEX*)malloc(numpoints*sizeof(D3DLVERTEX));
 566+ colorvertices = (COLORVERTEX*)malloc(numpoints*sizeof(COLORVERTEX));
 567+ mesh = (WORD*)malloc(numindices*sizeof(WORD));
 568+ // Generate vertex list
 569+ float u,v;
 570+ D3DVECTOR pos;
 571+ D3DVECTOR normal;
 572+ // Front face
 573+ ptr = 0;
 574+ for(int y = 0; y < detail; y++)
 575+ {
 576+ for(int x = 0; x < detail; x++)
 577+ {
 578+ u = (float)x/(float)(detail-1);
 579+ v = 1.f-((float)y/(float)(detail-1));
 580+ ptr = x+(detail*y);
 581+ pos = D3DVECTOR(face[ptr].x,face[ptr].y,-size/2.f);
 582+ normal = D3DVECTOR(0,0,-1);
 583+ vertices[ptr] = D3DVERTEX(pos,normal,u,v);
 584+ litvertices[ptr] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 585+ colorvertices[ptr] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 586+ }
 587+ }
 588+ // Right face
 589+ ptr = 0;
 590+ for(int y = 0; y < detail; y++)
 591+ {
 592+ for(int x = 0; x < detail; x++)
 593+ {
 594+ u = (float)x/(float)(detail-1);
 595+ v = 1.f-((float)y/(float)(detail-1));
 596+ ptr = x+(detail*y);
 597+ pos = D3DVECTOR(size/2.f,face[ptr].y,face[ptr].x);
 598+ normal = D3DVECTOR(1,0,0);
 599+ vertices[ptr+numfacevertices] = D3DVERTEX(pos,normal,u,v);
 600+ litvertices[ptr+numfacevertices] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 601+ colorvertices[ptr+numfacevertices] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 602+ }
 603+ }
 604+ // Back face
 605+ ptr = 0;
 606+ for(int y = 0; y < detail; y++)
 607+ {
 608+ for(int x = 0; x < detail; x++)
 609+ {
 610+ u = (float)x/(float)(detail-1);
 611+ v = 1.f-((float)y/(float)(detail-1));
 612+ ptr = x+(detail*y);
 613+ pos = D3DVECTOR(-face[ptr].x,face[ptr].y,size/2.f);
 614+ normal = D3DVECTOR(0,0,1);
 615+ vertices[ptr+(numfacevertices*2)] = D3DVERTEX(pos,normal,u,v);
 616+ litvertices[ptr+(numfacevertices*2)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 617+ colorvertices[ptr+(numfacevertices*2)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 618+ }
 619+ }
 620+ // Left face
 621+ ptr = 0;
 622+ for(int y = 0; y < detail; y++)
 623+ {
 624+ for(int x = 0; x < detail; x++)
 625+ {
 626+ u = (float)x/(float)(detail-1);
 627+ v = 1.f-((float)y/(float)(detail-1));
 628+ ptr = x+(detail*y);
 629+ pos = D3DVECTOR(-size/2.f,face[ptr].y,-face[ptr].x);
 630+ normal = D3DVECTOR(-1,0,0);
 631+ vertices[ptr+(numfacevertices*3)] = D3DVERTEX(pos,normal,u,v);
 632+ litvertices[ptr+(numfacevertices*3)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 633+ colorvertices[ptr+(numfacevertices*3)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 634+ }
 635+ }
 636+ // Top face
 637+ for(int y = 0; y < detail; y++)
 638+ {
 639+ for(int x = 0; x < detail; x++)
 640+ {
 641+ u = (float)x/(float)(detail-1);
 642+ v = 1.f-((float)y/(float)(detail-1));
 643+ ptr = x+(detail*y);
 644+ pos = D3DVECTOR(face[ptr].x,size/2.f,face[ptr].y);
 645+ normal = D3DVECTOR(0,1,0);
 646+ vertices[ptr+(numfacevertices*4)] = D3DVERTEX(pos,normal,u,v);
 647+ litvertices[ptr+(numfacevertices*4)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 648+ colorvertices[ptr+(numfacevertices*4)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 649+ }
 650+ }
 651+ // Bottom face
 652+ for(int y = 0; y < detail; y++)
 653+ {
 654+ for(int x = 0; x < detail; x++)
 655+ {
 656+ u = (float)x/(float)(detail-1);
 657+ v = 1.f-((float)y/(float)(detail-1));
 658+ ptr = x+(detail*y);
 659+ pos = D3DVECTOR(face[ptr].x,-size/2.f,-face[ptr].y);
 660+ normal = D3DVECTOR(0,-1,0);
 661+ vertices[ptr+(numfacevertices*5)] = D3DVERTEX(pos,normal,u,v);
 662+ litvertices[ptr+(numfacevertices*5)] = D3DLVERTEX(pos,0xFFFFFFFF,0,u,v);
 663+ colorvertices[ptr+(numfacevertices*5)] = COLORVERTEX(pos,normal,0xFFFFFFFF,0,u,v);
 664+ }
 665+ }
 666+ free(face);
 667+ // Generate index table
 668+ ptr = 0;
 669+ for(int i = 0; i < 6; i++)
 670+ {
 671+ for(int j = 0; j < numfaceindices; j++)
 672+ mesh[ptr++] = faceindex[j]+(i*numfacevertices);
 673+ }
 674+ free(faceindex);
534675 }
535676
536 -void SetVertexColor(D3DLVERTEX *start, int count, DWORD color)
 677+void SetVertexColor(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
537678 {
538679 for(int i = 0; i < count; i++)
 680+ {
539681 start[i].color = color;
 682+ start_color[i].color = color;
 683+ }
540684 }
541685
542 -void SetVertexSpecular(D3DLVERTEX *start, int count, DWORD color)
 686+void SetVertexSpecular(D3DLVERTEX *start, COLORVERTEX *start_color, int count, DWORD color)
543687 {
544688 for(int i = 0; i < count; i++)
 689+ {
545690 start[i].specular = color;
 691+ start_color[i].specular = color;
 692+ }
546693 }
547694
548695
@@ -586,6 +733,34 @@
587734 return true;
588735 }
589736
 737+void MakeLights()
 738+{
 739+ for(int i = 0; i < 8; i++)
 740+ {
 741+ lightenable[i] = FALSE;
 742+ ZeroMemory(&lights[i],sizeof(D3DLIGHT7));
 743+ lights[i].dcvDiffuse.r = lights[i].dcvDiffuse.g = lights[i].dcvDiffuse.b = 1;
 744+ lights[i].dltType = D3DLIGHT_DIRECTIONAL;
 745+ }
 746+ lightenable[0] = TRUE;
 747+ lights[0].dvPosition = D3DVECTOR(-10,-10,-10);
 748+ lights[1].dvPosition = D3DVECTOR(10,-10,-10);
 749+ lights[2].dvPosition = D3DVECTOR(-10,10,-10);
 750+ lights[3].dvPosition = D3DVECTOR(10,10,-10);
 751+ lights[4].dvPosition = D3DVECTOR(-10,-10,10);
 752+ lights[5].dvPosition = D3DVECTOR(10,-10,10);
 753+ lights[6].dvPosition = D3DVECTOR(-10,10,10);
 754+ lights[7].dvPosition = D3DVECTOR(10,10,10);
 755+ lights[0].dvDirection = D3DVECTOR(1,1,1);
 756+ lights[1].dvDirection = D3DVECTOR(-1,1,1);
 757+ lights[2].dvDirection = D3DVECTOR(1,-1,1);
 758+ lights[3].dvDirection = D3DVECTOR(-1,-1,1);
 759+ lights[4].dvDirection = D3DVECTOR(1,1,-1);
 760+ lights[5].dvDirection = D3DVECTOR(-1,1,-1);
 761+ lights[6].dvDirection = D3DVECTOR(1,-1,-1);
 762+ lights[7].dvDirection = D3DVECTOR(-1,-1,-1);
 763+}
 764+
590765 static const DDPIXELFORMAT fmt_rgba4444 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0xF00,0xF0,0xF,0xF000};
591766 static const DDPIXELFORMAT fmt_rgba1555 = {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0x7C00,0x3E0,0x1F,0x8000};
592767 static const DDPIXELFORMAT fmt_rgb565 = {sizeof(DDPIXELFORMAT),DDPF_RGB,0,16,0xF800,0x7E0,0x1F,0};
@@ -598,12 +773,11 @@
599774 D3DMATRIX matView;
600775 D3DMATRIX matProj;
601776 D3DMATRIX mat;
602 - D3DMATERIAL7 material;
603777 bgcolor = 0;
604778 switch(test)
605779 {
606780 case 0:
607 - MakeCube3D();
 781+ MakeCube3D(5,2);
608782 ZeroMemory(&material,sizeof(D3DMATERIAL7));
609783 material.ambient.r = 0.5f;
610784 material.ambient.g = 0.5f;
@@ -642,7 +816,7 @@
643817 error = d3d7dev->SetLight(0,&lights[0]);
644818 break;
645819 case 1:
646 - MakeCube3D();
 820+ MakeCube3D(5,2);
647821 cleartexformats();
648822 d3d7dev->EnumTextureFormats(gettexformat,NULL);
649823 gentexture(fmt_rgba4444,&textures[0],256,256,0);
@@ -660,6 +834,7 @@
661835 error = d3d7dev->LightEnable(0,TRUE);
662836 error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);
663837 error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xFFFFFFFF);
 838+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_CULLMODE,D3DCULL_CW);
664839 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
665840 mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
666841 mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
@@ -686,14 +861,20 @@
687862 lights[0].dvAttenuation1 = 0.4f;
688863 error = d3d7dev->SetLight(0,&lights[0]);
689864 break;
 865+ case 3:
 866+ ZeroMemory(lights,8*sizeof(D3DLIGHT7));
 867+ MakeLights();
690868 case 2:
691 - case 3:
692 - MakeCube3D();
 869+ MakeCube3D(5,8);
693870 ZeroMemory(&material,sizeof(D3DMATERIAL7));
694871 material.ambient.r = 1.0f;
695872 material.ambient.g = 1.0f;
696873 material.ambient.b = 1.0f;
697874 material.ambient.a = 1.0f;
 875+ material.diffuse.r = 1.0f;
 876+ material.diffuse.g = 1.0f;
 877+ material.diffuse.b = 1.0f;
 878+ material.diffuse.a = 1.0f;
698879 error = d3d7dev->SetMaterial(&material);
699880 error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
700881 error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xffffffff);
@@ -746,7 +927,7 @@
747928 mat._31 = (FLOAT)sin( (float)time );
748929 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
749930 error = d3d7dev->BeginScene();
750 - error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
 931+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,numpoints,mesh,numindices,0);
751932 error = d3d7dev->EndScene();
752933 break;
753934 case 1:
@@ -771,6 +952,19 @@
772953 error = d3d7dev->EndScene();
773954 break;
774955 case 2:
 956+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 957+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 958+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 959+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 960+ mat._11 = (FLOAT)cos( (float)time );
 961+ mat._33 = (FLOAT)cos( (float)time );
 962+ mat._13 = -(FLOAT)sin( (float)time );
 963+ mat._31 = (FLOAT)sin( (float)time );
 964+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 965+ error = d3d7dev->BeginScene();
 966+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_LVERTEX,litvertices,numpoints,mesh,numindices,0);
 967+ error = d3d7dev->EndScene();
 968+ break;
775969 case 3:
776970 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
777971 mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
@@ -782,7 +976,7 @@
783977 mat._31 = (FLOAT)sin( (float)time );
784978 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
785979 error = d3d7dev->BeginScene();
786 - error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_LVERTEX,litvertices,24,cube_mesh,36,0);
 980+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,FVF_COLORVERTEX,colorvertices,numpoints,mesh,numindices,0);
787981 error = d3d7dev->EndScene();
788982 break;
789983 default:
@@ -895,6 +1089,13 @@
8961090 SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Linear"));
8971091 }
8981092
 1093+void PopulateSourceCombo(HWND hWnd)
 1094+{
 1095+ SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Material"));
 1096+ SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Color 1"));
 1097+ SendMessage(hWnd,CB_ADDSTRING,0,(LPARAM)_T("Color 2"));
 1098+}
 1099+
8991100 void strupper(TCHAR *str)
9001101 {
9011102 TCHAR *ptr = str;
@@ -1294,7 +1495,7 @@
12951496 {
12961497 SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
12971498 _stscanf(tmpstring,_T("%x"),&number);
1298 - SetVertexColor(litvertices,24,number);
 1499+ SetVertexColor(litvertices,colorvertices,numpoints,number);
12991500 }
13001501 break;
13011502 case IDC_SPECULAR:
@@ -1302,7 +1503,7 @@
13031504 {
13041505 SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
13051506 _stscanf(tmpstring,_T("%x"),&number);
1306 - SetVertexSpecular(litvertices,24,number);
 1507+ SetVertexSpecular(litvertices,colorvertices,numpoints,number);
13071508 }
13081509 break;
13091510 case IDC_FACTOR:
@@ -1420,7 +1621,61 @@
14211622 }
14221623 break;
14231624 case WM_CLOSE:
1424 - ddinterface->Release();
 1625+ if(d3d7dev)
 1626+ {
 1627+ d3d7dev->Release();
 1628+ d3d7dev = NULL;
 1629+ }
 1630+ if(d3d7)
 1631+ {
 1632+ d3d7->Release();
 1633+ d3d7dev = NULL;
 1634+ }
 1635+ if(ddsrender)
 1636+ {
 1637+ ddsrender->Release();
 1638+ ddsrender = NULL;
 1639+ }
 1640+ if(ddsurface)
 1641+ {
 1642+ ddsurface->Release();
 1643+ ddsurface = NULL;
 1644+ }
 1645+ if(zbuffer)
 1646+ {
 1647+ zbuffer->Release();
 1648+ zbuffer = NULL;
 1649+ }
 1650+ if(ddclipper)
 1651+ {
 1652+ ddclipper->Release();
 1653+ ddclipper = NULL;
 1654+ }
 1655+ if(ddinterface)
 1656+ {
 1657+ ddinterface->Release();
 1658+ ddinterface = NULL;
 1659+ }
 1660+ if(mesh)
 1661+ {
 1662+ free(mesh);
 1663+ mesh = NULL;
 1664+ }
 1665+ if(vertices)
 1666+ {
 1667+ free(vertices);
 1668+ vertices = NULL;
 1669+ }
 1670+ if(litvertices)
 1671+ {
 1672+ free(litvertices);
 1673+ litvertices = NULL;
 1674+ }
 1675+ if(colorvertices)
 1676+ {
 1677+ free(colorvertices);
 1678+ colorvertices = NULL;
 1679+ }
14251680 EndDialog(hWnd,IDCANCEL);
14261681 break;
14271682 case WM_APP:
@@ -1504,6 +1759,8 @@
15051760 SendDlgItemMessage(hWnd,IDC_AMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
15061761 SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_SETTEXT,0,(LPARAM)_T("00000000"));
15071762 SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
 1763+ SendDlgItemMessage(hWnd,IDC_MATDIFFUSE,WM_SETTEXT,0,(LPARAM)_T("FFFFFFFF"));
 1764+ SendDlgItemMessage(hWnd,IDC_MATSPECULAR,WM_SETTEXT,0,(LPARAM)_T("00000000"));
15081765 PopulateFogCombo(GetDlgItem(hWnd,IDC_VERTEXFOGMODE));
15091766 PopulateFogCombo(GetDlgItem(hWnd,IDC_PIXELFOGMODE));
15101767 SendDlgItemMessage(hWnd,IDC_VERTEXFOGMODE,CB_SETCURSEL,D3DFOG_NONE,0);
@@ -1523,6 +1780,16 @@
15241781 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CW"));
15251782 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_ADDSTRING,0,(LPARAM)_T("CCW"));
15261783 SendDlgItemMessage(hWnd,IDC_CULLMODE,CB_SETCURSEL,2,0);
 1784+ PopulateSourceCombo(GetDlgItem(hWnd,IDC_DIFFUSESOURCE));
 1785+ PopulateSourceCombo(GetDlgItem(hWnd,IDC_SPECULARSOURCE));
 1786+ PopulateSourceCombo(GetDlgItem(hWnd,IDC_AMBIENTSOURCE));
 1787+ PopulateSourceCombo(GetDlgItem(hWnd,IDC_EMISSIVESOURCE));
 1788+ SendDlgItemMessage(hWnd,IDC_DIFFUSESOURCE,CB_SETCURSEL,D3DMCS_COLOR1,0);
 1789+ SendDlgItemMessage(hWnd,IDC_SPECULARSOURCE,CB_SETCURSEL,D3DMCS_COLOR2,0);
 1790+ SendDlgItemMessage(hWnd,IDC_AMBIENTSOURCE,CB_SETCURSEL,D3DMCS_COLOR2,0);
 1791+ SendDlgItemMessage(hWnd,IDC_EMISSIVESOURCE,CB_SETCURSEL,D3DMCS_MATERIAL,0);
 1792+ SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETRANGE32,2,64);
 1793+ SendDlgItemMessage(hWnd,IDC_SPINDETAIL,UDM_SETPOS32,0,8);
15271794 ::width = ddsd.dwWidth;
15281795 ::height = ddsd.dwHeight;
15291796 vertexshaderstate.texture = NULL;
@@ -1628,7 +1895,7 @@
16291896 {
16301897 SendDlgItemMessage(hWnd,IDC_DIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
16311898 _stscanf(tmpstring,_T("%x"),&number);
1632 - SetVertexColor(litvertices,24,number);
 1899+ SetVertexColor(litvertices,colorvertices,numpoints,number);
16331900 }
16341901 break;
16351902 case IDC_SPECULAR:
@@ -1636,7 +1903,7 @@
16371904 {
16381905 SendDlgItemMessage(hWnd,IDC_SPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
16391906 _stscanf(tmpstring,_T("%x"),&number);
1640 - SetVertexSpecular(litvertices,24,number);
 1907+ SetVertexSpecular(litvertices,colorvertices,numpoints,number);
16411908 }
16421909 break;
16431910 case IDC_FACTOR:
@@ -1662,12 +1929,150 @@
16631930 _stscanf(tmpstring,_T("%x"),&bgcolor);
16641931 }
16651932 break;
 1933+ case IDC_AMBIENT:
 1934+ {
 1935+ SendDlgItemMessage(hWnd,IDC_AMBIENT,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1936+ _stscanf(tmpstring,_T("%x"),&number);
 1937+ d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT,number);
 1938+ }
 1939+ break;
 1940+ case IDC_EMISSIVE:
 1941+ {
 1942+ SendDlgItemMessage(hWnd,IDC_EMISSIVE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1943+ _stscanf(tmpstring,_T("%x"),&number);
 1944+ material.emissive.b = (float)(number & 255) / 255.0;
 1945+ material.emissive.g = (float)((number>>8) & 255) / 255.0;
 1946+ material.emissive.r = (float)((number>>16) & 255) / 255.0;
 1947+ material.emissive.a = (float)((number>>24) & 255) / 255.0;
 1948+ d3d7dev->SetMaterial(&material);
 1949+ }
 1950+ break;
 1951+ case IDC_MATAMBIENT:
 1952+ {
 1953+ SendDlgItemMessage(hWnd,IDC_MATAMBIENT,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1954+ _stscanf(tmpstring,_T("%x"),&number);
 1955+ material.ambient.b = (float)(number & 255) / 255.0;
 1956+ material.ambient.g = (float)((number>>8) & 255) / 255.0;
 1957+ material.ambient.r = (float)((number>>16) & 255) / 255.0;
 1958+ material.ambient.a = (float)((number>>24) & 255) / 255.0;
 1959+ d3d7dev->SetMaterial(&material);
 1960+ }
 1961+ break;
 1962+ case IDC_MATDIFFUSE:
 1963+ {
 1964+ SendDlgItemMessage(hWnd,IDC_MATDIFFUSE,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1965+ _stscanf(tmpstring,_T("%x"),&number);
 1966+ material.diffuse.b = (float)(number & 255) / 255.0;
 1967+ material.diffuse.g = (float)((number>>8) & 255) / 255.0;
 1968+ material.diffuse.r = (float)((number>>16) & 255) / 255.0;
 1969+ material.diffuse.a = (float)((number>>24) & 255) / 255.0;
 1970+ d3d7dev->SetMaterial(&material);
 1971+ }
 1972+ break;
 1973+ case IDC_MATSPECULAR:
 1974+ {
 1975+ SendDlgItemMessage(hWnd,IDC_MATSPECULAR,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 1976+ _stscanf(tmpstring,_T("%x"),&number);
 1977+ material.specular.b = (float)(number & 255) / 255.0;
 1978+ material.specular.g = (float)((number>>8) & 255) / 255.0;
 1979+ material.specular.r = (float)((number>>16) & 255) / 255.0;
 1980+ material.specular.a = (float)((number>>24) & 255) / 255.0;
 1981+ d3d7dev->SetMaterial(&material);
 1982+ }
 1983+ break;
 1984+ case IDC_ENABLELIGHT:
 1985+ if(HIWORD(wParam) == BN_CLICKED)
 1986+ {
 1987+ if(SendDlgItemMessage(hWnd,IDC_ENABLELIGHT,BM_GETCHECK,0,0) == BST_CHECKED)
 1988+ {
 1989+ d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
 1990+ for(int i = 0; i < 8; i++)
 1991+ {
 1992+ d3d7dev->SetLight(i,&lights[i]);
 1993+ d3d7dev->LightEnable(i,lightenable[i]);
 1994+ }
 1995+ }
 1996+ else d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
 1997+ }
 1998+ break;
 1999+ case IDC_VERTEXCOLOR:
 2000+ if(HIWORD(wParam) == BN_CLICKED)
 2001+ {
 2002+ if(SendDlgItemMessage(hWnd,IDC_VERTEXCOLOR,BM_GETCHECK,0,0) == BST_CHECKED)
 2003+ d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX,TRUE);
 2004+ else d3d7dev->SetRenderState(D3DRENDERSTATE_COLORVERTEX,FALSE);
 2005+ }
 2006+ break;
 2007+ case IDC_DETAIL:
 2008+ if(HIWORD(wParam) == EN_CHANGE)
 2009+ {
 2010+ SendDlgItemMessage(hWnd,IDC_DETAIL,WM_GETTEXT,MAX_PATH,(LPARAM)tmpstring);
 2011+ number = _ttoi(tmpstring);
 2012+ if(number < 2) SendDlgItemMessage(hWnd,IDC_DETAIL,WM_SETTEXT,0,(LPARAM)_T("2"));
 2013+ if(number > 64) SendDlgItemMessage(hWnd,IDC_DETAIL,WM_SETTEXT,0,(LPARAM)_T("64"));
 2014+ MakeCube3D(5,number);
 2015+ }
 2016+ break;
16662017 default:
16672018 return FALSE;
16682019 }
16692020 break;
16702021 case WM_CLOSE:
1671 - ddinterface->Release();
 2022+ if(d3d7dev)
 2023+ {
 2024+ d3d7dev->Release();
 2025+ d3d7dev = NULL;
 2026+ }
 2027+ if(d3d7)
 2028+ {
 2029+ d3d7->Release();
 2030+ d3d7dev = NULL;
 2031+ }
 2032+ if(ddsrender)
 2033+ {
 2034+ ddsrender->Release();
 2035+ ddsrender = NULL;
 2036+ }
 2037+ if(ddsurface)
 2038+ {
 2039+ ddsurface->Release();
 2040+ ddsurface = NULL;
 2041+ }
 2042+ if(zbuffer)
 2043+ {
 2044+ zbuffer->Release();
 2045+ zbuffer = NULL;
 2046+ }
 2047+ if(ddclipper)
 2048+ {
 2049+ ddclipper->Release();
 2050+ ddclipper = NULL;
 2051+ }
 2052+ if(ddinterface)
 2053+ {
 2054+ ddinterface->Release();
 2055+ ddinterface = NULL;
 2056+ }
 2057+ if(mesh)
 2058+ {
 2059+ free(mesh);
 2060+ mesh = NULL;
 2061+ }
 2062+ if(vertices)
 2063+ {
 2064+ free(vertices);
 2065+ vertices = NULL;
 2066+ }
 2067+ if(litvertices)
 2068+ {
 2069+ free(litvertices);
 2070+ litvertices = NULL;
 2071+ }
 2072+ if(colorvertices)
 2073+ {
 2074+ free(colorvertices);
 2075+ colorvertices = NULL;
 2076+ }
16722077 EndDialog(hWnd,IDCANCEL);
16732078 break;
16742079 case WM_APP:
Index: dxgltest/dxgltest.rc
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream