Menu

SmallintRaster

Help
Daniel
2020-01-29
2020-02-04
  • Daniel

    Daniel - 2020-01-29

    Hello!

    I am trying to rebuild the demo from:
    / Examples / Terrains / TerrainLOD /

    But I get an error in this line:

      rasterLine := SmallintRaster[Y - YTop];
       for X := XLeft to XLeft + Size - 1 do
        rasterLine[X - XLeft] := map[X, Y] * 20;
    

    Error is: unit1.pas(80,37) Error: Incompatible types: got "TSmallIntRaster" expected "PSmallIntArray"

    Why would I get this error?

     

    Last edit: Daniel 2020-01-29
  • Jerome.D (BeanzMaster)

    Hi Daniel just need add ^ because is a pointer the char is needed under Lazarus

    procedure TfrmMain.GLCustomHDS1StartPreparingData(heightData: TGLHeightData);
    var
      rasterLine: GLHeightData.PSmallIntArray;
      b: SmallInt;
      X, Y: Integer;
    begin
    
      b := 128; // 128 = one unit
    
      heightData.DataState := hdsPreparing;
      with heightData do
      begin
        if (XLeft < 0) or (XLeft > cMapSize - 1) or (YTop < 0) or
          (YTop > cMapSize - 1) then
          heightData.DataState := hdsNone
        else
        begin
          Allocate(hdtSmallInt);
          for Y := YTop to YTop + Size - 1 do
          begin
            rasterLine := SmallIntRaster^[Y - YTop];
            for X := XLeft to XLeft + Size - 1 do
              rasterLine^[X - XLeft] := map[X, Y] * 20;
          end;
          DataState := hdsReady;
        end;
      end;
    end;      
    

    Replace also this code, is more fast

    procedure TfrmMain.LoadMap;
    var
      bmp: TBitmap;
      X, Y: Integer;
      PixPtr : PByte;
    begin
    
      // Load the image. It should be cMapsize and preferably grayscale.
      bmp := TBitmap.Create;
      bmp.LoadFromFile('terrain.bmp');
      for Y := 0 to cMapSize - 1 do
      begin
        PixPtr := bmp.RawImage.GetLineStart(y);
        for X := 0 to cMapSize - 1 do
        begin
          map[X, Y] := PixPtr^;
          inc(PixPtr, 3);
        end;
      end;
    
      bmp.Free;
    end;  
    
     
  • Daniel

    Daniel - 2020-01-30

    Works great!
    Thank you for taking the time to help me, Jerome!

    Cheers

     
  • Daniel

    Daniel - 2020-01-31

    Now I wonder how to update the terrain during runtime if I want to change the bmp?
    I tried this, but it doesn't work...

    procedure TForm1.Button1Click(Sender: TObject);
    var
    hds1: TGLCustomHDS;
    begin
      myHds1.Free; //current HDS
    
      hds1 := TGLCustomHDS.Create(form1);
      hds1.MaxPoolSize := 8 * 1024 * 1024;
      hds1.name := 'myHds1';
      terrain.HeightDataSource := myHds1;                                   
      loadMap;
      terrain.StructureChanged;
    
    end;               
    
     
  • Daniel

    Daniel - 2020-02-04

    MarkDirty did the trick!
    Cheers

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.