Unit1.cpp 2.7 KB

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