Beispiel #1
0
        public void SetupGLControl()
        {
            RenderingEnabled = false;

            if (glControl != null)
            {
                glControl.Dispose();
            }

            glControl = null;

            GLMode = null;

            try
            {
                GLMode = new OpenTK.Graphics.GraphicsMode(OpenTK.DisplayDevice.Default.BitsPerPixel, 24, 8, 4);
            }
            catch
            {
                GLMode = null;
            }

            try
            {
                if (GLMode == null)
                {
                    // Try default mode
                    glControl = new OpenTK.GLControl();
                }
                else
                {
                    glControl = new OpenTK.GLControl(GLMode);
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message, Helpers.LogLevel.Warning, client);
                glControl = null;
            }

            if (glControl == null)
            {
                Logger.Log("Failed to initialize OpenGL control, cannot continue", Helpers.LogLevel.Error, client);
                return;
            }

            Logger.Log("Initializing OpenGL mode: " + GLMode.ToString(), Helpers.LogLevel.Info);

            glControl.Paint += glControl_Paint;
            glControl.Resize += glControl_Resize;
            glControl.MouseDown += glControl_MouseDown;
            glControl.MouseUp += glControl_MouseUp;
            glControl.MouseMove += glControl_MouseMove;
            glControl.MouseWheel += glControl_MouseWheel;
            glControl.Load += new EventHandler(glControl_Load);
            glControl.Disposed += new EventHandler(glControl_Disposed);
            glControl.Click += new EventHandler(glControl_Click);
            glControl.BackColor = clearcolour;

            glControl.Dock = DockStyle.Fill;
            glControl.TabIndex = 0;

            Controls.Add(glControl);

            glControl.BringToFront();
            glControl.Focus();
        }
Beispiel #2
0
        public void Initialize(Language language)
        {
            // tools
            DodgeBurnOptions = new DodgeBurnOptions();
            DarkenLightenOptions = new DarkenLightenOptions();
            PencilOptions = new PencilOptions();
            FloodFillOptions = new FloodFillOptions();
            NoiseOptions = new NoiseOptions();
            EraserOptions = new EraserOptions();
            StampOptions = new StampOptions();

            _tools.Add(new ToolIndex(new CameraTool(), null, "T_TOOL_CAMERA", Resources.eye__1_, Keys.C));
            _tools.Add(new ToolIndex(new PencilTool(), PencilOptions, "T_TOOL_PENCIL", Resources.pen, Keys.P));
            _tools.Add(new ToolIndex(new EraserTool(), EraserOptions, "T_TOOL_ERASER", Resources.erase, Keys.E));
            _tools.Add(new ToolIndex(new DropperTool(), null, "T_TOOL_DROPPER", Resources.pipette, Keys.D));
            _tools.Add(new ToolIndex(new DodgeBurnTool(), DodgeBurnOptions, "T_TOOL_DODGEBURN", Resources.dodge, Keys.B));
            _tools.Add(new ToolIndex(new DarkenLightenTool(), DarkenLightenOptions, "T_TOOL_DARKENLIGHTEN", Resources.darkenlighten, Keys.L));
            _tools.Add(new ToolIndex(new FloodFillTool(), FloodFillOptions, "T_TOOL_BUCKET", Resources.fill_bucket, Keys.F));
            _tools.Add(new ToolIndex(new NoiseTool(), NoiseOptions, "T_TOOL_NOISE", Resources.noise, Keys.N));
            _tools.Add(new ToolIndex(new StampTool(), StampOptions, "T_TOOL_STAMP", Resources.stamp_pattern, Keys.M));

            for (int i = _tools.Count - 1; i >= 0; --i)
            {
                toolToolStripMenuItem.DropDownItems.Insert(0, _tools[i].MenuItem);
                _tools[i].MenuItem.Click += ToolMenuItemClicked;
                toolStrip1.Items.Insert(toolStrip1.Items.IndexOf(toolStripSeparator1) + 1, _tools[i].Button);
                _tools[i].Button.Click += ToolMenuItemClicked;

                languageProvider1.SetPropertyNames(_tools[i].MenuItem, "Text");
                languageProvider1.SetPropertyNames(_tools[i].Button, "Text");
            }

            // Shortcuts
            InitShortcuts();
            LoadShortcutKeys(GlobalSettings.ShortcutKeys);
            _shortcutEditor.ShortcutExists += _shortcutEditor_ShortcutExists;

            Editor.CurrentLanguage = language;
            SetSelectedTool(_tools[0]);

            Brushes.LoadBrushes();

            foreach (string x in GlobalSettings.SkinDirectories)
                Directory.CreateDirectory(MacroHandler.ReplaceMacros(x));

            // set up the GL control
            var mode = new GraphicsMode();

            reset:

            Renderer =
                new GLControl(new GraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, GlobalSettings.Multisamples));

            if (Renderer.Context == null)
            {
                mode = new GraphicsMode();
                goto reset;
            }

            Renderer.BackColor = Color.Black;
            Renderer.Dock = DockStyle.Fill;
            Renderer.Location = new Point(0, 25);
            Renderer.Name = "rendererControl";
            Renderer.Size = new Size(641, 580);
            Renderer.TabIndex = 4;

            splitContainer4.Panel2.Controls.Add(Renderer);
            Renderer.BringToFront();

            GLVendor = GL.GetString(StringName.Vendor);
            GLVersion = GL.GetString(StringName.Version);
            GLRenderer = GL.GetString(StringName.Renderer);
            GLExtensions = GL.GetString(StringName.Extensions);

            InitGL();

            Renderer.Paint += rendererControl_Paint;
            Renderer.MouseDown += rendererControl_MouseDown;
            Renderer.MouseMove += rendererControl_MouseMove;
            Renderer.MouseUp += rendererControl_MouseUp;
            Renderer.MouseLeave += rendererControl_MouseLeave;
            Renderer.Resize += rendererControl_Resize;
            Renderer.MouseWheel += rendererControl_MouseWheel;
            Renderer.MouseEnter += rendererControl_MouseEnter;

            #if NO
            if (!GlobalSettings.Loaded)
                MessageBox.Show(this, GetLanguageString("C_SETTINGSFAILED"));
            #endif

            _undoListBox = new UndoRedoPanel();
            _undoListBox.ActionString = "L_UNDOACTIONS";
            languageProvider1.SetPropertyNames(_undoListBox, "ActionString");

            _undoListBox.ListBox.MouseClick += UndoListBox_MouseClick;

            undoToolStripButton.DropDown = new Popup(_undoListBox);
            undoToolStripButton.DropDownOpening += undoToolStripButton_DropDownOpening;

            _redoListBox = new UndoRedoPanel();
            _redoListBox.ActionString = "L_REDOACTIONS";
            languageProvider1.SetPropertyNames(_redoListBox, "ActionString");

            _redoListBox.ListBox.MouseClick += RedoListBox_MouseClick;

            redoToolStripButton.DropDown = new Popup(_redoListBox);
            redoToolStripButton.DropDownOpening += redoToolStripButton_DropDownOpening;

            undoToolStripButton.DropDown.AutoClose = redoToolStripButton.DropDown.AutoClose = true;

            CreatePartList();
            Renderer.Invalidate();
        }
