Beispiel #1
0
        public void Bind(GLShaderProgram shaderProgram)
        {
            shaderProgram.SetUniform("uMatHasDiffuse", HasDiffuseTexture);

            if (HasDiffuseTexture)
            {
                DiffuseTexture.Bind();
            }

            shaderProgram.SetUniform("uMatAmbient", Ambient);
            shaderProgram.SetUniform("uMatDiffuse", Diffuse);
            shaderProgram.SetUniform("uMatSpecular", Specular);
            shaderProgram.SetUniform("uMatEmissive", Emissive);
            shaderProgram.SetUniform("uMatHasAlphaTransparency", HasAlphaTransparency);

            if (RenderWireframe)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            }

            if (!EnableBackfaceCulling)
            {
                GL.Disable(EnableCap.CullFace);
            }
        }
Beispiel #2
0
        public void Draw(GLShaderProgram shaderProgram, ref Matrix4 view, ref Matrix4 projection, double animationTime)
        {
            if (Animation != null)
            {
                AnimateNodes(animationTime);
            }

            shaderProgram.Use();
            shaderProgram.SetUniform("uView", view);
            shaderProgram.SetUniform("uProjection", projection);

            foreach (var glNode in Nodes)
            {
                if (!glNode.IsVisible)
                {
                    continue;
                }

                for (var i = 0; i < glNode.Meshes.Count; i++)
                {
                    var glMesh = glNode.Meshes[i];
                    if (Animation != null && glMesh.Mesh != null)
                    {
                        var oldGlMesh = glMesh;
                        glMesh = glNode.Meshes[i] = new GLMesh(oldGlMesh.Mesh, glNode.WorldTransform, ModelPack.Model.Bones, Nodes, Materials);
                        oldGlMesh.Dispose();
                    }

                    glMesh.Draw(glNode.WorldTransform.ToOpenTK(), shaderProgram);
                }
            }
        }
Beispiel #3
0
        public void Draw(GLShaderProgram shaderProgram, GLCamera camera, double animationTime)
        {
            var view = camera.View;
            var proj = camera.Projection;

            Draw(shaderProgram, ref view, ref proj, animationTime);
        }
Beispiel #4
0
        public static bool TryCreate(Stream vertexShaderStream, Stream fragmentShaderStream, out GLShaderProgram shaderProgram)
        {
            var vertexShaderSource   = new StreamReader(vertexShaderStream).ReadToEnd();
            var fragmentShaderSource = new StreamReader(fragmentShaderStream).ReadToEnd();

            using (var builder = new GLShaderProgramBuilder())
            {
                if (!builder.TryAttachShader(ShaderType.VertexShader, vertexShaderSource))
                {
                    shaderProgram = null;
                    return(false);
                }

                if (!builder.TryAttachShader(ShaderType.FragmentShader, fragmentShaderSource))
                {
                    shaderProgram = null;
                    return(false);
                }

                if (!builder.TryBuild(out var id))
                {
                    shaderProgram = null;
                    return(false);
                }

                shaderProgram = new GLShaderProgram(id);
                return(true);
            }
        }
Beispiel #5
0
 public void Draw(Matrix4 modelMatrix, GLShaderProgram shaderProgram)
 {
     shaderProgram.SetUniform("uModel", modelMatrix);
     Material.Bind(shaderProgram);
     shaderProgram.Check();
     VertexArray.Draw();
     Material.Unbind(shaderProgram);
 }
Beispiel #6
0
        public void Unbind(GLShaderProgram shaderProgram)
        {
            if (!EnableBackfaceCulling)
            {
                GL.Enable(EnableCap.CullFace);
            }

            if (RenderWireframe)
            {
                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            }
        }
Beispiel #7
0
 public void Bind(GLShaderProgram shaderProgram)
 {
     shaderProgram.SetUniform("uView", View);
     shaderProgram.SetUniform("uProjection", Projection);
 }
Beispiel #8
0
 public static bool TryCreate(string vertexShaderFilepath, string fragmentShaderFilepath, out GLShaderProgram shaderProgram)
 {
     return(TryCreate(File.OpenRead(vertexShaderFilepath), File.OpenRead(fragmentShaderFilepath), out shaderProgram));
 }