{**********************************************}
{      TeeOpenGL Editor Component              }
{   Copyright (c) 1999-2020 by Steema Software }
{         All Rights Reserved                  }
{**********************************************}
unit TeeGLEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  {$IFDEF D17}
  System.Types,
  {$ENDIF}

  Graphics, Controls, Forms, Dialogs, ComCtrls, ExtCtrls, StdCtrls,

  TeeOpenGL, TeCanvas, TeeProcs, TeePenDlg, TeeGLCanvas;

type
  TTeeOpenGLBackup=packed record
    Active        : Boolean;
    AmbientLight  : Integer;
    FontOutlines  : Boolean;
    LightColor    : TColor;
    LightVisible  : Boolean;
    LightX        : Double;
    LightY        : Double;
    LightZ        : Double;
    ShadeQuality  : Boolean;
    Shininess     : Double;
    FontExtrusion : Double;
    DrawStyle     : TTeeCanvasSurfaceStyle;
    Tilt          : Integer;
  end;

  TFormTeeGLEditor = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    BOK: TButton;
    BCancel: TButton;
    PageControl2: TPageControl;
    PanelActive: TPanel;
    CBActive: TCheckBox;
    TabOptions: TTabSheet;
    TabSheet6: TTabSheet;
    TabLighting: TTabSheet;
    CBFontStyle: TComboFlat;
    Label8: TLabel;
    EFontDepth: TEdit;
    Label17: TLabel;
    TabLights: TTabControl;
    PageControlLight: TPageControl;
    TabLightPos: TTabSheet;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    LightPosX: TLabel;
    LightPosY: TLabel;
    LightPosZ: TLabel;
    TBX: TTrackBar;
    TBY: TTrackBar;
    TBZ: TTrackBar;
    CBFixed: TCheckBox;
    TabLightDir: TTabSheet;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    TBXDirection: TTrackBar;
    TBYDirection: TTrackBar;
    TBZDirection: TTrackBar;
    CBUseDirection: TCheckBox;
    TabLightAmount: TTabSheet;
    Label10: TLabel;
    Label14: TLabel;
    TBDiffuse: TTrackBar;
    TBSpecular: TTrackBar;
    TabLightSpot: TTabSheet;
    Label9: TLabel;
    Label16: TLabel;
    UDSpot: TUpDown;
    ESpot: TEdit;
    CBDefaultSpot: TCheckBox;
    TBSpotExp: TTrackBar;
    Panel3: TPanel;
    Label7: TLabel;
    CBVisible: TCheckBox;
    BLightColor: TButtonColor;
    TBColor: TTrackBar;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label15: TLabel;
    CBShade: TCheckBox;
    TBAmbient: TTrackBar;
    TBShine: TTrackBar;
    CBStyle: TComboFlat;
    CBAntialias: TCheckBox;
    SBTilt: TScrollBar;
    CBTextureQuality: TCheckBox;
    TabSheet5: TTabSheet;
    MemoInfo: TMemo;
    CBSync: TCheckBox;
    CBLightHelpers: TCheckBox;
    LightDirX: TLabel;
    LightDirY: TLabel;
    LightDirZ: TLabel;
    procedure BOKClick(Sender: TObject);
    procedure CBShadeClick(Sender: TObject);
    procedure EFontDepthChange(Sender: TObject);
    procedure TBShineChange(Sender: TObject);
    procedure TBAmbientChange(Sender: TObject);
    procedure CBActiveClick(Sender: TObject);
    procedure CBVisibleClick(Sender: TObject);
    procedure TBColorChange(Sender: TObject);
    procedure TBXChange(Sender: TObject);
    procedure TBYChange(Sender: TObject);
    procedure TBZChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TabLightsChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure CBFixedClick(Sender: TObject);
    procedure BLightColorClick(Sender: TObject);
    procedure ESpotChange(Sender: TObject);
    procedure TBXDirectionChange(Sender: TObject);
    procedure TBYDirectionChange(Sender: TObject);
    procedure TBZDirectionChange(Sender: TObject);
    procedure CBUseDirectionClick(Sender: TObject);
    procedure CBDefaultSpotClick(Sender: TObject);
    procedure CBAntialiasClick(Sender: TObject);
    procedure SBTiltChange(Sender: TObject);
    procedure TBDiffuseChange(Sender: TObject);
    procedure TBSpecularChange(Sender: TObject);
    procedure TBSpotExpChange(Sender: TObject);
    procedure CBTextureQualityClick(Sender: TObject);
    procedure CBFontStyleChange(Sender: TObject);
    procedure CBSyncClick(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure CBLightHelpersClick(Sender: TObject);
  private
    { Private declarations }
    CreatingForm : Boolean;
    IRefreshingLight : Boolean;

    GL           : TTeeOpenGL;
    GLBackup     : TTeeOpenGLBackup;
    GLCanvas     : TGLCanvas;

    procedure RefreshGLCanvas;
    procedure RefreshInfo;
    Procedure SetLight(const ALight:TGLLightSource);

    function TheLight:TGLLightSource;
  public

    { Public declarations }
    procedure RefreshOpenGL(const AOpenGL:TTeeOpenGL);
  end;

Function EditTeeOpenGL(const AOwner:TComponent; const ATeeOpenGL:TTeeOpenGL):Boolean;

implementation

{$IFNDEF LCL}
{$ELSE}
{$R *.lfm}
{$ENDIF}
{$R *.DFM}

Uses
  TeeEditCha, OpenGL2;

Function EditTeeOpenGL(const AOwner:TComponent; const ATeeOpenGL:TTeeOpenGL):Boolean;
begin
  With TFormTeeGLEditor.Create(AOwner) do
  try
    Tag:=ObjectToTag(ATeeOpenGL);
    result:=ShowModal=mrOk;
  finally
    Free;
  end
end;

procedure TFormTeeGLEditor.BOKClick(Sender: TObject);
begin
  ModalResult:=mrOk;
end;

procedure TFormTeeGLEditor.CBShadeClick(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.ShadeQuality:=CBShade.Checked
     else
     if Assigned(GLCanvas) then
     begin
       GLCanvas.ShadeQuality:=CBShade.Checked;
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.EFontDepthChange(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.FontExtrusion:=StrToFloatDef(EFontDepth.Text,GL.FontExtrusion)
     else
     if Assigned(GLCanvas) then
        GLCanvas.FontExtrusion:=StrToFloatDef(EFontDepth.Text,GLCanvas.FontExtrusion);
end;

procedure TFormTeeGLEditor.TBShineChange(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.Shininess:=TBShine.Position*0.01
     else
     if Assigned(GLCanvas) then
     begin
       GLCanvas.Shininess:=TBShine.Position*0.01;
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.TBAmbientChange(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.AmbientLight:=TBAmbient.Position
     else
     if Assigned(GLCanvas) then
     begin
       GLCanvas.AmbientLight:=TBAmbient.Position;
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.CBActiveClick(Sender: TObject);
begin
  if not CreatingForm then
  begin
    GL.Active:=CBActive.Checked;

    CBSync.Enabled:=CBActive.Checked;

    RefreshInfo;
  end;
end;

procedure TFormTeeGLEditor.RefreshInfo;
begin
  if Assigned(glGetString) then
  begin
    MemoInfo.Clear;
    MemoInfo.Lines.Add(String(PAnsiChar(glGetString(GL_RENDERER))));
    MemoInfo.Lines.Add(String(PAnsiChar(glGetString(GL_VENDOR))));
    MemoInfo.Lines.Add(String(PAnsiChar(glGetString(GL_VERSION))));
  end
  else
     MemoInfo.Text:='(OpenGL not loaded)';
end;

function TFormTeeGLEditor.TheLight:TGLLightSource;
begin
  result:=GL.Lights[TabLights.TabIndex];
end;

procedure TFormTeeGLEditor.CBVisibleClick(Sender: TObject);
begin
  if not CreatingForm then TheLight.Visible:=CBVisible.Checked;
end;

procedure TFormTeeGLEditor.TBColorChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    with TBColor do
         TheLight.Color:=RGB(Position,Position,Position);

    BLightColor.Repaint;
  end;
end;

procedure TFormTeeGLEditor.TBXChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Position.X:=TBX.Position;
    LightPosX.Caption:=IntToStr(TBX.Position);
  end;
end;

procedure TFormTeeGLEditor.TBYChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Position.Y:=TBY.Position;
    LightPosY.Caption:=IntToStr(TBY.Position);
  end;
end;

procedure TFormTeeGLEditor.TBZChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Position.Z:=TBZ.Position;
    LightPosZ.Caption:=IntToStr(TBZ.Position);
  end;
end;

procedure TFormTeeGLEditor.RefreshGLCanvas;
begin
  CreatingForm:=True;

  if Assigned(GLCanvas) then
  with GLCanvas do
  try
    CBShade.Checked:=ShadeQuality;
    CBFontStyle.ItemIndex:=Ord(FontStyle);
    CBStyle.ItemIndex:=Ord(DrawStyle);
    EFontDepth.Text:=FloatToStr(FontExtrusion);
    TBShine.Position:=Round(Shininess*100.0);
    TBAmbient.Position:=AmbientLight;
    SBTilt.Position:=View3DOptions.Tilt;
    CBTextureQuality.Checked:=TextureQuality;

    CBSync.Enabled:=(ScreenSync<>ssSystem);
    CBSync.Checked:=(ScreenSync=ssYes);
  finally
    CreatingForm:=False;
  end;
end;

type
  TTeeOpenGLAccess=class(TTeeOpenGL);

procedure TFormTeeGLEditor.RefreshOpenGL(const AOpenGL:TTeeOpenGL);
begin
  GL:=AOpenGL;

  CreatingForm:=True;

  With GL do
  begin
    CBShade.Checked:=ShadeQuality;

    if Canvas<>nil then
    begin
      CBFontStyle.ItemIndex:=Ord(Canvas.FontStyle);

      CBSync.Enabled:=(Canvas.ScreenSync<>ssSystem);
      CBSync.Checked:=(Canvas.ScreenSync=ssYes);
    end
    else
    if FontOutlines then
       CBFontStyle.ItemIndex:=1
    else
       CBFontStyle.ItemIndex:=0;

    CBStyle.ItemIndex:=Ord(DrawStyle);
    EFontDepth.Text:=FloatToStr(FontExtrusion);
    TBShine.Position:=Round(Shininess*100.0);
    TBAmbient.Position:=AmbientLight;

    CBActive.Checked:=Active;
    PanelActive.Visible:=not TTeeOpenGLAccess(GL).IAlwaysActive;

    CBAntialias.Checked:=Antialias;

    if Assigned(TeePanel) then
       SBTilt.Position:=TeePanel.View3DOptions.Tilt;

    CBTextureQuality.Checked:=TextureQuality;

    CBLightHelpers.Checked:=LightHelpers;

    while TabLights.Tabs.Count>Lights.Count do
          TabLights.Tabs.Delete(TabLights.Tabs.Count-1);

    SetLight(Light0);

    GLBackup.ShadeQuality:=ShadeQuality;
    GLBackup.FontOutlines:=FontOutlines;
    GLBackup.DrawStyle:=DrawStyle;
    GLBackup.FontExtrusion:=FontExtrusion;
    GLBackup.Shininess:=Shininess;
    GLBackup.AmbientLight:=AmbientLight;
    GLBackup.Active:=Active;

    if Assigned(TeePanel) then
       GLBackup.Tilt:=TeePanel.View3DOptions.Tilt;
  end;

  if Assigned(Parent) and (not (Parent is TCustomForm)) then
     Panel1.Visible:=False;

  CreatingForm:=False;
end;

type
  TTeePanelAccess=class(TCustomTeePanel);

procedure TFormTeeGLEditor.FormShow(Sender: TObject);
var tmp : TObject;
begin
  if not Assigned(GL) then
  begin
    tmp:=TObject(Tag);

    if tmp is TTeeOpenGL then
       GL:=TTeeOpenGL(Tag)
    else
    if tmp is TGLCanvas then
    begin
      GLCanvas:=TGLCanvas(tmp);

      GL:=TTeeOpenGL(TTeePanelAccess(
            GLCanvas.View3DOptions.Parent as TCustomTeePanel).GLComponent);
    end;
  end;

  if Assigned(GL) then
     RefreshOpenGL(GL)
  else
  begin
    TabLighting.TabVisible:=False;
    TabLights.Hide;
    PanelActive.Hide;

    RefreshGLCanvas;
  end;

  if Assigned(Parent) then
     Panel1.Visible:=False;

  CreatingForm:=False;
end;

Procedure TFormTeeGLEditor.SetLight(const ALight:TGLLightSource);
begin
  IRefreshingLight:=True;

  CBVisible.Checked:=ALight.Visible;
  CBFixed.Checked:=ALight.FixedPosition;
  CBUseDirection.Checked:=ALight.UseDirection;

  TBColor.Position:=GetRValue(ALight.Color);
  TBDiffuse.Position:=GetRValue(ALight.Diffuse);
  TBSpecular.Position:=GetRValue(ALight.Specular);

  with ALight.Position.AsRound do
  begin
    TBX.Position:=X;
    TBY.Position:=Y;
    TBZ.Position:=Z;

    LightPosX.Caption:=IntToStr(TBX.Position);
    LightPosY.Caption:=IntToStr(TBY.Position);
    LightPosZ.Caption:=IntToStr(TBZ.Position);
  end;

  with ALight.Direction do
  begin
    TBXDirection.Position:=Round(180.0*(X+1));
    TBYDirection.Position:=Round(180.0*(Y+1));
    TBZDirection.Position:=Round(180.0*(Z+1));

    LightDirX.Caption:=FormatFloat('0.##',X);
    LightDirY.Caption:=FormatFloat('0.##',Y);
    LightDirZ.Caption:=FormatFloat('0.##',Z);
  end;

  BLightColor.LinkProperty(ALight,'Color'); // Do not localize

  GLBackup.LightVisible:=ALight.Visible;
  GLBackup.LightColor:=ALight.Color;

  with ALight.Position do
  begin
    GLBackup.LightX:=X;
    GLBackup.LightY:=Y;
    GLBackup.LightZ:=Z;
  end;

  CBDefaultSpot.Checked:=ALight.SpotDegrees=180;

  if CBDefaultSpot.Checked then
     UDSpot.Position:=0
  else
     UDSpot.Position:=Round(ALight.SpotDegrees);

  TBSpotExp.Position:=ALight.SpotExponent;

  EnableControls(not CBDefaultSpot.Checked,[ESpot,UDSpot]);

  IRefreshingLight:=False;
end;

procedure TFormTeeGLEditor.BCancelClick(Sender: TObject);
begin
  With GL do
  begin
    ShadeQuality:=GLBackup.ShadeQuality;
    FontOutlines:=GLBackup.FontOutlines;
    DrawStyle:=GLBackup.DrawStyle;
    FontExtrusion:=GLBackup.FontExtrusion;

    Shininess     :=GLBackup.Shininess;
    AmbientLight  :=GLBackup.AmbientLight;
    Active        :=GLBackup.Active;

    if Assigned(TeePanel) then
       TeePanel.View3DOptions.Tilt:=GLBackup.Tilt;

    With TheLight do
    begin
      Visible:=GLBackup.LightVisible;
      Color  :=GLBackup.LightColor;

      with Position do
      begin
        X:=GLBackup.LightX;
        Y:=GLBackup.LightY;
        Z:=GLBackup.LightZ;
      end;
    end;
  end;

  ModalResult:=mrCancel;
end;

procedure TFormTeeGLEditor.FormCreate(Sender: TObject);
var t : Integer;
begin
  CreatingForm:=True;
  BorderStyle:=TeeBorderStyle;

  PageControl2.ActivePage:=TabOptions;
  PageControlLight.ActivePage:=TabLightPos;

  InitOpenGL;
  RefreshInfo;

  TabLights.Tabs.Clear;

  for t:=0 to 7 do
      TabLights.Tabs.Add('Light '+IntToStr(t)); // <--- dont translate

  TeeTranslateControl(Self);
end;

Procedure TeeOpenGLShowEditor(AOwner:TComponent; APanel:TCustomTeePanel;
                              ATab:TTabSheet; APageControl:TPageControl);
const
  TeeMsg_OpenGL='OpenGL'; // Do not localize

var tmpForm : TFormTeeGLEditor;
    tmpGL   : TComponent;

    {$IFDEF TEEOCX}
    tmpHidden : TChartEditorHiddenTabs;
    {$ENDIF}
begin
  if Assigned(APanel) then
  begin
    tmpGL:=TTeePanelAccess(APanel).GLComponent;

    {$IFDEF TEEOCX}
    if AOwner is TChartEditForm then
       tmpHidden:=TChartEditForm(AOwner).TheHiddenTabs
    else
       tmpHidden:=[];
    {$ENDIF}

    if Assigned(tmpGL)
       {$IFDEF TEEOCX}
       and
        ( (not (cetOpenGL in tmpHidden)) or
          ( (cetOpenGL in tmpHidden) and TTeeOpenGL(tmpGL).Active )
        )
        {$ENDIF}
        then
    begin
      if not Assigned(ATab) then
      begin
        ATab:=TTabSheet.Create(AOwner);
        ATab.Caption:=TeeMsg_OpenGL;
        ATab.PageControl:=APageControl;
      end
      else
      if (ATab.ControlCount=0) and (ATab.Caption=TeeMsg_OpenGL) then
      begin
        tmpForm:=TFormTeeGLEditor.Create(AOwner);
        tmpForm.Align:=alClient;
        tmpForm.Panel1.Visible:=False;

        tmpForm.CBActive.Checked:=TTeeOpenGL(tmpGL).Active;

        {$IFDEF TEEOCX}
        if (cetOpenGL in tmpHidden) and TTeeOpenGL(tmpGL).Active then
           tmpForm.PanelActive.Visible:=False;
        {$ENDIF}

        AddFormTo(tmpForm,ATab,TTeeOpenGL(tmpGL));
      end;
    end;
  end;
end;

procedure TFormTeeGLEditor.TabLightsChange(Sender: TObject);
begin
  SetLight(TheLight);
end;

procedure TFormTeeGLEditor.CBStyleChange(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.DrawStyle:=TTeeCanvasSurfaceStyle(CBStyle.ItemIndex)
     else
     if Assigned(GLCanvas) then
     begin
       GLCanvas.DrawStyle:=TTeeCanvasSurfaceStyle(CBStyle.ItemIndex);
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.CBFixedClick(Sender: TObject);
begin
  if not CreatingForm then
     TheLight.FixedPosition:=CBFixed.Checked;
end;

procedure TFormTeeGLEditor.BLightColorClick(Sender: TObject);
begin
  TBColor.Position:=GetRValue(TheLight.Color);
end;

procedure TFormTeeGLEditor.ESpotChange(Sender: TObject);
begin
  if not CreatingForm then
  if not IRefreshingLight then
     if UDSpot.Enabled then
        TheLight.SpotDegrees:=UDSpot.Position;
end;

procedure TFormTeeGLEditor.TBXDirectionChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Direction.X:=(TBXDirection.Position/180)-1;
    LightDirX.Caption:=FormatFloat('0.##',TheLight.Direction.X);
  end;
end;

procedure TFormTeeGLEditor.TBYDirectionChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Direction.Y:=(TBYDirection.Position/180)-1;
    LightDirY.Caption:=FormatFloat('0.##',TheLight.Direction.Y);
  end;
end;

procedure TFormTeeGLEditor.TBZDirectionChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    TheLight.Direction.Z:=(TBZDirection.Position/180)-1;
    LightDirZ.Caption:=FormatFloat('0.##',TheLight.Direction.Z);
  end;
end;

procedure TFormTeeGLEditor.CBUseDirectionClick(Sender: TObject);
begin
  if not CreatingForm then
     TheLight.UseDirection:=CBUseDirection.Checked;
end;

procedure TFormTeeGLEditor.CBDefaultSpotClick(Sender: TObject);
begin
  if not CreatingForm then
  if not IRefreshingLight then
  begin
    EnableControls(not CBDefaultSpot.Checked,[ESpot,UDSpot]);

    if CBDefaultSpot.Checked then
       TheLight.SpotDegrees:=180
    else
       ESpotChange(Self);
  end;
end;

type
  TGLCanvasAccess=class(TGLCanvas);

procedure TFormTeeGLEditor.CBAntialiasClick(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.Antialias:=CBAntialias.Checked
     else
     if Assigned(GLCanvas) then
     begin
       TGLCanvasAccess(GLCanvas).SetAntiAlias(CBAntiAlias.Checked);
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.SBTiltChange(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) and Assigned(GL.TeePanel) then
        GL.TeePanel.View3DOptions.Tilt:=SBTilt.Position
     else
     if Assigned(GLCanvas) then
        GLCanvas.View3DOptions.Tilt:=SBTilt.Position;
end;

procedure TFormTeeGLEditor.TBDiffuseChange(Sender: TObject);
begin
  if not CreatingForm then
  with TBDiffuse do
       TheLight.Diffuse:=RGB(Position,Position,Position);
end;

procedure TFormTeeGLEditor.TBSpecularChange(Sender: TObject);
begin
  if not CreatingForm then
  with TBSpecular do
       TheLight.Specular:=RGB(Position,Position,Position);
end;

procedure TFormTeeGLEditor.TBSpotExpChange(Sender: TObject);
begin
  if not CreatingForm then
  if not IRefreshingLight then
     TheLight.SpotExponent:=TBSpotExp.Position;
end;

procedure TFormTeeGLEditor.CBTextureQualityClick(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.TextureQuality:=CBTextureQuality.Checked
     else
     if Assigned(GLCanvas) then
     begin
       GLCanvas.TextureQuality:=CBTextureQuality.Checked;
       GLCanvas.Repaint;
     end;
end;

procedure TFormTeeGLEditor.CBFontStyleChange(Sender: TObject);

  procedure SetCanvasFontStyle(ACanvas:TGLCanvas);
  begin
    if Assigned(ACanvas) then
    begin
      ACanvas.FontStyle:=TTeeFontStyle(CBFontStyle.ItemIndex);
      ACanvas.Repaint;
    end;
  end;

begin
  if not CreatingForm then
     if Assigned(GL) then
     begin
       GL.FontOutlines:=(CBFontStyle.ItemIndex=1);
       SetCanvasFontStyle(GL.Canvas);
     end
     else
     if Assigned(GLCanvas) then
        SetCanvasFontStyle(GLCanvas);
end;

procedure TFormTeeGLEditor.CBSyncClick(Sender: TObject);
var tmp : TGLScreenSync;
begin
  if CBSync.Checked then
     tmp:=ssYes
  else
     tmp:=ssNo;

  if Assigned(GL) then
     GL.Canvas.ScreenSync:=tmp
  else
     GLCanvas.ScreenSync:=tmp;
end;

procedure InstallHook;
begin
  TeeOnShowEditor.Add(@TeeOpenGLShowEditor);
end;

procedure RemoveHook;
begin
  TeeOnShowEditor.Remove(@TeeOpenGLShowEditor);
end;

procedure TFormTeeGLEditor.PageControl2Change(Sender: TObject);
begin
  // Just in case, try to refresh.
  // Needed if we loaded the OpenGL dlls after showing this Info tab.
  RefreshInfo;
end;

procedure TFormTeeGLEditor.CBLightHelpersClick(Sender: TObject);
begin
  if not CreatingForm then
     if Assigned(GL) then
        GL.LightHelpers:=CBLightHelpers.Checked;
end;

initialization
  RegisterClass(TFormTeeGLEditor);
  InstallHook;
finalization
  RemoveHook;
end.
