【轉】Direct3D頂點結構使用總結

【轉】Direct3D頂點結構使用總結

D3D里面最基本的就是頂點了,雖說一直在用,可是卻也是自己比較模糊的一個點,知道其中的意思,卻不是很清楚,今天就總結一下,掃一下這個盲區:

D3D中的頂點緩沖區的聲明:

LPDIRECT3DVERTEXBUFFER9 g_pVB??????? = NULL;??? //頂點緩沖區對象

通常都是用LPDIRECT3DVERTEXBUFFER9 來聲明頂點緩沖區,它其實就是IDirect3DVertexBuffer9的指針類型,這兩個起到的效果是一樣的。用LPDIRECT3DVERTEXBUFFER9 聲明之后,只是鎮定了一個緩沖區的指針,下面還需要開辟一個緩沖區給這個指針。

在開辟真正的內存之前,我們先看一下頂點格式的定義,D3D里面是采用的靈活頂點格式,這點大家應該都是知道的,下面就來總結一下這些靈活頂點格式都具體有哪些,有什么用處。

一般定義頂點結構的時候都是用一個結構體,當然用類去定義也可以,但是一般沒有那個必要。

struct CUSTOMVERTEX

{

??? FLOAT x, y, z, rhw;

??? DWORD color;

};

在還需要定義一個宏,來向D3D說明一下,自己定義的頂點的格式到底有哪些。

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)? //頂點格式

上面這一句話的意思就是,定義的頂點結構包含:位置變換信息(D3DFVF_XYZRHW)和漫反射顏色信息(D3DFVF_DIFFUSE);

那么,一共都有哪些類型可以定義呢,都有什么樣的用呢。

?

---------------------------------------------------------------------------------------------------------------------------------------

?

Vertex Data Flags

#defineDescriptionData order and type
D3DFVF_DIFFUSEVertex format includes a diffuse color component.DWORD in ARGB order. See D3DCOLOR_ARGB.
D3DFVF_NORMALVertex format includes a vertex normal vector. This flag cannot be used with the D3DFVF_XYZRHW flag.float, float, float
D3DFVF_PSIZEVertex format specified in point size. This size is expressed in camera space units for vertices that are not transformed and lit, and in device-space units for transformed and lit vertices.float
D3DFVF_SPECULARVertex format includes a specular color component.DWORD in ARGB order. See D3DCOLOR_ARGB.
D3DFVF_XYZVertex format includes the position of an untransformed vertex. This flag cannot be used with the D3DFVF_XYZRHW flag.float, float, float.
D3DFVF_XYZRHWVertex format includes the position of a transformed vertex. This flag cannot be used with the D3DFVF_XYZ or D3DFVF_NORMAL flags.float, float, float, float.
D3DFVF_XYZB1 through D3DFVF_XYZB5Vertex format contains position data, and a corresponding number of weighting (beta) values to use for multimatrix vertex blending operations. Currently, Direct3D can blend with up to three weighting values and four blending matrices. For more information about using blending matrices, see Indexed Vertex Blending (Direct3D 9). 1, 2, or 3 floats. When D3DFVF_LASTBETA_UBYTE4 is used, the last blending weight is treated as a DWORD.
D3DFVF_XYZWVertex format contains transformed and clipped (x, y, z, w) data. ProcessVertices does not invoke the clipper, instead outputting data in clip coordinates. This constant is designed for, and can only be used with, the programmable vertex pipeline.float, float, float, float

?

Texture Flags

?

#defineDescription
D3DFVF_TEX0 - D3DFVF_TEX8Number of texture coordinate sets for this vertex. The actual values for these flags are not sequential.
D3DFVF_TEXCOORDSIZEN(coordIndex)Define a texture coordinate data set. n indicates the dimension of the texture coordinates. coordIndex indicates texture coordinate index number. See D3DFVF_TEXCOORDSIZEN and Texture coordinates and Texture Stages.

?

Mask Flags

?

#defineDescription
D3DFVF_POSITION_MASKMask for position bits.
D3DFVF_RESERVED0, D3DFVF_RESERVED2Mask values for reserved bits in the FVF. Do not use.
D3DFVF_TEXCOUNT_MASKMask value for texture flag bits.

?

Miscellaneous Flags

?

