/// <summary> /// Set the fog /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="color"></param> public static void SetFog(float start, float end, VulpineLib.Util.Color color) { var fog = new UniformBlockFog { Start = start, End = end, FogColor = color }; unsafe { var ptr = (UniformBlockFog *)FogUniformBuffer.Map(BufferAccess.WriteOnly); ptr[0] = fog; FogUniformBuffer.Unmap(); } }
/// <summary> /// Draw a sprite /// </summary> /// <param name="sprite"></param> /// <param name="transform"></param> /// <param name="color"></param> /// <param name="blendType"></param> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="NullReferenceException"></exception> public void DrawSprite(Sprite sprite, ref Matrix4 <float> transform, VulpineLib.Util.Color color, BlendType blendType) { Assert(); if (!Drawing) { throw new InvalidOperationException("Not drawing; Begin() must be called first"); } var spriteSet = sprite.SpriteSet; // If this Sprite's SpriteSet is not the same as the cached previous one, then // update the cache to the new one and bind the new one's texture if (spriteSet != LastSpriteSet) { if (spriteSet.Texture == null) { throw new NullReferenceException($"Sprite's SpriteSet ({sprite.SpriteSet.Name}) has a null Texture"); } spriteSet.Texture.BindDiffuse(); LastSpriteSet = spriteSet; } // If this Sprite is not the same as the cached previous one, then // update the cache to the new one and set the relevant shader uniforms if (sprite != LastSprite !) { sprite.ShaderProgram.Bind(); sprite.ShaderProgram.SetTextureSource(sprite.TopLeftCoord, sprite.SizeCoord); sprite.ShaderProgram.Uniform("uniform_origin", sprite.Origin); LastSprite = sprite; } // Bind the BlendType blendType.Bind(); // Set the model color sprite.ShaderProgram.SetModelColor(color); // Set the model matrix sprite.ShaderProgram.SetModelMatrix(ref transform); // Draw 4 vertices GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); State.CheckError(); }
/// <summary> /// Draw a mesh /// </summary> /// <param name="mesh"></param> /// <param name="transform"></param> /// <param name="color"></param> /// <param name="blendType"></param> public void DrawMesh(GPUMesh <T> mesh, ref Matrix4 <float> transform, VulpineLib.Util.Color color, BlendType blendType) { Assert(); if (!Drawing) { throw new InvalidOperationException("Not drawing; Begin() must be called first"); } if (mesh != LastMesh !) { mesh.Bind(); LastMesh = mesh; } // Bind the BlendType blendType.Bind(); // Set the model color mesh.ShaderProgram.SetModelColor(color); // Set the model matrix mesh.ShaderProgram.SetModelMatrix(ref transform); // Draw mesh.Draw(); State.CheckError(); }
/// <summary> /// Draw a sprite spanning a rectangle /// </summary> /// <param name="sprite"></param> /// <param name="rectangle"></param> /// <param name="color"></param> /// <param name="blendType"></param> /// <exception cref="InvalidOperationException"></exception> /// <exception cref="NullReferenceException"></exception> public void DrawSprite(Sprite sprite, VulpineLib.Geometry.Rectangle rectangle, VulpineLib.Util.Color color, BlendType blendType) { DrawSprite( sprite, new Vector3 <float>( rectangle.Center, 0f ), new Vector2 <float>( rectangle.Width, rectangle.Height ), color, blendType ); }