OpenGL-aware WinForms control. The WinForms designer will always call the default constructor. Inherit from this class and call one of its specialized constructors to enable antialiasing or custom GraphicsModes.
Inheritance: System.Windows.Forms.UserControl
Exemplo n.º 1
0
        public HXMEditor(EditorHXMFile datafile, StandardUI host, string filename)
        {
            InitializeComponent();
            //can't use GLControls with designer? eh?
            glControl1          = new GLControl();
            glControl1.Location = new System.Drawing.Point(pictureBox3.Location.X, pictureBox3.Location.Y);
            glControl1.Size     = pictureBox3.Size;
            glControl1.Load    += glControl1_Load;
            glControl1.Paint   += glControl1_Paint;
            glControl1.Visible  = true;
            glControl1.Enabled  = true;
            tabPage7.Controls.Add(glControl1);
            tabPage7.PerformLayout();
            pictureBox3.Enabled = false;
            pictureBox3.Visible = false;

            robotPanel      = new EditorPanels.RobotPanel();
            robotPanel.Dock = DockStyle.Fill;
            RobotTabPage.Controls.Add(robotPanel);
            components.Add(robotPanel);

            this.datafile = datafile;
            this.host     = host;
            palette       = host.DefaultPalette;
            modelRenderer = new ModelRenderer(datafile.BaseHAM, host.DefaultPigFile, palette);
            this.Text     = string.Format("{0} - HXM Editor", currentFilename);
        }
Exemplo n.º 2
0
        /// <summary>
        /// プログラムを作成する
        /// </summary>
        /// <param name="viewport">描画対象</param>
        /// <param name="vertexSource">バーテックスシェーダのソース</param>
        /// <param name="geometrySource">ジオメトリシェーダのソース</param>
        /// <param name="fragmentSource">フラグメントシェーダのソース</param>
        public Program(
			Viewport viewport,
			string vertexSource,
			string geometrySource,
			string fragmentSource)
        {
            // コントロールを設定
            this.target = viewport.glControl;

            // コントロールを有効化
            this.target.MakeCurrent();

            // プログラムを作成
            this.ID = GL.CreateProgram();

            // 各シェーダーを作成して設定
            GL.AttachShader(this.ID, Program.CreateShader(vertexSource, ShaderType.VertexShader));
            GL.AttachShader(this.ID, Program.CreateShader(geometrySource, ShaderType.GeometryShader));
            GL.AttachShader(this.ID, Program.CreateShader(fragmentSource, ShaderType.FragmentShader));

            // プログラムをリンク
            GL.LinkProgram(this.ID);

            // バッファー群を初期化
            this.buffers = new List<Buffer>();
        }
Exemplo n.º 3
0
        public MapViewControl(frmMain Owner)
        {
            _Owner = Owner;

            InitializeComponent();

            ListSelect = new ContextMenuStrip();
            ListSelect.ItemClicked += ListSelect_Click;
            ListSelect.Closed += ListSelect_Close;
            UndoMessageTimer = new Timer();
            UndoMessageTimer.Tick += RemoveUndoMessage;

            OpenGLControl = Program.OpenGL1;
            pnlDraw.Controls.Add(OpenGLControl);

            GLInitializeDelayTimer = new Timer();
            GLInitializeDelayTimer.Interval = 50;
            GLInitializeDelayTimer.Tick += GLInitialize;
            GLInitializeDelayTimer.Enabled = true;

            tmrDraw = new Timer();
            tmrDraw.Tick += tmrDraw_Tick;
            tmrDraw.Interval = 1;

            tmrDrawDelay = new Timer();
            tmrDrawDelay.Tick += tmrDrawDelay_Tick;
            tmrDrawDelay.Interval = 30;

            UndoMessageTimer.Interval = 4000;
        }
Exemplo n.º 4
0
        public CanvasForm(Control parent)
        {
            InitializeComponent();

            ContextContainer = new Panel();
            ContextContainer.Padding = new Padding(1);
            ContextContainer.BackColor = Color.Black;

            Console.WriteLine(ContextContainer.Anchor);

            GraphicsMode mode = new GraphicsMode(
                new ColorFormat(8, 8, 8, 8),
                8, 8, MSAASamples,
                new ColorFormat(8, 8, 8, 8), 2, false
            );
            GLContext = new GLControl(mode, 2, 0, GraphicsContextFlags.Default);
            GLContext.Dock = DockStyle.Fill;
            GLContext.VSync = true;
            GLContext.Paint += new PaintEventHandler(this.GLContext_Paint);
            GLContext.MouseDown += new MouseEventHandler(this.GLContext_MouseDown);
            GLContext.MouseMove += new MouseEventHandler(this.GLContext_MouseMove);
            GLContext.MouseUp += new MouseEventHandler(this.GLContext_MouseUp);

            ContextContainer.Controls.Add(GLContext);
            Controls.Add(ContextContainer);

            // Setup stuff
            TopLevel = false;
            parent.Controls.Add(this);
        }
Exemplo n.º 5
0
        public Timeline(GLControl context)
        {
            GLContext = context;

            FrameNum = 0.0f;
            PlayStart = null;
        }
        public static void InitializeSharedResources()
        {
            // Only setup once. This is checked multiple times to prevent crashes.
            if (setupStatus == SharedResourceStatus.Initialized)
            {
                return;
            }

            try
            {
                // Make a permanent context to share resources.
                GraphicsContext.ShareContexts = true;
                var control = new OpenTK.GLControl();
                control.MakeCurrent();

                RenderTools.LoadTextures();
                GetOpenGLSystemInfo();
                ShaderTools.SetUpShaders();

                setupStatus = SharedResourceStatus.Initialized;
            }
            catch (AccessViolationException)
            {
                // Context creation failed.
                setupStatus = SharedResourceStatus.Failed;
            }
        }