#defineDescription
D3DFVF_LASTBETA_D3DCOLORThe last beta field in the vertex position data will be of type D3DCOLOR. The data in the beta fields are used with matrix palette skinning to specify matrix indices.
D3DFVF_LASTBETA_UBYTE4The last beta field in the vertex position data will be of type UBYTE4. The data in the beta fields are used with matrix palette skinning to specify matrix indices.
// Given the following vertex data definition: 
struct VERTEXPOSITION
{float pos[3];union {float beta[5];struct{float weights[4];DWORD MatrixIndices;  // Used as UBYTEs}}
};

Given the FVF is declared as: D3DFVF_XYZB5 | D3DFVF_LASTBETA_UBYTE4. Weight and MatrixIndices are included in beta[5], where D3DFVF_LASTBETA_UBYTE4 says to interpret the last DWORD in beta[5] as type UBYTE4.

D3DFVF_TEXCOUNT_SHIFTThe number of bits by which to shift an integer value that identifies the number of texture coordinates for a vertex. This value might be used as shown below.
DWORD dwNumTextures = 1;  // Vertex has only one set of coordinates.// Shift the value for use when creating a 
//   flexible vertex format (FVF) combination.
dwFVF = dwNumTextures << D3DFVF_TEXCOUNT_SHIFT;// Now, create an FVF combination using the shifted value.

?

Examples

The following examples show other common flag combinations.

// Untransformed vertex for lit, untextured, Gouraud-shaded content.
dwFVF = ( D3DFVF_XYZ | D3DFVF_DIFFUSE );
// Untransformed vertex for unlit, untextured, Gouraud-shaded 
//   content with diffuse material color specified per vertex.
dwFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE );
// Untransformed vertex for light-map-based lighting.
dwFVF = ( D3DFVF_XYZ | D3DFVF_TEX2 );
// Transformed vertex for light-map-based lighting with shared rhw.
dwFVF = ( D3DFVF_XYZRHW | D3DFVF_TEX2 );
// Heavyweight vertex for unlit, colored content with two 
//   sets of texture coordinates.
dwFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX2 );

?

------------------------------------------------------------------------------------------------------------------

?

?

在頂點結構體中沒有RHW時,Direct3D將執行視、投影、世界等變換以及進行光線計算,之后你才能在窗口中得到你所繪制的物體。當頂點結構體中有RHW時,就像上面那段英文所述,告知Direct3D使用的頂點已經在屏幕坐標系中了,不再執行視圖、投影、世界等變換和光線計算,因為D3DFVF_XYZRHW標志告訴它頂點已經經過了這些處理,并直接將頂點進行光柵操作,任何用SetTransform進行的轉換都對其無效。不過這時的原點就在客戶區的左上角了,其中x向右為正,y向下為正,而z的意義已經變為z-buffer的象素深度。

??? 值得注意的是,D3DFVF_XYZRHW和D3DFVF_XYZ、D3DFVF_NORMAL不能共存,因為后兩個標志與前一個矛盾。在使用這種頂點時,系統需要頂點的位置已經經過變換了,也就是說x、y必須在屏幕坐標系中,z必須是z-buffer中的象素深度,取值范圍:0.0-1.0,離觀察者最近的地方為0.0,觀察范圍內最遠可見的地方為1.0。(不過我測試的時候似乎z值不起作用。)引自:http://www.cppblog.com/lovedday/archive/2009/03/22/48507.html

在定義完頂點格式以后,就要開辟一塊頂點緩沖區:


g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),

????????????????????????????????????????????????? 0, D3DFVF_CUSTOMVERTEX,

????????????????????????????????????????????????? D3DPOOL_DEFAULT, &g_pVB, NULL )


開辟緩沖區后,就需要對這個緩沖區進行填寫,那么填寫的數據呢,也需要先指定出來:


CUSTOMVERTEX vertices[] =

??? {

{ 100.0f, 400.0f, 0.5f, 1.0f, 0xffff0000, },

??????? { 300.0f,? 50.0f, 0.5f, 1.0f, 0xff00ff00, },

??????? { 500.0f, 400.0f, 0.5f, 1.0f, 0xff0000ff, },

??? };

然后將數據寫入緩沖區:


VOID* pVertices;

??? if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )

