00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Windows.h>
00023 #include <stdio.h>
00024 #include <DDraw.h>
00025 #include <D3D.h>
00026
00027 #include "D3DDrv.h"
00028 #include "DCommon.h"
00029 #include "Render.h"
00030 #include "Scene.h"
00031 #include "D3D_FX.h"
00032 #include "D3D_Main.h"
00033 #include "D3D_Err.h"
00034
00035
00036
00037
00038 static D3DTEXTUREHANDLE OldTexHandle = NULL;
00039
00040
00041
00042 void D3DSetTexHandle(D3DTEXTUREHANDLE TexHandle)
00043 {
00044 if (TexHandle == OldTexHandle)
00045 return;
00046
00047 OldTexHandle = TexHandle;
00048
00049 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_TEXTUREHANDLE, TexHandle);
00050 }
00051
00052 static LPDIRECT3DTEXTURE2 OldTexture[8];
00053
00054
00055
00056 void D3DSetTexture(int32 Stage, LPDIRECT3DTEXTURE2 Texture)
00057 {
00058 if (Texture == OldTexture[Stage])
00059 return;
00060
00061 OldTexture[Stage] = Texture;
00062
00063 AppInfo.lpD3DDevice->SetTexture(Stage, Texture);
00064 }
00065
00066
00067
00068 void D3DBilinearFilter(D3DTEXTUREFILTER Min, D3DTEXTUREFILTER Mag)
00069 {
00070 AppInfo.lpD3DDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR);
00071 AppInfo.lpD3DDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
00072
00073 if (AppInfo.CanDoMultiTexture)
00074 {
00075 AppInfo.lpD3DDevice->SetTextureStageState(1, D3DTSS_MINFILTER, D3DTFN_LINEAR);
00076 AppInfo.lpD3DDevice->SetTextureStageState(1, D3DTSS_MAGFILTER, D3DTFG_LINEAR);
00077 }
00078 }
00079
00080
00081
00082
00083 void D3DTexturedPolyOld(void *Pnts, int32 NumPoints)
00084 {
00085 AppInfo.lpD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_TLVERTEX, Pnts, NumPoints, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP);
00086 }
00087
00088
00089
00090
00091 void D3DTexturedPoly(void *Pnts, int32 NumPoints)
00092 {
00093 AppInfo.lpD3DDevice->DrawPrimitive( D3DPT_TRIANGLEFAN,
00094
00095 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2,
00096 Pnts,
00097 NumPoints,
00098 D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP);
00099
00100 }
00101
00102
00103
00104
00105 void D3DViewport (int32 x, int32 y, int32 width, int32 height)
00106 {
00107 D3DVIEWPORT2 vport;
00108
00109 return;
00110
00111 vport.dwSize = sizeof(D3DVIEWPORT2);
00112 AppInfo.lpD3DViewport->GetViewport2(&vport);
00113 vport.dwX = x;
00114 vport.dwY = AppInfo.OldHeight - (y + height);
00115 vport.dwWidth = width;
00116 vport.dwHeight = height;
00117 vport.dvClipX = -1.0f;
00118 vport.dvClipY = 1.0f;
00119 vport.dvClipWidth = (float)width /2.0f;
00120 vport.dvClipHeight = (float)height/2.0f;
00121 AppInfo.lpD3DViewport->SetViewport2(&vport);
00122 }
00123
00124
00125
00126 void D3DDepthRange (float zNear, float zFar)
00127 {
00128 D3DVIEWPORT2 vport;
00129 vport.dwSize = sizeof(D3DVIEWPORT2);
00130 AppInfo.lpD3DViewport->GetViewport2(&vport);
00131 vport.dvMinZ = (D3DVALUE)(((-1.0) * (zFar + zNear)) / (zFar - zNear));
00132 vport.dvMaxZ = (D3DVALUE)(((-1.0) * (zFar + zNear - 2.0)) / (zFar - zNear));
00133 AppInfo.lpD3DViewport->SetViewport2(&vport);
00134 }
00135
00136 static D3DBLEND OldSFunc = D3DBLEND_ONE;
00137 static D3DBLEND OldDFunc = D3DBLEND_ONE;
00138
00139
00140
00141 void D3DBlendFunc (D3DBLEND SFunc, D3DBLEND DFunc)
00142 {
00143 if (SFunc != OldSFunc)
00144 {
00145 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, SFunc);
00146 OldSFunc = SFunc;
00147 }
00148 if (DFunc != OldDFunc)
00149 {
00150 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, DFunc);
00151 OldDFunc = DFunc;
00152 }
00153
00154 }
00155
00156 static BOOL OldBlend = FALSE;
00157
00158
00159
00160 void D3DBlendEnable(BOOL Enable)
00161 {
00162 if (OldBlend == Enable)
00163 return;
00164
00165 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, Enable);
00166
00167 OldBlend = Enable;
00168 }
00169
00170 static BOOL OldWrap = FALSE;
00171
00172 void D3DTexWrap(DWORD Stage, BOOL Wrap)
00173 {
00174 if (OldWrap == Wrap)
00175 return;
00176
00177 OldWrap = Wrap;
00178
00179 if (Wrap)
00180 {
00181 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESS, D3DTADDRESS_WRAP);
00182 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
00183 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
00184 }
00185 else
00186 {
00187 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP);
00188 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
00189 AppInfo.lpD3DDevice->SetTextureStageState(Stage, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
00190 }
00191 }
00192
00193 void D3DZWriteEnable (BOOL Enable)
00194 {
00195 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, Enable);
00196 }
00197
00198 void D3DZFunc (D3DCMPFUNC Func)
00199 {
00200 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZFUNC, Func);
00201 }
00202
00203 void D3DZEnable(BOOL Enable)
00204 {
00205 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, Enable);
00206 }
00207
00208 void D3DPolygonMode (D3DFILLMODE Mode)
00209 {
00210 AppInfo.lpD3DDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);
00211 }
00212
00213
00214