public static TextureCubeMap CreateTextureCubeMap(NutTexture t) { TextureCubeMap texture = new TextureCubeMap(Properties.Resources._10102000); texture.Bind(); // Necessary to access mipmaps past the base level. texture.MinFilter = TextureMinFilter.LinearMipmapLinear; // The number of mip maps needs to be specified first. GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureBaseLevel, 0); GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMaxLevel, t.surfaces[0].mipmaps.Count); GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap); for (int i = 0; i < t.surfaces.Count; i++) { GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, 0, (InternalFormat)t.pixelInternalFormat, t.Width, t.Height, 0, t.ImageSize, t.surfaces[i].mipmaps[0]); // Initialize the data for each level. for (int j = 1; j < t.surfaces[i].mipmaps.Count; j++) { GL.CompressedTexImage2D <byte>(TextureTarget.TextureCubeMapPositiveX + i, j, (InternalFormat)t.pixelInternalFormat, t.Width / (int)Math.Pow(2, j), t.Height / (int)Math.Pow(2, j), 0, t.ImageSize, t.surfaces[i].mipmaps[j]); } } return(texture); }
public override void Render(float time, float deltaTime) { _viewMatrix = Matrix4x4.CreateLookAt(_cameraPosition, _cameraTarget, Vector3Helper.Up); _modelMatrix = Matrix4x4.CreateRotationY(0f * 3f); _projectionMatrix = Matrix4x4.CreatePerspectiveFieldOfView(1.0f, Window.AspectRatio, 0.1f, 10_000.0f); _shader.SetUniform("model", ref _modelMatrix); _shader.SetUniform("view", ref _viewMatrix); _shader.SetUniform("projection", ref _projectionMatrix); _shader.TrySetUniform("lightPos", _lightPos); _shader.TrySetUniform("lightColor", _lightColor.ToVector3()); _shader.TrySetUniform("cameraPos", _cameraPosition); RenderContext.Clear(Color.Black); if (_skybox0 != null) { var viewMatrixNoTranslation = _viewMatrix; viewMatrixNoTranslation.Translation = Vector3.Zero; _skyboxShader.SetUniform("view", ref viewMatrixNoTranslation); _skyboxShader.SetUniform("projection", ref _projectionMatrix); _skyboxShader.SetUniform("skybox", 0); _skybox0.Bind(0, RenderContext); RenderContext.DepthMask = false; _skyboxMesh.Render(RenderContext, _skyboxShader); RenderContext.DepthMask = true; } if (_nanosuit != null) { RenderContext.Render(_nanosuit, _shader); } _shader.SetUniform("model", Matrix4x4.CreateTranslation(_lightPos)); _mesh.Render(RenderContext, _shader); ImGuiHelper.BeginGlobalDocking(false); ImGui.End(); ImGui.Begin("Controls"); { ImGui.DragFloat3("Camera Position", ref _cameraPosition); ImGui.DragFloat3("Camera Target", ref _cameraTarget); ImGui.Separator(); ImGuiHelper.ColorEdit4("Light Color", ref _lightColor); ImGui.DragFloat3("Light Position", ref _lightPos); } ImGui.End(); if (ImGui.Button("Quit")) { Quit(); } ImGui.Separator(); if (Window.VSync == VSyncMode.On) { if (ImGui.Button("Disable VSync")) { Window.VSync = VSyncMode.Off; _log.Info("VSync disabled."); } } else { if (ImGui.Button("Enable VSync")) { Window.VSync = VSyncMode.On; _log.Info("VSync enabled."); } } if (ImGui.Button("Set Fullscreen")) { Window.FullscreenState = FullscreenState.Fullscreen; } if (ImGui.Button("Set Windowed")) { Window.FullscreenState = FullscreenState.Windowed; } ImGui.End(); ImGui.ShowMetricsWindow(); }