public override void Render(Shader shader) { Mesh tmpMesh = null; foreach(Component comp in components) { if(tmpMesh != comp.Mesh) SetVBOs(comp.Mesh, shader); Matrix4 meshTransform = comp.Transform; Matrix4 rotationMatirx = Matrix4.Rotate(this.Orientation) * Matrix4.Rotate(comp.Orientation); shader.insertUniform(Shader.Uniform.mesh_matrix, ref meshTransform); shader.insertUniform(Shader.Uniform.rotation_matrix, ref rotationMatirx); shader.insertUniform(Shader.Uniform.model_matrix, ref transform); GL.DrawElements(BeginMode.Triangles, comp.Mesh.ElementsData.Length, DrawElementsType.UnsignedInt, IntPtr.Zero); tmpMesh = comp.Mesh; } }
public void loadShaderXml(ref Shader target) { XmlTextReader reader = new XmlTextReader(ContentDirectory + target.name); target.URL = new string[2]; while (reader.Read()) { // parsing data in material tag if (reader.Name == "shaderpair" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "vertex") target.URL[0] = ContentDirectory + reader.Value; else if (reader.Name == "fragment") target.URL[1] = ContentDirectory + reader.Value; } reader.MoveToElement(); } } loadShaderFromFile(ref target); }
public void loadShaderFromFile(ref Shader target) { string vfile = target.URL[0]; string ffile = target.URL[1]; target.vShader = readFile(vfile); target.fShader = readFile(ffile); loadShaderFromCache(ref target); }
public void loadShaderFromCache(ref Shader target) { int shaderProgramHandle; int vertexShaderHandle, fragmentShaderHandle; vertexShaderHandle = GL.CreateShader(All.VertexShader); fragmentShaderHandle = GL.CreateShader(All.FragmentShader); GL.ShaderSource(vertexShaderHandle, target.vShader); GL.ShaderSource(fragmentShaderHandle, target.fShader); GL.CompileShader(vertexShaderHandle); GL.CompileShader(fragmentShaderHandle); Console.WriteLine(GL.GetShaderInfoLog(vertexShaderHandle)); Console.WriteLine(GL.GetShaderInfoLog(fragmentShaderHandle)); // Create program shaderProgramHandle = GL.CreateProgram(); GL.AttachShader(shaderProgramHandle, vertexShaderHandle); GL.AttachShader(shaderProgramHandle, fragmentShaderHandle); GL.LinkProgram(shaderProgramHandle); Console.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle)); target.handle = shaderProgramHandle; getHandles(ref target); target.loaded = true; shaders.Add(target); }
public Shader LoadShader(string name) { Shader shader = new Shader(); shader.name = name; loadShaderXml(ref shader); return shader; }
public void getHandles(ref Shader target) { //int shaderProgramHandle = target.handle; // Set uniforms target.generateLocations(); }
public static void Load() { ShadowPassShader = ShaderLoader.GetShader("Shadow.xsp"); fbCreator = new FramebufferCreator(); LightFramebuffer= fbCreator.createFrameBuffer("LightFramebuffer", SceneManager.Window.Width, SceneManager.Window.Height, PixelInternalFormat.Rgba16f, false); LightFramebuffer.clearColor = new OpenTK.Graphics.Color4(0f, 0f, 0f, 0f); Scene.Load(); GL.MatrixMode(MatrixMode.Projection); GL.Ortho(0.0, (double)Window.Width, 0.0, (double)Window.Height, -10.0, 10.0); GL.MatrixMode(MatrixMode.Modelview); }