Ejemplo n.º 1
0
 public LineBatch()
 {
     _material = Material.CreateColor();
     _material.AlphaBlend = true;
     _material.DepthTest = false;
     _material.SmoothLines = false;
 }
Ejemplo n.º 2
0
 protected override void OnDispose()
 {
     if (_mat != null)
     {
         _mat.Dispose();
         _mat = null;
     }
 }
Ejemplo n.º 3
0
 protected override void OnDispose()
 {
     if (_atlas != null)
     {
         _atlas.UnLoad();
         _atlas = null;
     }
     if (_mat != null)
     {
         _mat.Dispose();
         _mat = null;
     }
 }
Ejemplo n.º 4
0
 protected override void OnLoad()
 {
     _spriteDef = this.Owner.Root.FindChild<SpriteDefinition>(_spriteDefName);
     if (_spriteDef != null)
     {
         var materialObj = _spriteDef.FindParent<PluginBase.GameObjects.Material>();
         materialObj.Load();
         _material = materialObj.Mat;
     }
     else
     {
         _material = null;
     }
 }
Ejemplo n.º 5
0
 public override void Load()
 {
     _texture = SelectedGameObject.FindParent<GameObjects.Texture>();
     if (_texture != null)
     {
         var bitmap = _texture.GetBitmap();
         if (bitmap != null)
         {
             _mat = TokGL.Material.CreateTextureColor(TokGL.Texture.FromBitmap(bitmap, true, false));
             Camera.Up = new Vector3(0, -1, 0);
             Camera.Position = new Vector3(bitmap.Width / 2.0f, bitmap.Height / 2.0f, -100);
             Camera.LookAt = new Vector3(bitmap.Width / 2.0f, bitmap.Height / 2.0f, 0);
             Camera.Fov = 1.0f;
         }
     }
 }
Ejemplo n.º 6
0
 public void AddSprite(Material mat, float x, float y, int px1, int py1, int width, int height, Color color)
 {
     if (!_sprites.ContainsKey(mat)) _sprites.Add(mat, new List<Sprite>(1000));
     _sprites[mat].Add(new Sprite
     {
         P1 = new Vector2(x, y),
         P2 = new Vector2(x + width, y),
         P3 = new Vector2(x + width, y + height),
         P4 = new Vector2(x, y + height),
         UV1 = new Vector2((float)px1 / (float)mat[TextureUnit.Texture0].Width, (float)py1 / (float)mat[TextureUnit.Texture0].Height),
         UV2 = new Vector2((float)(px1 + width) / (float)mat[TextureUnit.Texture0].Width, (float)py1 / (float)mat[TextureUnit.Texture0].Height),
         UV3 = new Vector2((float)(px1 + width) / (float)mat[TextureUnit.Texture0].Width, (float)(py1 + height) / (float)mat[TextureUnit.Texture0].Height),
         UV4 = new Vector2((float)px1 / (float)mat[TextureUnit.Texture0].Width, (float)(py1 + height) / (float)mat[TextureUnit.Texture0].Height),
         Color = color
     });
 }
Ejemplo n.º 7
0
        public static Material CreateColor()
        {
            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"));

            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));

            mat.Shader = new Shader(
            @"#version 150

            uniform mat4 camera;
            uniform mat4 model;
            in vec3 in_vertex;
            in vec4 in_color;
            out vec4 frag_color;

            void main()
            {
            gl_Position = camera * model * vec4(in_vertex, 1);
            frag_color = in_color;
            }",
            @"#version 150

            in vec4 frag_color;
            out vec4 final_color;

            void main()
            {
            final_color = frag_color;
            }", attributes, parameters);
            mat.DepthTest = true;
            mat.AlphaBlend = true;
            mat.SmoothLines = true;
            return mat;
        }
Ejemplo n.º 8
0
 protected override void OnUnLoad()
 {
     if (_material != null)
     {
         _material.Dispose();
         _material = null;
     }
 }
