fCustomQuadD.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. unit fCustomQuadD;
  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. MatLib: 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. Material: TGLLibMaterial;
  40. end;
  41. var
  42. FormCustomQuad: TFormCustomQuad;
  43. implementation
  44. {$R *.DFM}
  45. uses
  46. GLS.Context,
  47. GLS.State,
  48. GLScene.Utils;
  49. procedure TFormCustomQuad.FormCreate(Sender: TObject);
  50. begin
  51. var Path: TFileName := GetCurrentAssetPath();
  52. SetCurrentDir(Path + '\texture');
  53. // dynamically create 2 materials and load 2 textures
  54. MatLib.AddTextureMaterial('wood', 'ashwood.jpg').
  55. Material.FrontProperties.Emission.Color := clrGray50;
  56. MatLib.AddTextureMaterial('wood', 'ashwood.jpg').
  57. Material.FaceCulling := fcNoCull;
  58. MatLib.AddTextureMaterial('grass', 'grass.jpg').
  59. Material.FrontProperties.Emission.Color := clrGray50;
  60. MatLib.AddTextureMaterial('grass', 'grass.jpg').
  61. Material.FaceCulling := fcNoCull;
  62. Torus1.Material.Texture.Disabled := False;
  63. Torus1.Material.Texture.Image.LoadFromFile('walkway.jpg');
  64. end;
  65. procedure TFormCustomQuad.DirectOpenGL1Render(Sender: TObject;
  66. var rci: TGLRenderContextInfo);
  67. begin
  68. glDisable(GL_CULL_FACE);
  69. // 1st quad, textured with 'wood', using standard method
  70. MatLib.ApplyMaterial('wood', rci);
  71. glBegin(GL_QUADS);
  72. glTexCoord2f(0, 1);
  73. glVertex3f(0.5, 0.5, -0.5);
  74. glTexCoord2f(0, 0);
  75. glVertex3f(-0.5, 0.5, -0.5);
  76. glTexCoord2f(1, 0);
  77. glVertex3f(-0.5, 0, 0.5);
  78. glTexCoord2f(1, 1);
  79. glVertex3f(0.5, 0, 0.5);
  80. glEnd;
  81. MatLib.UnApplyMaterial(rci);
  82. // 2nd quad, textured with 'grass'
  83. // we could apply the material "manually", but this can be usefull if you want to have
  84. // some dynamic material control
  85. MatLib.ApplyMaterial('grass', rci);
  86. glBegin(GL_QUADS);
  87. glTexCoord2f(0, 1);
  88. glVertex3f(0.5, -0.5, -0.5);
  89. glTexCoord2f(0, 0);
  90. glVertex3f(0.5, 0, 0.5);
  91. glTexCoord2f(1, 0);
  92. glVertex3f(-0.5, 0, 0.5);
  93. glTexCoord2f(1, 1);
  94. glVertex3f(-0.5, -0.5, -0.5);
  95. glEnd;
  96. MatLib.UnApplyMaterial(rci);
  97. glEnable(GL_CULL_FACE);
  98. end;
  99. end.