private static OpenTK.Graphics.GraphicsMode GetMode() { var def = OpenTK.Graphics.GraphicsMode.Default; var val = new OpenTK.Graphics.GraphicsMode(def.ColorFormat, def.Depth, def.Stencil, 0); return(val); }
//a chance to intercept graphics mode prior to window initialization private static OpenTK.Graphics.GraphicsMode GetInitialGraphicsMode() { OpenTK.Graphics.GraphicsMode gm = OpenTK.Graphics.GraphicsMode.Default; //todo: tinker here //gm.Samples = 0; return(gm); }
/* * Textures found at: * http://www.solarsystemscope.com/nexus/textures/planet_textures/ */ public RenderWindow(int width, int height, OpenTK.Graphics.GraphicsMode mode, string title) : base(width, height, mode, title) { physController = new PhysicsController(); camController = new CameraController(new double[] { 0, 0.0f, -10000000 });//new double[] { -1000000.0f, 0.0f, -1000000.0f }); graphController = new GraphicsController(); graphController.ReadObjFile("sphere.obj"); graphController.ReadSkyObjFile("skybox.obj"); int[] newTextureIds = new int[8]; GL.GenTextures(8, newTextureIds); newTextureIds[0] = graphController.LoadTexture("Textures/texture_sun.jpg"); newTextureIds[1] = graphController.LoadTexture("Textures/texture_earth_clouds.jpg"); newTextureIds[2] = graphController.LoadTexture("Textures/texture_mercury.jpg"); newTextureIds[3] = graphController.LoadTexture("Textures/texture_venus_surface.jpg"); newTextureIds[4] = graphController.LoadTexture("Textures/texture_mars.jpg"); newTextureIds[5] = graphController.LoadTexture("Textures/texture_jupiter.jpg"); newTextureIds[6] = graphController.LoadTexture("Textures/texture_saturn.jpg"); newTextureIds[7] = graphController.LoadTexture("Textures/texture_moon.jpg"); skyboxTextureId = graphController.LoadTexture("Textures/texture_skybox.jpg"); textureIds = newTextureIds; // Skybox double[] skyboxPos = new double[] { (float)-Math.Pow(10, 11) / 2, (float)-Math.Pow(10, 11) / 2, (float)-Math.Pow(10, 11) / 2 }; skybox = new SimObject(skyboxPos, new PhysicsObject(), graphController.CreateSkyboxObj(1)); }
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; }
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; }
public OpenGLRenderControl(OpenTK.Graphics.GraphicsMode graphicsMode, int major, int minor, OpenTK.Graphics.GraphicsContextFlags graphicsContextFlags) { this.graphicsMode = graphicsMode; this.graphicsContextFlags = graphicsContextFlags; this.major = major; this.minor = minor; }
public CarbonGLNative(int x, int y, int width, int height, string title, OpenTK.Graphics.GraphicsMode mode, GameWindowFlags options, DisplayDevice device) { CreateNativeWindow(WindowClass.Document, WindowAttributes.StandardDocument | WindowAttributes.StandardHandler | WindowAttributes.InWindowMenu | WindowAttributes.LiveResize, new Rect((short)x, (short)y, (short)width, (short)height)); mDisplayDevice = device; }
public OpenTKGameWindow(int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) : base(width, height, mode, title, options, device, major, minor, flags) { CrowInterface = new Interface(); Thread t = new Thread(interfaceThread); t.IsBackground = true; t.Start(); }
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 Game(int width, int height, OpenTK.Graphics.GraphicsMode mode) : base(width, height, mode) { _gameWindow = this; GL.Enable(EnableCap.Texture2D); //GL.Enable(EnableCap. GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); Input.Initialize(this); //MouseDown += Mouse_ButtonDown; }
private void InitializeOgl(Control WinControl) { if (RenderingContext != null) { if (!RenderingContext.IsDisposed) { DisposeOglObjects(); } } /* private OpenTK.Platform.IWindowInfo*/ WindowsInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(WinControl.Handle); OpenTK.Graphics.GraphicsMode GraphicMode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(PfdColorBits), PfdDepthBits, PfdStencilBits, PfdAuxBits, new OpenTK.Graphics.ColorFormat(PfdAccumBits), PfdBuffers, PfdStereo); OpenTK.Graphics.GraphicsMode GraphicMode2 = OpenTK.Graphics.GraphicsMode.Default; RenderingContext = new OpenTK.Graphics.GraphicsContext(GraphicMode2, WindowsInfo); RenderingContext.LoadAll(); FBO.LoadMethods(); RenderingContext.SwapInterval = 1; GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.ShadeModel(ShadingModel.Smooth); GL.Enable(EnableCap.Normalize); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Lighting); ShadowMapSampler = GL.GenSampler(); // Texture.Sampler= GL.GenSampler(); ActivateShader(); Lights[0].Position = new xyzwf(3, 4, 10, 0); FieldOfView = 0; Selector.PickingShader = PickingShader; //System.Diagnostics.ConsoleTraceListener myWriter = new //System.Diagnostics.ConsoleTraceListener(); //System.Diagnostics.Debug.Listeners.Clear(); //System.Diagnostics.Debug.Listeners.Add(myWriter); CheckError(); ClockWise = true; Culling = false; SwapBuffers(); CheckError(); }
public MyGLControl() { OpenTK.Graphics.GraphicsMode gfxmode = new OpenTK.Graphics.GraphicsMode( DisplayDevice.Default.BitsPerPixel, //default 32 bits color 16, //depth buffer => 16 8, //stencil buffer => 8 ( //if want to use stencil buffer then set stencil buffer too! ) 0, //number of sample of FSAA 0, //accum buffer 2, // n buffer, 2=> double buffer false); //sterio ChildCtorOnlyResetGraphicMode(gfxmode); //----------- this.InitializeComponent(); }
public MyGLControl() { OpenTK.Graphics.GraphicsMode gfxmode = new OpenTK.Graphics.GraphicsMode( DisplayDevice.Default.BitsPerPixel,//default 32 bits color 16,//depth buffer => 16 8, //stencil buffer => 8 ( //if want to use stencil buffer then set stencil buffer too! ) 0,//number of sample of FSAA 0, //accum buffer 2, // n buffer, 2=> double buffer false);//sterio ChildCtorOnlyResetGraphicMode(gfxmode); //----------- this.InitializeComponent(); }
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(); }
protected override void OnLoad(EventArgs e) { if (opengl) { try { OpenTK.Graphics.GraphicsMode test = this.GraphicsMode; int[] viewPort = new int[4]; GL.GetInteger(GetPName.Viewport, viewPort); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, Width, Height, 0, -1, 1); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.PushAttrib(AttribMask.DepthBufferBit); GL.Disable(EnableCap.DepthTest); //GL.Enable(EnableCap.Texture2D); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); } catch (Exception) { } try { GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.PolygonSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.PointSmoothHint, HintMode.Nicest); GL.Hint(HintTarget.TextureCompressionHint, HintMode.Nicest); } catch (Exception) { } try { GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.PointSmooth); GL.Enable(EnableCap.PolygonSmooth); } catch (Exception) { } } started = true; }
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); }
public OpenGLSystemWindow() { // Set GraphicsMode via user overridable settings var config = AggContext.Config.GraphicsMode; var graphicsMode = new OpenTK.Graphics.GraphicsMode(config.Color, config.Depth, config.Stencil, config.FSAASamples); glControl = new AggGLControl(graphicsMode) { Dock = DockStyle.Fill, Location = new Point(0, 0), TabIndex = 0, VSync = false }; RenderOpenGl.OpenGl.GL.Instance = new OpenTkGl(); this.Controls.Add(glControl); }
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); }
public static OpenTK.Graphics.GraphicsMode GetDefaultGraphicsMode() { if (!s_initOpenTK) { InitGLES(); } if (s_gfxmode == null) { s_gfxmode = new OpenTK.Graphics.GraphicsMode( DisplayDevice.Default.BitsPerPixel, //default 32 bits color 16, //depth buffer => 16 8, //stencil buffer => 8 (set this if you want to use stencil buffer toos) 0, //number of sample of FSAA (not always work) 0, //accum buffer 2, // n buffer, 2=> double buffer false); //sterio } return(s_gfxmode); }
public OpenGLSystemWindow() { // Set GraphicsMode via user overridable settings var config = AggContext.Config.GraphicsMode; // NOTE: OpenTK3 will run in Windows Sandbox (no proper GL driver), but OpenTK4 won't, it seems. #if USE_OPENTK4 var graphicsMode = new OpenTK.WinForms.GLControlSettings { Profile = OpenTK.Windowing.Common.ContextProfile.Compatability, #if DEBUG Flags = OpenTK.Windowing.Common.ContextFlags.Debug, #endif NumberOfSamples = config.FSAASamples, IsEventDriven = true, }; #else var graphicsMode = new OpenTK.Graphics.GraphicsMode(config.Color, config.Depth, config.Stencil, config.FSAASamples); // If the GPU driver is disabled in Windows, this could be used to test context creation failure. //var graphicsMode = new OpenTK.Graphics.GraphicsMode(config.Color, config.Depth, config.Stencil, config.FSAASamples + 100, OpenTK.Graphics.ColorFormat.Empty, 100, true); #endif glControl = new AggGLControl(graphicsMode) { Dock = DockStyle.Fill, Location = new Point(0, 0), TabIndex = 0, #if !USE_OPENTK4 VSync = false, #endif }; // TODO: Disable VSync when using OpenTK 4? Current versions on NuGet do not expose VSync. #if !USE_OPENTK4 //(glControl.Context as OpenTK.Windowing.Desktop.GLFWGraphicsContext).SwapInterval = 0; #endif RenderOpenGl.OpenGl.GL.Instance = new OpenTkGl(); this.Controls.Add(glControl); }
public override Gk3Main.Graphics.IRenderer CreateRenderer() { if (_renderer != null) { throw new InvalidOperationException("A renderer has already been created"); } OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(32), _depth, 0, 0); _window = new OpenTK.NativeWindow(_width, _height, "FreeGeeKayThree - OpenGL 3.3 renderer", _fullscreen ? OpenTK.GameWindowFlags.Fullscreen : OpenTK.GameWindowFlags.FixedWindow, mode, OpenTK.DisplayDevice.Default); _window.Visible = true; _window.Closed += (x, y) => _closed = true; _context = new OpenTK.Graphics.GraphicsContext(mode, _window.WindowInfo, 3, 3, OpenTK.Graphics.GraphicsContextFlags.ForwardCompatible | OpenTK.Graphics.GraphicsContextFlags.Debug); _context.MakeCurrent(_window.WindowInfo); _context.LoadAll(); _renderer = new Gk3Main.Graphics.OpenGl.OpenGLRenderer(this); return(_renderer); }
/// <summary> /// コンストラクタ /// </summary> public Program(int width, int height, OpenTK.Graphics.GraphicsMode mode, string title) : base(width, height, mode, title) { IList <string> devices = OpenTK.Audio.AudioCapture.AvailableDevices; foreach (string device in devices) { Console.WriteLine(device); } // オーディオキャプチャ this.AudioCapture = new OpenTK.Audio.AudioCapture(); this.AudioCapture.Start(); // デバッグ Console.WriteLine("[INFO] " + this.AudioCapture.AvailableSamples); Console.WriteLine("[INFO] " + this.AudioCapture.CurrentDevice); Console.WriteLine("[INFO] " + this.AudioCapture.CurrentError); Console.WriteLine("[INFO] " + this.AudioCapture.SampleFormat); Console.WriteLine("[INFO] " + this.AudioCapture.SampleFrequency); Console.WriteLine("[INFO] Start Audio Capture"); }
/// <summary> /// Make a GL Control and attach to control. /// </summary> /// <param name="attachcontrol">Control to attach the GL Control to</param> /// <param name="mode">TK graphics mode</param> public GLWinFormControl(Control attachcontrol, OpenTK.Graphics.GraphicsMode mode = null) { if (mode == null) { mode = OpenTK.Graphics.GraphicsMode.Default; } glControl = new GLControlKeyOverride(mode); glControl.MakeCurrent(); // make sure GLControl is current context selected, in case operating with multiples glControl.Dock = DockStyle.Fill; glControl.BackColor = System.Drawing.Color.Black; glControl.Name = "glControl"; glControl.TabIndex = 0; glControl.VSync = true; glControl.PreviewKeyDown += Gl_PreviewKeyDown; attachcontrol.Controls.Add(glControl); glControl.MouseDown += Gc_MouseDown; glControl.MouseUp += Gc_MouseUp; glControl.MouseMove += Gc_MouseMove; glControl.MouseEnter += Gc_MouseEnter; glControl.MouseLeave += Gc_MouseLeave; glControl.MouseClick += Gc_MouseClick; glControl.MouseDoubleClick += Gc_MouseDoubleClick; glControl.MouseWheel += Gc_MouseWheel; glControl.KeyDown += Gc_KeyDown; glControl.KeyUp += Gc_KeyUp; glControl.KeyPress += Gc_KeyPress; glControl.Resize += Gc_Resize; glControl.Paint += GlControl_Paint; context = GLStatics.GetContext(); System.Diagnostics.Debug.WriteLine($"GL Context {context} created"); gltime.Start(); }
public override Gk3Main.Graphics.IRenderer CreateRenderer() { if (_renderer != null) { throw new InvalidOperationException("A renderer has already been created"); } OpenTK.Graphics.GraphicsMode mode = new OpenTK.Graphics.GraphicsMode(new OpenTK.Graphics.ColorFormat(32), _depth, 0, 0); _window = new OpenTK.NativeWindow(_width, _height, "FreeGeeKayThree - Direct3D 9 renderer", _fullscreen ? OpenTK.GameWindowFlags.Fullscreen : OpenTK.GameWindowFlags.FixedWindow, mode, OpenTK.DisplayDevice.Default); _window.Visible = true; _window.Closed += (x, y) => _closed = true; // _window = SDL2.SDL.SDL_CreateWindow("FreeGeeKayThree - Direct3D 9 Renderer", SDL2.SDL.SDL_WINDOWPOS_CENTERED, SDL2.SDL.SDL_WINDOWPOS_CENTERED, _width, _height, _fullscreen ? SDL2.SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN : 0); //Sdl.SDL_SetVideoMode(_width, _height, _depth, (_fullscreen ? Sdl.SDL_FULLSCREEN : 0)); // Sdl.SDL_WM_SetCaption("FreeGeeKayThree - Direct3D 9 Renderer", "FreeGK3"); // SDL_SysWMinfo wmInfo; // SDL_GetWMInfo(out wmInfo); _renderer = new Gk3Main.Graphics.Direct3D9.Direct3D9Renderer(this, Handle, _width, _height, false); return(_renderer); }
public void SetupGLControl() { RenderingEnabled = false; glControl?.Dispose(); glControl = null; GLMode = null; try { if (!UseMultiSampling) { GLMode = new OpenTK.Graphics.GraphicsMode(OpenTK.DisplayDevice.Default.BitsPerPixel, 24, 8, 0); } else { for (int aa = 0; aa <= 4; aa += 2) { var testMode = new OpenTK.Graphics.GraphicsMode(OpenTK.DisplayDevice.Default.BitsPerPixel, 24, 8, aa); if (testMode.Samples == aa) { GLMode = testMode; } } } } 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 == null ? "" : 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.Dock = DockStyle.Fill; Controls.Add(glControl); glControl.BringToFront(); }
/// <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); }
public void SetupGLControl() { RenderingEnabled = false; if (glControl != null) glControl.Dispose(); glControl = null; GLMode = null; try { if (!UseMultiSampling) { GLMode = new OpenTK.Graphics.GraphicsMode(OpenTK.DisplayDevice.Default.BitsPerPixel, 24, 8, 0); } else { for (int aa = 0; aa <= 4; aa += 2) { var testMode = new OpenTK.Graphics.GraphicsMode(OpenTK.DisplayDevice.Default.BitsPerPixel, 24, 8, aa); if (testMode.Samples == aa) { GLMode = testMode; } } } } 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.Dock = DockStyle.Fill; glControl.VSync = false; Controls.Add(glControl); glControl.BringToFront(); }
private int CheckColorDeep(int SetValue) { int _Result = 8; OpenTK.Graphics.GraphicsMode _mode = null; bool _done = false; while (!_done && (_Result <= 32)) { try { _mode = new OpenTK.Graphics.GraphicsMode(_Result, 0, 0, 0); } catch (Exception) { _done = true; _Result -= 8; if (_Result == 0) _Result = 8; } if (_mode != null) { try { if (_mode.ColorFormat == _Result) { _Result += 8; } else { _done = true; _Result -= 8; if (_Result == 0) _Result = 8; } } catch (Exception) { _done = true; _Result -= 8; if (_Result == 0) _Result = 8; } } else { _done = true; _Result -= 8; if (_Result == 0) _Result = 8; } } if (_Result > 32) _Result = 32; if (SetValue < _Result) return SetValue; else return _Result; }
private int CheckAntiAliasingMode(int SetValue) { int _Result = 0; OpenTK.Graphics.GraphicsMode _mode = null; bool _done = false; while (!_done && (_Result <= 32)) { try { _mode = new OpenTK.Graphics.GraphicsMode(16, 0, 0, _Result); } catch (Exception) { _done = true; _Result /= 2; if (_Result == 1) _Result = 0; } if (_mode != null) { try { if (_mode.Samples == _Result) { if (_Result == 0) _Result = 2; else _Result *= 2; } else { _done = true; _Result /= 2; if (_Result == 1) _Result = 0; } } catch (Exception) { _done = true; _Result /= 2; if (_Result == 1) _Result = 0; } } else { _done = true; _Result /= 2; if (_Result == 1) _Result = 0; } } if (_Result > 64) _Result = 32; if (SetValue < _Result) return SetValue; else return _Result; }
/// <summary> /// Sets up all necessary OpenGL resources for this RenderTarget. /// </summary> public void SetupOpenGLRes() { DualityApp.GuardSingleThreadState(); if (this.targetInfo == null || this.targetInfo.Count == 0) { return; } int highestAALevel = MathF.RoundToInt(MathF.Log(MathF.Max(MaxRenderTargetSamples, 1.0f), 2.0f)); int targetAALevel = highestAALevel; switch (this.multisampling) { case AAQuality.High: targetAALevel = highestAALevel; break; case AAQuality.Medium: targetAALevel = highestAALevel / 2; break; case AAQuality.Low: targetAALevel = highestAALevel / 4; break; case AAQuality.Off: targetAALevel = 0; break; } int targetSampleCount = MathF.RoundToInt(MathF.Pow(2.0f, targetAALevel)); OpenTK.Graphics.GraphicsMode sampleMode = DualityApp.AvailableModes.LastOrDefault(m => m.Samples <= targetSampleCount) ?? DualityApp.AvailableModes.Last(); this.samples = sampleMode.Samples; #region Setup FBO & RBO: Non-multisampled if (this.samples == 0) { // Generate FBO if (this.glFboId == 0) { GL.Ext.GenFramebuffers(1, out this.glFboId); } GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, this.glFboId); // Attach textures int oglWidth = 0; int oglHeight = 0; for (int i = 0; i < this.targetInfo.Count; i++) { if (!this.targetInfo[i].target.IsAvailable) { continue; } FramebufferAttachment attachment = (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0Ext + i); GL.Ext.FramebufferTexture2D( FramebufferTarget.FramebufferExt, attachment, TextureTarget.Texture2D, this.targetInfo[i].target.Res.OglTexId, 0); oglWidth = this.targetInfo[i].target.Res.TexelWidth; oglHeight = this.targetInfo[i].target.Res.TexelHeight; } // Generate Depth Renderbuffer if (this.glRboIdDepth == 0) { GL.Ext.GenRenderbuffers(1, out this.glRboIdDepth); } GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, this.glRboIdDepth); GL.Ext.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent24, oglWidth, oglHeight); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, this.glRboIdDepth); // Check status FramebufferErrorCode status = GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt); if (status != FramebufferErrorCode.FramebufferCompleteExt) { Log.Core.WriteError("Can't create RenderTarget '{0}'. Incomplete Framebuffer: {1}", this.path, status); } GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); } #endregion #region Setup FBO & RBO: Multisampled if (this.samples > 0) { // Generate texture target FBO if (this.glFboId == 0) { GL.Ext.GenFramebuffers(1, out this.glFboId); } GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, this.glFboId); // Attach textures int oglWidth = 0; int oglHeight = 0; for (int i = 0; i < this.targetInfo.Count; i++) { if (!this.targetInfo[i].target.IsAvailable) { continue; } FramebufferAttachment attachment = (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0Ext + i); GL.Ext.FramebufferTexture2D( FramebufferTarget.FramebufferExt, attachment, TextureTarget.Texture2D, this.targetInfo[i].target.Res.OglTexId, 0); oglWidth = this.targetInfo[i].target.Res.TexelWidth; oglHeight = this.targetInfo[i].target.Res.TexelHeight; } // Check status FramebufferErrorCode status = GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt); if (status != FramebufferErrorCode.FramebufferCompleteExt) { Log.Core.WriteError("Can't create RenderTarget '{0}'. Incomplete Texture Framebuffer: {1}", this.path, status); } // Generate rendering FBO if (this.glFboIdMSAA == 0) { GL.Ext.GenFramebuffers(1, out this.glFboIdMSAA); } GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, this.glFboIdMSAA); // Attach color renderbuffers for (int i = 0; i < this.targetInfo.Count; i++) { if (!this.targetInfo[i].target.IsAvailable) { continue; } TargetInfo info = this.targetInfo[i]; FramebufferAttachment attachment = (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0Ext + i); RenderbufferStorage rbColorFormat = TexFormatToRboFormat(info.target.Res.PixelFormat); if (info.glRboIdColorMSAA == 0) { GL.GenRenderbuffers(1, out info.glRboIdColorMSAA); } GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, info.glRboIdColorMSAA); GL.Ext.RenderbufferStorageMultisample(RenderbufferTarget.RenderbufferExt, this.samples, rbColorFormat, oglWidth, oglHeight); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, attachment, RenderbufferTarget.RenderbufferExt, info.glRboIdColorMSAA); this.targetInfo[i] = info; } GL.Ext.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); // Attach depth renderbuffer if (this.glRboIdDepth == 0) { GL.Ext.GenRenderbuffers(1, out this.glRboIdDepth); } GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, this.glRboIdDepth); GL.Ext.RenderbufferStorageMultisample(RenderbufferTarget.RenderbufferExt, this.samples, RenderbufferStorage.DepthComponent24, oglWidth, oglHeight); GL.Ext.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, this.glRboIdDepth); GL.Ext.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, 0); // Check status status = GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt); if (status != FramebufferErrorCode.FramebufferCompleteExt) { Log.Core.WriteError("Can't create RenderTarget '{0}'. Incomplete Multisample Framebuffer: {1}", this.path, status); } GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); } #endregion }
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> /// コンストラクタ /// </summary> public Program(int width, int height, OpenTK.Graphics.GraphicsMode mode, string title) : base(width, height, mode, title) { System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(0, 0, 1024, 1024); }
/// <summary>Constructs a new NativeWindow with the specified attributes.</summary> /// <param name="x">Horizontal screen space coordinate of the NativeWindow's origin.</param> /// <param name="y">Vertical screen space coordinate of the NativeWindow's origin.</param> /// <param name="width">The width of the NativeWindow in pixels.</param> /// <param name="height">The height of the NativeWindow in pixels.</param> /// <param name="title">The title of the NativeWindow.</param> /// <param name="options">GameWindow options specifying window appearance and behavior.</param> /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param> /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param> /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception> /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception> public NativeWindow(int x, int y, int width, int height, string title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, DisplayDevice device) { // TODO: Should a constraint be added for the position? if (width < 1) { throw new ArgumentOutOfRangeException("width", "Must be greater than zero."); } if (height < 1) { throw new ArgumentOutOfRangeException("height", "Must be greater than zero."); } if (mode == null) { throw new ArgumentNullException("mode"); } if (device == null) { throw new ArgumentNullException("device"); } this.options = options; this.device = device; implementation = (INativeWindow2)Factory.Default.CreateNativeWindow(x, y, width, height, title, mode, options, this.device); if ((options & GameWindowFlags.Fullscreen) != 0) { this.device.ChangeResolution(width, height, mode.ColorFormat.BitsPerPixel, 0); WindowState = WindowState.Fullscreen; } }
// TODO: Remaining constructors. /// <summary>Constructs a new centered NativeWindow with the specified attributes.</summary> /// <param name="width">The width of the NativeWindow in pixels.</param> /// <param name="height">The height of the NativeWindow in pixels.</param> /// <param name="title">The title of the NativeWindow.</param> /// <param name="options">GameWindow options specifying window appearance and behavior.</param> /// <param name="mode">The OpenTK.Graphics.GraphicsMode of the NativeWindow.</param> /// <param name="device">The OpenTK.Graphics.DisplayDevice to construct the NativeWindow in.</param> /// <exception cref="System.ArgumentOutOfRangeException">If width or height is less than 1.</exception> /// <exception cref="System.ArgumentNullException">If mode or device is null.</exception> public NativeWindow(int width, int height, string title, GameWindowFlags options, OpenTK.Graphics.GraphicsMode mode, DisplayDevice device) : this(device.Bounds.Left + (device.Bounds.Width - width) / 2, device.Bounds.Top + (device.Bounds.Height - height) / 2, width, height, title, options, mode, device) { }
static void Main() { Console.Title = "Tetraquark Console"; Running = true; const string ConfigFile = "cfg.yaml"; if (File.Exists(ConfigFile)) { Console.WriteLine("Loading config file {0}", ConfigFile); Settings.Load(File.ReadAllText(ConfigFile)); } GameWatch = new Stopwatch(); GameWatch.Start(); PackMgr.Mount("Default.zip"); string[] Files = PackMgr.GetFiles(); for (int i = 0; i < Files.Length; i++) { if (Files[i].StartsWith("resources/fonts/")) ResourceMgr.Register<Font>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); else if (Files[i].StartsWith("resources/textures/")) ResourceMgr.Register<Texture>(PackMgr.OpenFile(Files[i]), Path.GetFileNameWithoutExtension(Files[i])); } Scales.Init(new Vector2f(ResX, ResY)); // OpenTK ToolkitOptions TOpt = ToolkitOptions.Default; TOpt.Backend = PlatformBackend.PreferNative; TOpt.EnableHighResolution = true; Toolkit.Init(TOpt); // SFML VideoMode VMode = new VideoMode((uint)Scales.XRes, (uint)Scales.YRes, (uint)BitsPerPixel); ContextSettings CSet = new ContextSettings((uint)DepthBits, (uint)StencilBits); CSet.MajorVersion = 4; CSet.MinorVersion = 2; CSet.AntialiasingLevel = (uint)Samples; Styles S = Styles.None; if (Border) S |= Styles.Titlebar | Styles.Close; RenderWindow RWind = new RenderWindow(VMode, "Tetraquark", S, CSet); RWind.Closed += (Snd, E) => Running = false; RWind.SetKeyRepeatEnabled(false); // OpenTK IWindowInfo WindInfo = Utilities.CreateWindowsWindowInfo(RWind.SystemHandle); var GfxMode = new GraphicsMode(new ColorFormat(BitsPerPixel), DepthBits, StencilBits, Samples, new ColorFormat(0)); var GfxCtx = new GraphicsContext(GfxMode, WindInfo, (int)CSet.MajorVersion, (int)CSet.MinorVersion, GfxCtxFlags.Default); GfxCtx.MakeCurrent(WindInfo); GfxCtx.LoadAll(); RWind.ResetGLStates(); //GL.Enable(EnableCap.FramebufferSrgb); Renderer.Init(RWind); Stopwatch Clock = new Stopwatch(); Clock.Start(); while (Running) { RWind.DispatchEvents(); while (Clock.ElapsedMilliseconds < 10) ; float Dt = (float)Clock.ElapsedMilliseconds / 1000; Clock.Restart(); Renderer.Update(Dt); Renderer.Draw(RWind); RWind.Display(); } RWind.Close(); RWind.Dispose(); Console.WriteLine("Flushing configs"); File.WriteAllText(ConfigFile, Settings.Save()); Environment.Exit(0); }
/// <summary> Constructor </summary> public GLControlKeyOverride(OpenTK.Graphics.GraphicsMode m) : base(m) { }
public CrowWindow(int width, int height, OpenTK.Graphics.GraphicsMode mode, string title, GameWindowFlags options, DisplayDevice device, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) : base(width, height, mode, title, options, device, major, minor, flags) { }