Example #1
0
        public static void Initialize(ResourceManager resourceManager, int width, int height)
        {
            retrieveRendererInfo();
            setupDebugOutput();

            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);
            SetCapability(EnableCap.Lighting, false);

            if (UseSrgb && HasCapabilities(3, 0, "GL_ARB_framebuffer_object"))
            {
                int defaultFramebufferColorEncoding;
                GL.GetFramebufferAttachmentParameter(FramebufferTarget.Framebuffer, FramebufferAttachment.BackLeft, FramebufferParameterName.FramebufferAttachmentColorEncoding, out defaultFramebufferColorEncoding);
                if (defaultFramebufferColorEncoding == (int)0x8C40)
                {
                    SetCapability(EnableCap.FramebufferSrgb, true);
                    colorCorrected = true;
                }
                else
                {
                    Trace.WriteLine("Warning: The default framebuffer isn't sRgb");
                }
            }

            // glActiveTexture requires opengl 1.3
            maxFpTextureUnits            = HasCapabilities(1, 3) ? GL.GetInteger(GetPName.MaxTextureUnits) : 1;
            maxTextureImageUnits         = GL.GetInteger(GetPName.MaxTextureImageUnits);
            maxVertexTextureImageUnits   = GL.GetInteger(GetPName.MaxVertexTextureImageUnits);
            maxGeometryTextureImageUnits = HasCapabilities(3, 2, "GL_ARB_geometry_shader4") ? GL.GetInteger(GetPName.MaxGeometryTextureImageUnits) : 0;
            maxCombinedTextureImageUnits = GL.GetInteger(GetPName.MaxCombinedTextureImageUnits);
            maxTextureCoords             = GL.GetInteger(GetPName.MaxTextureCoords);

            // glDrawBuffers requires opengl 2.0
            maxDrawBuffers = HasCapabilities(2, 0) ? GL.GetInteger(GetPName.MaxDrawBuffers) : 1;

            Trace.WriteLine($"texture units available: fp:{maxFpTextureUnits} ps:{maxTextureImageUnits} vs:{maxVertexTextureImageUnits} gs:{maxGeometryTextureImageUnits} combined:{maxCombinedTextureImageUnits} coords:{maxTextureCoords}");

            samplerTextureIds     = new int[maxTextureImageUnits];
            samplerTexturingModes = new TexturingModes[maxTextureImageUnits];

            CheckError("initializing openGL context");

            whitePixel  = Texture2d.Create(Color4.White, "whitepixel");
            normalPixel = Texture2d.Create(new Color4(0.5f, 0.5f, 1, 1), "normalpixel", 1, 1, new TextureOptions()
            {
                Srgb = false,
            });
            textGenerator   = new TextGenerator(resourceManager);
            textFontManager = new TextFontManager();

            Viewport = new Rectangle(0, 0, width, height);
        }
Example #2
0
        /// <summary>
        ///     Create option combobox with selection of font
        /// </summary>
        private static void CreateFontCompoBox(UIOptionWindow __instance)
        {
            var parent = __instance.languageComp.transform.parent.parent;

            if (_originalUICount == null)
            {
                _originalUICount = parent.childCount;
            }

            var genericComboBox = __instance.tipLevelComp.transform.parent;

            if (languageComboBoxes == null)
            {
                languageComboBoxes = new UIComboBox[InGameFonts.Length];
            }

            // Needs to initialize UI
            if (_originalUICount == parent.childCount)
            {
                Localization.OnLanguageChange += ReloadFontsComboBox;

                for (int i = 0; i < InGameFonts.Length; i++)
                {
                    var fontName = InGameFonts[i];
                    // Add new combobox
                    var root = Object.Instantiate(genericComboBox,
                                                  genericComboBox.parent);

                    root.gameObject.SetActive(true);
                    Object.Destroy(root.GetComponent <Localizer>());
                    root.GetComponent <Text>().text = $"Font - {fontName}";

                    languageComboBoxes[i] = root.GetComponentInChildren <UIComboBox>();
                    UIComboBox languageComboBox = languageComboBoxes[i];
                    languageComboBox.Items.Clear();
                    languageComboBox.Items.Add(fontName);
                    foreach (var installedFont in TextFontManager.InstalledFonts)
                    {
                        languageComboBox.Items.Add(installedFont);
                    }


                    languageComboBox.text = fontName;

                    var settingsIndex = TextFontManager.GetSettingIndex(fontName);
                    ConsoleLogger.LogWarning("TextFontManager.GetSettingIndex " + settingsIndex);
                    languageComboBox.itemIndex = settingsIndex;

                    languageComboBox.onItemIndexChange.AddListener(() =>
                    {
                        var selectedFontName = languageComboBox.Items[languageComboBox.itemIndex];
                        if (selectedFontName == fontName)
                        {
                            TextFontManager.RestoreDefaultFont(fontName);
                        }
                        else
                        {
                            Font font;
                            try
                            {
                                if (TranslationManager.CurrentLanguage == null || TranslationManager.CurrentLanguage.Fonts == null)
                                {
                                    throw new InvalidOperationException();
                                }

                                font = TranslationManager.CurrentLanguage.Fonts.First(font1 => font1.name == selectedFontName);
                            }
                            catch (InvalidOperationException)
                            {
                                font = Font.CreateDynamicFontFromOSFont(selectedFontName, 12);
                            }

                            TextFontManager.ApplyCustomFont(fontName, font);
                        }
                    });

                    // Set Option position
                    var rectTransform            = root.GetComponent <RectTransform>();
                    var childCountWithoutRestore = __instance.languageComp.transform.parent.parent.childCount - 2;
                    var position = __instance.languageComp.transform.parent.GetComponent <RectTransform>().anchoredPosition;
                    var offset   = 40;
                    rectTransform.anchoredPosition = new Vector2(position.x, position.y - offset * childCountWithoutRestore);
                }
            }
        }