fTilesC.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fTilesC.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.Graph"
  12. #pragma link "GLS.Material"
  13. #pragma link "GLS.Objects"
  14. #pragma link "GLS.Scene"
  15. #pragma link "GLS.TilePlane"
  16. #pragma link "GLS.SceneViewer"
  17. #pragma resource "*.dfm"
  18. TForm1* Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
  21. //---------------------------------------------------------------------------
  22. void __fastcall TForm1::FormCreate(TObject* Sender)
  23. {
  24. int i, j;
  25. TFileName Path = GetCurrentAssetPath();
  26. SetCurrentDir(Path + "\\texture");
  27. GLMaterialLibrary->TexturePaths = GetCurrentDir();
  28. GLMaterialLibrary->LibMaterialByName("beigemarble")
  29. ->Material->Texture->Image->LoadFromFile("beigemarble.jpg");
  30. GLMaterialLibrary->LibMaterialByName("marbletiles")
  31. ->Material->Texture->Image->LoadFromFile("marbletiles.jpg");
  32. GLMaterialLibrary->LibMaterialByName("walkway")
  33. ->Material->Texture->Image->LoadFromFile("walkway.jpg");
  34. // fill the tiled area with random tiles
  35. RandSeed = 0;
  36. for (int i = -20; i < 20; i++)
  37. for (int j = -20; j < 20; j++)
  38. GLTilePlane->Tiles[i][j] = Random(GLMaterialLibrary->Materials->Count - 1) + 1;
  39. // set all tile materials to anisotropic add them to the material selection combo
  40. for (i = 0; GLMaterialLibrary->Materials->Count - 1; i++) {
  41. GLMaterialLibrary->Materials->Items[i]
  42. ->Material->Texture->FilteringQuality = tfAnisotropic;
  43. CBMaterial->Items->Add(GLMaterialLibrary->Materials->Items[i]->Name);
  44. }
  45. CBMaterial->ItemIndex = 0;
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TForm1::FormMouseWheel(TObject *Sender, TShiftState Shift, int WheelDelta,
  49. TPoint &MousePos, bool &Handled)
  50. {
  51. GLCamera->AdjustDistanceToTarget(Power(1.1, WheelDelta / 120));
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::GLDirectOpenGLRender(TObject *Sender, TGLRenderContextInfo &rci)
  55. {
  56. // we clear the depth buffer, so that the grid is always in front of the
  57. // tile plane and won't Z-Fight with it
  58. glClear(GL_DEPTH_BUFFER_BIT);
  59. }
  60. //---------------------------------------------------------------------------