示例#1
0
        // =====================================================================
        // Updating
        // =====================================================================
        // =====================================================================
        // Shortcuts
        // =====================================================================
        // =====================================================================
        // Overrides
        // =====================================================================
        // =====================================================================
        // Private functions
        // =====================================================================
        private void InitGL()
        {
            GL.ClearColor(GlobalSettings.BackgroundColor);

            GL.Enable(EnableCap.Texture2D);
            GL.ShadeModel(ShadingModel.Smooth); // Enable Smooth Shading
            GL.Enable(EnableCap.DepthTest); // Enables Depth Testing
            GL.DepthFunc(DepthFunction.Lequal); // The Type Of Depth Testing To Do
            GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); // Really Nice Perspective Calculations
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);

            _toolboxUpNormal = new TextureGL(Resources.buttong);
            _toolboxUpHover = new TextureGL(Resources.buttong_2);
            _toolboxDownNormal = new TextureGL(Resources.buttong_down);
            _toolboxDownHover = new TextureGL(Resources.buttong_down2);
            _cubeSides = new TextureGL(Resources.cube_sides);
            _cubeSides.SetMipmapping(true);
            _cubeSides.SetRepeat(true);

            _font = new TextureGL(Resources.tinyfont);
            _font.SetMipmapping(false);
            _font.SetRepeat(false);

            _grassTop = new TextureGL(GlobalSettings.GetDataURI("grass.png"));
            _grassTop.SetMipmapping(false);
            _grassTop.SetRepeat(true);

            _dynamicOverlay = new BackgroundImage("Dynamic", "Dynamic", null);
            _dynamicOverlay.Item = mDYNAMICOVERLAYToolStripMenuItem;
            _backgrounds.Add(_dynamicOverlay);

            foreach (string file in Directory.GetFiles(GlobalSettings.GetDataURI("Overlays"), "*.png"))
            {
                try
                {
                    var image = new TextureGL(file);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);

                    _backgrounds.Add(new BackgroundImage(file, Path.GetFileNameWithoutExtension(file), image));
                }
                catch
                {
                    MessageBox.Show(this, string.Format(GetLanguageString("B_MSG_OVERLAYERROR"), file));
                }
            }

            int index = 0;
            foreach (BackgroundImage b in _backgrounds)
            {
                ToolStripMenuItem item = b.Item ?? new ToolStripMenuItem(b.Name);
                b.Item = item;

                if (b.Path == GlobalSettings.LastBackground)
                {
                    item.Checked = true;
                    _selectedBackground = index;
                }

                item.Click += item_Clicked;
                item.Tag = index++;

                if (!backgroundsToolStripMenuItem.DropDownItems.Contains(item))
                    backgroundsToolStripMenuItem.DropDownItems.Add(item);
            }

            _previewPaint = new TextureGL();
            GlobalDirtiness.CurrentSkin = new TextureGL();
            _alphaTex = new TextureGL();

            var arra = new byte[64 * 32];
            _previewPaint.Upload(arra, 64, 32);
            _previewPaint.SetMipmapping(false);
            _previewPaint.SetRepeat(false);

            GlobalDirtiness.CurrentSkin.Upload(arra, 64, 32);
            GlobalDirtiness.CurrentSkin.SetMipmapping(false);
            GlobalDirtiness.CurrentSkin.SetRepeat(false);

            arra = new byte[]
            {
                127,
                127,
                127,
                255,
                80,
                80,
                80,
                255,
                80,
                80,
                80,
                255,
                127,
                127,
                127,
                255
            };

            _alphaTex.Upload(arra, 2, 2);
            _alphaTex.SetMipmapping(false);
            _alphaTex.SetRepeat(true);

            bool supportsArrays = GL.GetString(StringName.Extensions).Contains("GL_EXT_vertex_array");
            bool forceImmediate = GlobalSettings.RenderMode == 0;

            clientArraysToolStripMenuItem.Enabled = supportsArrays;

            if (supportsArrays && !forceImmediate)
            {
                MeshRenderer = new ClientArrayRenderer();
                clientArraysToolStripMenuItem.Checked = true;
                GlobalSettings.RenderMode = 1;
            }
            else
            {
                MeshRenderer = new ImmediateRenderer();
                immediateToolStripMenuItem.Checked = true;
                GlobalSettings.RenderMode = 0;
            }
        }