DirectX基礎學習系列5 融合技術

2022-03-06 03:13:50 字數 3093 閱讀 3259

7.1融合方程

1概念融合技術將當前光柵化畫素的顏色與以前已光柵化並處於同乙個位置的畫素顏色進行合成,即將當前要進行光柵化的三角形單元與已寫入後台的畫素進行融合

2需要遵循的原則:

(1)先繪製不需要融合的物體

(2)需要融合的物品按照攝像機的深度值進行排序

3融合方程

color = (rgbsrc * ksrc) op (rgbdst * kdst)

ksrc   op    kdst都為可以設定的引數

4開啟融合運算

device->setrenderstate(d3drs_alphaenable,true);

7.2融合因子

設定融合因子

device->setrenderstate(d3drs_srcblend,flag);

device->setrenderstate(d3drs_destblend,flag);

flag為d3dblend型別引數,可以為如下引數:

typedef enum d3dblend

d3dblend, *lpd3dblend;

半透明效果可以將src設定為d3dblend_srcalpha ,dst設定為d3dblend_invdestalpha ,可以實現透明效果
參考網頁:
7.3透明度的**
hresult settexturestagestate
dword stage,

d3dtexturestagestatetype type,

dword value

);

typedef enum d3dtexturestagestatetype

d3dtexturestagestatetype, *lpd3dtexturestagestatetype;

device->settexturestagestate(0,d3dtss_alpharg1,d3dda_texture);
device->settexturestagestate(0,d3dtss_alpha_op,d3dop_selectarg1);
7.4透明效果
(1)設定融合因子 d3drs_srcblend d3drs_destblend
(2)設定alpha資料**
(3)啟用融合狀態
#include "d3dutility.h"
//
// globals
//
idirect3ddevice9* device = 0;
const

int width = 640;

const

int height = 480;

id3dxmesh*   teapot = 0;
d3dmaterial9 teapotmtrl;
idirect3dvertexbuffer9* bkgndquad = 0;
idirect3dtexture9*      bkgndtex  = 0;
d3dmaterial9            bkgndmtrl;
//
// classes and structures
//
struct vertex
vertex(
float x, float y, float z,
float nx, float ny, float nz,
float u, float v)
float _x, _y, _z;
float _nx, _ny, _nz;
float _u, _v; // texture coordinates
static

const dword fvf;

};
const dword vertex::fvf = d3dfvf_xyz | d3dfvf_normal | d3dfvf_tex1;
//
// framework functions
//
bool setup()
void cleanup()
bool display(float timedelta)
return

true;

}
//
// wndproc
//
lresult callback d3d::wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam)
return ::defwindowproc(hwnd, msg, wparam, lparam);
}
//
// winmain
//
int winapi winmain(hinstance hinstance,
hinstance previnstance,
pstr cmdline,
int showcmd)
if(!setup())
d3d::entermsgloop( display );
cleanup();
device->release();
return 0;
}

DirectX 基礎學習系列6 字型

directx9自帶id3dxfont類 內部呼叫gdi的介面,效率一般,但能夠處理一些複雜的字型 hresult d3dxcreatefontindirect lpdirect3ddevice9 pdevice,const d3dxfont desc pdesc,lpd3dxfont ppfont...

DirectX基礎學習系列4 顏色和光照

4.1顏色表示 rgb顏色 d3dcolor 可以用巨集d3dcolor argb a,r,g,b d3dcolor xrgb 255,r,g,b 另外一種浮點表示 d3dcolorvalue,浮點型別,最小為0 最大為1 4.2頂點顏色 struct colorvetex float x,y,z ...

DirectX學習 數學基礎 1

向量的基本運用 建立3d向量 typedef struct d3dxvector3 public d3dvector d3dxvector3 const float d3dxvector3 const d3dvector d3dxvector3 const d3dxfloat16 d3dxvecto...