スポンサーサイト
--/--/--
上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。
新しい記事を書く事で広告が消せます。
- --/--/-- --:-- |
- スポンサー広告
ゲームの話をしたり、色々技術的な話をするブログ
2015/10/23
2015/10/23
if (this.VboBufferId[0] != 0)
{
GL.DeleteBuffers(1, this.VboBufferId);
}
GL.GenBuffers(1, this.VboBufferId);
Polygon[] polygons = this.Polygons;
this.VboArray = new float[polygons.GetLength(0) * 9 * 3];
for (int polygonInd = 0; polygonInd < polygons.GetLength(0); polygonInd++)
{
// vertex 0
this.VboArray [polygonInd * 9 * 3] = polygons[polygonInd].VertexC.X;
this.VboArray [(polygonInd * 9 * 3) + 1] = polygons[polygonInd].VertexC.Y;
this.VboArray [(polygonInd * 9 * 3) + 2] = polygons[polygonInd].VertexC.Z;
this.VboArray [(polygonInd * 9 * 3) + 3] = polygons[polygonInd].NormalVectC.X;
this.VboArray [(polygonInd * 9 * 3) + 4] = polygons[polygonInd].NormalVectC.Y;
this.VboArray [(polygonInd * 9 * 3) + 5] = polygons[polygonInd].NormalVectC.Z;
this.VboArray [(polygonInd * 9 * 3) + 6] = polygons[polygonInd].Color.X;
this.VboArray [(polygonInd * 9 * 3) + 7] = polygons[polygonInd].Color.Y;
this.VboArray [(polygonInd * 9 * 3) + 8] = polygons[polygonInd].Color.Z;
// vertex 1
this.VboArray [(polygonInd * 9 * 3) + 9] = polygons[polygonInd].VertexB.X;
this.VboArray [(polygonInd * 9 * 3) + 10] = polygons[polygonInd].VertexB.Y;
this.VboArray [(polygonInd * 9 * 3) + 11] = polygons[polygonInd].VertexB.Z;
this.VboArray [(polygonInd * 9 * 3) + 12] = polygons[polygonInd].NormalVectB.X;
this.VboArray [(polygonInd * 9 * 3) + 13] = polygons[polygonInd].NormalVectB.Y;
this.VboArray [(polygonInd * 9 * 3) + 14] = polygons[polygonInd].NormalVectB.Z;
this.VboArray [(polygonInd * 9 * 3) + 15] = polygons[polygonInd].Color.X;
this.VboArray [(polygonInd * 9 * 3) + 16] = polygons[polygonInd].Color.Y;
this.VboArray [(polygonInd * 9 * 3) + 17] = polygons[polygonInd].Color.Z;
// vertex 2
this.VboArray [(polygonInd * 9 * 3) + 18] = polygons[polygonInd].VertexA.X;
this.VboArray [(polygonInd * 9 * 3) + 19] = polygons[polygonInd].VertexA.Y;
this.VboArray [(polygonInd * 9 * 3) + 20] = polygons[polygonInd].VertexA.Z;
this.VboArray [(polygonInd * 9 * 3) + 21] = polygons[polygonInd].NormalVectA.X;
this.VboArray [(polygonInd * 9 * 3) + 22] = polygons[polygonInd].NormalVectA.Y;
this.VboArray [(polygonInd * 9 * 3) + 23] = polygons[polygonInd].NormalVectA.Z;
this.VboArray [(polygonInd * 9 * 3) + 24] = polygons[polygonInd].Color.X;
this.VboArray [(polygonInd * 9 * 3) + 25] = polygons[polygonInd].Color.Y;
this.VboArray [(polygonInd * 9 * 3) + 26] = polygons[polygonInd].Color.Z;
}
GL.EnableClientState(ArrayCap.VertexArray);
GL.EnableClientState(ArrayCap.NormalArray);
GL.EnableClientState(ArrayCap.ColorArray);
GL.DisableClientState(ArrayCap.TextureCoordArray);
GL.BindBuffer(BufferTarget.ArrayBuffer, this.VboBufferId[0]);
GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(this.VboArray.Length * sizeof(float)), this.VboArray, BufferUsageHint.StaticDraw);
}
GL.BindBuffer(BufferTarget.ArrayBuffer, this.VboBufferId[0]);
// set strides/offsets
GL.VertexPointer(3, VertexPointerType.Float, 9 * sizeof(float), 0);
GL.NormalPointer(NormalPointerType.Float, 9 * sizeof(float), 3 * sizeof(float));
GL.ColorPointer(3, ColorPointerType.Float, 9 * sizeof(float), 6 * sizeof(float));
GL.Enable(EnableCap.ColorMaterial);
GL.ColorMaterial(MaterialFace.Front, ColorMaterialParameter.Diffuse);
GL.Material(MaterialFace.Front, MaterialParameter.Shininess, 32);
GL.ShadeModel(ShadingModel.Smooth);
GL.Enable(EnableCap.Normalize);
GL.DrawArrays(BeginMode.Triangles, 0, this.VboArray.Length / 9);
GL.Disable(EnableCap.Normalize);
//GL.DisableClientState(ArrayCap.ColorArray);
GL.Disable(EnableCap.ColorMaterial);
2015/10/21