public void AddSprite(Sprite2 sprite) { // If the RenderBatch is full, render what is already there and // then start again if (sprite.Vertices.Count + _currentBatchSize > MaxVertexNumber) { Draw(); } // Add current Sprite to the batch for(int i = 0; i < sprite.Vertices.Count; i++) { _vertices[_currentBatchSize + 1] = sprite.Vertices[i]; } _currentBatchSize += sprite.Vertices.Count; }
public void DrawSprite(Sprite2 sprite) { GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, sprite.Texture.Id); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Begin(PrimitiveType.Triangles); { for(int i = 0; i < sprite.Vertices.Count; i++) { DrawImmediateModeVertex( sprite.Vertices[i].Position, sprite.Vertices[i].Color, sprite.Vertices[i].UVs); } } GL.End(); }
public CharacterSprite CreateSprite(char c) { CharacterData data = Characters[c]; Sprite2 sprite = new Sprite2(this._texture); // Setup UV Data // We need to divide by the texture Width since OpenGL has UVs in range // 0 to 1 Point topLeft = new Point( (float)data.X / (float)_texture.Width, (float)data.Y / (float)_texture.Height); Point bottomRight = new Point( topLeft.X + ((float)data.Width / (float)_texture.Width), topLeft.Y + ((float)data.Height / (float)_texture.Height) ); sprite.SetUVs(topLeft, bottomRight); sprite.RenderWidth = data.Width; sprite.RenderHeight = data.Height; sprite.SetColor(new Color(1, 1, 1, 1)); return new CharacterSprite(sprite, data); }
public CharacterSprite(Sprite2 sprite, CharacterData data) { this.Sprite = sprite; this.Data = data; }