Exemplo n.º 7
0
        public Viewport(Window parentWindow)
        {
            ParentWindow = parentWindow;

            OpenTK.Graphics.GraphicsMode Mode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), 24);
            GLControl = new GLControl(Mode, 4, 4, OpenTK.Graphics.GraphicsContextFlags.Default);
            GLControl.MakeCurrent();
            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.MouseLeave += GLControl_MouseLeave;
            GLControl.Dock = System.Windows.Forms.DockStyle.Fill;

            GL.Disable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            GL.DepthMask(true);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            _Camera = new Camera();
            _Camera.ViewportSize = new int2(GLControl.Width, GLControl.Height);
            _Camera.PropertyChanged += _Camera_PropertyChanged;
        }
Exemplo n.º 8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Create the GLControl.
            glc = new GLControl();

            // Assign Load and Paint events of GLControl.
            glc.Load += new EventHandler(glc_Load);
            glc.Paint += new PaintEventHandler(glc_Paint);

            // Assign the GLControl as the host control's child.
            host.Child = glc;

            // Initiate Kinect runtime and streams
            nui = Runtime.Kinects[0];
            try
            {
                nui.Initialize(RuntimeOptions.UseColor);
                nui.VideoStream.Open(ImageStreamType.Video, 2,
                    ImageResolution.Resolution640x480, ImageType.Color);
            }
            catch (InvalidOperationException)
            {
                return;
            }
            // Assign stream events
            nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_VideoFrameReady);
        }
		public static void Add(GLControl control)
		{
			IGraphicsContext context = control.Context;
			IWindowInfo window = control.WindowInfo;

			Contexts.Add(context, new ContextAsset(window));
		}
Exemplo n.º 10
0
        private void GlControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl glControl = sender as OpenTK.GLControl;

            if (glControl.ClientSize.Height == 0)
            {
                glControl.ClientSize = new System.Drawing.Size(glControl.ClientSize.Width, 1);
            }

            float aspectRatio = (float)Width / (float)Height;

            //OpenTK.Matrix4 perpective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, 1, 64);
            //GL.MatrixMode(MatrixMode.Projection);
            //GL.LoadMatrix(ref perpective);

            GL.MatrixMode(MatrixMode.Projection);
            Matrix4 ortho = Matrix4.CreateOrthographic(glControl.ClientSize.Width, glControl.ClientSize.Height, 10, 3000);

            GL.LoadMatrix(ref ortho);
            var v = Matrix4.LookAt(0, 0, 100, 0, 0, 0, 0, 1, 0);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref v);

            GL.Viewport(0, 0, glControl.ClientSize.Width, glControl.ClientSize.Height);
        }
Exemplo n.º 11
0
        public PolymodelPreviewer(Polymodel model, StandardUI host)
        {
            InitializeComponent();
            //moo
            this.glControl1           = new GLControl();
            this.glControl1.BackColor = System.Drawing.Color.Black;
            this.glControl1.Location  = new System.Drawing.Point(63, 12);
            this.glControl1.Name      = "glControl1";
            this.glControl1.Size      = new System.Drawing.Size(384, 384);
            this.glControl1.TabIndex  = 3;
            this.glControl1.VSync     = false;
            this.glControl1.Load     += new System.EventHandler(this.glControl1_Load);
            this.glControl1.Paint    += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
            glControl1.Anchor         = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

            this.Controls.Add(glControl1);
            this.PerformLayout();

            this.model = model;
            if (this.model.IsAnimated)
            {
                numericUpDown1.Minimum = 0;
                numericUpDown1.Maximum = Robot.NumAnimationStates - 1;
            }
            else
            {
                numericUpDown1.Enabled = false;
                chkAnimation.Enabled   = false;
            }
            this.host     = host;
            this.renderer = new ModelRenderer(host.DefaultPigFile, host.DefaultPalette);
        }
