コード例 #1
0
ファイル: BlockBatchView.cs プロジェクト: veggielane/BlockRTS
        public void Load()
        {
            _shader = _assets.Shader<BlockShaderProgram>();

            var stl = new STL("chamfer_cube.stl", Color.Yellow);
            var cubedata = new List<float>();

            foreach (var vertex in stl.ToMesh().Vertices)
            {
                cubedata.Add((float)vertex.Position.X);
                cubedata.Add((float)vertex.Position.Y);
                cubedata.Add((float)vertex.Position.Z);
            }
            foreach (var vertex in stl.ToMesh().Vertices)
            {
                cubedata.Add((float)vertex.Normal.X);
                cubedata.Add((float)vertex.Normal.Y);
                cubedata.Add((float)vertex.Normal.Z);
            }

            _squareVertices = cubedata.ToArray();

            GL.GenVertexArrays(1, out _squareVao);
            GL.GenBuffers(1, out _squareVbo);
            GL.BindVertexArray(_squareVao);
            GL.BindBuffer(BufferTarget.ArrayBuffer, _squareVbo);

            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            GL.EnableVertexAttribArray(3);
            GL.EnableVertexAttribArray(4);

            GL.Arb.VertexAttribDivisor(2, 1);//position
            GL.Arb.VertexAttribDivisor(3, 1);//rotation
            GL.Arb.VertexAttribDivisor(4, 1);//color

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 0, 0);
            GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, 11 * sizeof(float), _squareVertices.Length * sizeof(float));
            GL.VertexAttribPointer(3, 4, VertexAttribPointerType.Float, false, 11 * sizeof(float), (_squareVertices.Length + 3) * sizeof(float));
            GL.VertexAttribPointer(4, 4, VertexAttribPointerType.Float, false, 11 * sizeof(float), (_squareVertices.Length + 3 + 4) * sizeof(float));

            Loaded = true;
        }