unit uMaterials;

interface

uses
  Windows, uGlobal;

const
  Wireframe = false;
  TextureCompression = tcHighSpeed;

procedure LoadMaterials;
procedure LoadPFX;

implementation

procedure LoadMaterials;
var
  Material: integer;
begin
  call('glShaderAdd', [stCelShader, 'CelShader1']);
  call('glShaderParams', ['CelShader1', 3]);
  call('glShaderAdd', [stCelShader, 'CelShader_ground']);
  call('glShaderParams', ['CelShader_ground', 2]);

  //=================== GUI =====================
  Material:=call('glMaterialAdd',['cross']);
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'data\gui\cross.tga']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialBlendingMode', [Material, bmTransparency]);
  call('glMaterialTextureAlpha', [Material, tiaSuperBlackTransparent]);
  Call('glMaterialTextureMode', [Material, tmBlend]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);    
  
  Material:=call('glMaterialAdd',['icon_saloon']);
  Call('glMaterialTextureLoad', [Material, 'data\gui\icons\dialog.tga']);
  call('glMaterialBlendingMode', [Material, bmTransparency]);
  call('glMaterialTextureAlpha', [Material, tiaSuperBlackTransparent]);
  Call('glMaterialTextureMode', [Material, tmBlend]);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialColor', [Material, mfFront, mcDiffuse, 1,1,1,0.5]);
  call('glMaterialColor', [Material, mfFront, mcEmission, 1,1,1,0.5]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);

  Material:=call('glMaterialAdd',['icon_jail']);
  Call('glMaterialTextureLoad', [Material, 'data\gui\icons\jail.tga']);
  call('glMaterialBlendingMode', [Material, bmTransparency]);
  call('glMaterialTextureAlpha', [Material, tiaSuperBlackTransparent]);
  Call('glMaterialTextureMode', [Material, tmBlend]);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialColor', [Material, mfFront, mcDiffuse, 1,1,1,0.5]);
  call('glMaterialColor', [Material, mfFront, mcEmission, 1,1,1,0.5]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);

  //=================== Ground =====================
  Material:=call('glMaterialAdd',['ground_sand']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'data\gfx\enviroment\sand.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmReplace]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);
  call('glMaterialShader', [Material, 'CelShader_ground']);

  Material:=call('glMaterialAdd',['ground_dirt']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\enviroment\dirt.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);

  //=================== buildings =====================
  Material:=call('glMaterialAdd',['wall_wood']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\wood.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);   
  call('glMaterialShader', [Material, 'CelShader1']);
  
  Material:=call('glMaterialAdd',['wall_stone']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\brick.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);   
  call('glMaterialShader', [Material, 'CelShader1']);

    
  Material:=call('glMaterialAdd',['wall_brick']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\redbrick.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);   
  call('glMaterialShader', [Material, 'CelShader1']);

  Material:=call('glMaterialAdd',['signboard_saloon']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  Call('glMaterialTextureLoad', [Material, 'data\gfx\signboards\saloon.tga']);
  call('glMaterialBlendingMode', [Material, bmTransparency]);
  call('glMaterialTextureAlpha', [Material, tiaTopLeftPointColorTransparent]);
  Call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureEnable', [Material, true]); 
  call('glMaterialColor', [Material, mfFront, mcAmbient, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcSpecular, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcDiffuse, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcEmission, 1,1,1,1]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);


  Material:=call('glMaterialAdd',['signboard_jail']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  Call('glMaterialTextureLoad', [Material, 'data\gfx\signboards\jail.tga']);
  call('glMaterialBlendingMode', [Material, bmTransparency]);
  call('glMaterialTextureAlpha', [Material, tiaTopLeftPointColorTransparent]);
  Call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureEnable', [Material, true]); 
  call('glMaterialColor', [Material, mfFront, mcAmbient, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcSpecular, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcDiffuse, 1,1,1,1]);
  call('glMaterialColor', [Material, mfFront, mcEmission, 1,1,1,1]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);

  Material:=call('glMaterialAdd',['metal']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\metal.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);
  call('glMaterialShader', [Material, 'CelShader1']);

  Material:=call('glMaterialAdd',['house_body']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\body.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);
  call('glMaterialShader', [Material, 'CelShader1']);

  //=================== Plants =====================
  Material:=call('glMaterialAdd',['plants_cactus']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\enviroment\plant.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);
  call('glMaterialShader', [Material, 'CelShader1']);


  //=================== Weapons =====================
  Material:=call('glMaterialAdd',['machine_gun']);
  if Wireframe then
  begin
    Call('glMaterialPolygonMode', [Material, mfFront, pmLines]);
    Call('glMaterialPolygonMode', [Material, mfBack, pmLines]);
  end;
  call('glMaterialColor', [material, mfFront, mcAmbient, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcDiffuse, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcEmission, 0.5, 0.5, 0.5, 1]);
  call('glMaterialColor', [material, mfFront, mcSpecular, 0.5, 0.5, 0.5, 1]);
  Call('glMaterialTextureLoad', [Material, 'Data\gfx\buildings\metal.jpg']);
  call('glMaterialTextureEnable', [Material, true]);
  call('glMaterialTextureMode', [Material, tmModulate]);
  call('glMaterialTextureCompression', [Material, TextureCompression]);
  call('glMaterialShader', [Material, 'CelShader1']);
end;

procedure LoadPFX;
var
  pfx: integer;
begin
  pfx:=call('pfxAdd',['sand']);
  call('pfxParticleSize', [pfx, 7]);
  call('pfxParticleColor',[pfx, 0.7,0.6,0.5, 0.2,0.5,0.4,0.1, 0.1 ]);
  call('pfxFriction', [pfx, 0.1]);
  call('pfxAcceleration', [pfx, 0,0.05,0]);

  pfx:=call('pfxAdd',['smoke']);
  call('pfxParticleSize', [pfx, 1]);
  call('pfxParticleColor',[pfx, 0.2,0.2,0.2, 0.4,0.1,0.1,0.1, 0.1 ]);
  call('pfxFriction', [pfx, 4]);
  call('pfxAcceleration', [pfx, 0,1,0]);
end;

end.