Ejemplo n.º 9
0
        protected override void OnLoad()
        {
            _material = new TokGL.Material();

            var shader = Plugins.Container.ResolveNamed<TokED.ShaderDefinition>(_shader);
            if (shader == null) throw new Exception(string.Format("Did not find shader {0}!", _shader));

            _material.Shader = new TokGL.Shader(shader.VertexProgram, shader.FragmentProgram, shader.Attributes, shader.Parameters);
            _material.Activate();

            if (_shader != _parameterShader)
            {
                //Get default parameters
                _parameters.Clear();
                foreach (var p in _material.Shader.Parameters)
                {
                    _parameters.Add(p.Clone());
                }
                _parameterShader = _shader;
            }
            else ApplyParameters();

            //Load Textures
            if (_material.TextureCount > 0) throw new Exception("Textures not cleaned up!");
            foreach (var param in _material.Shader.Parameters)
            {
                if (param.Type == ShaderParamType.Texture)
                {
                    TokGL.Texture texture;

                    if (!string.IsNullOrWhiteSpace(param.TextureName))
                    {
                        var t = this.Root.FindChild<GameObject>(param.TextureName) as ITexture;
                        texture = TokGL.Texture.FromBitmap(t.GetBitmap(), true, false);
                    }
                    else
                    {
                        texture = TokGL.Texture.FromBitmap(_notTexture, true, false);
                    }
                    texture.MinFilter = _minFilter;
                    texture.MagFilter = _magFilter;
                    _material.AddTexture(param.TexUnit, texture);
                }
            }
            _material.DepthTest = _depthTest;
            _material.AlphaBlend = _alphaBlend;
            _material.SmoothLines = _smoothLines;
            _material.Deactivate();
        }
Ejemplo n.º 10
0
 public static void RegisterTexture(string resourceName)
 {
     _currentMaterial = Material.CreateTextureColor(Texture.CreateFromStream(Plugins.LoadResourceStream(resourceName), true, false));
     _currentMaterial[TextureUnit.Texture0].MagFilter = TextureMagFilter.Nearest;
     _currentMaterial[TextureUnit.Texture0].MinFilter = TextureMinFilter.Nearest;
     _currentMaterial.AlphaBlend = true;
     _currentMaterial.DepthTest = false;
 }
Ejemplo n.º 11
0
 public void AddSprite(Material mat, Vector2 a, Vector2 b, Vector2 c, Vector2 d, Vector2 origin)
 {
     AddSprite(mat, a, b, c, d, origin, Color.White);
 }
Ejemplo n.º 12
0
 public void AddSprite(Material mat, Vector2 a, Vector2 b, Vector2 c, Vector2 d, Vector2 origin, Color color)
 {
     if (!_sprites.ContainsKey(mat)) _sprites.Add(mat, new List<Sprite>(1000));
     if (mat[TextureUnit.Texture0] != null)
     {
         _sprites[mat].Add(new Sprite
         {
             P1 = a - origin,
             P2 = b - origin,
             P3 = c - origin,
             P4 = d - origin,
             UV1 = new Vector2(a.X / mat[TextureUnit.Texture0].Width, a.Y / mat[TextureUnit.Texture0].Height),
             UV2 = new Vector2(b.X / mat[TextureUnit.Texture0].Width, b.Y / mat[TextureUnit.Texture0].Height),
             UV3 = new Vector2(c.X / mat[TextureUnit.Texture0].Width, c.Y / mat[TextureUnit.Texture0].Height),
             UV4 = new Vector2(d.X / mat[TextureUnit.Texture0].Width, d.Y / mat[TextureUnit.Texture0].Height),
             Color = color
         });
     }
     else
     {
         _sprites[mat].Add(new Sprite
         {
             P1 = a - origin,
             P2 = b - origin,
             P3 = c - origin,
             P4 = d - origin,
             UV1 = new Vector2(a.X / 256, a.Y / 256),
             UV2 = new Vector2(b.X / 256, b.Y / 256),
             UV3 = new Vector2(c.X / 256, c.Y / 256),
             UV4 = new Vector2(d.X / 256, d.Y / 256),
             Color = color
         });
     }
 }
Ejemplo n.º 13
0
 public void AddSprite(Material mat, Vector2 a, Vector2 b, float u1, float v1, float u2, float v2)
 {
     AddSprite(mat, a, b, u1, v1, u2, v2, Color.White);
 }
Ejemplo n.º 14
0
 public void AddSprite(Material mat, Vector2 a, Vector2 b, float u1, float v1, float u2, float v2, Color color)
 {
     if (!_sprites.ContainsKey(mat)) _sprites.Add(mat, new List<Sprite>(1000));
     _sprites[mat].Add(new Sprite
     {
         P1 = a,
         P2 = new Vector2(b.X, a.Y),
         P3 = b,
         P4 = new Vector2(a.X, b.Y),
         UV1 = new Vector2(u1, v1),
         UV2 = new Vector2(u2, v1),
         UV3 = new Vector2(u2, v2),
         UV4 = new Vector2(u1, v2),
         Color = color
     });
 }
Ejemplo n.º 15
0
 public void AddSprite(Material mat, Vector2 a, Vector2 b, int px1, int py1, int width, int height)
 {
     AddSprite(mat, a, b, px1, py1, width, height);
 }
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
0
 public void AddSprite(Material mat, float x, float y, int px1, int py1, int width, int height)
 {
     AddSprite(mat, x, y, px1, py1, width, height, Color.White);
 }
Ejemplo n.º 18
0
Archivo: Font.cs Proyecto: Tokter/TokED
        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;
        }