private INativeWindow ConstructMessageWindow() { INativeWindow nativeWindow = (INativeWindow) new NativeWindow(); nativeWindow.ProcessEvents(); Functions.SetParent((nativeWindow.WindowInfo as WinWindowInfo).WindowHandle, Constants.MESSAGE_ONLY); nativeWindow.ProcessEvents(); return(nativeWindow); }
/// <summary> /// /// </summary> /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/> public override void InitSynchronizedOnce() { if (!AlreadySynchronized) { AlreadySynchronized = true; AutoResetEvent CompletedEvent = new AutoResetEvent(false); var CThread = new Thread(() => { Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.CultureName); NativeWindow = new OpenTK.NativeWindow(512, 272, "PspGraphicEngine", GameWindowFlags.Default, GraphicsMode.Default, DisplayDevice.Default); NativeWindow.Visible = false; GraphicsContext = new GraphicsContext(GraphicsMode.Default, NativeWindow.WindowInfo); GraphicsContext.MakeCurrent(NativeWindow.WindowInfo); { (GraphicsContext as IGraphicsContextInternal).LoadAll(); Initialize(); } GraphicsContext.MakeCurrent(null); CompletedEvent.Set(); while (Running) { NativeWindow.ProcessEvents(); Thread.Sleep(1); } StopEvent.Set(); }); CThread.IsBackground = true; CThread.Start(); CompletedEvent.WaitOne(); } }
public void Run() { var targetInterval = TimeSpan.FromSeconds(1 / _config.Window.FPS); var stopwatch = new Stopwatch(); stopwatch.Start(); while (_running) { var startTime = stopwatch.Elapsed; _time = startTime.TotalSeconds; Update(); var canvas = _skScreenSurface.Canvas; canvas.Clear(); Draw(canvas); _skContext.Flush(); _tkContext.SwapBuffers(); _tkWindow.ProcessEvents(); var endTime = stopwatch.Elapsed; var pauseTime = (startTime + targetInterval) - endTime; if (pauseTime > TimeSpan.Zero) { Thread.Sleep(pauseTime); } } }
public void Run() { DateTime previousFrameStartTime; while (window.Exists) { previousFrameStartTime = DateTime.UtcNow; Render(); window.ProcessEvents(); DateTime afterFrameTime = DateTime.UtcNow; double elapsed = (afterFrameTime - previousFrameStartTime).TotalSeconds; double sleepTime = setting.DesiredFrameRate - elapsed; if (sleepTime > 0.0) { DateTime finishTime = afterFrameTime + TimeSpan.FromSeconds(sleepTime); while (DateTime.UtcNow < finishTime) { Thread.Sleep(0); } } } }
/// <summary> /// Processes operating system events until the NativeWindow becomes idle. /// </summary> /// <param name="retainEvents">If true, the state of underlying system event propagation will be preserved, otherwise event propagation will be enabled if it has not been already.</param> protected void ProcessEvents(bool retainEvents) { EnsureUndisposed(); if (this.thread_id != System.Threading.Thread.CurrentThread.ManagedThreadId) { throw new InvalidOperationException("ProcessEvents must be called on the same thread that created the window."); } if (!retainEvents && !events) { Events = true; } implementation.ProcessEvents(); }
/// <summary> /// /// </summary> /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/> public override void InitSynchronizedOnce() { if (!AlreadyInitialized) { AlreadyInitialized = true; AutoResetEvent CompletedEvent = new AutoResetEvent(false); var CThread = new Thread(() => { Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.ThreadCultureName); var UsedGraphicsMode = new GraphicsMode( color: new OpenTK.Graphics.ColorFormat(8, 8, 8, 8), depth: 16, stencil: 8, samples: 0, accum: new OpenTK.Graphics.ColorFormat(16, 16, 16, 16), //accum: new OpenTK.Graphics.ColorFormat(0, 0, 0, 0), buffers: 2, stereo: false ); var UsedGameWindowFlags = GameWindowFlags.Default; //Console.Error.WriteLine(UsedGraphicsMode); //Console.ReadKey(); #if USE_GL_CONTROL GLControl = new GLControl(UsedGraphicsMode, 3, 0, GraphicsContextFlags.Default); #else NativeWindow = new NativeWindow(512, 272, "PspGraphicEngine", UsedGameWindowFlags, UsedGraphicsMode, DisplayDevice.GetDisplay(DisplayIndex.Default)); #endif #if SHOW_WINDOW NativeWindow.Visible = true; #endif //Utilities.CreateWindowsWindowInfo(handle); GraphicsContext = new GraphicsContext(UsedGraphicsMode, WindowInfo); GraphicsContext.MakeCurrent(WindowInfo); { GraphicsContext.LoadAll(); Initialize(); } GraphicsContext.SwapInterval = 0; #if true //Console.WriteLine("## {0}", UsedGraphicsMode); Console.WriteLine("## UsedGraphicsMode: {0}", UsedGraphicsMode); Console.WriteLine("## GraphicsContext.GraphicsMode: {0}", GraphicsContext.GraphicsMode); Console.WriteLine("## OpenGL Context Version: {0}.{1}", GlGetInteger(GetPName.MajorVersion), GlGetInteger(GetPName.MinorVersion)); Console.WriteLine("## Depth Bits: {0}", GlGetInteger(GetPName.DepthBits)); Console.WriteLine("## Stencil Bits: {0}", GlGetInteger(GetPName.StencilBits)); Console.WriteLine("## Accum Bits: {0},{1},{2},{3}", GlGetInteger(GetPName.AccumRedBits), GlGetInteger(GetPName.AccumGreenBits), GlGetInteger(GetPName.AccumBlueBits), GlGetInteger(GetPName.AccumAlphaBits)); if (GlGetInteger(GetPName.StencilBits) <= 0) { ConsoleUtils.SaveRestoreConsoleState(() => { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("No stencil bits available!"); }); } /* GL.Enable(EnableCap.StencilTest); GL.StencilMask(0xFF); GL.ClearColor(new Color4(Color.FromArgb(0x11, 0x22, 0x33, 0x44))); GL.ClearStencil(0x7F); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); var TestData = new uint[16 * 16]; TestData[0] = 0x12345678; GL.ReadPixels(0, 0, 16, 16, PixelFormat.Rgba, PixelType.UnsignedInt8888Reversed, TestData); Console.WriteLine(GL.GetError()); for (int n = 0; n < TestData.Length; n++) Console.Write("{0:X}", TestData[n]); */ #endif GraphicsContext.MakeCurrent(null); CompletedEvent.Set(); while (Running) { #if !USE_GL_CONTROL NativeWindow.ProcessEvents(); #endif Thread.Sleep(1); } StopEvent.Set(); }); CThread.Name = "GpuImplEventHandling"; CThread.IsBackground = true; CThread.Start(); CompletedEvent.WaitOne(); } }
public void Run() { Window = Factory.CreateWindow(640, 400, Program.AppName, GraphicsMode.Default, DisplayDevice.Default); Window.Visible = true; Drawer = new GdiPlusDrawer2D(); UpdateClientSize(); Init(); TryLoadTexturePack(); platformDrawer.window = Window; platformDrawer.Init(); Downloader = new AsyncDownloader(Drawer); Downloader.Init(""); Downloader.Cookies = new CookieContainer(); Downloader.KeepAlive = true; fetcher = new ResourceFetcher(); fetcher.CheckResourceExistence(); checkTask = new UpdateCheckTask(); checkTask.RunAsync(this); if (!fetcher.AllResourcesExist) { SetScreen(new ResourcesScreen(this)); } else { SetScreen(new MainScreen(this)); } while (true) { Window.ProcessEvents(); if (!Window.Exists) { break; } if (ShouldExit) { if (Screen != null) { Screen.Dispose(); Screen = null; } break; } checkTask.Tick(); Screen.Tick(); if (Dirty) { Display(); } Thread.Sleep(10); } if (Options.Load()) { LauncherSkin.SaveToOptions(); Options.Save(); } if (ShouldUpdate) { Updater.Applier.ApplyUpdate(); } if (Window.Exists) { Window.Close(); } }
void Draw() { //Show the window _win.Visible = true; while (_win.Exists) { #region FBO Buffer _fbo.Begin(); //Set the projection type Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, _fbo.Width / (float)_fbo.Height, 1.0f, 64.0f); GL.MatrixMode(MatrixMode.Projection); GL.LoadMatrix(ref projection); //Set the 3D view Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); GL.MatrixMode(MatrixMode.Modelview); GL.LoadMatrix(ref modelview); GL.Translate(0f, 0.0f, 3.0f); GL.Rotate(squareRotx, 1.0f, 0.0f, 0.0f); GL.Rotate(squareRoty, 0.0f, 1.0f, 0.0f); _texLogo.Bind(); GL.Begin(BeginMode.Quads); #region Draw Sqaure GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-0.5f, -0.5f, 0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(0.5f, -0.5f, 0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(0.5f, 0.5f, 0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-0.5f, 0.5f, 0.5f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-0.5f, -0.5f, -0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(-0.5f, 0.5f, -0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(0.5f, 0.5f, -0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.5f, -0.5f, -0.5f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-0.5f, -0.5f, 0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(-0.5f, 0.5f, 0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(-0.5f, 0.5f, -0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-0.5f, -0.5f, -0.5f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(0.5f, -0.5f, -0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(0.5f, 0.5f, -0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(0.5f, 0.5f, 0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.5f, -0.5f, 0.5f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-0.5f, 0.5f, 0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(0.5f, 0.5f, 0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(0.5f, 0.5f, -0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-0.5f, 0.5f, -0.5f); GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-0.5f, -0.5f, 0.5f); GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(-0.5f, -0.5f, -0.5f); GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(0.5f, -0.5f, -0.5f); GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(0.5f, -0.5f, 0.5f); #endregion GL.End(); //Create a Buffer and store the frame IntPtr buffer; _videoFrame.GetBytes(out buffer); GL.ReadPixels(0, 0, 1280, 720, PixelFormat.Bgra, PixelType.UnsignedInt8888Reversed, buffer); _fbo.End(); #endregion int width = _win.Size.Width; int height = _win.Size.Height; #region Back Buffer GL.Viewport(0, 0, width, height); //Set projection to 2D plane GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0, width, height, 0, -1, 1); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); //Draw a full screen Quad with the FBO texture _fbo.ColorTexture.Bind(); //Draw the framebuffer as a quad to a screen GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 1); GL.Vertex2(0, 0); GL.TexCoord2(0, 0); GL.Vertex2(0, height); GL.TexCoord2(1, 0); GL.Vertex2(width, height); GL.TexCoord2(1, 1); GL.Vertex2(width, 0); GL.End(); Texture.Unbind(); #endregion Thread.Sleep(5); _context.SwapBuffers(); _win.ProcessEvents(); } }