Exemplo n.º 12
0
        public GLForm(OpenTKGraphics graphics)
        {
            this.graphics = graphics;

            InitializeComponent();

            glControl = new GLControl();
            glControl.BackColor = System.Drawing.Color.Black;
            glControl.Dock = DockStyle.Fill;
            glControl.TabIndex = 0;
            glControl.VSync = false;

            Controls.Add(glControl);

            glControl.Paint += new PaintEventHandler(glControl_Paint);
            glControl.Disposed += new EventHandler(glControl_Disposed);

            glControl.KeyDown += new KeyEventHandler(glControl_KeyDown);
            glControl.KeyUp += new KeyEventHandler(glControl_KeyUp);
            glControl.MouseDown += new MouseEventHandler(glControl_MouseDown);
            glControl.MouseUp += new MouseEventHandler(glControl_MouseUp);
            glControl.MouseMove += new MouseEventHandler(glControl_MouseMove);
            glControl.MouseWheel += new MouseEventHandler(glControl_MouseWheel);
            glControl.PreviewKeyDown += new PreviewKeyDownEventHandler(glControl_PreviewKeyDown);

            Resize += new EventHandler(GLForm_Resize);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public OpenGLWriteableBitmapUpdater(Size size, GraphicsMode graphicsMode, Action<GLControl> onPrepare = null, Action<GLControl> onFinalize = null)
        {
            this.loaded = false;
            this.Size = size;
            this.framebufferId = -1;

            this.OnPrepare += onPrepare;
            this.OnFinalize += onFinalize;

            messagingTask.StartMessageLoop(
                prepare: () =>
                {
                    this.glControl = new GLControl(graphicsMode);
                    this.glControl.MakeCurrent();
                    if (this.OnPrepare != null)
                    {
                        this.OnPrepare(this.glControl);
                        this.OnPrepare -= onPrepare;
                    }
                },
                finalize: () =>
                {
                    if (this.OnFinalize != null)
                    {
                        this.OnFinalize(this.glControl);
                        this.OnFinalize -= onFinalize;
                    }
                    this.glControl.Context.MakeCurrent(null);
                    this.glControl.Dispose();
                });
        }
Exemplo n.º 14
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this._glControl = ((OpenTK.GLControl)(target));

            #line 12 "..\..\MainWindow.xaml"
                this._glControl.Load += new System.EventHandler(this.GLControl_Load);

            #line default
            #line hidden

            #line 12 "..\..\MainWindow.xaml"
                this._glControl.Paint += new System.Windows.Forms.PaintEventHandler(this.GLControl_Paint);

            #line default
            #line hidden

            #line 12 "..\..\MainWindow.xaml"
                this._glControl.Resize += new System.EventHandler(this._glControl_Resize);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
		public NativeEditorGraphicsContext()
		{
			GraphicsMode defaultGraphicsMode = this.GetDefaultGraphicsMode();
			this.mainContextControl = new GLControl(defaultGraphicsMode);
			this.mainContextControl.VSync = false;
			this.mainContextControl.MakeCurrent();
		}
Exemplo n.º 16
0
        public FullScreenWindow(ref GLRenderer renderer, ref GLCamera camera,
            ref AnimationController animationController,
            ref GLControl control,
            float fieldOfView, float nearPlane, float farPlane)
        {
            // Store references
            this.renderer = renderer;
            this.camera = camera;
            this.animationController = animationController;
            this.fieldOfView = fieldOfView;
            this.nearPlane = nearPlane;
            this.farPlane = farPlane;
            this.mainGLControl = control;

            InitializeComponent();

            //
            // Set up callbacks.
            //

            // GLControl Callbacks
            glControlMain.Load += new EventHandler(GLControlMainOnLoad);
            glControlMain.Resize += new EventHandler(GLControlMainOnResize);
            glControlMain.Paint += new PaintEventHandler(GLControlMainOnPaint);

            // Set mouse events
            glControlMain.MouseDown += new MouseEventHandler(GLControlOnMouseDown);
            glControlMain.MouseUp += new MouseEventHandler(GLControlOnMouseUp);
            glControlMain.MouseWheel += new MouseEventHandler(GLControlOnMouseWheel);
            glControlMain.MouseMove += new MouseEventHandler(GLControlOnMouseMove);

            // Set keyboard events
            glControlMain.KeyDown += new KeyEventHandler(GLControlMainOnKeyDown);
            glControlMain.KeyUp += new KeyEventHandler(GLControlMainOnKeyUp);
        }
Exemplo n.º 17
0
        public MapViewExCtrl()
        {
            InitializeComponent();

            _glControl      = new OpenTK.GLControl();
            _glControl.Dock = DockStyle.Fill;
            Controls.Add(_glControl);
        }
Exemplo n.º 18
0
 public Input(GLControl control)
 {
     Control = control;
     control.MouseMove += control_MouseMove;
     control.MouseLeave += delegate { _mouseInside = false; };
     control.MouseEnter += delegate { _mouseInside = true; };
     control.MouseWheel += control_MouseWheel;
 }
		void IDisposable.Dispose()
		{
			if (this.mainContextControl != null)
			{
				this.mainContextControl.Dispose();
				this.mainContextControl = null;
			}
		}
Exemplo n.º 20
0
		void IDisposable.Dispose()
		{
			if (this.control != null)
			{
				this.control.Dispose();
				this.control = null;
			}
		}
        public CartesianFieldRenderer(CartesianField field, FieldRendererControl renderControl)
        {
            Field         = field;
            RenderControl = renderControl;

            FieldOfView = new Camera(new Vector2(-5, -5), new Vector2(10, 10));
            P_Renderer  = new PrimitiveRenderer(renderControl);
        }
Exemplo n.º 22
0
        public MyCamera(GLControl glControl)
        {
            m_glControl = glControl;

            glControl.MouseDown += new MouseEventHandler(glControl_MouseDown);
            glControl.MouseMove += new MouseEventHandler(glControl_MouseMove);
            glControl.MouseUp += new MouseEventHandler(glControl_MouseUp);
        }
Exemplo n.º 23
0
        public void Run()
        {
            using (Form form = CreateForm())
            {
                var mGLControl = new GLControl
                {
                    Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                    BackColor = Color.LightGreen,
                    Location = new Point(1, 0),
                    Name = "GL Control",
                    Size = new Size(WIDTH, HEIGHT),
                    TabIndex = 0,
                    VSync = false
                };
                form.Controls.Add(mGLControl);

                //have to set this to get a -1 to 1 system view
                GL.Viewport(0, 0, WIDTH, HEIGHT);

                if (false)//!GL.SupportsExtension("VERSION_1_5"))
                {
                    Assert.Fail("You need at least OpenGL 1.5 to run this example. Aborting.", "VBOs not supported");
                }

                var positions = new[]
                {
                    new Vector3(-1, -1, 0),
                    new Vector3(1, -1, 0),
                    new Vector3(1, 1, 0),
                    new Vector3(-1, 1, 0),
                };
                var colors = new[]
                {
                    new Vector3(1, 0, 0), new Vector3(0, 1, 0),
                    new Vector3(0, 0, 1), new Vector3(1, 1, 0)
                };

                var indices = new uint[] { 0, 1, 2, 0, 2, 3 };

                LoadBuffers(positions, indices, colors);

                Application.Idle +=
                    delegate
                    {
                        mGLControl.MakeCurrent();

                        GL.ClearColor(mGLControl.BackColor);
                        GL.Clear(ClearBufferMask.ColorBufferBit);

                        RenderFrame();

                        mGLControl.SwapBuffers();
                    };

                form.BringToFront();
                Application.Run(form);
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="size">initialize surface size</param>
 /// <param name="graphicsMode">OpenGL graphics mode</param>
 public OpenGLD3DImageUpdater(
     Size size,
     GraphicsMode graphicsMode)
 {
     this.glControl = new GLControl(graphicsMode);
     this.glControl.MakeCurrent();
     Size = size;
     this.CreateD3D9ExContext(this.glControl.Handle, graphicsMode.Depth > 0, graphicsMode.Stencil > 0);
 }
Exemplo n.º 25
0
        private void glControl1_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl glControl = sender as OpenTK.GLControl;

            if (glControl.Height == 0)
            {
                glControl.ClientSize = new System.Drawing.Size(glControl.ClientSize.Width, 1);
            }
        }
Exemplo n.º 26
0
 public static void HandleResize(GLControl glCtrl, double viewdistance)
 {
     GL.Viewport(0, 0, glCtrl.ClientSize.Width, glCtrl.ClientSize.Height);
       GL.MatrixMode(MatrixMode.Projection);
       GL.LoadIdentity();
       Glu.Perspective(45, (double)glCtrl.Width / glCtrl.Height, 0.5, viewdistance);
       glCtrl.Invalidate();
       GL.MatrixMode(MatrixMode.Modelview);
 }
Exemplo n.º 27
0
        public void LoadROM(byte[] romBuffer, ref GLControl control)
        {
            Buffer.BlockCopy(romBuffer, 0x0000, _rom, 0x0000, _rom.Length);
            Buffer.BlockCopy(romBuffer, 0xC000, _wram, 0x0000, _wram.Length);
            Buffer.BlockCopy(romBuffer, 0xA000, _eram, 0x0000, _eram.Length);
            Buffer.BlockCopy(romBuffer, 0xFF80, _zram, 0x0000, _zram.Length);

            GBCGPU.LoadROM(ref romBuffer, ref control);
        }
Exemplo n.º 28
0
        public App(Form1 form)
        {
            form.Loaded += new Form1.NonTimeEvent(form_Load);
            form.Think += new Form1.TimeEvent(form_Update);
            form.Draw += new Form1.TimeEvent(form_Draw);
            form.Control.Resize += new EventHandler(Control_Resize);

            Control = form.Control;
        }
Exemplo n.º 29
0
		static public void Init(GLControl renderTarget)
		{
			shaders.Add("def", CreateShader(Encoding.UTF8.GetString(Properties.Resources.textured_vert), Encoding.UTF8.GetString(Properties.Resources.textured_frag)));
			shaders.Add("gray", CreateShader(Encoding.UTF8.GetString(Properties.Resources.textured_vert), Encoding.UTF8.GetString(Properties.Resources.gray_frag)));
			shaders.Add("sepia", CreateShader(Encoding.UTF8.GetString(Properties.Resources.textured_vert), Encoding.UTF8.GetString(Properties.Resources.sepia_frag)));

			plane = new Plane(shaders["def"]);

			MyTexture.renderTarget = renderTarget;
		}
Exemplo n.º 30
0
		public MainWindow()
		{
			this.gl = new GLControl(GraphicsMode.Default, 1, 0, GraphicsContextFlags.Default);

			this.gl.Dock = DockStyle.Fill;
			this.gl.Load += this.GLControlLoad;
			this.gl.Paint += this.GLControlPaint;
			this.gl.Resize += this.GLControlResize;
			this.Controls.Add(this.gl);
		}
Exemplo n.º 31
0
 public Camera(GLControl c)
 {
     control=c;
     MoveSpeed = 15;
     MouseSpeed = 5;
     MousePosition = new Point(control.Width/2, control.Height/2);
     control.MouseMove += new MouseEventHandler(control_MouseMove);
     control.KeyDown += new KeyEventHandler(control_KeyDown);
     movetime = Stopwatch.StartNew();
 }
Exemplo n.º 32
0
        internal static void Resize(ref ModernGLControl glControl1)
        {
            viewport_changed = true;

            renderView     = glControl1;
            viewportWidth  = renderView.Width;
            viewportHeight = renderView.Height;

            renderView.Invalidate();
        }
Exemplo n.º 33
0
        public COpenGL()
        {
            this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon));

            _Textures = new List<STexture>();

            //Check AA Mode
            CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode);

            OpenTK.Graphics.ColorFormat cf = new OpenTK.Graphics.ColorFormat(32);
            OpenTK.Graphics.GraphicsMode gm;

            bool ok = false;
            try
            {
                gm = new OpenTK.Graphics.GraphicsMode(cf, 24, 0, (int)CConfig.AAMode);
                control = new GLControl(gm, 2, 1, OpenTK.Graphics.GraphicsContextFlags.Default);
                if (control.GraphicsMode != null)
                    ok = true;
            }
            catch (Exception)
            {
                ok = false;
            }

            if (!ok)
                control = new GLControl();

            control.MakeCurrent();
            control.VSync = (CConfig.VSync == EOffOn.TR_CONFIG_ON);

            this.Controls.Add(control);

            _Keys = new CKeys();
            this.Paint += new PaintEventHandler(this.OnPaintEvent);
            this.Closing += new CancelEventHandler(this.OnClosingEvent);
            this.Resize += new EventHandler(this.OnResizeEvent);

            control.KeyDown += new KeyEventHandler(this.OnKeyDownEvent);
            control.PreviewKeyDown += new PreviewKeyDownEventHandler(this.OnPreviewKeyDownEvent);
            control.KeyPress += new KeyPressEventHandler(this.OnKeyPressEvent);
            control.KeyUp += new KeyEventHandler(this.OnKeyUpEvent);

            _Mouse = new CMouse();
            control.MouseMove += new MouseEventHandler(this.OnMouseMove);
            control.MouseWheel += new MouseEventHandler(this.OnMouseWheel);
            control.MouseDown += new MouseEventHandler(this.OnMouseDown);
            control.MouseUp += new MouseEventHandler(this.OnMouseUp);
            control.MouseLeave += new EventHandler(this.OnMouseLeave);
            control.MouseEnter += new EventHandler(this.OnMouseEnter);

            this.ClientSize = new Size(CConfig.ScreenW, CConfig.ScreenH);
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque, true);
            this.CenterToScreen();
        }
