internal void SwapBuffers() { if (IsInitialized) { graphicsContext.SwapBuffers(); } }
/// <summary> /// Swaps the front and back buffers, presenting the rendered scene to the screen. /// </summary> protected void SwapBuffers() { if (m_context != null) { m_context.SwapBuffers(); } }
/// <summary> /// Called when the widget is exposed. /// </summary> /// <param name="cr"></param> /// <returns></returns> protected override bool OnExposeEvent(Gdk.EventExpose evnt) #endif { if (!_Initialized) { Initialize(); } else { _GraphicsContext.MakeCurrent(_WindowInfo); } #if GTK3 var result = base.OnDrawn(cr); #else bool result = base.OnExposeEvent(evnt); #endif OnRenderFrame(); #if !GTK3 evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? #endif _GraphicsContext.SwapBuffers(); return(result); }
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); } } }
/// <summary> /// Render method /// </summary> /// <returns>Always true</returns> public virtual bool Render() { OnRenderFrame(); graphicsContext.SwapBuffers(); return(true); }
public override void EndFrame(Game game) { glContext.SwapBuffers(); #if GL11 activeList = -1; #endif }
/// <summary> /// Manages the entire drawing scene, from clearing to drawing to swapping the buffers /// </summary> /// <param name="context">Context to swap after drawn</param> public static void DrawEvent(IGraphicsContext context) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); EventManager.Draw.Invoke(); context.SwapBuffers(); }
// FIXME: This logic belongs in GraphicsDevice.Present, not // here. If it can someday be moved there, then the // normal call to Present in Game.Tick should cover // this. For now, iOSGamePlatform will call Present // in the Draw/Update loop handler. public void Present() { AssertNotDisposed(); AssertValidContext(); this.MakeCurrent(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this._colorbuffer); GL.InvalidateFramebuffer(FramebufferTarget.Framebuffer, 2, attachements); __renderbuffergraphicsContext.SwapBuffers(); }
/// <summary> /// Presents the rendered result of this instance. The rendering buffers are flushed and the deltatime is recalulated. /// Call this function after rendering. /// </summary> public void Present() { // Recalculate time tick. float newTick = Timer; _deltaFrameTime = newTick - _lastTimeTick; _lastTimeTick = newTick; // _context.MakeCurrent(_wi); _context.SwapBuffers(); }
public virtual void SwapBuffers() { if (!initialized) { return; } Display.Flush(); graphicsContext.SwapBuffers(); Display.Sync(); }
/// <inheritdoc /> public override void Render() { EnsureActive(); GL.ClearColor(Color.Black); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); foreach (var view in OrderedViews()) { view.Render(m_renderStates); } m_graphicsContext.SwapBuffers(); }
private void OnRenderFrame() { GL.Viewport(0, 0, nativeWindow.Size.X, nativeWindow.Size.Y); GL.Clear(ClearBufferMask.ColorBufferBit); GL.RasterPos2(-1, 1); GL.PixelZoom(1, -1); lock (framebufferLock) GL.DrawPixels(nativeWindow.Size.X, nativeWindow.Size.Y, PixelFormat.Rgb, PixelType.UnsignedByte, _framebuffer); graphicsContext.SwapBuffers(); }
void Update(OpenTKApplication a_app) { switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: { m_graphics.Update(a_app.WindowInfo); break; } } m_graphicsPipeline.Update(); Vector2 size = new Vector2(a_app.Width, a_app.Height); GL.Viewport(0, 0, (int)size.X, (int)size.Y); List <Canvas> gui = m_pipeline.GUIs; foreach (Canvas canvas in gui) { if (canvas.Visible) { canvas.Draw(size); } } m_consoleDisplay.Draw(size, m_pipeline.DisplayConsole); lock (this) { if (!m_shutDown && m_graphics != null) { if (PipelineTime.FPS <= 55.0f) { m_graphics.SwapInterval = 0; } else { m_graphics.SwapInterval = 1; } m_graphics.SwapBuffers(); } } #if DEBUG_INFO Pipeline.GLError("Pipeline: Update: "); #endif }
public void OnUpdate() { if (Glfw.WindowShouldClose(window)) { return; } try { context.SwapBuffers(); } catch (Exception ex) { Logger.Error("An error occured while swapping buffers!", ex); } }
public void Swap() { try { if (CurrentContext == this && _context != null && _context.IsCurrent && !_context.IsDisposed) { _context.SwapBuffers(); } } catch //(Exception x) { //MessageBox.Show(x.ToString()); Reset(); } }
// Called when a widget is realized. (window handles and such are valid) // protected override void OnRealized() { base.OnRealized(); } // Called when the widget needs to be (fully or partially) redrawn. protected override bool OnDrawn(Cairo.Context cr) { if (!_Initialized) { Initialize(); } else { _GraphicsContext.MakeCurrent(_WindowInfo); } bool result = base.OnDrawn(cr); OnRenderFrame(); _GraphicsContext.SwapBuffers(); return(result); }
/// <summary> /// Called when the widget is exposed. /// </summary> /// <param name="cr"></param> /// <returns></returns> protected override bool OnExposeEvent(Gdk.EventExpose evnt) { if (!_initialized) { Initialize(); } else { _graphicsContext.MakeCurrent(_windowInfo); } bool result = base.OnExposeEvent(evnt); OnRenderFrame(); evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? _graphicsContext.SwapBuffers(); return(result); }
private static void FreeContext() { try { GL.Finish(); ErrorCode error = GL.GetError(); if (error != ErrorCode.NoError) { throw Exceptions.CreateException("GLError: {0} ({1})", error, (int)error); } } finally { if (0 == --ContextReferenceCount.Value) { GLGraphicsContext.SwapBuffers(); GLGraphicsContext.MakeCurrent(null); } Monitor.Exit(Lock); } }
/// <summary> /// Swaps buffers on a context. This presents the rendered scene to the user. /// </summary> public void SwapBuffers() { implementation.SwapBuffers(); }
// Called when the widget needs to be (fully or partially) redrawn. protected override bool OnExposeEvent(Gdk.EventExpose eventExpose) { if (!initialized) { initialized = true; // If this looks uninitialized... initialize. if (ColorBPP == 0) { ColorBPP = 32; if (DepthBPP == 0) { DepthBPP = 16; } } ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP); ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP); int buffers = 2; if (SingleBuffer) { buffers--; } GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); // IWindowInfo if (Configuration.RunningOnWindows) { IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle); windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowHandle); } else if (Configuration.RunningOnMacOS) { IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle); IntPtr contentView = gdk_quartz_window_get_nsview(GdkWindow.Handle); // Problem: gdk_window_ensure_native() crashes when used more than once. // For now, just create a NSView in place and use that instead. // Needs some care updating when resizing, hiding, etc, but seems to work. // (I'd guess this is pretty much what gdk_window_ensure_native() does internally.) var customView = Class.AllocateClass("CustomNSView" + uniqueId++, "NSView"); //Class.RegisterMethod(windowClass, new WindowKeyDownDelegate(WindowKeyDown), "keyDown:", "v@:@"); //Class.RegisterMethod(customView, new OnHitTestDelegate(OnHitTest), "hitTest:", "@@:{NSPoint=ff}"); Class.RegisterMethod(customView, new OnMouseDownDelegate(OnMouseDown), "mouseDown:", "v@:@"); Class.RegisterMethod(customView, new OnMouseDraggedDelegate(OnMouseDragged), "mouseDragged:", "v@:@"); Class.RegisterMethod(customView, new OnMouseUpDelegate(OnMouseUp), "mouseUp:", "v@:@"); Class.RegisterClass(customView); nsView = SendIntPtr(SendIntPtr(customView, sel_registerName("alloc")), sel_registerName("initWithFrame:"), new RectangleF(0, 0, 100, 100)); SendVoid(contentView, sel_registerName("addSubview:"), nsView); // bool native = gdk_window_ensure_native(GdkWindow.Handle); // if (!native) // { // throw new PlatformNotSupportedException("Could not create native view."); // } // // nsView = gdk_quartz_window_get_nsview(GdkWindow.Handle); windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(windowHandle, nsView); UpdateNSView(); } else if (Configuration.RunningOnX11) { IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle); int screen = Screen.Number; IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle); IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle); IntPtr visualInfo; if (graphicsMode.Index.HasValue) { XVisualInfo info = new XVisualInfo(); info.VisualID = graphicsMode.Index.Value; int dummy; visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); } else { visualInfo = GetVisualInfo(display); } windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo); XFree(visualInfo); } else { throw new PlatformNotSupportedException(); } // GraphicsContext graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags); graphicsContext.MakeCurrent(windowInfo); if (GraphicsContext.ShareContexts) { Interlocked.Increment(ref graphicsContextCount); if (!sharedContextInitialized) { sharedContextInitialized = true; ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } } else { ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } OnInitialized(); } else { try // Hack: Fix crash when returning from sleep mode on windows, using nvidia drivers. See: http://www.opentk.com/node/2634 { graphicsContext.MakeCurrent(windowInfo); } catch { } } bool result = base.OnExposeEvent(eventExpose); OnRenderFrame(); eventExpose.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? graphicsContext.SwapBuffers(); return(result); }
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(); } }
public void Present() => context.SwapBuffers();
public void SwapBuffer() { control2Context.SwapBuffers(); GL.DeleteTexture(_texture[0].gltextureid); }
public void SwapBuffers() { tkContext.SwapBuffers(); }
// Called when the widget needs to be (fully or partially) redrawn. protected override bool OnExposeEvent(Gdk.EventExpose eventExpose) { if (!initialized) { initialized = true; // If this looks uninitialized... initialize. if (ColorBPP == 0) { ColorBPP = 32; if (DepthBPP == 0) { DepthBPP = 16; } } ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP); ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP); int buffers = 2; if (SingleBuffer) { buffers--; } GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); // IWindowInfo if (Configuration.RunningOnWindows) { IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle); windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowHandle); } else if (Configuration.RunningOnMacOS) { IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle); bool ownHandle = true; bool isControl = true; windowInfo = OpenTK.Platform.Utilities.CreateMacOSCarbonWindowInfo(windowHandle, ownHandle, isControl); } else if (Configuration.RunningOnX11) { IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle); int screen = Screen.Number; IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle); IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle); IntPtr visualInfo; if (graphicsMode.Index.HasValue) { XVisualInfo info = new XVisualInfo(); info.VisualID = graphicsMode.Index.Value; int dummy; visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); } else { visualInfo = GetVisualInfo(display); } windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo); XFree(visualInfo); } else { throw new PlatformNotSupportedException(); } // GraphicsContext graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags); graphicsContext.MakeCurrent(windowInfo); if (GraphicsContext.ShareContexts) { Interlocked.Increment(ref graphicsContextCount); if (!sharedContextInitialized) { sharedContextInitialized = true; ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } } else { ((IGraphicsContextInternal)graphicsContext).LoadAll(); OnGraphicsContextInitialized(); } OnInitialized(); } else { graphicsContext.MakeCurrent(windowInfo); } OnRenderFrame(); graphicsContext.SwapBuffers(); //base.OnExposeEvent(eventExpose); return(true); }
public void RenderFrameAndSwapBuffers(bool force = false) { graphicsContext.MakeCurrent(windowInfo); RenderFrame(force); graphicsContext.SwapBuffers(); }
private void BatchFileFormat(IFileFormat format, string fileName) { if (format == null) { return; } if (CancelOperation) { IsOperationActive = false; return; } //Add file to pipeline var modelRender = format as IRenderableFile; if (modelRender.Renderer.Models.Count == 0) { return; } modelRender.Renderer.ID = DataCache.ModelCache.Values.Count.ToString(); DataCache.ModelCache.Add(modelRender.Renderer.ID.ToString(), modelRender.Renderer); //Setup the camera var boundingSphere = modelRender.Renderer.BoundingSphere; Control.Camera.FrameBoundingSphere(boundingSphere); Control.Camera.RotationX = CameraRotationX * STMath.Deg2Rad; Control.Camera.RotationY = -CameraRotationY * STMath.Deg2Rad; Control.Camera.TargetDistance += CameraDistance; if (fileName.EndsWith("2D.szs")) { Control.Camera.RotationY = -90 * STMath.Deg2Rad; } else { Control.Camera.RotationY = 0; } Control.Camera.UpdateMatrices(); //Render out the file to the pipeline FBO Framebuffer.Bind(); GL.Viewport(0, 0, Control.Width, Control.Height); GL.ClearColor(0, 0, 0, 0); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); if (Control.UseSRBFrameBuffer) { GL.Enable(EnableCap.FramebufferSrgb); } modelRender.Renderer.DrawModel(Control, Pass.OPAQUE, Vector4.Zero); modelRender.Renderer.DrawModel(Control, Pass.TRANSPARENT, Vector4.Zero); GL.Flush(); Context.SwapBuffers(); string name = Path.GetFileNameWithoutExtension(fileName); name = PreventDuplicateNames(name); Framebuffer.ReadImagePixels(false).Save($"{OutputFolder}\\{name}.png"); Framebuffer.Unbind(); }
void RenderPass(Region dc, Size ReqSize) { renderTime.Start(); double w = ReqSize.width, h = ReqSize.height; // Resize the window Win32Util.Size w32Size = new Win32Util.Size((int)ReqSize.width, (int)ReqSize.height); Win32Util.SetWindowSize(w32Size, w32.handle); // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance) RenderSizeChanged(ReqSize); foreach (var tex in new int[] { _backRenderer.T2D_Draw, _backRenderer.T2D_Window }) { GL.BindTexture(TextureTarget.Texture2D, tex); // bind to texture, set things, GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)w, (int)h, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); GL.BindTexture(TextureTarget.Texture2D, 0);// unbind from texture } // bind to framebuffer, and bind its output to the texture GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, _backRenderer.FBO_Draw); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, _backRenderer.T2D_Draw, 0); // Alpha... GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); // set up ortho GL.Viewport(0, 0, (int)w, (int)h); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0.0, w, 0.0, h, 0.0, 1.0); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); // draw on fbo noForm.DrawBase(this, dc); rprocessor.ProcessRenderBuffer(_backRenderer.renderData); // Intermediate render to window buffer... GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, _backRenderer.FBO_Window); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, _backRenderer.T2D_Window, 0); // Alpha... GL.Disable(EnableCap.Blend); // we just want to emplace. // set up ortho GL.Viewport(0, 0, (int)w, (int)h); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0.0, w, 0.0, h, 0.0, 1.0); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); // Texture mapping... GL.Enable(EnableCap.Texture2D); // Draw the Color Texture - only parts of it!! GL.BindTexture(TextureTarget.Texture2D, _backRenderer.T2D_Draw); GL.Color4(1f, 1f, 1f, 1f); GL.Begin(PrimitiveType.Quads); foreach (var d in dc.AsRectangles()) { double fl = d.left / w; double fr = d.right / w; double ft = d.top / h; double fb = d.bottom / h; double l = d.left; double r = d.right; double t = d.top; double b = d.bottom; //FIXME lazy...use drawarrays GL.TexCoord2(fl, ft); GL.Vertex2(l, t); GL.TexCoord2(fr, ft); GL.Vertex2(r, t); GL.TexCoord2(fr, fb); GL.Vertex2(r, b); GL.TexCoord2(fl, fb); GL.Vertex2(l, b); } GL.End(); GL.BindTexture(TextureTarget.Texture2D, 0); // bind to window (FBO Zero!) GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); // Texture mapping... GL.Enable(EnableCap.Texture2D); // set up ortho GL.Viewport(0, 0, (int)w, (int)h); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(0.0, w, 0.0, h, 0.0, 1.0); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); GL.BindTexture(TextureTarget.Texture2D, _backRenderer.T2D_Window); GL.Color4(1f, 1f, 1f, 1f); GL.Disable(EnableCap.Blend); // we just want to emplace. //FIXME lazy also... GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0f, 1f); GL.Vertex2(0.0, 0.0); GL.TexCoord2(1f, 1f); GL.Vertex2(w, 0.0); GL.TexCoord2(1f, 0f); GL.Vertex2(w, h); GL.TexCoord2(0f, 0f); GL.Vertex2(0.0, h); GL.End(); GL.BindTexture(TextureTarget.Texture2D, 0); // Swap buffers on window FBO glContext.SwapBuffers(); lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds; renderTime.Reset(); }
unsafe void RenderImDrawData(DrawData *draw_data) { // Rendering int display_w, display_h; display_w = window.Width; display_h = window.Height; Vector4 clear_color = new Vector4(114f / 255f, 144f / 255f, 154f / 255f, 1.0f); GL.Viewport(0, 0, display_w, display_h); GL.ClearColor(clear_color.X, clear_color.Y, clear_color.Z, clear_color.W); GL.Clear(ClearBufferMask.ColorBufferBit); // We are using the OpenGL fixed pipeline to make the example code simpler to read! // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. int last_texture; GL.GetInteger(GetPName.TextureBinding2D, out last_texture); GL.PushAttrib(AttribMask.EnableBit | AttribMask.ColorBufferBit | AttribMask.TransformBit); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.ScissorTest); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.ColorArray); GL.Enable(EnableCap.Texture2D); GL.UseProgram(0); // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays) IO io = ImGui.GetIO(); ImGui.ScaleClipRects(draw_data, io.DisplayFramebufferScale); // Setup orthographic projection matrix GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Ortho( 0.0f, io.DisplaySize.X / io.DisplayFramebufferScale.X, io.DisplaySize.Y / io.DisplayFramebufferScale.Y, 0.0f, -1.0f, 1.0f); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); // Render command lists for (int n = 0; n < draw_data->CmdListsCount; n++) { NativeDrawList *cmd_list = draw_data->CmdLists[n]; byte * vtx_buffer = (byte *)cmd_list->VtxBuffer.Data; ushort * idx_buffer = (ushort *)cmd_list->IdxBuffer.Data; DrawVert vert0 = *((DrawVert *)vtx_buffer); DrawVert vert1 = *(((DrawVert *)vtx_buffer) + 1); DrawVert vert2 = *(((DrawVert *)vtx_buffer) + 2); GL.VertexPointer(2, VertexPointerType.Float, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.PosOffset)); GL.TexCoordPointer(2, TexCoordPointerType.Float, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.UVOffset)); GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(DrawVert), new IntPtr(vtx_buffer + DrawVert.ColOffset)); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { DrawCmd *pcmd = &(((DrawCmd *)cmd_list->CmdBuffer.Data)[cmd_i]); if (pcmd->UserCallback != IntPtr.Zero) { throw new NotImplementedException(); } else { GL.BindTexture(TextureTarget.Texture2D, pcmd->TextureId.ToInt32()); GL.Scissor( (int)pcmd->ClipRect.X, (int)(io.DisplaySize.Y - pcmd->ClipRect.W), (int)(pcmd->ClipRect.Z - pcmd->ClipRect.X), (int)(pcmd->ClipRect.W - pcmd->ClipRect.Y)); ushort[] indices = new ushort[pcmd->ElemCount]; for (int i = 0; i < indices.Length; i++) { indices[i] = idx_buffer[i]; } GL.DrawElements(PrimitiveType.Triangles, (int)pcmd->ElemCount, DrawElementsType.UnsignedShort, new IntPtr(idx_buffer)); } idx_buffer += pcmd->ElemCount; } } // Restore modified state GL.DisableClientState(ArrayCap.ColorArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.VertexArray); GL.BindTexture(TextureTarget.Texture2D, last_texture); GL.MatrixMode(MatrixMode.Modelview); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.PopAttrib(); gfxContext.SwapBuffers(); }
public void Present() { _nativeContext.SwapBuffers(); }