fCustomQuadC.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include "fCustomQuadC.h"
  4. // ---------------------------------------------------------------------------
  5. #pragma package(smart_init)
  6. #pragma link "GLS.BaseClasses"
  7. #pragma link "GLS.Behaviours"
  8. #pragma link "GLS.Cadencer"
  9. #pragma link "GLS.Coordinates"
  10. #pragma link "GLS.GeomObjects"
  11. #pragma link "GLS.Material"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.Context"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. // ---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
  20. }
  21. // ---------------------------------------------------------------------------
  22. void __fastcall TForm1::FormCreate(TObject *Sender) {
  23. SetGLSceneMediaDir();
  24. // dynamically create 2 materials and load 2 textures
  25. GLMaterialLibrary->AddTextureMaterial("wood", "ashwood.jpg")
  26. ->Material->FrontProperties->Emission->Color = clrGray50;
  27. GLMaterialLibrary->AddTextureMaterial("wood", "ashwood.jpg")
  28. ->Material->FaceCulling = fcNoCull;
  29. GLMaterialLibrary->AddTextureMaterial("stone", "walkway.jpg")
  30. ->Material->FrontProperties->Emission->Color = clrGray50;
  31. GLMaterialLibrary->AddTextureMaterial("stone", "walkway.jpg")
  32. ->Material->FaceCulling = fcNoCull;
  33. }
  34. // ---------------------------------------------------------------------------
  35. void __fastcall TForm1::DirectOpenGL1Render(TObject *Sender,
  36. TGLRenderContextInfo &rci)
  37. {
  38. TGLLibMaterial *Material;
  39. // disable face culling
  40. //glDisable(GL_CULL_FACE);
  41. // 1st quad, textured with 'wood', using standard method
  42. GLMaterialLibrary->ApplyMaterial("wood", rci);
  43. glBegin(GL_QUADS);
  44. glTexCoord2f(0, 1);
  45. glVertex3f(0.5, 0.5, -0.5);
  46. glTexCoord2f(0, 0);
  47. glVertex3f(-0.5, 0.5, -0.5);
  48. glTexCoord2f(1, 0);
  49. glVertex3f(-0.5, 0, 0.5);
  50. glTexCoord2f(1, 1);
  51. glVertex3f(0.5, 0, 0.5);
  52. glEnd;
  53. GLMaterialLibrary->UnApplyMaterial(rci);
  54. // 2nd quad, textured with 'stone'
  55. // we "manually" apply the material, this can be usefull if you want to have
  56. // some dynamic material control
  57. Material = GLMaterialLibrary->Materials->GetLibMaterialByName("stone");
  58. Material->Material->Apply(rci); // - unconsistent content
  59. glBegin(GL_QUADS);
  60. glTexCoord2f(0, 1);
  61. glVertex3f(0.5, -0.5, -0.5);
  62. glTexCoord2f(0, 0);
  63. glVertex3f(0.5, 0, 0.5);
  64. glTexCoord2f(1, 0);
  65. glVertex3f(-0.5, 0, 0.5);
  66. glTexCoord2f(1, 1);
  67. glVertex3f(-0.5, -0.5, -0.5);
  68. glEnd;
  69. Material->Material->UnApply(rci);
  70. // enable face culling again
  71. glEnable(GL_CULL_FACE);
  72. }
  73. // ---------------------------------------------------------------------------