Esempio n. 1
0
        public static void LoadFont(string fontPath)
        {
            var surf = SDL_image.IMG_Load(fontPath);

            if (surf == IntPtr.Zero)
            {
                Console.WriteLine("Font loading failed, things about to break");
                Console.WriteLine(SDL_image.IMG_GetError());
                return;
            }
            var fontSurface = Marshal.PtrToStructure <SDL.SDL_Surface>(surf);

            fontWidth  = fontSurface.w;
            fontHeight = fontSurface.h;

            fontBuffer = new bool[fontWidth, fontHeight];
            unsafe {
                Color32 *colors = (Color32 *)fontSurface.pixels;

                for (int i = 0; i < fontWidth; i++)
                {
                    for (int j = 0; j < fontHeight; j++)
                    {
                        int fontColorBufferIndex = (j * fontWidth) + i;
                        fontBuffer[i, fontHeight - j - 1] = colors[fontColorBufferIndex].r > 0;
                    }
                }
            }

            fontWidth  = fontSurface.w / 16;
            fontHeight = fontSurface.h / 8;
        }