fArchipelagoC.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. // ---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5. #include "fArchipelagoC.h"
  6. // ---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "GLS.BaseClasses"
  9. #pragma link "GLS.BitmapFont"
  10. #pragma link "GLS.Cadencer"
  11. #pragma link "GLS.Coordinates"
  12. #pragma link "GLS.HeightData"
  13. #pragma link "GLS.HeightTileFileHDS"
  14. #pragma link "GLS.Material"
  15. #pragma link "GLS.Objects"
  16. #pragma link "GLS.Scene"
  17. #pragma link "GLS.SkyDome"
  18. #pragma link "GLS.TerrainRenderer"
  19. #pragma link "GLS.VectorFileObjects"
  20. #pragma link "GLS.SceneViewer"
  21. #pragma link "GLS.WindowsFont"
  22. #pragma link "GLS.HUDObjects"
  23. #pragma link "GLS.File3DS"
  24. #pragma resource "*.dfm"
  25. TForm1 *Form1;
  26. #define cWaterLevel -10000
  27. #define cWaterOpaqueDepth 2000
  28. #define cWaveAmplitude 120
  29. // ---------------------------------------------------------------------------
  30. __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
  31. }
  32. // ---------------------------------------------------------------------------
  33. void __fastcall TForm1::FormCreate(TObject *Sender) {
  34. int i, j;
  35. String name;
  36. TGLLibMaterial *libMat;
  37. String DataPath;
  38. DataPath = ExtractFilePath(ParamStr(0));
  39. DataPath += "Data\\";
  40. SetCurrentDir(DataPath);
  41. MaterialLibrary->TexturePaths = DataPath;
  42. GLCustomHDS1->MaxPoolSize = 8 * 1024 * 1024;
  43. GLCustomHDS1->DefaultHeight = cWaterLevel;
  44. // load texmaps
  45. for (i = 0; i <= 3; i++)
  46. for (j = 0; j <= 3; j++) {
  47. name = Format("Tex_%d_%d.bmp", ARRAYOFCONST((i, j)));
  48. if (!FileExists(name)) {
  49. ShowMessage("Texture file " + name + " not found...\r\
  50. Did you run " "splitter->exe"
  51. " as said in the readme->txt?");
  52. Application->Terminate();
  53. Abort();
  54. }
  55. libMat = MaterialLibrary->AddTextureMaterial(name, name, false);
  56. libMat->Material->Texture->TextureMode = tmReplace;
  57. libMat->Material->Texture->TextureWrap = twNone;
  58. // comment out to turn off texture compression
  59. libMat->Material->Texture->Compression = tcStandard;
  60. libMat->Material->Texture->FilteringQuality = tfAnisotropic;
  61. libMat->Texture2Name = "detail";
  62. }
  63. // Initial camera height offset (controled with pageUp/pageDown)
  64. CamHeight = 20;
  65. // Water plane active
  66. WaterPlane = true;
  67. // load the sailboat
  68. /* lost material for sailboat
  69. FFSailBoat->LoadFromFile("sailboat.glsm");
  70. MLSailBoat->LoadFromFile("sailboat.glml");
  71. */
  72. FFSailBoat->LoadFromFile("boat.3DS");
  73. FFSailBoat->Position->SetPoint(-125*TerrainRenderer->Scale->X, 0,
  74. -100*TerrainRenderer->Scale->Z);
  75. FFSailBoat->TurnAngle = -30;
  76. // boost ambient
  77. for (i = 0; i < MLSailBoat->Materials->Count; i++)
  78. MLSailBoat->Materials->Items[i]
  79. ->Material->FrontProperties->Ambient->Color =
  80. MLSailBoat->Materials->Items[i]
  81. ->Material->FrontProperties->Diffuse->Color;
  82. // Move camera starting point near the sailboat
  83. DCCamera->Position = FFSailBoat->Position;
  84. DCCamera->Translate(25, 0, -15);
  85. DCCamera->Turn(200);
  86. // Help text
  87. HTHelp->Text = "Archipelago Demo\r\
  88. * : Increase CLOD precision\r\
  89. / : decrease CLOD precision\r\
  90. W : wireframe on/off\r\
  91. S : sea surface on/off\r\
  92. B : sailboat visible on/off\r\
  93. Num4 & Num6 : steer the sailboat\r\
  94. F1: show this help";
  95. HTHelp->Position->SetPoint(Screen->Width / 2 - 100,
  96. Screen->Height / 2 - 150, 0);
  97. HelpOpacity = 4;
  98. GLSceneViewer->Cursor = crNone;
  99. }
  100. // ---------------------------------------------------------------------------
  101. void TForm1::ResetMousePos(void) {
  102. if (GLSceneViewer->Cursor == crNone)
  103. SetCursorPos(Screen->Width / 2, Screen->Height / 2);
  104. }
  105. // ---------------------------------------------------------------------------
  106. void __fastcall TForm1::GLCadencerProgress(TObject *Sender,
  107. const double deltaTime, const double newTime) {
  108. float Speed, Alpha, f;
  109. float TerrainHeight, SurfaceHeight;
  110. TGLVector Sbp;
  111. POINT NewMousePos;
  112. // Handle keypresses
  113. if (IsKeyDown(VK_SHIFT))
  114. Speed = 100 * deltaTime;
  115. else
  116. Speed = 20 * deltaTime;
  117. if (IsKeyDown(VK_UP))
  118. DCCamera->Position->AddScaledVector(Speed,
  119. GLCamera->AbsoluteVectorToTarget());
  120. if (IsKeyDown(VK_DOWN))
  121. DCCamera->Position->AddScaledVector(-Speed,
  122. GLCamera->AbsoluteVectorToTarget());
  123. if (IsKeyDown(VK_LEFT))
  124. DCCamera->Position->AddScaledVector(-Speed,
  125. GLCamera->AbsoluteRightVectorToTarget());
  126. if (IsKeyDown(VK_RIGHT))
  127. DCCamera->Position->AddScaledVector(Speed,
  128. GLCamera->AbsoluteRightVectorToTarget());
  129. if (IsKeyDown(VK_PRIOR))
  130. CamHeight = CamHeight + Speed;
  131. if (IsKeyDown(VK_NEXT))
  132. CamHeight = CamHeight - Speed;
  133. if (IsKeyDown(VK_ESCAPE))
  134. Close();
  135. if (IsKeyDown(VK_F1))
  136. HelpOpacity = ClampValue(HelpOpacity + deltaTime * 5, 3, 5);
  137. if (IsKeyDown(VK_NUMPAD4))
  138. FFSailBoat->Turn(-deltaTime*3);
  139. if (IsKeyDown(VK_NUMPAD6))
  140. FFSailBoat->Turn(deltaTime*3);
  141. // Mouse movements and actions
  142. if (IsKeyDown(VK_LBUTTON)) {
  143. Alpha = DCCamera->Position->Y;
  144. DCCamera->Position->AddScaledVector(Speed,
  145. GLCamera->AbsoluteVectorToTarget());
  146. CamHeight = CamHeight + DCCamera->Position->Y - Alpha;
  147. }
  148. if (IsKeyDown(VK_RBUTTON)) {
  149. Alpha = DCCamera->Position->Y;
  150. DCCamera->Position->AddScaledVector(-Speed,
  151. GLCamera->AbsoluteVectorToTarget());
  152. CamHeight = CamHeight + DCCamera->Position->Y - Alpha;
  153. }
  154. GetCursorPos(&NewMousePos);
  155. GLCamera->MoveAroundTarget((Screen->Height / 2 - NewMousePos.y)*0.25,
  156. (Screen->Width / 2 - NewMousePos.x)*0.25);
  157. ResetMousePos();
  158. // Don"t drop our target through terrain!
  159. TerrainHeight = TerrainRenderer->InterpolatedHeight
  160. (DCCamera->Position->AsVector);
  161. SurfaceHeight = TerrainRenderer->Scale->Z * cWaterLevel / 128;
  162. if (TerrainHeight < SurfaceHeight)
  163. TerrainHeight = SurfaceHeight;
  164. DCCamera->Position->Y = TerrainHeight + CamHeight;
  165. // Adjust fog distance/color for air/water
  166. if ((GLCamera->AbsolutePosition.Y > SurfaceHeight) || (!WaterPlane)) {
  167. if (!WasAboveWater) {
  168. SkyDome->Visible = true;
  169. GLSceneViewer->Buffer->FogEnvironment->FogColor->Color = clrWhite;
  170. GLSceneViewer->Buffer->FogEnvironment->FogEnd = 1000;
  171. GLSceneViewer->Buffer->FogEnvironment->FogStart = 500;
  172. GLSceneViewer->Buffer->BackgroundColor = clWhite;
  173. GLCamera->DepthOfView = 1000;
  174. WasAboveWater = true;
  175. }
  176. }
  177. else {
  178. if (WasAboveWater) {
  179. SkyDome->Visible = false;
  180. GLSceneViewer->Buffer->FogEnvironment->FogColor->AsWinColor =
  181. clNavy;
  182. GLSceneViewer->Buffer->FogEnvironment->FogEnd = 100;
  183. GLSceneViewer->Buffer->FogEnvironment->FogStart = 0;
  184. GLSceneViewer->Buffer->BackgroundColor = clNavy;
  185. GLCamera->DepthOfView = 100;
  186. WasAboveWater = false;
  187. }
  188. }
  189. // Visibility of Help
  190. if (HelpOpacity > 0) {
  191. HelpOpacity = HelpOpacity - deltaTime;
  192. Alpha = ClampValue(HelpOpacity, 0, 1);
  193. if (Alpha > 0) {
  194. HTHelp->Visible = true;
  195. HTHelp->ModulateColor->Alpha = Alpha;
  196. }
  197. else
  198. HTHelp->Visible = false;
  199. }
  200. // Rock the sailboat
  201. Sbp = TerrainRenderer->AbsoluteToLocal(FFSailBoat->AbsolutePosition);
  202. Alpha = WaterPhase(Sbp.X + TerrainRenderer->TileSize * 0.5,
  203. Sbp.Y + TerrainRenderer->TileSize * 0.5);
  204. FFSailBoat->Position->Y = (cWaterLevel + sin(Alpha) * cWaveAmplitude) *
  205. (TerrainRenderer->Scale->Z / 128) + 10;
  206. f = cWaveAmplitude * 0.01;
  207. FFSailBoat->Up->SetVector(cos(Alpha)*0.02*f, 1,
  208. (sin(Alpha)*0.02 - 0.005)*f);
  209. FFSailBoat->Move(deltaTime*2);
  210. }
  211. // ---------------------------------------------------------------------------
  212. void __fastcall TForm1::Timer1Timer(TObject *Sender) {
  213. HTFPS->Text = GLSceneViewer->FramesPerSecondText(0) + ", " + TerrainRenderer->LastTriangleCount + ", " + WaterPolyCount;
  214. GLSceneViewer->ResetPerformanceMonitor();
  215. }
  216. // ---------------------------------------------------------------------------
  217. void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key) {
  218. int i;
  219. TGLPolygonMode pm;
  220. switch (Key) {
  221. case 'w':
  222. case 'W': {
  223. if (MaterialLibrary->Materials->Items[0]->Material->PolygonMode ==
  224. pmLines)
  225. pm = pmFill;
  226. else
  227. pm = pmLines;
  228. for (i = 0; i < MaterialLibrary->Materials->Count; i++)
  229. MaterialLibrary->Materials->Items[i]
  230. ->Material->PolygonMode = pm;
  231. for (i = 0; i < MLSailBoat->Materials->Count; i++)
  232. MLSailBoat->Materials->Items[i]->Material->PolygonMode = pm;
  233. FFSailBoat->StructureChanged();
  234. break;
  235. }
  236. case 's':
  237. case 'S':
  238. WaterPlane = !WaterPlane;
  239. break;
  240. case 'b':
  241. case 'B':
  242. FFSailBoat->Visible = !FFSailBoat->Visible;
  243. break;
  244. case '*':
  245. if (TerrainRenderer->CLODPrecision > 1)
  246. TerrainRenderer->CLODPrecision =
  247. (int)(TerrainRenderer->CLODPrecision * 0.8);
  248. break;
  249. case '/':
  250. if (TerrainRenderer->CLODPrecision < 1000)
  251. TerrainRenderer->CLODPrecision =
  252. (int)(TerrainRenderer->CLODPrecision * 1.2 + 1);
  253. break;
  254. }
  255. Key = 0x0;
  256. }
  257. // ---------------------------------------------------------------------------
  258. void __fastcall TForm1::GLCustomHDS1MarkDirtyEvent(const TRect &area) {
  259. GLHeightTileFileHDS1->MarkDirty(area);
  260. }
  261. // ---------------------------------------------------------------------------
  262. void __fastcall TForm1::GLCustomHDS1StartPreparingData(TGLHeightData *heightData)
  263. {
  264. TGLHeightData *htfHD;
  265. int i, j, n;
  266. TTexPoint offset;
  267. htfHD = GLHeightTileFileHDS1->GetData(heightData->XLeft, heightData->YTop,
  268. heightData->Size, heightData->DataType);
  269. if ((htfHD->DataState == hdsNone))
  270. // or (htfHD->HeightMax<=cWaterLevel-cWaterOpaqueDepth)
  271. heightData->DataState = hdsNone;
  272. else {
  273. i = (heightData->XLeft / 128);
  274. j = (heightData->YTop / 128);
  275. if ((Cardinal(i) < 4) & (Cardinal(j) < 4)) {
  276. heightData->MaterialName =
  277. Format("Tex_%d_%d.bmp", ARRAYOFCONST((i, j)));
  278. heightData->TextureCoordinatesMode = tcmLocal;
  279. n = ((heightData->XLeft / 32) & 3);
  280. offset.S = n * 0.25;
  281. n = ((heightData->YTop / 32) & 3);
  282. offset.T = -n * 0.25;
  283. heightData->TextureCoordinatesOffset = offset;
  284. heightData->TextureCoordinatesScale = TexPointMake(0.25, 0.25);
  285. heightData->DataType = hdtSmallInt;
  286. htfHD->DataType = hdtSmallInt;
  287. heightData->Allocate(hdtSmallInt);
  288. Move(htfHD->SmallIntData, heightData->SmallIntData,
  289. htfHD->DataSize);
  290. heightData->DataState = hdsReady;
  291. heightData->HeightMin = htfHD->HeightMin;
  292. heightData->HeightMax = htfHD->HeightMax;
  293. }
  294. else
  295. heightData->DataState = hdsNone;
  296. }
  297. GLHeightTileFileHDS1->Release(htfHD);
  298. }
  299. // ---------------------------------------------------------------------------
  300. void __fastcall TForm1::GLSceneViewerBeforeRender(TObject *Sender) {
  301. int i, n;
  302. PAProgress->Left = (Width - PAProgress->Width) / 2;
  303. PAProgress->Visible = true;
  304. n = MaterialLibrary->Materials->Count;
  305. ProgressBar->Max = n - 1;
  306. try {
  307. for (i = 0; i < n; i++) {
  308. ProgressBar->Position = i;
  309. MaterialLibrary->Materials->Items[i]->Material->Texture->Handle;
  310. PAProgress->Repaint();
  311. }
  312. }
  313. __finally {
  314. ResetMousePos();
  315. PAProgress->Visible = false;
  316. GLSceneViewer->BeforeRender = NULL;
  317. }
  318. }
  319. // ---------------------------------------------------------------------------
  320. float TForm1::WaterPhase(const float px, const float py) {
  321. return GLCadencer->CurrentTime * 1.0 + px * 0.16 + py * 0.09;
  322. }
  323. // ---------------------------------------------------------------------------
  324. float TForm1::WaterHeight(const float px, const float py) {
  325. float alpha;
  326. alpha = WaterPhase(px + TerrainRenderer->TileSize * 0.5,
  327. py + TerrainRenderer->TileSize * 0.5);
  328. return (cWaterLevel + sin(alpha) * cWaveAmplitude) *
  329. (TerrainRenderer->Scale->Z * (1.0 / 128));
  330. }
  331. // ---------------------------------------------------------------------------
  332. void TForm1::IssuePoint(TGLHeightData *hd, int x, int y, int s2, float t, int rx,
  333. int ry) {
  334. const float r = 0.75;
  335. const float g = 0.75;
  336. const float b = 1.0;
  337. float px, py;
  338. float alpha, colorRatio, ca, sa;
  339. px = x + rx + s2;
  340. py = y + ry + s2;
  341. // if (hd->DataState == hdsNone) {
  342. alpha = 1;
  343. /*
  344. }
  345. else {
  346. alpha = (cWaterLevel - hd->SmallIntHeight(rx, ry)) *
  347. (1 / cWaterOpaqueDepth);
  348. alpha = ClampValue(alpha, 0.5, 1.0);
  349. }
  350. */
  351. SinCos(WaterPhase(px, py), sa, ca);
  352. colorRatio = 1 - alpha * 0.1;
  353. glColor4f(r*colorRatio, g*colorRatio, b, alpha);
  354. glTexCoord2f(px*0.01 + 0.002*sa, py*0.01 + 0.0022*ca - t*0.002);
  355. glVertex3f(px, py, cWaterLevel + cWaveAmplitude*sa);
  356. }
  357. // ---------------------------------------------------------------------------
  358. void __fastcall TForm1::TerrainRendererHeightDataPostRender
  359. (TGLRenderContextInfo &rci, TList *&HeightDatas) {
  360. int i, x, y, s, s2;
  361. float t;
  362. TGLHeightData *hd;
  363. if (WaterPlane) {
  364. t = GLCadencer->CurrentTime;
  365. MaterialLibrary->ApplyMaterial("water", rci);
  366. do {
  367. if (!WasAboveWater)
  368. rci.GLStates->InvertFrontFace();
  369. glPushAttrib(GL_ENABLE_BIT);
  370. glDisable(GL_LIGHTING);
  371. glDisable(GL_NORMALIZE);
  372. glStencilFunc(GL_ALWAYS, 1, 255);
  373. glStencilMask(255);
  374. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  375. glEnable(GL_STENCIL_TEST);
  376. glNormal3f(0, 0, 1);
  377. for (i = 0; i < HeightDatas->Count; i++) {
  378. hd = (TGLHeightData*)(HeightDatas->List[i]);
  379. if ((hd->DataState == hdsReady) && (hd->HeightMin >
  380. cWaterLevel))
  381. continue;
  382. x = hd->XLeft;
  383. y = hd->YTop;
  384. s = hd->Size - 1;
  385. s2 = s / 2;
  386. glBegin(GL_TRIANGLE_FAN);
  387. IssuePoint(hd, x, y, s2, t, s2, s2);
  388. IssuePoint(hd, x, y, s2, t, 0, 0);
  389. IssuePoint(hd, x, y, s2, t, s2, 0);
  390. IssuePoint(hd, x, y, s2, t, s, 0);
  391. IssuePoint(hd, x, y, s2, t, s, s2);
  392. IssuePoint(hd, x, y, s2, t, s, s);
  393. IssuePoint(hd, x, y, s2, t, s2, s);
  394. IssuePoint(hd, x, y, s2, t, 0, s);
  395. IssuePoint(hd, x, y, s2, t, 0, s2);
  396. IssuePoint(hd, x, y, s2, t, 0, 0);
  397. glEnd();
  398. }
  399. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  400. glPopAttrib();
  401. if (!WasAboveWater)
  402. rci.GLStates->InvertFrontFace();
  403. WaterPolyCount = HeightDatas->Count * 8;
  404. }
  405. while (MaterialLibrary->UnApplyMaterial(rci));
  406. }
  407. }
  408. // ---------------------------------------------------------------------------
  409. void __fastcall TForm1::DOWakeProgress(TObject *Sender, const double deltaTime,
  410. const double newTime) {
  411. int i;
  412. TGLVector sbp, sbr;
  413. if (WakeVertices == NULL) {
  414. WakeVertices = new TGLAffineVectorList();
  415. WakeStretch = new TGLAffineVectorList();
  416. WakeTime = new TGLSingleList();
  417. }
  418. // enlarge current vertices
  419. i = 0;
  420. while (i < WakeVertices->Count) {
  421. WakeVertices->CombineItem(i, WakeStretch->Items[i >> 1],
  422. -0.45*deltaTime);
  423. WakeVertices->CombineItem(i + 1, WakeStretch->Items[i >> 1],
  424. 0.45*deltaTime);
  425. i += 2;
  426. }
  427. // Progress wake
  428. if (newTime > DOWake->TagFloat) {
  429. if (DOWake->TagFloat == 0) {
  430. DOWake->TagFloat = newTime + 0.2;
  431. }
  432. else {
  433. DOWake->TagFloat = newTime + 1;
  434. sbp = VectorCombine(FFSailBoat->AbsolutePosition,
  435. FFSailBoat->AbsoluteDirection, 1, 3);
  436. sbr = FFSailBoat->AbsoluteRight();
  437. // add new
  438. WakeVertices->Add(VectorCombine(sbp, sbr, 1, -2));
  439. WakeVertices->Add(VectorCombine(sbp, sbr, 1, 2));
  440. WakeStretch->Add(VectorScale(sbr, (0.95 + Random()*0.1)));
  441. WakeTime->Add(newTime*0.1);
  442. if (WakeVertices->Count >= 80) {
  443. WakeVertices->Delete(0);
  444. WakeVertices->Delete(0);
  445. WakeStretch->Delete(0);
  446. WakeTime->Delete(0);
  447. }
  448. }
  449. }
  450. }
  451. // ---------------------------------------------------------------------------
  452. void __fastcall TForm1::DOWakeRender(TObject *Sender, TGLRenderContextInfo &rci) {
  453. int i, n;
  454. Vectortypes::TVector3f p;
  455. TGLVector sbp;
  456. float c;
  457. if (!(WakeVertices) && (!((FFSailBoat->Visible) || (WaterPlane)))) {
  458. MaterialLibrary->ApplyMaterial("wake", rci);
  459. do {
  460. glPushAttrib(GL_ENABLE_BIT);
  461. glDisable(GL_LIGHTING);
  462. glDisable(GL_FOG);
  463. glEnable(GL_BLEND);
  464. glBlendFunc(GL_ONE, GL_ONE);
  465. glStencilFunc(GL_EQUAL, 1, 255);
  466. glStencilMask(255);
  467. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  468. glEnable(GL_STENCIL_TEST);
  469. glDisable(GL_DEPTH_TEST);
  470. if (!WasAboveWater)
  471. rci.GLStates->InvertFrontFace();
  472. glBegin(GL_TRIANGLE_STRIP);
  473. n = WakeVertices->Count;
  474. for (i = 0; i < n; i++) {
  475. p = WakeVertices->Items[i ^ 1];
  476. sbp = TerrainRenderer->AbsoluteToLocal(VectorMake(p, 0));
  477. if ((i & 1) == 0) {
  478. c = (i & 0xFFE) * 0.2 / n;
  479. glColor3f(c, c, c);
  480. glTexCoord2f(0, WakeTime->Items[i / 2]);
  481. }
  482. else
  483. glTexCoord2f(1, WakeTime->Items[i / 2]);
  484. glVertex3f(p.X, WaterHeight(sbp.X, sbp.Y), p.Z);
  485. }
  486. glEnd();
  487. if (!WasAboveWater)
  488. rci.GLStates->InvertFrontFace();
  489. glPopAttrib();
  490. glDisable(stStencilTest);
  491. }
  492. while (MaterialLibrary->UnApplyMaterial(rci));
  493. }
  494. }
  495. // ---------------------------------------------------------------------------