typedef enum _D3DRENDERSTATETYPE {
D3DRS_ZENABLE = 7, /* D3DZBUFFERTYPE (or TRUE/FALSE for legacy) */
D3DRS_FILLMODE = 8, /* D3DFILLMODE */
D3DRS_SHADEMODE = 9, /* D3DSHADEMODE */
D3DRS_ZWRITEENABLE = 14, /* TRUE to enable z writes */
D3DRS_ALPHATESTENABLE = 15, /* TRUE to enable alpha tests */
D3DRS_LASTPIXEL = 16, /* TRUE for last-pixel on lines */
D3DRS_SRCBLEND = 19, /* D3DBLEND */
D3DRS_DESTBLEND = 20, /* D3DBLEND */
D3DRS_CULLMODE = 22, /* D3DCULL */
D3DRS_ZFUNC = 23, /* D3DCMPFUNC */
D3DRS_ALPHAREF = 24, /* D3DFIXED */
D3DRS_ALPHAFUNC = 25, /* D3DCMPFUNC */
D3DRS_DITHERENABLE = 26, /* TRUE to enable dithering */
D3DRS_ALPHABLENDENABLE = 27, /* TRUE to enable alpha blending */
D3DRS_FOGENABLE = 28, /* TRUE to enable fog blending */
D3DRS_SPECULARENABLE = 29, /* TRUE to enable specular */
D3DRS_FOGCOLOR = 34, /* D3DCOLOR */
D3DRS_FOGTABLEMODE = 35, /* D3DFOGMODE */
D3DRS_FOGSTART = 36, /* Fog start (for both vertex and pixel fog) */
D3DRS_FOGEND = 37, /* Fog end */
D3DRS_FOGDENSITY = 38, /* Fog density */
D3DRS_RANGEFOGENABLE = 48, /* Enables range-based fog */
D3DRS_STENCILENABLE = 52, /* BOOL enable/disable stenciling */
D3DRS_STENCILFAIL = 53, /* D3DSTENCILOP to do if stencil test fails */
D3DRS_STENCILZFAIL = 54, /* D3DSTENCILOP to do if stencil test passes and Z test fails */
D3DRS_STENCILPASS = 55, /* D3DSTENCILOP to do if both stencil and Z tests pass */
D3DRS_STENCILFUNC = 56, /* D3DCMPFUNC fn. Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true */
D3DRS_STENCILREF = 57, /* Reference value used in stencil test */
D3DRS_STENCILMASK = 58, /* Mask value used in stencil test */
D3DRS_STENCILWRITEMASK = 59, /* Write mask applied to values written to stencil buffer */
D3DRS_TEXTUREFACTOR = 60, /* D3DCOLOR used for multi-texture blend */
D3DRS_WRAP0 = 128, /* wrap for 1st texture coord. set */
D3DRS_WRAP1 = 129, /* wrap for 2nd texture coord. set */
D3DRS_WRAP2 = 130, /* wrap for 3rd texture coord. set */
D3DRS_WRAP3 = 131, /* wrap for 4th texture coord. set */
D3DRS_WRAP4 = 132, /* wrap for 5th texture coord. set */
D3DRS_WRAP5 = 133, /* wrap for 6th texture coord. set */
D3DRS_WRAP6 = 134, /* wrap for 7th texture coord. set */
D3DRS_WRAP7 = 135, /* wrap for 8th texture coord. set */
D3DRS_CLIPPING = 136,
D3DRS_LIGHTING = 137,
D3DRS_AMBIENT = 139,
D3DRS_FOGVERTEXMODE = 140,
D3DRS_COLORVERTEX = 141,
D3DRS_LOCALVIEWER = 142,
D3DRS_NORMALIZENORMALS = 143,
D3DRS_DIFFUSEMATERIALSOURCE = 145,
D3DRS_SPECULARMATERIALSOURCE = 146,
D3DRS_AMBIENTMATERIALSOURCE = 147,
D3DRS_EMISSIVEMATERIALSOURCE = 148,
D3DRS_VERTEXBLEND = 151,
D3DRS_CLIPPLANEENABLE = 152,
D3DRS_POINTSIZE = 154, /* float point size */
D3DRS_POINTSIZE_MIN = 155, /* float point size min threshold */
D3DRS_POINTSPRITEENABLE = 156, /* BOOL point texture coord control */
D3DRS_POINTSCALEENABLE = 157, /* BOOL point size scale enable */
D3DRS_POINTSCALE_A = 158, /* float point attenuation A value */
D3DRS_POINTSCALE_B = 159, /* float point attenuation B value */
D3DRS_POINTSCALE_C = 160, /* float point attenuation C value */
D3DRS_MULTISAMPLEANTIALIAS = 161, // BOOL - set to do FSAA with multisample buffer
D3DRS_MULTISAMPLEMASK = 162, // DWORD - per-sample enable/disable
D3DRS_PATCHEDGESTYLE = 163, // Sets whether patch edges will use float style tessellation
D3DRS_DEBUGMONITORTOKEN = 165, // DEBUG ON
D3DRS_POINTSIZE_MAX = 166, /* float point size max threshold */
D3DRS_INDEXEDVERTEXBLENDENABLE = 167,
D3DRS_COLORWRITEENABLE = 168, // per-channel write enable
D3DRS_TWEENFACTOR = 170, // float tween factor
D3DRS_BLENDOP = 171, // D3DBLENDOP setting
D3DRS_POSITIONDEGREE = 172, // NPatch position interpolation degree. D3DDEGREE_LINEAR or D3DDEGREE_CUBIC (default)
D3DRS_NORMALDEGREE = 173, // NPatch normal interpolation degree. D3DDEGREE_LINEAR (default) or D3DDEGREE_QUADRATIC
D3DRS_SCISSORTESTENABLE = 174,
D3DRS_SLOPESCALEDEPTHBIAS = 175,
D3DRS_ANTIALIASEDLINEENABLE = 176,
D3DRS_MINTESSELLATIONLEVEL = 178,
D3DRS_MAXTESSELLATIONLEVEL = 179,
D3DRS_ADAPTIVETESS_X = 180,
D3DRS_ADAPTIVETESS_Y = 181,
D3DRS_ADAPTIVETESS_Z = 182,
D3DRS_ADAPTIVETESS_W = 183,
D3DRS_ENABLEADAPTIVETESSELLATION = 184,
D3DRS_TWOSIDEDSTENCILMODE = 185, /* BOOL enable/disable 2 sided stenciling */
D3DRS_CCW_STENCILFAIL = 186, /* D3DSTENCILOP to do if ccw stencil test fails */
D3DRS_CCW_STENCILZFAIL = 187, /* D3DSTENCILOP to do if ccw stencil test passes and Z test fails */
D3DRS_CCW_STENCILPASS = 188, /* D3DSTENCILOP to do if both ccw stencil and Z tests pass */
D3DRS_CCW_STENCILFUNC = 189, /* D3DCMPFUNC fn. ccw Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true */
D3DRS_COLORWRITEENABLE1 = 190, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
D3DRS_COLORWRITEENABLE2 = 191, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
D3DRS_COLORWRITEENABLE3 = 192, /* Additional ColorWriteEnables for the devices that support D3DPMISCCAPS_INDEPENDENTWRITEMASKS */
D3DRS_BLENDFACTOR = 193, /* D3DCOLOR used for a constant blend factor during alpha blending for devices that support D3DPBLENDCAPS_BLENDFACTOR */
D3DRS_SRGBWRITEENABLE = 194, /* Enable rendertarget writes to be DE-linearized to SRGB (for formats that expose D3DUSAGE_QUERY_SRGBWRITE) */
D3DRS_DEPTHBIAS = 195,
D3DRS_WRAP8 = 198, /* Additional wrap states for vs_3_0+ attributes with D3DDECLUSAGE_TEXCOORD */
D3DRS_WRAP9 = 199,
D3DRS_WRAP10 = 200,
D3DRS_WRAP11 = 201,
D3DRS_WRAP12 = 202,
D3DRS_WRAP13 = 203,
D3DRS_WRAP14 = 204,
D3DRS_WRAP15 = 205,
D3DRS_SEPARATEALPHABLENDENABLE = 206, /* TRUE to enable a separate blending function for the alpha channel */
D3DRS_SRCBLENDALPHA = 207, /* SRC blend factor for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
D3DRS_DESTBLENDALPHA = 208, /* DST blend factor for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
D3DRS_BLENDOPALPHA = 209, /* Blending operation for the alpha channel when D3DRS_SEPARATEDESTALPHAENABLE is TRUE */
D3DRS_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
} D3DRENDERSTATETYPE;
DDRS_ZENABLE 用于控制深度缓存的状态。它的状态是用一个枚举类型来表示的:D3DZB_TRUE、D3DZB_FALSE和D3DZB_USEW。在D3D中z-buffering 是对z轴上的信息起作用,所以,如果你需要表示的是2D信息的话,可以用pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE ); 关闭z-buffering。比如游戏中的UI,需要用到一些控制面板之类的DD,这个时候就是需要关闭它的。这个渲染参数的默认值是跟 D3DPRESENT_PARAMETERS 中的EnableAutoDepthStencil的值是相关联的;如果这个值是TRUE,那么渲染状态就是 D3DZB_TRUE,反之为D3DZB_FALSE。
D3DRS_FILLMODE 从名字看的话,这个渲染模式是用来;控制填充模式的,它的值也是一个枚举类型 D3DFILL_POINT、D3DFILL_WIREFRAME和D3DFILL_SOLID。默认值是D3DFILL_SOLID,不过这个值的作用现在还没有看出来。:P
D3DRS_SHADEMODE 这个参数控制的是阴影模式,默认值是 D3DSHADE_GOURAND,翻译过来一般是叫做 高络德渲染。另外两个 D3DSHADE_FLAT 和 D3DSHADE_PHONG。高络德阴影模式是对一个三角形的3个顶点的颜色进行线性叉值算法得到的。平面阴影模式只利用三角形的第一个顶点进行描述。很显然用D3DSHADE_GOURAND渲染方式可以得到更加逼真的阴影效果。
D3DRS_ZWRITEENABLE 默认值TRUE表示可以写深度缓存,这个参数可以保护深度缓存不被系统修改。深度比对规则是依照D3DRS_ZFUNC参数的,如果值为FALSE的话,假设深度缓存被修改,但是这个值却不能写进缓存。
D3DRS_ALPHATESTENABLE 这个参数将允许每个象素点都做alpha测试;如果测试通过的话,这个象素就会被帧缓存处理,否则的话,它会被所有帧缓存忽略掉。这个测试其实就是通过D3DRS_ALPHAFUNC参数提供的对比函数,比较输入的alpha值和参照值之间的差别,这个参照值是由D3DRS_ALPHAREF参数确定的,默认值是FALSE。
D3DRS_LASTPIXEL 默认值是TRUE,绘制一条线的最后一个象素,如果是FALSE,就是不画。这个参数的主要作用是在绘制线框的时候体现出来的,假设我们要画一个矩形边框,有时候,矩形的两条线段的端点会出现重叠的现象,影响效果,这个时候,你可以把这个参数设为FALSE;但是要注意的是,除非你有明确的目的,一般不要轻易修改这个参数的值,它可能导致线框的结合处出现断开的现象。
D3DRS_SRCBLEND 和 D3DRS_DESTBLEND 是用来设定支持的混合模式。
D3DRS_CULLMODE 这个参数用来指定三角形背面的剔除方式。它的值是一个D3DCULL类型的枚举类型。D3DCULL_NONE,不要剔除背面;D3DCULL_CW,按照顺时针的方向的顶点剔除背面;D3DCULL_CCW,按照逆时针方向剔除背面。而最后一个就是默认值,还没弄清楚区别在什么地方。
D3DRS_ZFUNC 这个参数在前面有提到,与D3DRS_ZWRITTENABLE有些关联。它的值是 D3DCMPFUNC 枚举类型的值;默认值是 D3DCMP_LESSEQUAL。它允许程序根据一个象素距离摄像机的长度来接受或者拒绝它。这个象素的深度值会与depth-buffer的值进行比较,如果通过了这个测试,这个象素就会被写。实际上,如果象素没有通过测试的话,软件光栅处理和很多硬件加速都会更加快一些,因为不要渲染象素的话,就不需要对纹理进行过滤和调节。
D3DRS_ALPHAREF 设定象素alpha测试的参考值,它的值是一个DWORD型的低8位,区间是从0x00000000到0x000000ff。默认值是0。
D3DRS_ALPHAFUNC 这个参数允许程序根据象素的alpha值来决定是否接受。类似D3DRS_ZFUNC。
D3DRS_DITHERENABLE 使程序允许抖动,默认是FALSE。
D3DRS_ALPHABLENDENABLE 允许使用alpha混合,默认是FALSE。而混合类型是由D3DRS_SRCBLEND 和 D3DRS_DESTBLEND决定的。
D3DRS_FOGENABLE 允许烟雾混合,也就是常说的烟雾效果。默认FALSE。
D3DRS_SPECULARENABLE 打开镜面反射效果,默认是FALSE。
D3DRS_FOGCOLOR 设定烟雾颜色。
D3DRS_FOGTABLEMODE 这个烟雾公式被用来计算象烟雾,设定烟雾模式,默认值是D3DFOG_NONE,另外还有D3DFOG_EXP,D3DFOG_EXP2,D3DFOG_LINEAR。
SetRenderState( D3DRS_POINTSCALEENABLE, TRUE ); //打开缩放功能
SetRenderState( D3DRS_POINTSCALE_A , FtoDW( 1.00f ));//设置因子,下同
SetRenderState( D3DRS_POINTSCALE_B , FtoDW( 1.00F ));
SetRenderState( D3DRS_POINTSCALE_C , FtoDW( 1.00f ));
SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW( 5.00f ));//设置点大小上限,下类似
SetRenderState( D3DRS_POINTSIZE_MAX, FtoDW( 5.00f ));
SetRenderState( D3DRS_POINTSPRITEENABLE , TRUE ) ; //打开点精灵效果
SetRenderState( D3DRS_AMBIENT, 0xffffffff ); //设置环境光颜色
开启ALPHA混合效果
SetRenderState( D3DRS_ALPHABLENDABLE,TRUE)//开启。默认是关闭的FALSE
SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);就是让逆时针的三角形显示出来,DX默认也是拣选逆时针的三角形
SetRenderState(D3DRS_LIGHTING, FALSE);//关闭照明,因为我们明确指出了我们的顶点颜色
设置混合因子:
源:SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA );
目的:SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA);
第二个参数是 D3DBLEND的枚举结构。
|
- 上一篇:Open