public RenderControl(GraphicsMode mode, int major, int minor, GraphicsContextFlags flags) : base(mode, major, minor, flags) { if (DesignMode) { return; } Resize += (sender, args) => { GL.Viewport(0, 0, Width, Height); Camera?.SetViewport(Width, Height); }; Context.MakeCurrent(null); MakeCurrent(); Context.ErrorChecking = true; GL.ClearColor(Color4.Black); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); SwapBuffers(); Program = new ShaderProgram(); Program.AddVertexShader("./shaders/vertex.shader"); Program.AddFragmentShader("./shaders/fragment.shader"); Program.Link(); Texture = new TerrainTexture(); }
public Terrain(int gridX, int gridZ, Loader loader, TerrainTexturePack texturePack, TerrainTexture blendMap) { this.texturePack = texturePack; this.blendMap = blendMap; this.x = gridX; this.z = gridZ; this.model = generateTerrain(loader); }
public void BindTextures(Terrain terrain) { TerrainTexture texturePack = terrain.texturePack; texturePack.backgroundTexture.Bind(TextureUnit.Texture0); texturePack.rTexture.Bind(TextureUnit.Texture1); texturePack.gTexture.Bind(TextureUnit.Texture2); texturePack.bTexture.Bind(TextureUnit.Texture3); texturePack.blendMap.Bind(TextureUnit.Texture4); }
public void GenerateMap() { if (width < 1) { width = 1; } if (height < 1) { height = 1; } if (lacunarity < 1) { lacunarity = 1; } if (octaves < 0) { octaves = 0; } float[,] noiseMap = NoiseGenerator.Generate(seed, width, height, noiseScale, octaves, persistance, lacunarity, offset); Color[] colormap = new Color[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float PointHeight = noiseMap[x, y]; for (int i = 0; i < TerrainColors.Length; i++) { if (PointHeight <= TerrainColors[i].height) { colormap[y * width + x] = TerrainColors[i].Color; break; } } } } if (displayMode == DisplayMode.NoiseMap) { GenerateTerrainTexture(TerrainTexture.TextureHeightMap(noiseMap, TextureFilterMode)); } else if (displayMode == DisplayMode.ColorMap) { GenerateTerrainTexture(TerrainTexture.TextureColorMap(colormap, width, height, TextureFilterMode)); } }
private void UpdateVisibleQuadrants() { // Find quadrants that have to be visible List <Quadrant> newActiveQuadrants = new List <Quadrant>(); foreach (Quadrant quadrant in root.FindQuadrantsOfSize(visibleQuadrantScale)) { if (quadrant.VisibleByMainCam()) { newActiveQuadrants.Add(quadrant); } } // Deactivate visible quadrants that have to be invisible for (int i = visibleQuadrants.Count - 1; i >= 0; i--) { Quadrant quadrant = visibleQuadrants[i]; if (!newActiveQuadrants.Contains(quadrant)) { quadrant.SetVisible(false); TerrainTexture terrainTexture = visibleQuadrantPairs[quadrant]; terrainTexture.Deactivate(); visibleQuadrantPairs.Remove(quadrant); terrainTexturePool.Add(terrainTexture); } } // Activate new visible quadrants visibleQuadrants = newActiveQuadrants; foreach (Quadrant quadrant in visibleQuadrants) { if (!visibleQuadrantPairs.ContainsKey(quadrant)) { quadrant.SetVisible(true); // Only instantiate a new terrainTexture if the pool is empty if (terrainTexturePool.Count == 0) { terrainTexturePool.Add(Instantiate(terrainPlanePrefab, transform)); } TerrainTexture terrainTexture = terrainTexturePool[0]; terrainTexturePool.Remove(terrainTexture); terrainTexture.gameObject.SetActive(true); terrainTexture.Setup(quadrant, loadType != TerrainLoadType.NONE); visibleQuadrantPairs.Add(quadrant, terrainTexture); } } }
public BiomeData( BiomeType newType, TerrainTexture newTexture, Color newColor, string[] newBigNames, string[] newMediumNames, string[] newSmallNames ) { Type = newType; TextureID = newTexture; MinimapColor = newColor; BigNames = newBigNames; MediumNames = newMediumNames; SmallNames = newSmallNames; }
public void OnSave() { if (m_LastNumSection == numSection) { return; } m_LastNumSection = numSection; terrain = GetComponent <Terrain>(); terrainData = GetComponent <TerrainCollider>().terrainData; TerrainTexture HeightTexture = new TerrainTexture(sectorSize); HeightTexture.TerrainDataToHeightmap(terrainData); boundSector = new FBoundSector(numSection, sectorSize, sectionSize, transform.position, terrainData.bounds); boundSector.BuildBounds(sectorSize, sectionSize, terrainScaleY, transform.position, HeightTexture.HeightMap); HeightTexture.Release(); }
internal static void Dispose() { ItemTexture.Dispose(); TerrainTexture.Dispose(); EntityTexture.Dispose(); ButtonTex.Dispose(); LabelTex.Dispose(); TextboxTex.Dispose(); GameBackgroundTex.Dispose(); DesertBackgroundTex.Dispose(); NightBackgroundTex.Dispose(); TitleBackgroundTex.Dispose(); FontCenturyGothicTex.Dispose(); FontChillerTex.Dispose(); FontDialogInputTex.Dispose(); FontLucidaConsoleTex.Dispose(); }
public override void Construct() { PreviewPanel = AddChild(new Gui.Widget { AutoLayout = Gui.AutoLayout.DockFill, OnLayout = (sender) => { Camera.Rect = sender.Rect; }, OnClick = (sender, args) => { if (Generator.CurrentState != OverworldGenerator.GenerationState.Finished) { return; } if (args.MouseButton == 0) { var clickPoint = Camera.ScreenToWorld(new Vector2(args.X, args.Y)); var colonyCell = Overworld.ColonyCells.GetCellAt(clickPoint.X, clickPoint.Y); if (colonyCell != null) { Overworld.InstanceSettings.Cell = colonyCell; previewText = Generator.GetSpawnStats(); Camera.SetGoalFocus(new Vector3((float)colonyCell.Bounds.Center.X / (float)Overworld.Width, 0, (float)colonyCell.Bounds.Center.Y / (float)Overworld.Height)); } UpdatePreview = true; OnCellSelectionMade?.Invoke(); } }, OnMouseMove = (sender, args) => { if (Generator.CurrentState != OverworldGenerator.GenerationState.Finished) { return; } Camera.OnMouseMove(args); }, OnScroll = (sender, args) => { if (Generator.CurrentState != OverworldGenerator.GenerationState.Finished) { return; } Camera.OnScroll(args); } }); OnClose += (sender) => { Mesh.Dispose(); TerrainTexture.Dispose(); PreviewTexture.Dispose(); }; Camera.Overworld = Overworld; }
static void Main(string[] args) { // Initialize OpenGL Gl.Initialize(); // If the library isn't in the environment path we need to set it Glfw.ConfigureNativesDirectory("..\\..\\libs/glfw-3.2.1.bin.WIN32/lib-mingw"); // Initialize the GLFW if (!Glfw.Init()) { Environment.Exit(-1); } // Create a windowed mode window and its OpenGL context var window = Glfw.CreateWindow(width, height, "Unreal Engine 4"); if (!window) { Glfw.Terminate(); Environment.Exit(-1); } // set window icon Glfw.Image icon = Utils.getImage("..\\..\\res/logo.png"); Glfw.SetWindowIcon(window, icon); // Make the window's context current Glfw.MakeContextCurrent(window); // create loder and renderer Loader loader = new Loader(); // create terrain texture pack TerrainTexture backgroundTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/grassy2.png")); TerrainTexture rTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/mud.png")); TerrainTexture gTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/grassFlowers.png")); TerrainTexture bTexture = new TerrainTexture(loader.loadTexture("..\\..\\res/path.png")); TerrainTexturePack texturePack = new TerrainTexturePack(backgroundTexture, rTexture, gTexture, bTexture); // create blend map TerrainTexture blendMap = new TerrainTexture(loader.loadTexture("..\\..\\res/blendMap.png")); // create models RawModel fern = OBJLoader.loadObjModel("fern", loader); ModelTexture fernTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedFern = new TexturedModel(fern, fernTexture); texturedFern.modelTexture.shineDamper = 10; texturedFern.modelTexture.reflectivity = 0; texturedFern.modelTexture.isHasTransparency = true; RawModel grass = OBJLoader.loadObjModel("grassModel", loader); ModelTexture grassTexture = new ModelTexture(loader.loadTexture("..\\..\\res/flower.png")); TexturedModel texturedGrass = new TexturedModel(grass, grassTexture); texturedGrass.modelTexture.shineDamper = 10; texturedGrass.modelTexture.reflectivity = 0; texturedGrass.modelTexture.isHasTransparency = true; texturedGrass.modelTexture.isUseFakeLighting = true; RawModel model = OBJLoader.loadObjModel("lowPolyTree", loader); ModelTexture texture = new ModelTexture(loader.loadTexture("..\\..\\res/lowPolyTree.png")); TexturedModel staticModel = new TexturedModel(model, texture); staticModel.modelTexture.shineDamper = 10; staticModel.modelTexture.reflectivity = 0; Entity entity = new Entity(staticModel, new Vertex3f(0, 0, -25), 0, 0, 0, 1); Light light = new Light(new Vertex3f(0, 0, -20), new Vertex3f(1f, 1f, 1f)); Random rand = new Random(); ModelTexture terrainTexture = new ModelTexture(loader.loadTexture("..\\..\\res/grass.png")); terrainTexture.shineDamper = 10; terrainTexture.reflectivity = 0; Terrain terrain = new Terrain(800, 0, loader, texturePack, blendMap); Terrain terrain2 = new Terrain(800, -1600, loader, texturePack, blendMap); RawModel tree = OBJLoader.loadObjModel("normal_tree", loader); ModelTexture treeTexture = new ModelTexture(loader.loadTexture("..\\..\\res/normal_tree.png")); TexturedModel texturedTree = new TexturedModel(tree, treeTexture); RawModel stanfordBunny = OBJLoader.loadObjModel("person", loader); ModelTexture stanfordBunnyTexture = new ModelTexture(loader.loadTexture("..\\..\\res/PlayerTexture.png")); stanfordBunnyTexture.shineDamper = 3; stanfordBunnyTexture.reflectivity = 0.00000000001f; TexturedModel texturedStanfordBunny = new TexturedModel(stanfordBunny, stanfordBunnyTexture); Player player = new Player(texturedStanfordBunny, new Vertex3f(0, 0, -100), 0, 0, 0, 3); Random random = new Random(); Camera camera = new Camera(); List <Entity> allCubes = new List <Entity>(); List <Entity> allGrass = new List <Entity>(); List <Entity> allFerns = new List <Entity>(); List <Entity> allTrees = new List <Entity>(); for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allCubes.Add(new Entity(staticModel, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, rand.Next(1, 4))); } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allGrass.Add(new Entity(texturedGrass, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } for (int i = 0; i < 1000; i++) { double x = random.NextDouble() * -1600 + 800; double y = 0; double z = random.NextDouble() * -2410; allFerns.Add(new Entity(texturedFern, new Vertex3f((float)x, (float)y, (float)z), 0, 0, 0, 3)); } MasterRenderer renderer = new MasterRenderer(new WinowInfo(width, height)); lastFrameTime = getCurrentTime(); // Loop until the user closes the window while (!Glfw.WindowShouldClose(window)) { // Render here player.move(window); renderer.processTerrain(terrain); renderer.processTerrain(terrain2); foreach (Entity cube in allCubes) { renderer.processEntity(cube); } foreach (Entity gr in allGrass) { renderer.processEntity(gr); } foreach (Entity fr in allFerns) { renderer.processEntity(fr); } foreach (Entity tr in allTrees) { renderer.processEntity(tr); } renderer.processEntity(player); renderer.render(light, camera); //Swap front and back buffers Glfw.SwapBuffers(window); // Poll for and process events Glfw.PollEvents(); long currentFrameTime = getCurrentTime(); delta = (currentFrameTime - lastFrameTime) / 1000f; lastFrameTime = currentFrameTime; } // clean memory renderer.cleanUP(); loader.CleanUp(); // terminate program Glfw.Terminate(); }
public void MaybeUpdateThemeDecal(TerrainTexture terrainTexture) { if (!Mod.ThemeDecalsEnabled) { return; } if (terrainTexture == null || terrainTexture.Texture == null) { return; } string meshName = string.Empty; switch (terrainTexture.Name) { case TerrainTexture.TextureName.CliffDiffuseTexture: meshName = "themedecal-cliff"; break; case TerrainTexture.TextureName.GrassDiffuseTexture: meshName = "themedecal-grass"; break; case TerrainTexture.TextureName.GravelDiffuseTexture: meshName = "themedecal-gravel"; break; case TerrainTexture.TextureName.OreDiffuseTexture: meshName = "themedecal-ore"; break; case TerrainTexture.TextureName.OilDiffuseTexture: meshName = "themedecal-oil"; break; case TerrainTexture.TextureName.PavementDiffuseTexture: meshName = "themedecal-pavement"; break; case TerrainTexture.TextureName.RuinedDiffuseTexture: meshName = "themedecal-ruined"; break; case TerrainTexture.TextureName.SandDiffuseTexture: meshName = "themedecal-sand"; break; } for (uint i = 0; i < PrefabCollection <PropInfo> .LoadedCount(); i++) { PropInfo prefab = PrefabCollection <PropInfo> .GetLoaded(i); if (prefab == null) { continue; } if (prefab.m_mesh == null) { continue; } if (prefab.m_mesh.name != meshName) { continue; } prefab.m_material.SetTexture("_MainTex", terrainTexture.Texture); prefab.m_lodMaterialCombined.SetTexture("_MainTex", terrainTexture.Texture); prefab.m_lodMaterial = prefab.m_material; prefab.m_lodRenderDistance = 18000; } }