Beispiel #3
0
 public void Reset()
 {
     if (glControl != null)
     {
         Destroy();
     }
     scaledScreen = new uint[imageScaler.ResizedX * imageScaler.ResizedY];
     glControl = new GLControl(new GraphicsMode());
     glControl.Location = Point.Empty;
     glControl.Size = renderTarget.Size;
     glControl.Visible = true;
     glControl.TabStop = false;
     glControl.Enabled = false;
     renderTarget.Controls.Add(glControl);
     renderTarget.FindForm().Show(); //Need this in here when running a rom from double click, may cause problems elsewhere?
     glControl.VSync = false;
     glControl.BringToFront();
     GL.ClearColor(Color.Black);
     GL.MatrixMode(MatrixMode.Projection);
     GL.LoadIdentity();
     GL.Ortho(0, renderTarget.Width, renderTarget.Height, 0, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
     GL.Viewport(0, 0, renderTarget.Width, renderTarget.Height); // Use all of the glControl painting area
     GL.Enable(EnableCap.Texture2D);
     GL.Enable(EnableCap.Blend);
     GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
     GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);
     textureName = GL.GenTexture();
     GL.BindTexture(TextureTarget.Texture2D, textureName);
     GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, new int[] { (int)TextureWrapMode.Clamp });//Clamp to edges
     GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, new int[] { (int)TextureWrapMode.Clamp });
     if (smoothOutput)
     {
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, new int[] { (int)TextureMagFilter.Linear });
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, new int[] { (int)TextureMagFilter.Linear });
     }
     else
     {
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, new int[] { (int)TextureMagFilter.Nearest });
         GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, new int[] { (int)TextureMagFilter.Nearest });
     }
     GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, new int[] { (int)TextureEnvMode.Modulate }); //Enables blending and lighting
     LoadCharSheet();
 }