Forum > LCL

Flickering with TCustomControl using OpenGL to paint

(1/1)

deadbeef:
I'm trying to render to a panel like component which works but causes flicker everytime it is updated (e.g. calling Repaint), which is really bad when scrolling.
It seems like the default painting code is used and then the OpenGL code overrides it again.
Any idea how to fix this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit OpenGLPanel; {$mode Delphi} interface uses  Classes, SysUtils, Controls, Graphics, GR32, XVector, XMatrix, dglOpenGL, OpenGLContext;  type  TOpenGLPanel = class(TCustomControl)    strict private      var        FContext  : TOpenGLContext;        FGlColor  : TXVector;        FGlMatrix : TXMatrix;      protected      procedure   SetColor(Value: TColor); override;      procedure   Paint; override;     public      constructor Create(TheOwner: TComponent); override;      destructor  Destroy; override;      property    Context: TOpenGLContext read FContext;      property    Matrix : TXMatrix read FGlMatrix;    end;   implementation   constructor TOpenGLPanel.Create;var i: GLint;begin  inherited Create(TheOwner);   Parent          := TheOwner as TWinControl;   Visible         := True;  DoubleBuffered  := False; // True = does not render   BringToFront;   FContext        := TOpenGLContext.CreateCore3D(Handle, False, True);  FGlMatrix       := TXMatrix.CreateOrtho2D(0, Width, Height, 0);   FContext.EnableDebugToStdOut;end;  destructor TOpenGLPanel.Destroy;begin  FContext.Free;  inherited;end;  procedure TOpenGLPanel.Paint;begin  FContext.Activate;   FGlMatrix:= TXMatrix.CreateOrtho2D(0, Width, Height, 0);   glFrontFace(GL_CCW); // Y axis is flipped   glEnable(GL_CULL_FACE);  glCullFace(GL_BACK);   glViewport(0, 0, Width, Height);  glClearColor(FGlColor.X, FGlColor.Y, FGlColor.Z, FGlColor.W);  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT);   inherited;   FContext.SwapBuffer;end;  procedure TOpenGLPanel.SetColor;var c: TColor32Entry;begin  c       := TColor32Entry(Color32(Value));  FGlColor:= TXVector.Create(c.R, c.G, c.B, c.A) / TXVector.Create(255.0);  inherited;end;   end. 

Navigation

[0] Message Index

Go to full version