コード例 #1
0
        public static TextFileData Build(string id, string relativePath)
        {
            var text = File.ReadAllLines(ResourceLoader.GetFullResourcePath(relativePath));

            var text_file_data = new TextFileData()
            {
                Id = id,
            };

            text = text
                   .Where(t => t.Length > 0)
                   .ToArray();

            text_file_data.TextData = new byte[text.Length][];

            for (int i = 0; i < text.Length; ++i)
            {
                var line = text[i];

                var bytes = System.Text.Encoding.UTF8.GetBytes(line);

                text_file_data.TextData[i] = new byte[bytes.Length];

                Unsafe.CopyBlockUnaligned(ref text_file_data.TextData[i][0], ref bytes[0], (uint)bytes.Length);
            }

            return(text_file_data);
        }
コード例 #2
0
ファイル: ImageBuilder.cs プロジェクト: parhelia512/OMEGA
        public static ImageData Build(string id, string relative_path)
        {
            using var file = File.OpenRead(ResourceLoader.GetFullResourcePath(relative_path));

            var image = ImageResult.FromStream(file, ColorComponents.RedGreenBlueAlpha);

            var image_data = new ImageData()
            {
                Id     = id,
                Data   = image.Data,
                Width  = image.Width,
                Height = image.Height
            };

            return(image_data);
        }
コード例 #3
0
        public static ShaderProgramData Build(string id, string relativeVsPath, string relativeFsPath)
        {
            Console.WriteLine($"Compiling Shader: {id}");

            var result = ShaderCompiler.Compile(ResourceLoader.GetFullResourcePath(relativeVsPath), ResourceLoader.GetFullResourcePath(relativeFsPath));

            var shader_program_data = new ShaderProgramData()
            {
                Id             = id,
                VertexShader   = result.VsBytes,
                FragmentShader = result.FsBytes,
                Samplers       = result.Samplers,
                Params         = result.Params
            };

            return(shader_program_data);
        }
コード例 #4
0
        public static FontData Build(FontBuildParams @params)
        {
            var compile_params = new FontCompileParams()
            {
                CharRangeLevel = @params.CharRangeLevel,
                FontFilePath   = ResourceLoader.GetFullResourcePath(@params.Path),
                FontName       = @params.Id,
                FontSize       = @params.Size,
                SpacingH       = 1,
                SpacingV       = 1,
                PaddingUp      = @params.PaddingUp,
                PaddingDown    = @params.PaddingDown,
                PaddingLeft    = @params.PaddingLeft,
                PaddingRight   = @params.PaddingRight
            };

            Console.WriteLine($"Compiling Font: {@params.Id}, Size: {@params.Size}");

            if (@params.DropShadow)
            {
                if (Calc.Abs(@params.ShadowOffsetX) > @params.PaddingLeft + @params.PaddingRight)
                {
                    @params.PaddingLeft  = Calc.Abs(@params.ShadowOffsetX);
                    @params.PaddingRight = Calc.Abs(@params.ShadowOffsetX);
                }

                if (Calc.Abs(@params.ShadowOffsetY) > @params.PaddingUp + @params.PaddingDown)
                {
                    @params.PaddingUp   = Calc.Abs(@params.ShadowOffsetY);
                    @params.PaddingDown = Calc.Abs(@params.ShadowOffsetY);
                }

                compile_params.PaddingUp    = @params.PaddingUp;
                compile_params.PaddingDown  = @params.PaddingDown;
                compile_params.PaddingLeft  = @params.PaddingLeft;
                compile_params.PaddingRight = @params.PaddingRight;
            }

            var compile_result = FontCompiler.Compile(compile_params);

            if (@params.DropShadow)
            {
                Blitter.Begin(compile_result.FontImageData, compile_result.FontImageWidth, compile_result.FontImageHeight);

                Blitter.DropShadow(@params.ShadowOffsetX, @params.ShadowOffsetY, new Color(@params.ShadowColor));

                Blitter.End();
            }

            var font_data = new FontData()
            {
                Id        = @params.Id,
                FontSheet = new ImageData()
                {
                    Id     = @params.Id + "_texture",
                    Data   = compile_result.FontImageData,
                    Width  = compile_result.FontImageWidth,
                    Height = compile_result.FontImageHeight
                },
            };

            FontDescrParser.ParseAndFillData(font_data, compile_result.FontDescrData);

            return(font_data);
        }