Example #1
0
            // Methods
            public void Draw(Mesh.Slots slot)
            {
                if (Slot != slot)
                {
                    return;
                }

                // Get the material
                var mat = (string.IsNullOrEmpty(MaterialName) ||
                           !Data.Materials.ContainsKey(MaterialName)) ?
                          Data.DefaultMaterial : Data.Materials[MaterialName];

                // Get the texture
                string texName = (mat.Texset.Textures.Count > 0) ?
                                 mat.Texset.Textures[0].TextureName : null;

                int tex = (string.IsNullOrEmpty(texName) ||
                           !Data.Textures.ContainsKey(texName)) ?
                          Data.DefaultTexture : Data.Textures[texName];

                // Bind the texture and the mesh's VAO
                GL.BindTexture(TextureTarget.Texture2D, tex);
                GL.BindVertexArray(VAO);

                // Draw the mesh
                GL.DrawElements(PrimitiveType.Triangles, TriangleCount,
                                DrawElementsType.UnsignedInt, IntPtr.Zero);

                // Un-bind the VAO
                GL.BindVertexArray(0);
            }
Example #2
0
        public void Draw(int shaderID, Mesh.Slots slot)
        {
            if (meshes == null)
            {
                throw new Exception("Cannot draw model - model not initialized!");
            }

            int modelLoc     = GL.GetUniformLocation(shaderID, "model");
            int highlightLoc = GL.GetUniformLocation(shaderID, "highlight");

            GL.Uniform4(highlightLoc, new OpenTK.Vector4(1, 1, 1, 1));

            foreach (var transform in Instances)
            {
                // Update Transforms
                var modelTransform = transform.Matrix;

                // Update shader transform matrices
                GL.UniformMatrix4(modelLoc, false, ref modelTransform);

                // Update Highlight Color
                bool selected = Viewport.SelectedInstances.Contains(transform);
                if (selected)
                {
                    GL.Uniform4(highlightLoc, new OpenTK.Vector4(1, 0, 0, 1));
                }

                // Draw the meshes
                for (int i = 0; i < meshes.Length; ++i)
                {
                    meshes[i].Draw(slot);
                }

                // Set Highlight Color back to default
                if (selected)
                {
                    GL.Uniform4(highlightLoc, new OpenTK.Vector4(1, 1, 1, 1));
                }
            }
        }