Unit1.cpp 17 KB

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