Exemplo n.º 1
0
 public void DrawTextured(object context, Coordinate cameraLocation, ShaderProgram program)
 {
     // Todo abstract this out a bit, repeated code all over the place
     _array.Bind(context, 0);
     foreach (var subset in _array.TextureSubsets)
     {
         var tex = subset.Instance;
         if (tex != null) tex.Bind();
         else TextureHelper.Unbind();
         program.Set("isTextured", tex != null);
         _array.Array.DrawElements(0, subset.Start, subset.Count);
     }
     _array.Bind(context, 1);
     foreach (var subset in _array.TransparentSubsets.OrderByDescending(x => (cameraLocation - x.Instance.Origin).LengthSquared()))
     {
         var tf = subset.Instance;
         if (tf.Texture != null) tf.Texture.Bind();
         else TextureHelper.Unbind();
         program.Set("isTextured", tf.Texture != null);
         _array.Array.DrawElements(0, subset.Start, subset.Count);
     }
     _array.Unbind();
     GL.Disable(EnableCap.CullFace);
     _decalArray.Bind(context, 0);
     foreach (var subset in _decalArray.TextureSubsets)
     {
         var tex = subset.Instance;
         if (tex != null) tex.Bind();
         else TextureHelper.Unbind();
         program.Set("isTextured", tex != null);
         _decalArray.Array.DrawElements(0, subset.Start, subset.Count);
     }
     _decalArray.Unbind();
     GL.Enable(EnableCap.CullFace);
 }
Exemplo n.º 2
0
        public MapObject3DShader()
        {
            Shader = new ShaderProgram(GetShader(ShaderType.VertexShader), GetShader(ShaderType.FragmentShader));

            Shader.Bind();

            Perspective = Camera = ModelView = SelectionTransform = Matrix4.Identity;
            IsTextured = true;
            IsLit = true;
            Show3DGrid = false;
            GridSpacing = 64;
            SelectionColourMultiplier = new Vector4(1, 0.5f, 0.5f, 1);
            Transformation = Matrix4.Identity;

            GL.ActiveTexture(TextureUnit.Texture0);
            Shader.Set("currentTexture", 0);

            Shader.Unbind();
        }