??????? return E_FAIL;

??? memcpy( pVertices, vertices, sizeof(vertices) );

??? g_pVB->Unlock();

?

posted on 2012-10-29 17:37 Lilac_F 閱讀(...) 評論(...) 編輯 收藏

轉載于:https://www.cnblogs.com/Lilac-F/archive/2012/10/29/2745128.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/260288.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/260288.shtml
英文地址,請注明出處:http://en.pswp.cn/news/260288.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

quick cocos2d-x 精靈大小(寬高)獲取

quick下sprite的大小獲取&#xff0c;記錄一下&#xff1a; local w sprite:getContentSize().width local h sprite:getContentSize().height 今天連這個最基本的&#xff0c;都不知道怎么獲取。挺實用的代碼額~轉載于:https://www.cnblogs.com/vokie/p/3822248.html

velocityjs 動畫庫 比jquery默認的animate強

神坑記錄&#xff1a; 1、transform: translate3d(80%,0,0); 無法作為參數&#xff0c;必須修改為這種&#xff1a;translateX: 0% 官方文檔 http://velocityjs.org/ github地址 https://github.com/julianshapiro/velocity npm下載安裝 npm install velocity-animate --save-d…

python中的可變數據類型有列表和元組_Python中列表的 += 和 .extend() 的異同

一道Python題最近有朋友“考”了我一個Python的題&#xff1a;使用和.extend()兩種方法擴展元組中的列表會發生什么。雖然我對Python中的可變數據類型、不可變數據類型的概念都有較深的理解&#xff0c;并且也對list的、、.extend()、.append()做過性能分析&#xff0c;但是和.…

簡易貪吃蛇小游戲java版_用GUI實現java版貪吃蛇小游戲

本文實例為大家分享了java版貪吃蛇小游戲的具體代碼&#xff0c;供大家參考&#xff0c;具體內容如下項目結構新建一個JFrame窗口,作為程序入口public class GameStart{public static void main(String[] args) {JFrame jFrame new JFrame();jFrame.setBounds(100,100,900,720…

幾種代價函數

SAD&#xff08;Sum of Absolute Difference&#xff09;SAE&#xff08;Sum of Absolute Error)即絕對誤差和 SATD&#xff08;Sum of Absolute Transformed Difference&#xff09;即hadamard變換后再絕對值求和 SSD&#xff08;Sum of Squared Difference&#xff09;SSE&am…

Markdown文件導出為HTML的小程序

Markdown文件導出為HTML的小程序為什么做 最近把一些學習經驗記下來&#xff0c;總結成MarkDown文件&#xff0c;不知不覺已經有12篇了。 Sublime Text 的 MarkDown Preview 插件能夠將MarkDown語法轉換為HTML&#xff0c;并提供三種預覽方式&#xff1a;瀏覽器預覽、保存為HTM…

python制作自動回復腳本_python itchat實現微信自動回復的示例代碼

今天在實驗樓發現一個特別好玩的&#xff0c;Python 微信庫itchat,可以實現自動回復等多種功能&#xff0c;好玩到根本停不下來啊&#xff0c;尤其是調戲調戲不懂計算機的&#xff0c;特別有成就感&#xff0c;哈哈&#xff01;&#xff01;代碼如下&#xff1a;#codingutf8imp…

pta龜兔賽跑Java_PTA-龜兔賽跑

烏龜與兔子進行賽跑&#xff0c;跑場是一個矩型跑道&#xff0c;跑道邊可以隨地進行休息。烏龜每分鐘可以前進3米&#xff0c;兔子每分鐘前進9米&#xff1b;兔子嫌烏龜跑得慢&#xff0c;覺得肯定能跑贏烏龜&#xff0c;于是&#xff0c;每跑10分鐘回頭看一下烏龜&#xff0c;…

視頻壓縮算法的相關知識

視頻壓縮算法的相關知識MPEG-1MPEG 視頻壓縮編碼后包括三種元素&#xff1a;I幀&#xff08;I-frames&#xff09;、P幀&#xff08;P-frames&#xff09;和B幀&#xff08;B-frames&#xff09;。在MPEG編碼的過程中&#xff0c;部分視頻幀序列壓縮成為I幀&#xff1b;部分壓縮…

安裝MariaDB數據庫(未完成)

