我想在較大的四邊形上重複小2×2像素紋理,例如50x50像素。紋理重複
組頂點 -
float X = 100, Y = 100, Width = 50, Height = 50;
float TextureLeft = 0, TextureTop = 0, TextureRight = 25, TextureBottom = 25;
Vertices[0].x = X;
Vertices[0].y = Y + Height;
Vertices[0].z = 0;
Vertices[0].rhw = 1;
Vertices[0].tu = TextureLeft;
Vertices[0].tv = TextureBottom;
Vertices[1].x = X;
Vertices[1].y = Y;
Vertices[1].z = 0;
Vertices[1].rhw = 1;
Vertices[1].tu = TextureLeft;
Vertices[1].tv = TextureTop;
Vertices[2].x = X + Width;
Vertices[2].y = Y;
Vertices[2].z = 0;
Vertices[2].rhw = 1;
Vertices[2].tu = TextureRight;
Vertices[2].tv = TextureTop;
Vertices[3].x = X;
Vertices[3].y = Y + Height;
Vertices[3].z = 0;
Vertices[3].rhw = 1;
Vertices[3].tu = TextureLeft;
Vertices[3].tv = TextureBottom;
Vertices[4].x = X + Width;
Vertices[4].y = Y;
Vertices[4].z = 0;
Vertices[4].rhw = 1;
Vertices[4].tu = TextureRight;
Vertices[4].tv = TextureTop;
Vertices[5].x = X + Width;
Vertices[5].y = Y + Height;
Vertices[5].z = 0;
Vertices[5].rhw = 1;
Vertices[5].tu = TextureRight;
Vertices[5].tv = TextureBottom;
抽獎 -
DrawPrimitive(D3DPT_TRIANGLELIST, 0, 6);
問題是在三角形的邊緣「毛刺」,因爲錯誤的頂點大概座標,並在四邊框「毛刺」。
原有的質感 - http://i.imgur.com/tNqYePs.png
結果 - http://i.imgur.com/sgUZvqE.png
您尚未指定您正在使用的光柵化器狀態。也許你錯過了紋理夾/重複設置。在DrawPrimitive設置紋理之前你還要調用什麼? –
你能告訴我應該設置哪個光柵器/鉗位/重複設置?我用單紋理四繪製空場景。 – Demion
「重複」設置在DX中稱爲「換行」。如果您對這些值有疑問,我已將答案添加到MSDN的鏈接中。 –