private void MeshControl_Load(object sender, EventArgs e) { meshControl.MakeCurrent(); Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version)); Console.WriteLine("OpenGL vendor: " + GL.GetString(StringName.Vendor)); Console.WriteLine("GLSL version: " + GL.GetString(StringName.ShadingLanguageVersion)); CheckOpenGL(); LoadBoundingBox(); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); GL.ClearColor(Settings.BackgroundColor); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); InitializeInputTick(); // If no defaul camera was found, make one up if (ActiveCamera == null) { ActiveCamera = Camera.FromBoundingBox(MinBounds, MaxBounds); } cameraBox.Items.Add(ActiveCamera, true); // Set camera viewport size ActiveCamera.SetViewportSize(meshControl.Width, meshControl.Width); foreach (var cameraInfo in cameras) { var camera = new Camera(cameraInfo.Item2, cameraInfo.Item1); cameraBox.Items.Add(camera); } ActiveAnimation = Animations.Count > 0 ? Animations[0] : null; animationBox.Items.AddRange(Animations.ToArray()); foreach (var obj in MeshesToRender) { obj.LoadFromResource(MaterialLoader); } // Gather render modes var renderModes = MeshesToRender .SelectMany(mesh => mesh.DrawCalls.SelectMany(drawCall => drawCall.Shader.RenderModes)) .Distinct() .ToArray(); if (SubjectType == RenderSubject.Model) { renderModeComboBox.Items.Clear(); renderModeComboBox.Items.Add("Change render mode..."); renderModeComboBox.Items.AddRange(renderModes); renderModeComboBox.SelectedIndex = 0; } #if DEBUG Debug.Setup(); #endif // Create animation texture AnimationTexture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, AnimationTexture); // Set clamping to edges GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); // Set nearest-neighbor sampling since we don't want to interpolate matrix rows GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest); //Unbind texture again GL.BindTexture(TextureTarget.Texture2D, 0); // TODO: poor hack FileExtensions.ClearCache(); Loaded = true; Console.WriteLine("{0} draw calls total", MeshesToRender.Sum(x => x.DrawCalls.Count)); }
private void MeshControl_Load(object sender, EventArgs e) { meshControl.MakeCurrent(); Console.WriteLine("OpenGL version: " + GL.GetString(StringName.Version)); Console.WriteLine("OpenGL vendor: " + GL.GetString(StringName.Vendor)); Console.WriteLine("GLSL version: " + GL.GetString(StringName.ShadingLanguageVersion)); CheckOpenGL(); LoadBoundingBox(); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); GL.ClearColor(Settings.BackgroundColor); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); InitializeInputTick(); ActiveCamera = new Camera(tabs.Width, tabs.Height, MinBounds, MaxBounds); cameraBox.Items.Add(ActiveCamera, true); foreach (var cameraInfo in cameras) { var camera = new Camera(tabs.Width, tabs.Height, cameraInfo.Item2, cameraInfo.Item1); cameraBox.Items.Add(camera); } ActiveAnimation = Animations.Count > 0 ? Animations[0] : null; animationBox.Items.AddRange(Animations.ToArray()); foreach (var obj in MeshesToRender) { obj.LoadFromResource(MaterialLoader); } #if DEBUG Debug.Setup(); //Skeleton.DebugDraw(Debug); #endif // Create animation texture AnimationTexture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, AnimationTexture); // Set clamping to edges GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); // Set nearest-neighbor sampling since we don't want to interpolate matrix rows GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Nearest); //Unbind texture again GL.BindTexture(TextureTarget.Texture2D, 0); // TODO: poor hack FileExtensions.ClearCache(); Loaded = true; Console.WriteLine("{0} draw calls total", MeshesToRender.Sum(x => x.DrawCalls.Count)); }