Exemplo n.º 34
0
        public void InjectGlControl(GLControl gl)
        {
            var s = splitContainer.Controls[0];

            s.Controls.Add(gl);
            gl.Left = s.Left;
            gl.Top = s.Top;

            gl.Width = s.Width;
            gl.Height = s.Height;
        }
Exemplo n.º 35
0
        public static void Main()
        {
            Application.EnableVisualStyles();

            App.PlatformPathSeparator = Path.DirectorySeparatorChar;
            App.SetProgramSubDirs();

            SettingsManager.CreateSettingOptions();
            KeyboardManager.CreateControls(); //needed to load key control settings
            clsResult SettingsLoadResult = SettingsManager.Settings_Load(ref SettingsManager.InitializeSettings);
            InitializeResult.Add(SettingsLoadResult);

            OpenGL1 =
                new GLControl(new GraphicsMode(new ColorFormat(SettingsManager.InitializeSettings.MapViewBPP), SettingsManager.InitializeSettings.MapViewDepth, 0));
            OpenGL2 =
                new GLControl(new GraphicsMode(new ColorFormat(SettingsManager.InitializeSettings.TextureViewBPP), SettingsManager.InitializeSettings.TextureViewDepth,
                    0));

            while ( OpenGL1.Context == null || OpenGL2.Context == null )
            {
                //todo, why is this needed
            }

            frmMainInstance = new frmMain();
            frmMainInstance.FormClosing += frmMainInstance.frmMain_FormClosing;
            frmMainInstance.DragEnter += frmMainInstance.OpenGL_DragEnter;
            frmMainInstance.DragDrop += frmMainInstance.OpenGL_DragDrop;

            try
            {
                App.ProgramIcon =
                    new Icon((new ConsoleApplicationBase()).Info.DirectoryPath +
                             Convert.ToString(App.PlatformPathSeparator) + "flaME.ico");
            }
            catch ( Exception ex )
            {
                InitializeResult.WarningAdd(Constants.ProgramName + " icon is missing: " + ex.Message);
            }
            frmMainInstance.Icon = App.ProgramIcon;
            frmGeneratorInstance.Icon = App.ProgramIcon;

            InitializeDelay = new Timer();
            InitializeDelay.Tick += frmMainInstance.Initialize;
            InitializeDelay.Interval = 50;
            InitializeDelay.Enabled = true;

            while ( !App.ProgramInitializeFinished )
            {
                System.Threading.Thread.Sleep(50);
                Application.DoEvents();
            }

            Application.Run(frmMainInstance);
        }
