mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-06-03 00:58:13 -04:00
improve GLControl:
- resize when form changes size - keep aspect
This commit is contained in:
parent
0c23548817
commit
b49d5bdeb4
1
AssetStudio/AssetStudioForm.Designer.cs
generated
1
AssetStudio/AssetStudioForm.Designer.cs
generated
@ -619,6 +619,7 @@
|
|||||||
this.previewPanel.Name = "previewPanel";
|
this.previewPanel.Name = "previewPanel";
|
||||||
this.previewPanel.Size = new System.Drawing.Size(838, 632);
|
this.previewPanel.Size = new System.Drawing.Size(838, 632);
|
||||||
this.previewPanel.TabIndex = 1;
|
this.previewPanel.TabIndex = 1;
|
||||||
|
this.previewPanel.Resize += new System.EventHandler(this.preview_Resize);
|
||||||
//
|
//
|
||||||
// assetInfoLabel
|
// assetInfoLabel
|
||||||
//
|
//
|
||||||
|
@ -40,6 +40,7 @@ namespace AssetStudio
|
|||||||
private int attributeVertexColor;
|
private int attributeVertexColor;
|
||||||
private int uniformModelMatrix;
|
private int uniformModelMatrix;
|
||||||
private int uniformViewMatrix;
|
private int uniformViewMatrix;
|
||||||
|
private int uniformProjMatrix;
|
||||||
private int vao;
|
private int vao;
|
||||||
private Vector3[] vertexData;
|
private Vector3[] vertexData;
|
||||||
private Vector3[] normalData;
|
private Vector3[] normalData;
|
||||||
@ -47,6 +48,7 @@ namespace AssetStudio
|
|||||||
private Vector4[] colorData;
|
private Vector4[] colorData;
|
||||||
private Matrix4 modelMatrixData;
|
private Matrix4 modelMatrixData;
|
||||||
private Matrix4 viewMatrixData;
|
private Matrix4 viewMatrixData;
|
||||||
|
private Matrix4 projMatrixData;
|
||||||
private int[] indiceData;
|
private int[] indiceData;
|
||||||
private int wireFrameMode;
|
private int wireFrameMode;
|
||||||
private int shadeMode;
|
private int shadeMode;
|
||||||
@ -584,6 +586,31 @@ namespace AssetStudio
|
|||||||
resizeAssetListColumns();
|
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)
|
private void listSearch_Enter(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listSearch.Text == " Filter ")
|
if (listSearch.Text == " Filter ")
|
||||||
@ -1496,7 +1523,7 @@ namespace AssetStudio
|
|||||||
|
|
||||||
private void initOpenTK()
|
private void initOpenTK()
|
||||||
{
|
{
|
||||||
GL.Viewport(0, 0, glControl1.ClientSize.Width, glControl1.ClientSize.Height);
|
changeGLSize(glControl1.Size);
|
||||||
GL.ClearColor(Color.CadetBlue);
|
GL.ClearColor(Color.CadetBlue);
|
||||||
pgmID = GL.CreateProgram();
|
pgmID = GL.CreateProgram();
|
||||||
loadShader("vs", ShaderType.VertexShader, pgmID, out int vsID);
|
loadShader("vs", ShaderType.VertexShader, pgmID, out int vsID);
|
||||||
@ -1518,6 +1545,7 @@ namespace AssetStudio
|
|||||||
attributeVertexColor = GL.GetAttribLocation(pgmColorID, "vertexColor");
|
attributeVertexColor = GL.GetAttribLocation(pgmColorID, "vertexColor");
|
||||||
uniformModelMatrix = GL.GetUniformLocation(pgmID, "modelMatrix");
|
uniformModelMatrix = GL.GetUniformLocation(pgmID, "modelMatrix");
|
||||||
uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix");
|
uniformViewMatrix = GL.GetUniformLocation(pgmID, "viewMatrix");
|
||||||
|
uniformProjMatrix = GL.GetUniformLocation(pgmID, "projMatrix");
|
||||||
glControl1.Visible = false;
|
glControl1.Visible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1590,6 +1618,7 @@ namespace AssetStudio
|
|||||||
createVBO(out var vboColors, colorData, attributeVertexColor);
|
createVBO(out var vboColors, colorData, attributeVertexColor);
|
||||||
createVBO(out var vboModelMatrix, modelMatrixData, uniformModelMatrix);
|
createVBO(out var vboModelMatrix, modelMatrixData, uniformModelMatrix);
|
||||||
createVBO(out var vboViewMatrix, viewMatrixData, uniformViewMatrix);
|
createVBO(out var vboViewMatrix, viewMatrixData, uniformViewMatrix);
|
||||||
|
createVBO(out var vboProjMatrix, projMatrixData, uniformProjMatrix);
|
||||||
createEBO(out var eboElements, indiceData);
|
createEBO(out var eboElements, indiceData);
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
|
||||||
GL.BindVertexArray(0);
|
GL.BindVertexArray(0);
|
||||||
@ -1613,6 +1642,7 @@ namespace AssetStudio
|
|||||||
GL.UseProgram(shadeMode == 0 ? pgmID : pgmColorID);
|
GL.UseProgram(shadeMode == 0 ? pgmID : pgmColorID);
|
||||||
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
||||||
|
GL.UniformMatrix4(uniformProjMatrix, false, ref projMatrixData);
|
||||||
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
|
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
|
||||||
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
}
|
}
|
||||||
@ -1624,6 +1654,7 @@ namespace AssetStudio
|
|||||||
GL.UseProgram(pgmBlackID);
|
GL.UseProgram(pgmBlackID);
|
||||||
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
GL.UniformMatrix4(uniformModelMatrix, false, ref modelMatrixData);
|
||||||
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
GL.UniformMatrix4(uniformViewMatrix, false, ref viewMatrixData);
|
||||||
|
GL.UniformMatrix4(uniformProjMatrix, false, ref projMatrixData);
|
||||||
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
|
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
|
||||||
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
GL.DrawElements(BeginMode.Triangles, indiceData.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
GL.Disable(EnableCap.PolygonOffsetLine);
|
GL.Disable(EnableCap.PolygonOffsetLine);
|
||||||
|
3
AssetStudio/Properties/Resources.Designer.cs
generated
3
AssetStudio/Properties/Resources.Designer.cs
generated
@ -145,13 +145,14 @@ namespace AssetStudio.Properties {
|
|||||||
///in vec4 vertexColor;
|
///in vec4 vertexColor;
|
||||||
///uniform mat4 modelMatrix;
|
///uniform mat4 modelMatrix;
|
||||||
///uniform mat4 viewMatrix;
|
///uniform mat4 viewMatrix;
|
||||||
|
///uniform mat4 projMatrix;
|
||||||
///
|
///
|
||||||
///out vec3 normal;
|
///out vec3 normal;
|
||||||
///out vec4 color;
|
///out vec4 color;
|
||||||
///
|
///
|
||||||
///void main()
|
///void main()
|
||||||
///{
|
///{
|
||||||
/// gl_Position = viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
/// gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
||||||
/// normal = normalDirection;
|
/// normal = normalDirection;
|
||||||
/// color = vertexColor;
|
/// color = vertexColor;
|
||||||
///} 的本地化字符串。
|
///} 的本地化字符串。
|
||||||
|
@ -170,13 +170,14 @@ in vec3 normalDirection;
|
|||||||
in vec4 vertexColor;
|
in vec4 vertexColor;
|
||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 viewMatrix;
|
uniform mat4 viewMatrix;
|
||||||
|
uniform mat4 projMatrix;
|
||||||
|
|
||||||
out vec3 normal;
|
out vec3 normal;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
gl_Position = projMatrix * viewMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
||||||
normal = normalDirection;
|
normal = normalDirection;
|
||||||
color = vertexColor;
|
color = vertexColor;
|
||||||
}</value>
|
}</value>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user