diff --git a/AssetStudio/AssetStudioForm.Designer.cs b/AssetStudio/AssetStudioForm.Designer.cs index 00bc2dc..d0c8e0f 100644 --- a/AssetStudio/AssetStudioForm.Designer.cs +++ b/AssetStudio/AssetStudioForm.Designer.cs @@ -792,8 +792,10 @@ this.glControl1.Size = new System.Drawing.Size(838, 632); this.glControl1.TabIndex = 4; this.glControl1.VSync = false; + this.glControl1.Visible = false; this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint); this.glControl1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.glControl1_MouseWheel); + this.glControl1.Load += new System.EventHandler(this.glControl1_Load); // // classPreviewPanel // diff --git a/AssetStudio/AssetStudioForm.cs b/AssetStudio/AssetStudioForm.cs index 7fb4304..145c0a5 100644 --- a/AssetStudio/AssetStudioForm.cs +++ b/AssetStudio/AssetStudioForm.cs @@ -34,6 +34,7 @@ namespace AssetStudio private Bitmap imageTexture; #region OpenTK + private bool glControlLoaded; private int pgmID, pgmColorID, pgmBlackID; private int attributeVertexPosition; private int attributeNormalDirection; @@ -586,31 +587,6 @@ namespace AssetStudio resizeAssetListColumns(); } - private void changeGLSize(Size size) - { - GL.Viewport(0, 0, size.Width, size.Height); - - if (size.Width <= size.Height) - { - float k = 1.0f * size.Width / size.Height; - projMatrixData = Matrix4.CreateScale(1, k, 1); - } - else - { - float k = 1.0f * size.Height / size.Width; - projMatrixData = Matrix4.CreateScale(k, 1, 1); - } - } - - private void preview_Resize(object sender, EventArgs e) - { - glControl1.Size = previewPanel.Size; - changeGLSize(glControl1.Size); - - if (glControl1.Visible) - glControl1.Invalidate(); - } - private void listSearch_Enter(object sender, EventArgs e) { if (listSearch.Text == " Filter ") @@ -1546,7 +1522,6 @@ namespace AssetStudio uniformModelMatrix = GL.GetUniformLocation(pgmID, "modelMatrix"); uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix"); uniformProjMatrix = GL.GetUniformLocation(pgmID, "projMatrix"); - glControl1.Visible = false; } private void loadShader(string filename, ShaderType type, int program, out int address) @@ -1624,10 +1599,35 @@ namespace AssetStudio GL.BindVertexArray(0); } - protected override void OnLoad(EventArgs e) + private void changeGLSize(Size size) + { + GL.Viewport(0, 0, size.Width, size.Height); + + if (size.Width <= size.Height) + { + float k = 1.0f * size.Width / size.Height; + projMatrixData = Matrix4.CreateScale(1, k, 1); + } + else + { + float k = 1.0f * size.Height / size.Width; + projMatrixData = Matrix4.CreateScale(k, 1, 1); + } + } + + private void preview_Resize(object sender, EventArgs e) + { + if (glControlLoaded && glControl1.Visible) + { + changeGLSize(glControl1.Size); + glControl1.Invalidate(); + } + } + + private void glControl1_Load(object sender, EventArgs e) { - base.OnLoad(e); initOpenTK(); + glControlLoaded = true; } private void glControl1_Paint(object sender, PaintEventArgs e)