예제 #1
0
파일: Model.cs 프로젝트: Azzi777/Lux
        private void Finish(ShaderProgram textureShader)
        {
            if (IsFinished)
            {
                return;
            }

            int ArrayID;
            GL.GenVertexArrays(1, out ArrayID);
            GL.BindVertexArray(ArrayID);
            GL.GenBuffers(1, out VertexBufferID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferID);

            GL.BufferData<MeshVertex>(BufferTarget.ArrayBuffer, (IntPtr)(TempVertices.Length * MeshVertex.GetSize()), TempVertices, BufferUsageHint.StaticDraw);

            textureShader.SetVertexFormat();

            TempVertices = null;

            Texture.FinishTextures(TempTextures);

            TempTextures = null;

            foreach (Mesh m in Meshes)
            {
                m.Finish();
            }

            IsFinished = true;
        }
예제 #2
0
파일: Model.cs 프로젝트: Azzi777/Lux
        public void Render(Entity entity, ShaderProgram textureShader)
        {
            Finish(textureShader);
            textureShader.SetMatrix4("mat_world", entity.TransformMatrix);

            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferID);

            foreach (Mesh m in Meshes)
            {
                m.Render(textureShader);
            }
        }
예제 #3
0
파일: Graphics.cs 프로젝트: Azzi777/Lux
        internal void SetupRender()
        {
            Parent.Window.Visible = true;

            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(Color4.CornflowerBlue);

            View = Parent.Camera.OpenTKViewMatrix;
            Projection = OpenTK.Matrix4d.CreatePerspectiveFieldOfView(OpenTK.MathHelper.PiOver3, (float)Parent.Window.Width / Parent.Window.Height, 0.1F, 10000.0F);

            GraphicsContext.CurrentContext.VSync = true;

            TextureShader = new ShaderProgram(ShaderProgram.TextureVertexShaderSource, ShaderProgram.TextureFragmentShaderSource);
            ScreenShader = new ShaderProgram(ShaderProgram.ScreenFragmentShaderSource);

            ColorFramebuffer = new Framebuffer(Parent.Window.Width, Parent.Window.Height);
        }
예제 #4
0
파일: Mesh.cs 프로젝트: Azzi777/Lux
 private void TextureUndefine(ShaderProgram shaderProgram)
 {
     GL.ActiveTexture(TextureUnit.Texture0);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture1);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture2);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture3);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture4);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture5);
         GL.BindTexture(TextureTarget.Texture2D, 0);
         GL.ActiveTexture(TextureUnit.Texture6);
         GL.BindTexture(TextureTarget.Texture2D, 0);
 }
예제 #5
0
파일: Mesh.cs 프로젝트: Azzi777/Lux
        private void TextureDefine(ShaderProgram shaderProgram)
        {
            if (AmbientTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                GL.BindTexture(TextureTarget.Texture2D, AmbientTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_ambient"), 0);
            }

            if (DiffuseTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                GL.BindTexture(TextureTarget.Texture2D, DiffuseTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_diffuse"), 1);
            }

            if (AlphaTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture2);
                GL.BindTexture(TextureTarget.Texture2D, AlphaTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_alpha"), 2);
            }

            if (BumpMapTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture3);
                GL.BindTexture(TextureTarget.Texture2D, BumpMapTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_bump"), 3);
            }

            if (SpecularHighlightTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture4);
                GL.BindTexture(TextureTarget.Texture2D, SpecularHighlightTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_specular_highlight"), 4);
            }

            if (SpecularTexture != null)
            {
                GL.ActiveTexture(TextureUnit.Texture5);
                GL.BindTexture(TextureTarget.Texture2D, SpecularTexture.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_specular"), 5);
            }

            if (StencilDecal != null)
            {
                GL.ActiveTexture(TextureUnit.Texture6);
                GL.BindTexture(TextureTarget.Texture2D, StencilDecal.TextureID);
                GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "tex_stencil_decal"), 6);
            }
        }
예제 #6
0
파일: Mesh.cs 프로젝트: Azzi777/Lux
        public void Render(ShaderProgram shaderProgram)
        {
            TextureDefine(shaderProgram);

            GL.Uniform4(GL.GetUniformLocation(shaderProgram.ID, "mat_ambient"), AmbientColor.GetOpenTKEquivalent());
            GL.Uniform4(GL.GetUniformLocation(shaderProgram.ID, "mat_diffuse"), DiffuseColor.GetOpenTKEquivalent());
            GL.Uniform4(GL.GetUniformLocation(shaderProgram.ID, "mat_specular"), /*SpecularColor*/DiffuseColor.GetOpenTKEquivalent());
            GL.Uniform1(GL.GetUniformLocation(shaderProgram.ID, "mat_shininess"), SpecularCoefficient);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBufferID);

            GL.DrawElements(BeginMode.Triangles, VertexCount, DrawElementsType.UnsignedInt, 0);

            TextureUndefine(shaderProgram);
        }