public void Draw(Camera cam, SimTime t) { GL.Disable(All.DepthTest); GL.Enable(All.Texture2D); _textures.BeginFrame(); _geometries.BeginFrame(); if (MissingTileTexture == 0) { using (var img = UIImage.FromFile("MissingTile.png")) { MissingTileTexture = img.ToGLTexture(); } } GL.EnableClientState(All.TextureCoordArray); GL.EnableClientState(All.NormalArray); var zoom = cam.Zoom; if (_lastZoom < 0) { _lastZoom = zoom; } if (zoom != _lastZoom) { _prevZoom = _lastZoom; _lastZoomFadeTime = t.WallTime; } var fadeTime = t.WallTime - _lastZoomFadeTime; var shouldFade = fadeTime.TotalSeconds < FadeSecs; var fade = shouldFade ? (float)(fadeTime.TotalSeconds / FadeSecs) : 1.0f; _lastZoom = zoom; var centerTile1 = TileName.FromLocation(cam.LookAt, _prevZoom); var centerTile = TileName.FromLocation(cam.LookAt, zoom); // // Draw the tiles // if (shouldFade) { DrawTiles(cam, centerTile1, 1.0f); } DrawTiles(cam, centerTile, fade); GL.DisableClientState(All.TextureCoordArray); GL.DisableClientState(All.NormalArray); GL.Disable(All.Texture2D); GL.Enable(All.DepthTest); }
void DrawTiles(Camera cam, TileName centerTile, float alpha) { // // Determine the number of tiles to show // int minX = 99999999, minY = 99999999, maxX = 0, maxY = 0; for (var i = 0; i < cam.ScreenLocations.Length; i++) { var loc = cam.ScreenLocations[i]; if (loc != null) { var c = TileName.FromLocation(loc, centerTile.Zoom); minX = Math.Min(c.X, minX); minY = Math.Min(c.Y, minY); maxX = Math.Max(c.X, maxX); maxY = Math.Max(c.Y, maxY); } } minX = Math.Min(centerTile.X, minX); minY = Math.Min(centerTile.Y, minY); maxX = Math.Max(centerTile.X, maxX); maxY = Math.Max(centerTile.Y, maxY); minX -= 1; minY -= 1; maxX += 1; maxY += 1; // // Draw them // var nd = 0; var tile = new TileName() { Zoom = centerTile.Zoom }; var n = (int)Math.Pow(2, tile.Zoom); foreach (var p in RenderOrder) { tile.X = centerTile.X + p.X; tile.Y = centerTile.Y + p.Y; while (tile.X < 0) { tile.X += n; } while (tile.Y < 0) { tile.Y += n; } while (tile.X >= n) { tile.X -= n; } while (tile.Y >= n) { tile.Y -= n; } if (tile.X < minX || tile.Y < minY) { continue; } if (tile.X > maxX || tile.Y > maxY) { continue; } DrawTile(tile, alpha); nd++; } }