Exemplo n.º 36
0
        /**
         * Initialise un jeu.
         */
        public Game(GLControl glControl, int playerCount)
        {
            level = new Level(glControl, playerCount);

            //Mettre en place le timer pour faire évoluer le monde
            timer = new System.Timers.Timer();
            timer.Interval = 1000 / THREAD_FREQ;
            timer.Elapsed += new ElapsedEventHandler(timerRoutine);
            timer.Start();
            isRunning = true;
        }
Exemplo n.º 37
0
 public void OnMouseMove(GLControl sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (cameraRotating)
     {
         cameraYaw += (e.X - lastMousePosition.X) / 130.0f;
         cameraPitch += (e.Y - lastMousePosition.Y) / 130.0f;
         cameraPitch = MathEx.Clamp(cameraPitch, (float)-Math.PI / 2.0f + 0.01f, (float)Math.PI / 2.0f - 0.01f);
         lastMousePosition.X = e.X;
         lastMousePosition.Y = e.Y;
     }
 }
 public CompositeRenderingAdapter(IController controller, Direct3DRenderer renderer, Device device, GLControl glControl, double frameRate)
 {
   if (controller == null) throw new ArgumentNullException("controller");
   if (renderer == null) throw new ArgumentNullException("renderer");
   if (device == null) throw new ArgumentNullException("device");
   if (glControl == null) throw new ArgumentNullException("glControl");
   _controller = controller;
   _renderer = renderer;
   _glControl = glControl;
   _frameRate = frameRate;
   Device = device;
 }
