public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); Logger.SetLogControl(richTextBox1); glWin = new GLControl(); splitContainer2.Panel2.Controls.Add(glWin); OpenTK.Toolkit.Init(); glWin.CreateControl(); glWin.CreateGraphics(); glWin.Dock = DockStyle.Fill; glWin.BackColor = Color.DarkGray; glWin.BringToFront(); // // TODO: Add constructor code after the InitializeComponent() call. // Scene.Init(glWin); glWin.KeyDown += glWin_KeyPress; glWin.KeyUp += glWin_KeyRelease; glWin.MouseMove += glWin_MouseMove; glWin.MouseWheel += glWin_MouseWheel; glWin.Paint += glWin_Paint; RenderTimer.Interval = 15; RenderTimer.Tick += Repaint; RenderTimer.Start(); }
private void InitializeGlControl() { // TODO: в более надлежащее место OpenGlApplication.Setup(); _glControl = new GLControl { Parent = openTkControlContainer, Dock = DockStyle.Fill }; _glControl.CreateControl(); _glControl.Resize += GlControlOnResize; GL.Viewport(Point.Empty, _glControl.Size); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); OpenGlApplication.EnableDebugMessages(); // TODO: в более надлежащее место Singleton.Get <OpenClApplication>().SetupUsingOpenGLContext(); _glControl.Paint += GlControlOnPaint; _glControl.MouseClick += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseClickEvent(args)); _glControl.MouseDoubleClick += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseDoubleClickEvent(args)); _glControl.MouseDown += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseDownEvent(args)); _glControl.MouseUp += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseUpEvent(args)); _glControl.MouseMove += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseMoveEvent(args)); _glControl.MouseWheel += (sender, args) => _tool?.MouseEvent(MouseEventData.FromMouseWheelEvent(args)); }
public Visualization(WindowsFormsHost winFormsHost, Server server) { this.server = server; this.DefineBones(); //vytvorenie kontrolky glControl = new GLControl(); //pridanie eventov glControl.Load += glControl_Load; glControl.Paint += glControl_Paint; glControl.KeyDown += glControl_KeyDown; //reakcia na stlacanie klavesov //automaticke prekreslenie pomocou timera (25FPS) timer = new DispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 40); timer.Tick += timer_onTick; //existuje event, ze ak formular nic nerobi, tak generuje event, ze nic nerobi :D vie sa to zijst ComponentDispatcher.ThreadIdle += (sender, e) => idle = true; OpenTK.Toolkit.Init(); glControl.CreateControl(); winFormsHost.Child = glControl; }
private void InitializeGlComponent() { glControl = new GLControl(); Toolkit.Init(); glControl.Paint += GlControl_Paint; glControl.Resize += GlControl_Resize; WFHost.Child = glControl; glControl.CreateControl(); }
private void InitializeGlComponent() { scene = new Graphics.Scene(); glc = new GLControl(); Toolkit.Init(); glc.Paint += Draw; glc.Resize += Resize; glc.MouseMove += Glc_MouseMove; glc.MouseUp += (s, e) => ClearMousePosition(); glc.MouseLeave += (s, e) => ClearMousePosition(); glc.PreviewKeyDown += Glc_PreviewKeyDown; WfHost.Child = glc; glc.CreateControl(); }
static GLService() { Lock = new object(); ContextReferenceCount = new ThreadLocal <int>(() => 0, false); GLControl = new GLControl(GraphicsMode.Default); GLControl.CreateControl(); //GLWindow = new NativeWindow(); GLGraphicsContext = GLControl.Context; //GLGraphicsContext = new GraphicsContext(GraphicsMode.Default, GLControl.WindowInfo); SubscribeContexts = new ConcurrentDictionary <WindowsFormsHost, SubscribeContext>(); DrawingContexts = new ConcurrentDictionary <Action, DrawingContext>(); GLGraphicsContext.MakeCurrent(null); DisposableSerivce.Register(new DisposableAction(Dispose)); }
/// <summary> /// Creates the internal glControl and attaches it to a WindowsFormsHost /// </summary> public WpfOpenGLControl() { InitializeComponent(); // create and wrap WINFORM control if (!DesignerProperties.GetIsInDesignMode(this)) { //TODO: performance with an INTEL integrated 620 on 4k is not good (see example on full screen) glControl = new GLControl(); glControl.HandleCreated += GlControl_HandleCreated; host.Child = glControl; WindowsFormsHost.EnableWindowsFormsInterop(); glControl.Paint += GlControl_Paint; glControl.Resize += GlControl_Invalidate; glControl.CreateControl(); //force creation of control, so dependent constructors have valid OpenGL glControl.VSync = true; } }
public Form1() { InitializeComponent(); OpenTK.Toolkit.Init(); this.SuspendLayout(); glControl.CreateControl(); glControl.Width = Width - 16; glControl.Height = Height - 63; glControl.Location = new Point(0, 24); this.Controls.Add(glControl); glControl_Load(); glControl.MouseMove += glControl_MouseMove; glControl.KeyDown += Form1_KeyDown; devX = (float)screen.Width / (float)glControl.Width; devY = (float)screen.Height / (float)glControl.Height; glControl.Load += control_Load; glControl.Paint += control_Paint; glControl.MouseDown += new MouseEventHandler(Form1_MouseDown); FPS.Start(); }
public Window(WindowOptions options) { if (Application.MainWindow != null && Application.RenderingBackend == RenderingBackend.ES20) { // ES20 doesn't allow multiple contexts for now, because of a bug in OpenTK throw new Lime.Exception("Attempt to create a second window for ES20 rendering backend. Use OpenGL backend instead."); } if (options.UseTimer && options.AsyncRendering) { throw new Lime.Exception("Can't use both timer and async rendering"); } if (options.ToolWindow) { form = new ToolForm(); } else { form = new Form(); } Input = new WindowInput(this); using (var graphics = form.CreateGraphics()) { PixelScale = CalcPixelScale(graphics.DpiX); } if (options.Style == WindowStyle.Borderless) { borderStyle = FormBorderStyle.None; } else { borderStyle = options.FixedSize ? FormBorderStyle.FixedSingle : FormBorderStyle.Sizable; } form.FormBorderStyle = borderStyle; form.MaximizeBox = !options.FixedSize; if (options.MinimumDecoratedSize != Vector2.Zero) { MinimumDecoratedSize = options.MinimumDecoratedSize; } if (options.MaximumDecoratedSize != Vector2.Zero) { MaximumDecoratedSize = options.MaximumDecoratedSize; } glControl = CreateGLControl(); glControl.CreateControl(); glControl.Context.MakeCurrent(null); glControl.Dock = DockStyle.Fill; glControl.Paint += OnPaint; glControl.KeyDown += OnKeyDown; glControl.KeyUp += OnKeyUp; glControl.KeyPress += OnKeyPress; glControl.MouseDown += OnMouseDown; glControl.MouseUp += OnMouseUp; glControl.Resize += OnResize; glControl.MouseWheel += OnMouseWheel; glControl.MouseEnter += (sender, args) => { Application.WindowUnderMouse = this; }; glControl.MouseLeave += (sender, args) => { if (Application.WindowUnderMouse == this) { Application.WindowUnderMouse = null; } }; glControl.BeforeBoundsChanged += WaitForRendering; form.Move += OnMove; form.Activated += OnActivated; form.Deactivate += OnDeactivate; form.FormClosing += OnClosing; form.FormClosed += OnClosed; active = Form.ActiveForm == form; if (options.UseTimer) { timer = new System.Windows.Forms.Timer { Interval = (int)(1000.0 / 65), Enabled = true, }; timer.Tick += OnTick; } else { vSync = options.VSync; glControl.MakeCurrent(); glControl.VSync = vSync; glControl.Context.MakeCurrent(null); System.Windows.Forms.Application.Idle += OnTick; } form.Controls.Add(glControl); stopwatch = new Stopwatch(); stopwatch.Start(); if (options.Icon != null) { form.Icon = (System.Drawing.Icon)options.Icon; } Cursor = MouseCursor.Default; Title = options.Title; ClientSize = options.ClientSize; if (options.Visible) { Visible = true; } if (options.Screen != null && options.Screen >= 0 && Screen.AllScreens.Length > options.Screen) { form.Location = GetCenter(Screen.AllScreens[options.Screen.Value].WorkingArea); } if (options.Centered) { Center(); } if (Application.MainWindow == null) { Application.MainWindow = this; Closing += reason => Application.DoExiting(); Closed += Application.DoExited; } else { Form.Owner = Application.MainWindow.Form; Form.StartPosition = FormStartPosition.CenterParent; } AsyncRendering = options.AsyncRendering; if (AsyncRendering) { renderThreadTokenSource = new CancellationTokenSource(); renderThreadToken = renderThreadTokenSource.Token; renderThread = new Thread(RenderLoop); renderThread.IsBackground = true; renderThread.Start(); } Application.Windows.Add(this); }