public void AddTexture(TextureUnit texUnit, Texture texture) { _textures.Add(texUnit, texture); }
public static Material CreateTextureColor(Texture texture) { var mat = new Material(); var attributes = new List<ShaderAttribute>(); attributes.Add(new ShaderAttribute(ShaderAttributeType.Vertex, "in_vertex")); attributes.Add(new ShaderAttribute(ShaderAttributeType.Color, "in_color")); attributes.Add(new ShaderAttribute(ShaderAttributeType.UV, "in_uv")); var parameters = new List<ShaderParam>(); parameters.Add(new ShaderParam(ShaderParamType.Camera, "camera", "Camera Matrix", Matrix4.Identity)); parameters.Add(new ShaderParam(ShaderParamType.Model, "model", "Model Matrix", Matrix4.Identity)); parameters.Add(new ShaderParam(ShaderParamType.Texture, "tex", "Texture", TextureUnit.Texture0)); mat.Shader = new Shader( @"#version 150 uniform mat4 camera; uniform mat4 model; in vec3 in_vertex; in vec4 in_color; in vec2 in_uv; out vec2 frag_TexCoord; out vec4 frag_Color; void main() { gl_Position = camera * model * vec4(in_vertex, 1); frag_TexCoord = in_uv; frag_Color = in_color; }", @"#version 150 uniform sampler2D tex; in vec4 frag_Color; in vec2 frag_TexCoord; out vec4 final_color; void main() { final_color = texture(tex, frag_TexCoord) * frag_Color; }", attributes, parameters); mat.AddTexture(TextureUnit.Texture0, texture); mat.DepthTest = true; mat.AlphaBlend = true; mat.SmoothLines = true; return mat; }
public static Texture FromFile(string filename, bool preMultiplyAlpha, bool createAlpha) { var result = new Texture(); result.LoadFromFile(filename, preMultiplyAlpha, createAlpha); return result; }
public static Texture FromBitmap(Bitmap image, bool preMultiplyAlpha, bool createAlpha) { var result = new Texture(); result.LoadFromBitmap(image, preMultiplyAlpha, createAlpha); return result; }
public static Texture CreateFromStream(Stream stream, bool preMultiplyAlpha, bool createAlpha) { var texture = new Texture(); texture.LoadFromStream(stream, preMultiplyAlpha, createAlpha); return texture; }
private void CreateMaterial(Stream fontStream, Stream fontInfoStream) { var texture = new Texture(); texture.LoadFromStream(fontStream, true, false); using (var sr = fontInfoStream) { using (var br = new BinaryReader(sr)) { for (int i = 33; i < 256; i++) { var x1 = br.ReadByte(); var y1 = br.ReadByte(); var x2 = br.ReadByte(); var y2 = br.ReadByte(); _charInfo[i].U1 = x1 / (float)texture.Width; _charInfo[i].V1 = y1 / (float)texture.Height; _charInfo[i].U2 = x2 / (float)texture.Width; _charInfo[i].V2 = y2 / (float)texture.Height; _charInfo[i].Width = x2 - x1; _charInfo[i].Height = y2 - y1; _charInfo[i].YOffset = br.ReadByte(); } for (int i = 0; i < 256*256; i++) { _kerning[i] = br.ReadByte(); } } } _charInfo[32].Width = _charInfo[101].Width-2; _charInfo[32].Height = _charInfo[101].Height; _material = Material.CreateTextureColor(texture); _material.AlphaBlend = true; _material.DepthTest = false; }