Exemplo n.º 39
0
		public Viewer(GLControl glcontrol)
		{
			_glControl = glcontrol;

			// りそーすハンドル
			_models_res = new List<Tuple<int, int, int>>();

			// キュー生成
			_lines = new List<Tuple<Vector3, Vector3, Vector4>>();
			_points = new List<Tuple<Vector3, Vector4>>();
			_models = new List<Tuple<int, Vector3, Vector3, Vector3>>();
		}
Exemplo n.º 40
0
        private void glControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl c = sender as OpenTK.GLControl;

            if (c.ClientSize.Height == 0)
            {
                c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
            }

            GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);

            cam.OnResize(c.ClientSize.Width, c.ClientSize.Height);
        }
Exemplo n.º 41
0
        public static void Initialize(OpenTK.GLControl game)
        {
            keyDown     = new List <Key>();
            keyDownLast = new List <Key>();

            buttonDown     = new List <MouseButton>();
            buttonDownLast = new List <MouseButton>();


            //game.KeyDown += Game_KeyDown;
            //game.KeyUp += Game_KeyUp;
            //game.MouseDown += Game_MouseDown;
            //game.MouseUp += Game_MouseUp;
        }
Exemplo n.º 42
0
        public void Draw(OpenTK.GLControl glControl)
        {
            GL.ClearColor(Color.AliceBlue);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.UseProgram(BasicProgramID);

            // Camera
            int location = GL.GetUniformLocation(BasicProgramID, "scale");

            GL.Uniform2(location, new Vector2(1, 1 / aspect));

            // Tracing depth
            int traceDepth = GL.GetUniformLocation(BasicProgramID, "traceDepth");

            GL.Uniform1(traceDepth, uniform_traceDepth);

            // Materials color
            for (int i = 0; i < uniform_materialColors.Length; i++)
            {
                int   materialColor = GL.GetUniformLocation(BasicProgramID, $"materialColor{i}");
                Color color         = uniform_materialColors[i];
                GL.Uniform3(materialColor, new Vector3(color.R / 255f, color.G / 255f, color.B / 255f));
            }

            // Quad
            GL.Color3(Color.White);
            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(0, 1);
            GL.Vertex2(-1, -1);

            GL.TexCoord2(1, 1);
            GL.Vertex2(1, -1);

            GL.TexCoord2(1, 0);
            GL.Vertex2(1, 1);

            GL.TexCoord2(0, 0);
            GL.Vertex2(-1, 1);

            GL.End();

            glControl.SwapBuffers();

            GL.UseProgram(0);
        }
Exemplo n.º 43
0
        /// <summary>
        /// Resize event handler
        /// </summary>
        /// <param name="sender">The sender</param>
        /// <param name="e">The parameters</param>
        private void GLViewport3D_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl c = sender as OpenTK.GLControl;

            if (c.ClientSize.Height == 0)
            {
                c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
            }

            if (c.ClientSize.Width == 0)
            {
                c.ClientSize = new System.Drawing.Size(1, c.ClientSize.Height);
            }

            // Readjust arcball instance
            arcball.SetBounds(Width, Height);
        }
        void glControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl c = sender as OpenTK.GLControl;

            if (c.ClientSize.Height == 0)
            {
                c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
            }

            GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);

            float   aspect_ratio = Width / (float)Height;
            Matrix4 perpective   = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 1, 64);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref perpective);
        }
Exemplo n.º 45
0
        private void AddGLControl()
        {
            glcontrol1                  = new OpenTK.GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 4));
            glcontrol1.Dock             = DockStyle.Fill;
            this.glcontrol1.Size        = new System.Drawing.Size(632, 295);
            this.glcontrol1.TabIndex    = 1;
            this.glcontrol1.VSync       = false;
            this.glcontrol1.KeyDown    += LayerDisplay_KeyDown;
            this.glcontrol1.KeyPress   += LayerDisplay_KeyPress;
            this.glcontrol1.MouseEnter += pictureBox1_MouseEnter;
            this.glcontrol1.MouseMove  += pictureBox1_MouseMove;
            this.glcontrol1.MouseLeave += pictureBox1_MouseLeave;

            glcontrol1.Paint += Glcontrol1_Paint;

            this.Controls.Add(glcontrol1);
        }
Exemplo n.º 46
0
        //    base.OnClosing(e);
        //}
        void glControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl c = sender as OpenTK.GLControl;

            if (c.ClientSize.Height == 0)
            {
                c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
            }

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            double aspectRatio = Width / (float)Height;

            GL.Ortho(0, Width, 0, Height, 0, 1); // Origin in lower-left corner
        }
