Ejemplo n.º 1
0
        public void DrawTile(float x, float y, float offset, float scale, uint tileNumber)
        {
            GL.Color4(Color4.White);
            GL.BindTexture(TextureTarget.Texture2D, tileSet.Handle); // bind font texture
            const uint tilesPerColumn = 10;
            const uint tilesPerRow    = 5;
            var        rect           = new Rect(x + offset, y + offset, 1f - scale, 1f - scale);
            var        tileCoords     = SpriteSheetTools.CalcTexCoords(tileNumber, tilesPerRow, tilesPerColumn);

            DrawRectangleTexture(rect, tileCoords);
        }
Ejemplo n.º 2
0
        private void DrawExplosion(IEnumerable <Explosion> explosions)
        {
            GL.Enable(EnableCap.Texture2D);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.Enable(EnableCap.Blend);
            GL.Color4(Color4.White);
            // how many sprites are in each column and row
            const uint spritesPerColumn = 8;
            const uint spritesPerRow    = 8;

            foreach (var explosion in explosions)
            {
                GL.BindTexture(TextureTarget.Texture2D, texExplosion.Handle);
                // calculate the current frame of an animation
                var spriteId  = (uint)MathF.Round(explosion.NormalizedAnimationTime * (spritesPerRow * spritesPerColumn - 1));
                var texCoords = SpriteSheetTools.CalcTexCoords(spriteId, spritesPerRow, spritesPerColumn);
                DrawCircleTexture(explosion, texCoords);
            }
            GL.Disable(EnableCap.Texture2D);
            GL.Disable(EnableCap.Blend);
        }
Ejemplo n.º 3
0
        private void DrawText(string text, float x, float y, float size)
        {
            GL.Color4(Color4.White);
            const uint firstCharacter      = 32;          // the ASCII code of the first character stored in the bitmap font
            const uint charactersPerColumn = 12;          // how many characters are in each column
            const uint charactersPerRow    = 8;           // how many characters are in each row
            var        rect = new Rect(x, y, size, size); // rectangle of the first character

            foreach (var spriteId in SpriteSheetTools.StringToSpriteIds(text, firstCharacter))
            {
                //TODO: Calculate the texture coordinates of the characters letter from the bitmap font texture
                //TODO: Draw a rectangle at the characters relative position
                var texCoords = SpriteSheetTools.CalcTexCoords(spriteId, charactersPerRow, charactersPerColumn);


                GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
                GL.Enable(EnableCap.Blend);
                DrawRectangleTexture(rect, texCoords);
                GL.Disable(EnableCap.Blend);
                rect.MinX += rect.SizeX;
            }
        }