render little thumbnails for each loaded image
This commit is contained in:
parent
6fc66aba8f
commit
225a1a623c
56
Program.cs
56
Program.cs
@ -221,18 +221,18 @@ public class Game : GameWindow {
|
|||||||
protected override void OnLoad() {
|
protected override void OnLoad() {
|
||||||
base.OnLoad();
|
base.OnLoad();
|
||||||
|
|
||||||
GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
GL.ClearColor(0.0f, 0.0f, 0.05f, 1.0f);
|
||||||
|
|
||||||
VertexArrayObject = GL.GenVertexArray();
|
VertexArrayObject = GL.GenVertexArray();
|
||||||
GL.BindVertexArray(VertexArrayObject);
|
GL.BindVertexArray(VertexArrayObject);
|
||||||
|
|
||||||
VertexBufferObject = GL.GenBuffer();
|
VertexBufferObject = GL.GenBuffer();
|
||||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
|
||||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
|
|
||||||
|
|
||||||
ElementBufferObject = GL.GenBuffer();
|
ElementBufferObject = GL.GenBuffer();
|
||||||
|
|
||||||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||||
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.StaticDraw);
|
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.DynamicDraw);
|
||||||
|
|
||||||
shader = new Shader();
|
shader = new Shader();
|
||||||
shader.Use();
|
shader.Use();
|
||||||
@ -269,11 +269,25 @@ public class Game : GameWindow {
|
|||||||
base.OnRenderFrame(e);
|
base.OnRenderFrame(e);
|
||||||
frameCount++;
|
frameCount++;
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
GL.BindVertexArray(VertexArrayObject);
|
|
||||||
|
SetVertices(0, 0, windowWidth - 152, windowHeight);
|
||||||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||||
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
||||||
GL.ActiveTexture(TextureUnit.Texture0);
|
GL.ActiveTexture(TextureUnit.Texture0);
|
||||||
GL.BindTexture(TextureTarget.Texture2D, textures[textureIndex].Handle);
|
GL.BindTexture(TextureTarget.Texture2D, textures[textureIndex].Handle);
|
||||||
shader.Use();
|
shader.Use();
|
||||||
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < textures.Count; i++) {
|
||||||
|
SetVertices(windowWidth - 150, i * 100, windowWidth, i * 100 + 98);
|
||||||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||||
|
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
||||||
|
GL.ActiveTexture(TextureUnit.Texture0);
|
||||||
|
GL.BindTexture(TextureTarget.Texture2D, textures[i].Handle);
|
||||||
|
shader.Use();
|
||||||
|
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
SwapBuffers();
|
SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,6 +301,36 @@ public class Game : GameWindow {
|
|||||||
GL.UniformMatrix4(shader.GetUniformLocation("projection"), true, ref projection);
|
GL.UniformMatrix4(shader.GetUniformLocation("projection"), true, ref projection);
|
||||||
GL.Viewport(0, 0, windowWidth, windowHeight);
|
GL.Viewport(0, 0, windowWidth, windowHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetVertices(float left, float top, float right, float bottom) {
|
||||||
|
// top left
|
||||||
|
vertices[0] = left;
|
||||||
|
vertices[1] = top;
|
||||||
|
vertices[2] = 0f;
|
||||||
|
vertices[3] = 0f;
|
||||||
|
vertices[4] = 0f;
|
||||||
|
|
||||||
|
// top right
|
||||||
|
vertices[5] = right;
|
||||||
|
vertices[6] = top;
|
||||||
|
vertices[7] = 0f;
|
||||||
|
vertices[8] = 1f;
|
||||||
|
vertices[9] = 0f;
|
||||||
|
|
||||||
|
// bottom right
|
||||||
|
vertices[10] = right;
|
||||||
|
vertices[11] = bottom;
|
||||||
|
vertices[12] = 0f;
|
||||||
|
vertices[13] = 1f;
|
||||||
|
vertices[14] = 1f;
|
||||||
|
|
||||||
|
// bottom left
|
||||||
|
vertices[15] = left;
|
||||||
|
vertices[16] = bottom;
|
||||||
|
vertices[17] = 0f;
|
||||||
|
vertices[18] = 0f;
|
||||||
|
vertices[19] = 1f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Program {
|
static class Program {
|
||||||
|
Loading…
Reference in New Issue
Block a user