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