Exemplo n.º 47
0
        private void glControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl client = sender as OpenTK.GLControl;

            graphicsUtility.Resize(client.ClientSize.Width, client.ClientSize.Height);

            /*if (c.ClientSize.Height == 0)
             *  c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
             *
             * GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);
             *
             * viewport = new Size(c.ClientSize.Width, c.ClientSize.Height);
             * //vp = new float[] { 0.0f, 0.0f, c.ClientSize.Width, c.ClientSize.Height};
             *
             * //float aspect_ratio = Width / (float)Height;
             * float aspect_ratio = c.ClientSize.Width / (float)c.ClientSize.Height;
             * perpective = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 1.0f, 64.0f);
             * GL.MatrixMode(MatrixMode.Projection);
             * GL.LoadMatrix(ref perpective);*/
        }
Exemplo n.º 48
0
        private void glControl_Resize(object sender, EventArgs e)
        {
            OpenTK.GLControl c = sender as OpenTK.GLControl;

            if (c.ClientSize.Height == 0)
            {
                c.ClientSize = new System.Drawing.Size(c.ClientSize.Width, 1);
            }

            GL.CullFace(CullFaceMode.Back);

            float   aspect_ratio = Width / (float)Height;
            Matrix4 perpective   = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect_ratio, 0.1f, 64);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.LoadMatrix(ref perpective);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);// 'Enable correct Z Drawings
            GL.Viewport(0, 0, c.ClientSize.Width, c.ClientSize.Height);
        }
Exemplo n.º 49
0
        private void InitGL()
        {
            if (glview == null)
            {
                previewType       = PreviewGeometryType.Cube;
                previewCameraMode = PreviewCameraMode.Perspective;
                previewPosition   = PreviewCameraPosition.Front;

                glview             = new TK.GLControl(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24));
                glview.Load       += Glview_Load;
                glview.Paint      += Glview_Paint;
                glview.MouseWheel += Glview_MouseWheel;
                glview.MouseMove  += Glview_MouseMove;
                glview.MouseDown  += Glview_MouseDown;
                FHost.Child        = glview;
                rotX              = 25;
                rotY              = 45;
                rotation          = Quaternion.FromEulerAngles(rotX * ((float)Math.PI / 180.0f), rotY * ((float)Math.PI / 180.0f), 0);
                cameraTranslation = new Vector3(0, 0, 3);
                objectTranslation = new Vector3(0, 0, 0);
            }
        }
Exemplo n.º 50
0
        public Form2()
        {
            InitializeComponent();
            glControl = new OpenTK.GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8));

            DebugHelper.Error = (x) => { infoPanel.AddError(x); };


            if (glControl.Context.GraphicsMode.Samples == 0)
            {
                glControl = new OpenTK.GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8));
            }
            evwrapper = new EventWrapperGlControl(glControl);

            glControl.Paint += Gl_Paint;
            ViewManager      = new DefaultCameraViewManager();
            ViewManager.Attach(evwrapper, camera1);

            panel1.Controls.Add(glControl);
            glControl.Dock = DockStyle.Fill;
            infoPanel.Dock = DockStyle.Bottom;
            panel1.Controls.Add(infoPanel);
        }
Exemplo n.º 51
0
        public GLGui(OpenTK.GLControl parent) : base(null)
        {
            GLCursor.LoadCursors(null);

            Gui           = this;
            base.Parent   = this;
            ParentControl = parent;
            Outer         = parent.ClientRectangle;
            Anchor        = GLAnchorStyles.All;

            int lastX = 0, lastY = 0, wheelValue = 0;

            parent.MouseMove  += (s, e) => { DoMouseMove(new MouseMoveEventArgs(e.X, e.Y, e.X - lastX, e.Y - lastY)); lastX = e.X; lastY = e.Y; };
            parent.MouseDown  += (s, e) => OnMouseDown(s, new MouseButtonEventArgs(e.X, e.Y, ToOpenTK(e.Button), true));
            parent.MouseUp    += (s, e) => OnMouseUp(s, new MouseButtonEventArgs(e.X, e.Y, ToOpenTK(e.Button), false));
            parent.MouseWheel += (s, e) => { wheelValue += e.Delta; DoMouseWheel(new MouseWheelEventArgs(e.X, e.Y, wheelValue, e.Delta)); };
            parent.MouseEnter += (s, e) => DoMouseEnter();
            parent.MouseLeave += (s, e) => DoMouseLeave();
            parent.KeyDown    += (s, e) => DoKeyDown(ToOpenTK(e));
            parent.KeyUp      += (s, e) => DoKeyUp(ToOpenTK(e));
            parent.KeyPress   += (s, e) => DoKeyPress(new KeyPressEventArgs(e.KeyChar));
            parent.Resize     += (s, e) => Outer = parent.ClientRectangle;
        }