1轉載于:https://www.cnblogs.com/centos7/p/5994533.html

python接口開發django_用 Django 開發接口

環境搭建1、pip install django2.2.0一、django-admin startproject UITESTpython manage.py startapp paltform創建Django項目1. 創建方式&#xff1a;#方式1&#xff1a;終端輸入django-admin startproject UITEST#方式2:pycharm中新建django項目在settings.py文件中添加應用…

戒掉dota

立言為證。 每次不想學習想到dota就強迫自己去培養的興趣。 比如看一本喜歡的書&#xff1b;比如去跑個步&#xff1b;比如研究某個興趣點寫個報告&#xff1b;比如寫份隨筆。 轉載于:https://www.cnblogs.com/hongxia/p/3830348.html

java切入式編程顯示屏_C語言嵌入式系統編程修煉之四:屏幕操作

C語言嵌入式系統編程修煉之四:屏幕操作作者:宋寶華 更新日期:2005-07-22漢字處理現在要解決的問題是&#xff0c;嵌入式系統中經常要使用的并非是完整的漢字庫&#xff0c;往往只是需要提供數量有限的漢字供必要的顯示功能。例如&#xff0c;一個微波爐的LCD上沒有必要提供顯…

DIV的邊距屬性在Chrome和IE中的區別

突然間&#xff0c;在Chrome下看起來很整齊的布局&#xff0c;在IE下變成一團糟。為了找出原因&#xff0c;我改動了div的background-color屬性。最后&#xff0c;發現同一個DIV的寬度在IE和Chrome下卻不一樣。這大晚上的&#xff0c;真是怪嚇人滴&#xff01; 之后&#xff0c…

算法之矩陣計算斐波那契數列

算法之矩陣計算斐波那契數列 本節內容 斐波那契介紹普通方式求解斐波那契矩陣概念矩陣求冪矩陣求解斐波那契1.斐波那契介紹 斐波那契數列有關十分明顯的特點&#xff0c;那是&#xff1a;前面相鄰兩項之和&#xff0c;構成了后一項。即f(n)f(n-1)f(n-2),f(0)0,f(1)f(2)1,推導下…

python中去除字符串中首尾空格的函數_Python中去除字符串首尾特定字符的函數:strip()...

Python中strip()函數的作用是去除一個字符串前導和尾部的特定字符&#xff0c;并返回結果字符串。Python中strip()函數默認是刪除字符串前導和尾部空格&#xff0c;通過設定參數&#xff0c;也可以去除字符串前導和尾部的其它特定字符。strip()函數的語法格式str.strip( [ char…

SeekBar和RatingBar

1. SeekBar的主要屬性 2. OnSeekBarChangeListener 3. RatingBar的主要屬性 4. OnRatingBarChangeListener 1. SeekBar的主要屬性 2. OnSeekBarChangeListener 1 <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android"2 xmlns:tools&qu…

用“Web的思想”做PC客戶端

一直在想&#xff0c;用HTML搭建前端頁面這么方便&#xff0c;而且效果這么炫&#xff0c;為什么在PC端的軟件要如此麻煩呢&#xff1f;就連C#也是&#xff0c;更何況C了。 盡管C有DirectUI這樣優秀的圖形庫&#xff0c;但是開發起來仍然非常吃力。C#的WPF雖然工具鏈完善&#…

Java點擊按鈕div縮放_[Java教程]怎樣給div增加resize事件

[Java教程]怎樣給div增加resize事件0 2016-10-31 11:00:04當瀏覽器窗口被調整到一個新的高度或寬度時&#xff0c;就會觸發resize事件,這個事件在window上面觸發,那么如何給div元素增加resize事件&#xff0c;監聽div的高度或寬度的改變呢&#xff1f;某位大神用jquery實現的方…

python判斷題題庫大數據技術_智慧樹_大數據分析的python基礎_搜題公眾號

智慧樹_大數據分析的python基礎_搜題公眾號更多相關問題社會公眾可以查閱煙草專賣行政主管部門的監督檢查記錄。()公民、法人或者其他組織不得利用自動售貨機銷售煙草制品。()煙草廣告中不得有下列情形()。A、社會公益廣告B、遷址、換房、更名等啟事廣告C、表示吸煙有利人體健公…