我想要用Mesh的方式畫出box來
參考了MSDN上的code可以順利的畫出來
但當我寫入我自己原本檔案之中
畫出來的box卻一直是白色的
//以下是box的宣告 基本上跟MSDN上敎的一樣
public void CreateBoxs(Device dev)
{
if (meshes == null)
meshes = new Mesh[numberOfBoxs];
if (meshLocations == null)
meshLocations = new Vector3[numberOfBoxs];
if (meshBoundingBoxMinValues == null)
meshBoundingBoxMinValues = new Vector3[numberOfBoxs];
if (meshBoundingBoxMaxValues == null)
meshBoundingBoxMaxValues = new Vector3[numberOfBoxs];
//activeMesh = null;
for (int i = 0; i < numberOfBoxs; i++)
{
//GraphicsStream vertexData;
meshes[i] = Mesh.Box(device, 0.05f, 0.05f, 0.05f);
InitBox();
VertexBufferDescription description =
meshes[i].VertexBuffer.Description;
GraphicsStream vertexData = meshes[i].VertexBuffer.Lock
(0, 0, LockFlags.ReadOnly);
Geometry.ComputeBoundingBox(vertexData,
meshes[i].NumberVertices, description.VertexFormat,
out meshBoundingBoxMinValues[i],
out meshBoundingBoxMaxValues[i]);
meshes[i].VertexBuffer.Unlock();
device.RenderState.Ambient = Color.White;
}
//以下是box顏色和位置的設定
public void InitBox()
{
if (meshLocations == null)
meshLocations = new Vector3[numberOfBoxs];
if (meshColor == null)
meshColor = new Color[numberOfBoxs];
meshLocations[0] = new Vector3(0.2f, 0.0f, -2.3f);
meshLocations[1] = new Vector3(0.1f, 0.0f, -2.3f);
meshLocations[2] = new Vector3(0.0f, 0.0f, -2.3f);
meshLocations[3] = new Vector3(-0.1f, 0.0f, -2.3f);
meshLocations[4] = new Vector3(-0.2f, 0.0f, -2.3f);
meshColor[0] = Color.Red;
meshColor[1] = Color.Blue;
meshColor[2] = Color.Green;
meshColor[3] = Color.Purple;
meshColor[4] = Color.Pink;
}
//以下是我render的部份
煩請板上大大幫我看看到底為何只會是white的box
private void Render()
{
if (isRendering)
{ return; }
isRendering = true;
if (device == null)
return;
Material material = new Material();
device.BeginScene();
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
System.Drawing.Color.Black, 1.0f, 0);
SetupMatrices();
device.RenderState.FogColor = Color.Black;
device.RenderState.FogStart = 0.0f;//IR_Z_Real / screenHeightInMM;
device.RenderState.FogEnd = 0.0f + fogDepth;//IR_Z_Real /
screenHeightInMM + fogDepth;
device.RenderState.FogVertexMode = FogMode.Linear;
device.RenderState.FogEnable = true;
if (showBox)
{
for (int i = 0; i < numberOfBoxs; i++)
{
material.Ambient = meshColor[i];
device.Transform.World = Matrix.Translation(meshLocations[i]);
device.Material = material;
meshes[i].DrawSubset(0);
}
}
//下面是我除了box另外會畫出的東西 就算我把這段略過
//box還是白色的
if (showIRCursor)
{
device.SetTexture(0, cursorTexture);
//Render States
device.RenderState.AlphaBlendEnable = true;
device.RenderState.AlphaFunction = Compare.Greater;
device.RenderState.AlphaTestEnable = true;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DiffuseMaterialSource =
ColorSource.Material;
//Color blending operations
device.TextureState[0].ColorOperation =
TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 =
TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 =
TextureArgument.Diffuse;
//set the first alpha stage to texture alpha
device.TextureState[0].AlphaOperation =
TextureOperation.SelectArg1;
device.TextureState[0].AlphaArgument1 =
TextureArgument.TextureColor;
device.VertexFormat = Vertex.FVF_Flags;
device.SetStreamSource(0, cursorBuffer, 0);
...
}
device.EndScene();
device.Present();
isRendering = false;
}
不清楚到底是哪個地方的繪圖出了問題
導致box只畫出white( 想要五個box各有一種顏色)
另外想要請教關於繪圖的buffer之類的概念該去哪裡看
我是自己抓程式下來 但是很多基礎理論都不懂orz
感謝版上大大解惑<(___ ___)>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.44.27