Exemplo n.º 52
0
        public EditorUI()
        {
            InitializeComponent();
            this.gl3DView = new OpenTK.GLControl();
            //I love this pile of shit system that continually forgets basic things like "the GLControl is a toolbox item that exists in this project!"
            //and then you can't even actually load it from the binary because ??? so where did it load it from initally then?
            //f**k this
            this.gl3DView.BackColor   = System.Drawing.Color.Black;
            this.gl3DView.Dock        = System.Windows.Forms.DockStyle.Fill;
            this.gl3DView.Location    = new System.Drawing.Point(635, 3);
            this.gl3DView.Name        = "gl3DView";
            this.gl3DView.Size        = new System.Drawing.Size(626, 334);
            this.gl3DView.TabIndex    = 0;
            this.gl3DView.VSync       = false;
            this.gl3DView.Load       += new System.EventHandler(this.GLControlPerspective_Load);
            this.gl3DView.Paint      += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
            this.gl3DView.KeyDown    += new System.Windows.Forms.KeyEventHandler(this.gl3DView_KeyDown);
            this.gl3DView.MouseDown  += new System.Windows.Forms.MouseEventHandler(this.gl3DView_MouseDown);
            this.gl3DView.MouseEnter += new System.EventHandler(this.gl3DView_MouseEnter);
            this.gl3DView.MouseMove  += new System.Windows.Forms.MouseEventHandler(this.gl3DView_MouseMove);
            this.gl3DView.MouseUp    += new System.Windows.Forms.MouseEventHandler(this.gl3DView_MouseUp);

            /*this.tableLayoutPanel1.Controls.Add(this.glTopView, 0, 0);
             * this.tableLayoutPanel1.Controls.Add(this.gl3DView, 1, 0);
             * this.tableLayoutPanel1.Controls.Add(this.glFrontView, 0, 1);
             * this.tableLayoutPanel1.Controls.Add(this.glSideView, 1, 1);*/

            this.Controls.Add(this.gl3DView);

            /*SharedRendererState sharedState = new SharedRendererState(level);
             * state = new EditorState(level, datafile, this);
             * gl3DView.Tag = new MineRender(state, sharedState, gl3DView);
             * state.AttachRenderer((MineRender)gl3DView.Tag);
             * sharedState.AddRenderer((MineRender)gl3DView.Tag);*/
            //sharedState.LevelData.BuildWorld();
        }
Exemplo n.º 53
0
 public void RecoverFromBackup(System.Drawing.Rectangle ClientRectangle, OpenTK.GLControl RenderPanel, ComboBox SelectedTexture)
 {
     CurrentROM = ROMBackup;
     SelectedTexture.SelectedIndex = 0;
 }
Exemplo n.º 54
0
 public static void Resize(OpenTK.GLControl control)
 {
     shaderBuilder.Resize(control);
 }
Exemplo n.º 55
0
 public void BindGL(OpenTK.GLControl control)
 {
     GLControl              = control;
     GLControl.SizeChanged += GLViewSizeChanged;
 }
Exemplo n.º 56
0
 public void setControl(OpenTK.GLControl glControl)
 {
     glControl_ = glControl;
     initializeGL();
 }
Exemplo n.º 57
0
        public void Release()
        {
            if (defaultBlack != null)
            {
                defaultBlack.Release();
                defaultBlack = null;
            }

            if (defaultWhite != null)
            {
                defaultWhite.Release();
                defaultWhite = null;
            }

            if (defaultGray != null)
            {
                defaultGray.Release();
                defaultGray = null;
            }

            if (defaultDarkGray != null)
            {
                defaultDarkGray.Release();
                defaultDarkGray = null;
            }

            if (irradiance != null)
            {
                irradiance.Release();
                irradiance = null;
            }

            if (prefiltered != null)
            {
                prefiltered.Release();
                prefiltered = null;
            }

            if (mat != null)
            {
                mat.Release();
                mat = null;
            }

            if (sphere != null)
            {
                sphere.Release();
                sphere = null;
            }

            if (cube != null)
            {
                cube.Release();
                cube = null;
            }

            if (glview != null)
            {
                FHost.Child = null;
                glview.Dispose();
                glview = null;
            }
        }
        //static int numPoints = 0;

        public drawing.Bitmap ParseSqlGeometry(List <SqlGeometry> geometries, double width, double height, Func <Point, Point> transform, drawing.Pen pen, drawing.Brush brush)//, ImageSource pointSymbol = null, Geometry symbol = null)
        {
            //if (width + height > 5000)
            //{
            //    throw new NotImplementedException();
            //}

            gl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 8, 4));
            gl.MakeCurrent();

            //Debug.Print("ParseSqlGeometry started");
            //numPoints = 0;

            gl.Width = (int)width; gl.Height = (int)height;

            GL.Enable(EnableCap.PointSmooth);
            GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest);
            //GL.Enable(EnableCap.LineSmooth);
            //GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);

            //GL.Disable(EnableCap.Texture2D);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.Ortho(0, width, 0, height, -1, 1);       // Bottom-left corner pixel has coordinate (0, 0)
            GL.Viewport(0, 0, (int)width, (int)height); // Use all of the glControl painting area

            GL.ClearColor(drawing.Color.Transparent);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.Color3(pen.Color);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
            GL.PointSize(5f);
            GL.LineWidth(2f);
            //GL.Color4(System.Drawing.Color.LightBlue);
            //GL.Enable(EnableCap.VertexArray);

            //OpenTKHelper.pen = pen;

            //OpenTKHelper.brush = brush;

            int p = 0;

            if (geometries != null)
            {
                foreach (SqlGeometry item in geometries)
                {
                    p += AddGeometry(item, transform);
                }
            }
            //***************
            //var image2 = GrabScreenshot((int)width, (int)height);

            //image2.Save(DateTime.Now.ToString("yyyy,MM,dd,hh,mm,ss") + ".png", drawing.Imaging.ImageFormat.Png);

            //image2.Dispose();
            //**********
            GL.Finish();

            var result = GrabScreenshot();

            gl.Dispose();

            return(result);
        }
Exemplo n.º 59
0
 public OpenGLController(GLControl glControl)
 {
     controller = glControl;
 }
Exemplo n.º 60
0
 public static void Paint(OpenTK.GLControl control)
 {
     shaderBuilder.Paint(control);
 }