Search code examples
delphiopenglglscene

How to draw on a single GLSceneViewer using GLCanvas but not on all viewers?


I'm usually using TGLCanvas on GLDirectOpenGL1Render to draw lines like this:

uses
  GLCanvas,
  GLRenderContextInfo
{...}

procedure TForm1.GLDirectOpenGL1Render(Sender: TObject;
  var rci: TRenderContextInfo);
var
   glc: TGLCanvas;
begin
  glc:=TGLCanvas.Create(GLSceneViewerL.Width, GLSceneViewerL.Height);
  with glc do
  begin
    //Drawing lines here
    Line(0, 0, 10, 20);
    Line(10, 20, 30, 30);
    {...}
  end;
  glc.Free;
end;

But in current project I have more than one GLSceneViewer with different cameras and I need to draw lines only on one GLSceneViewer but not on all other scene viewers. OpenGl draw for fast speed is preffered. Any ideas?


Solution

  • Ok, after playing around with GLSceneViewer I figured out how to do it: instead of drawing lines on onRender event of GLDirectOpenGL1, you should draw lines on PostRender event of a necessary GLSceneViewer, so code should look like that:

    procedure TForm1.GLSceneViewerL(Sender: TObject);
    var
       glc : TGLCanvas;
    begin
        glc:=TGLCanvas.Create(GLSceneViewerL.Width, GLSceneViewerL.Height);
        with glc do
        begin
          //Drawing lines here
          Line(0, 0, 10, 20);
          Line(10, 20, 30, 30);
          {...}
        end;
        glc.Free;
    end;
    

    That's it, lines will be drawn exclusively on viewer with a "GLSceneViewerL" name, but not for all viewers of the scene.