diff --git a/Program.cs b/Program.cs index 7486425..f456286 100644 --- a/Program.cs +++ b/Program.cs @@ -221,18 +221,18 @@ public class Game : GameWindow { protected override void 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(); GL.BindVertexArray(VertexArrayObject); VertexBufferObject = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject); - GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw); - 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.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.Use(); @@ -257,7 +257,7 @@ public class Game : GameWindow { foreach (string file in files) { if (file.ToLower().EndsWith(".jpg")) { textures.Add(new Texture(file)); - } + } } } @@ -269,11 +269,25 @@ public class Game : GameWindow { base.OnRenderFrame(e); frameCount++; 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.BindTexture(TextureTarget.Texture2D, textures[textureIndex].Handle); shader.Use(); 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(); } @@ -287,6 +301,36 @@ public class Game : GameWindow { GL.UniformMatrix4(shader.GetUniformLocation("projection"), true, ref projection); 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 {