program SimpleDemo;

uses
  Windows,
  madVRTestPattern in '..\..\interfaces\madVRTestPattern.pas';

{$R *.res}

const
  GrayRamp : array [0..10] of array [0..2] of double =
    ( (0.0, 0.0, 0.0), (0.1, 0.1, 0.1), (0.2, 0.2, 0.2), (0.3, 0.3, 0.3),
      (0.4, 0.4, 0.4), (0.5, 0.5, 0.5), (0.6, 0.6, 0.6), (0.7, 0.7, 0.7),
      (0.8, 0.8, 0.8), (0.9, 0.9, 0.9), (1.0, 1.0, 1.0) );

procedure MeasureTestPattern;
begin
  // replace "Sleep()" with your measurement code
  Sleep(1000);
end;

var i1 : integer;
begin
  if not madVR_IsAvailable then
    MessageBox(0, 'madVR network dll not found.', 'Error', MB_ICONERROR)
  else
    if madVR_ConnectDialog then
    begin
      madVR_Disable3dlut();
      madVR_SetOsdText('measuring display, please wait...');
      madVR_SetBackground(22, $808080);
      madVR_ShowProgressBar(length(GrayRamp));
      for i1 := 0 to high(GrayRamp) do
      begin
        if not madVR_ShowRGB(GrayRamp[i1][0], GrayRamp[i1][1], GrayRamp[i1][2]) then
        begin
          MessageBox(0, 'Test pattern failure.', 'Error', MB_ICONERROR);
          break;
        end;
        // sleep a bit to work around display input latency
        Sleep(50);
        MeasureTestPattern;
      end;
      madVR_Disconnect;
    end;
end.
