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(); }
public GraphicsMode( OpenTK.Graphics.ColorFormat color, int depth, int stencil, int samples, OpenTK.Graphics.ColorFormat accum, int buffers, bool stereo ) : base(color, depth, stencil, samples, accum, buffers, stereo) { }
private void Form1_Load(object sender, EventArgs e) { // create an anti-aliased skglControl and add it to the panel var cf = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8); var gm = new OpenTK.Graphics.GraphicsMode(color: cf, depth: 24, stencil: 8, samples: 4); skglControl1 = new SkiaSharp.Views.Desktop.SKGLControl(gm); skglControl1.BackColor = Color.Black; skglControl1.Dock = DockStyle.Fill; skglControl1.VSync = true; skglControl1.PaintSurface += SkglControl1_PaintSurface; panel1.Controls.Add(skglControl1); Reset(); }
public Form1() { InitializeComponent(); // create the OpenGL control formatted to match Skia var colorFormat = new OpenTK.Graphics.ColorFormat(32); var graphicsMode = new OpenTK.Graphics.GraphicsMode(colorFormat, 24, 8, 4); glControl1 = new OpenTK.GLControl(graphicsMode) { BackColor = Color.Black, Dock = DockStyle.Fill, VSync = true }; panel1.Controls.Add(glControl1); }
private void ConstructContext() { OpenTK.Graphics.GraphicsContextFlags flags = OpenTK.Graphics.GraphicsContextFlags.Default; int major = 1; int minor = 0; OpenTK.Platform.IWindowInfo windowInfo = Window.window.WindowInfo; if (System.Environment.OSVersion.Platform == PlatformID.Win32NT || System.Environment.OSVersion.Platform == PlatformID.Win32S || System.Environment.OSVersion.Platform == PlatformID.Win32Windows || System.Environment.OSVersion.Platform == PlatformID.WinCE) { major = 4; minor = 4; } if (this.Context == null || this.Context.IsDisposed) { OpenTK.Graphics.ColorFormat colorFormat = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8); int depth = 24;//TODO: wth? int stencil = 8; int samples = 4; OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(colorFormat, depth, stencil, samples); try { this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags); //this.Context = Window.Context; } catch (Exception ex) { mode = OpenTK.Graphics.GraphicsMode.Default; major = 1; minor = 0; flags = OpenTK.Graphics.GraphicsContextFlags.Default; this.Context = new OpenTK.Graphics.GraphicsContext(mode, windowInfo, major, minor, flags); } } this.Context.MakeCurrent(windowInfo); (this.Context as OpenTK.Graphics.IGraphicsContextInternal).LoadAll(); ThreadingHelper.Initialize(windowInfo, major, minor, contextFlags); this.Context.MakeCurrent(windowInfo); }
private void frmPicture_Load(object sender, EventArgs e) { //ToolStripItem ti = btnFilter.DropDownItems.Add("teste"); //ti.Click += new EventHandler(ti_Click); #region OpenGL Window creation OpenTK.Graphics.ColorFormat cf = new OpenTK.Graphics.ColorFormat(); OpenTK.Graphics.GraphicsMode gm = new OpenTK.Graphics.GraphicsMode(32, 24, 8, 4, cf, 4, true); this.GLPic = new OpenTK.GLControl(gm); GLPic.MakeCurrent(); this.Controls.Add(GLPic); GLPic.Paint += new PaintEventHandler(GLWindow_Paint); frmPicture_Resize(sender, e); #endregion Application.DoEvents(); #region Mouse events GLPic.MouseWheel += new MouseEventHandler(GLPic_MouseWheel); GLPic.MouseDown += new MouseEventHandler(GLPic_MouseDown); GLPic.MouseUp += new MouseEventHandler(GLPic_MouseUp); GLPic.MouseMove += new MouseEventHandler(GLPic_MouseMove); GLPic.MouseEnter += new EventHandler(GLPic_MouseEnter); GLPic.MouseLeave += new EventHandler(GLPic_MouseLeave); GLPic.Cursor = Cursors.Cross; GLPic.DoubleClick += new EventHandler(GLPic_DoubleClick); GLPic.KeyDown += new KeyEventHandler(GLPic_KeyDown); #endregion #region VBO Creation if (curMode == StereoMode.CrossedEyes) { CreateCrossedEyesVBOData(); } else if (curMode == StereoMode.Wiggle) { CreateAnimated3DVBOData(); } UpdateVBOs(); #endregion GLPic.MakeCurrent(); GL.Enable(EnableCap.DepthTest); GL.ClearColor(0.1f, 0.1f, 0.3f, 0.0f); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); //Z-Buffer GL.ClearDepth(1.0f); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.DepthTest); GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.DontCare); ////Materiais, funcoes para habilitar cor //GL.ColorMaterial(MaterialFace.FrontAndBack, ColorMaterialParameter.AmbientAndDiffuse); //tem q vir antes do enable //GL.Enable(EnableCap.ColorMaterial); //Redimension to picture if (curMode == StereoMode.Wiggle) { this.Width = (int)(aspect * (float)GLPic.Height * 0.5f); } else if (curMode == StereoMode.CrossedEyes) { this.Width = (int)(aspect * (float)GLPic.Height * 1.8f); } SetupViewport(); timer.Enabled = true; //Filters if (StereoEditor.CLFilters.Count > 0) { foreach (StereoEditor.CLFilter f in StereoEditor.CLFilters) { ToolStripItem t = btnFilter.DropDownItems.Add(f.FilterName); t.Click += new EventHandler(t_Click); } } }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); var cf = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8); var gm = new OpenTK.Graphics.GraphicsMode(color: cf, depth: 24, stencil: 8, samples: 4); this.skglControl1 = new SkiaSharp.Views.Desktop.SKGLControl(gm); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(39, 23); this.button1.TabIndex = 0; this.button1.Text = "10"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(57, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(39, 23); this.button2.TabIndex = 1; this.button2.Text = "1k"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.Location = new System.Drawing.Point(102, 12); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(39, 23); this.button3.TabIndex = 2; this.button3.Text = "10k"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Location = new System.Drawing.Point(147, 12); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(39, 23); this.button4.TabIndex = 3; this.button4.Text = "100k"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // skglControl1 // this.skglControl1.BackColor = System.Drawing.Color.Purple; this.skglControl1.Location = new System.Drawing.Point(12, 41); this.skglControl1.Name = "skglControl1"; this.skglControl1.Size = new System.Drawing.Size(600, 400); this.skglControl1.TabIndex = 4; this.skglControl1.VSync = false; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(624, 451); this.Controls.Add(this.skglControl1); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; this.Text = "SkiaSharp with OpenGL Benchmark"; this.ResumeLayout(false); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); var cf = new OpenTK.Graphics.ColorFormat(8, 8, 8, 8); var gm = new OpenTK.Graphics.GraphicsMode(color: cf, depth: 24, stencil: 8, samples: 4); this.skglControl1 = new SkiaSharp.Views.Desktop.SKGLControl(gm); this.rb500 = new System.Windows.Forms.RadioButton(); this.rb100k = new System.Windows.Forms.RadioButton(); this.label1 = new System.Windows.Forms.Label(); this.lblAlpha = new System.Windows.Forms.Label(); this.trackBar1 = new System.Windows.Forms.TrackBar(); this.timer1 = new System.Windows.Forms.Timer(this.components); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); this.SuspendLayout(); // // skglControl1 // this.skglControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.skglControl1.BackColor = System.Drawing.Color.Black; this.skglControl1.Location = new System.Drawing.Point(12, 58); this.skglControl1.Name = "skglControl1"; this.skglControl1.Size = new System.Drawing.Size(600, 400); this.skglControl1.TabIndex = 0; this.skglControl1.VSync = false; // // rb500 // this.rb500.AutoSize = true; this.rb500.Checked = true; this.rb500.Location = new System.Drawing.Point(12, 12); this.rb500.Name = "rb500"; this.rb500.Size = new System.Drawing.Size(68, 17); this.rb500.TabIndex = 1; this.rb500.TabStop = true; this.rb500.Text = "500 stars"; this.rb500.UseVisualStyleBackColor = true; this.rb500.CheckedChanged += new System.EventHandler(this.rb500_CheckedChanged); // // rb100k // this.rb100k.AutoSize = true; this.rb100k.Location = new System.Drawing.Point(12, 35); this.rb100k.Name = "rb100k"; this.rb100k.Size = new System.Drawing.Size(89, 17); this.rb100k.TabIndex = 2; this.rb100k.Text = "100,000 stars"; this.rb100k.UseVisualStyleBackColor = true; this.rb100k.CheckedChanged += new System.EventHandler(this.rb100k_CheckedChanged); // // label1 // this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Location = new System.Drawing.Point(555, 8); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(50, 21); this.label1.TabIndex = 3; this.label1.Text = "Alpha"; // // lblAlpha // this.lblAlpha.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.lblAlpha.AutoSize = true; this.lblAlpha.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblAlpha.Location = new System.Drawing.Point(546, 22); this.lblAlpha.Name = "lblAlpha"; this.lblAlpha.Size = new System.Drawing.Size(74, 32); this.lblAlpha.TabIndex = 4; this.lblAlpha.Text = "100%"; // // trackBar1 // this.trackBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.trackBar1.Location = new System.Drawing.Point(107, 7); this.trackBar1.Maximum = 100; this.trackBar1.Name = "trackBar1"; this.trackBar1.Size = new System.Drawing.Size(433, 45); this.trackBar1.TabIndex = 5; this.trackBar1.Value = 100; this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll); // // timer1 // this.timer1.Enabled = true; this.timer1.Interval = 1; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(623, 469); this.Controls.Add(this.trackBar1); this.Controls.Add(this.label1); this.Controls.Add(this.lblAlpha); this.Controls.Add(this.rb100k); this.Controls.Add(this.rb500); this.Controls.Add(this.skglControl1); this.Name = "Form1"; this.Text = "Starfield with SkiaSharp and OpenGL"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); }