fCustomQuad.pas 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. unit fCustomQuad;
  2. interface
  3. uses
  4. Winapi.OpenGL,
  5. System.SysUtils,
  6. System.Classes,
  7. Vcl.Graphics,
  8. Vcl.Controls,
  9. Vcl.Forms,
  10. Vcl.Dialogs,
  11. Vcl.Imaging.Jpeg,
  12. GLS.Cadencer,
  13. GLS.Scene,
  14. GLS.Objects,
  15. GLS.Texture,
  16. GLS.Behaviours,
  17. GLS.SceneViewer,
  18. GLS.GeomObjects,
  19. GLS.Color,
  20. GLS.Material,
  21. GLS.Coordinates,
  22. GLS.BaseClasses,
  23. GLS.RenderContextInfo;
  24. type
  25. TFormCustomQuad = class(TForm)
  26. GLScene1: TGLScene;
  27. GLSceneViewer1: TGLSceneViewer;
  28. GLMaterialLibrary: TGLMaterialLibrary;
  29. GLCamera1: TGLCamera;
  30. DummyCube1: TGLDummyCube;
  31. Torus1: TGLTorus;
  32. DirectOpenGL1: TGLDirectOpenGL;
  33. GLLightSource1: TGLLightSource;
  34. GLCadencer1: TGLCadencer;
  35. procedure DirectOpenGL1Render(Sender: TObject;
  36. var rci: TGLRenderContextInfo);
  37. procedure FormCreate(Sender: TObject);
  38. private
  39. end;
  40. var
  41. FormCustomQuad: TFormCustomQuad;
  42. implementation
  43. {$R *.DFM}
  44. uses
  45. GLS.Context,
  46. GLS.State,
  47. GLS.Utils;
  48. procedure TFormCustomQuad.FormCreate(Sender: TObject);
  49. begin
  50. SetGLSceneMediaDir();
  51. // dynamically create 2 materials and load 2 textures
  52. with GLMaterialLibrary do
  53. begin
  54. AddTextureMaterial('wood', 'ashwood.jpg').Material.FrontProperties.Emission.
  55. Color := clrGray50;
  56. AddTextureMaterial('wood', 'ashwood.jpg').Material.FaceCulling := fcNoCull;
  57. AddTextureMaterial('stone', 'walkway.jpg').Material.FrontProperties.Emission.
  58. Color := clrGray50;
  59. AddTextureMaterial('stone', 'walkway.jpg').Material.FaceCulling := fcNoCull;
  60. end;
  61. end;
  62. procedure TFormCustomQuad.DirectOpenGL1Render(Sender: TObject;
  63. var rci: TGLRenderContextInfo);
  64. var
  65. Material: TGLLibMaterial;
  66. begin
  67. // 1st quad, textured with 'wood', using standard method
  68. GLMaterialLibrary.ApplyMaterial('wood', rci);
  69. glBegin(GL_QUADS);
  70. glTexCoord2f(0, 1);
  71. glVertex3f(0.5, 0.5, -0.5);
  72. glTexCoord2f(0, 0);
  73. glVertex3f(-0.5, 0.5, -0.5);
  74. glTexCoord2f(1, 0);
  75. glVertex3f(-0.5, 0, 0.5);
  76. glTexCoord2f(1, 1);
  77. glVertex3f(0.5, 0, 0.5);
  78. glEnd;
  79. GLMaterialLibrary.UnApplyMaterial(rci);
  80. // 2nd quad, textured with 'stone'
  81. // we "manually" apply the material, this can be usefull if you want to have
  82. // some dynamic material control
  83. Material := GLMaterialLibrary.Materials.GetLibMaterialByName('stone');
  84. Material.Material.Apply(rci);
  85. glBegin(GL_QUADS);
  86. glTexCoord2f(0, 1);
  87. glVertex3f(0.5, -0.5, -0.5);
  88. glTexCoord2f(0, 0);
  89. glVertex3f(0.5, 0, 0.5);
  90. glTexCoord2f(1, 0);
  91. glVertex3f(-0.5, 0, 0.5);
  92. glTexCoord2f(1, 1);
  93. glVertex3f(-0.5, -0.5, -0.5);
  94. glEnd;
  95. Material.Material.UnApply(rci);
  96. end;
  97. end.