public MagicBackground() { shader = new Shader(); float v = Shader.Version; shader.LoadVertexFile(Path.Combine("Effects", v < 3.3f ? "v12" : "v33", "magic_background.vert")); shader.LoadFragmentFile(Path.Combine("Effects", v < 3.3f ? "v12" : "v33", "magic_background.frag")); shader.Link(); buffer = new VertexBuffer(4); buffer.DeclareNextAttribute("vposition", 2); buffer.DeclareNextAttribute("vtexcoord", 2); buffer.DeclareNextAttribute("vcolor", 4); buffer.Attach(shader); buffer.AddVertex(-1, -1, 0, 0, 1f, 1f, 1f, 1f); buffer.AddVertex(1, -1, 1, 0, 1f, 1f, 1f, 1f); buffer.AddVertex(1, 1, 1, 1, 1, 1, 1, 1); buffer.AddVertex(-1, 1, 0, 1, 1, 1, 1, 1); buffer.AddIndices(0, 1, 2, 0, 2, 3); buffer.UpdateBuffer(); }
public SpriteBatch() { _batchItemList = new List<BatchItem>(256); _freeBatchItemQueue = new Queue<BatchItem>(256); vbuffer = new VertexBuffer(1024); defaultShader = new Shader(); if (Shader.Version < 3.3f) { defaultShader.LoadVertexSource(@"#version 120 uniform mat4 projection, view; attribute vec2 vposition; attribute vec4 vcolor; attribute vec2 vtexcoord; varying vec4 fcolor; varying vec2 ftexcoord; void main(void) { fcolor = vcolor; ftexcoord = vtexcoord; gl_Position = projection * view * vec4(vposition, 0, 1); }"); defaultShader.LoadFragmentSource(@"#version 120 uniform sampler2D colorTexture; varying vec4 fcolor; varying vec2 ftexcoord; void main(void) { gl_FragColor = texture2D(colorTexture, ftexcoord) * fcolor; }"); } else { defaultShader.LoadVertexSource(@"#version 330 core uniform mat4 projection, view; in vec2 vposition; in vec4 vcolor; in vec2 vtexcoord; out vec4 fcolor; out vec2 ftexcoord; void main(void) { fcolor = vcolor; ftexcoord = vtexcoord; gl_Position = projection * view * vec4(vposition, 0, 1); }"); defaultShader.LoadFragmentSource(@"#version 330 core uniform sampler2D colorTexture; in vec4 fcolor; in vec2 ftexcoord; out vec4 color; void main(void) { color = texture(colorTexture, ftexcoord) * fcolor; }"); } defaultShader.Link(); BindShader(this.defaultShader, "vposition", "vcolor", "vtexcoord", "projection", "view"); int[] p = new int[4]; GL.GetInteger(GetPName.Viewport, p); proj = Matrix4.CreateOrthographicOffCenter(p[0], p[2], p[3], p[1], 1, -1); GL.GenTextures(1, out pixelTex); GL.BindTexture(TextureTarget.Texture2D, pixelTex); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 0); float[] pix = new float[] { 1.0f, 1.0f, 1.0f, 1.0f }; GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, 1, 1, 0, PixelFormat.Bgra, PixelType.Float, pix); }
public void Init() { blood_blend_shader = new Shader(); float v = Shader.Version; blood_blend_shader.LoadVertexFile(Path.Combine("Effects", v < 3.3f ? "v12" : "v33", "blood_blend.vert")); blood_blend_shader.LoadFragmentFile(Path.Combine("Effects", v < 3.3f ? "v12" : "v33", "blood_blend.frag")); blood_blend_shader.Link(); blend_buffer = new VertexBuffer(4); blend_buffer.DeclareNextAttribute("vposition", 2); blend_buffer.DeclareNextAttribute("vtexcoord", 2); blend_buffer.DeclareNextAttribute("vcolor", 4); blend_buffer.Attach(blood_blend_shader); blend_buffer.AddVertex(-1, -1, 0, 0, 1f, 1f, 1f, 1f); blend_buffer.AddVertex(1, -1, 1, 0, 1f, 1f, 1f, 1f); blend_buffer.AddVertex(1, 1, 1, 1, 1, 1, 1, 1); blend_buffer.AddVertex(-1, 1, 0, 1, 1, 1, 1, 1); blend_buffer.AddIndices(0, 1, 2, 0, 2, 3); blend_buffer.UpdateBuffer(); }