Пример #1
0
        public void Init(Shader.ShadingType type, float [] verts, uint [] indices, Texture texture)
        {
            CleanObject();
            shader             = Shader.GetShader(type);
            objPos             = Matrix4.Identity;
            tintColor          = Utils.ColorToVector("ffffffff");
            vertexBufferObject = GL.GenBuffer();
            if (indices != null)
            {
                useIndices          = true;
                elementBufferObject = GL.GenBuffer();
            }

            // calculate strides strides
            int stride = 3, size1 = 0;

            switch (type)
            {
            case Shader.ShadingType.Flat2D: break;

            case Shader.ShadingType.MultiColor2D: size1 = 3; break;

            case Shader.ShadingType.Textured2D: size1 = 2; break;

            case Shader.ShadingType.Textured3D: size1 = 2; is3D = true; usetexture = true; tintVar = "tintColor"; break;

            case Shader.ShadingType.Flat3D: is3D = true; break;

            case Shader.ShadingType.FlatNorm3D: size1 = 3; is3D = true; break;
            }
            stride    += size1;
            nTriangles = useIndices ? indices.Length : verts.Length / stride;

            // VAO
            vertexArrayObject = GL.GenVertexArray();
            GL.BindVertexArray(vertexArrayObject);

            // VBO
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferObject);
            GL.BufferData(BufferTarget.ArrayBuffer, verts.Length * sizeof(float), verts, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, stride * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);
            if (size1 > 0)
            {
                GL.VertexAttribPointer(1, size1, VertexAttribPointerType.Float, false, stride * sizeof(float), 3 * sizeof(float));
                GL.EnableVertexAttribArray(1);
            }

            if (useIndices)
            {
                // EBO
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, elementBufferObject);
                GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.StaticDraw);
            }

            if (usetexture)
            {
                this.texture = texture;
            }
        }
Пример #2
0
        public void Init(Shader.ShadingType type, float[] verts, uint[] indices = null, string textureName = "")
        {
            Texture tex = null;

            // texture
            if (textureName != null && textureName.Length > 0)
            {
                tex = Texture.From(textureName);
            }
            Init(type, verts, indices, tex);
        }