diff --git a/WhatTheTexture/App.config b/InstanceTiles/App.config
similarity index 59%
rename from WhatTheTexture/App.config
rename to InstanceTiles/App.config
index 88fa402..bae5d6d 100644
--- a/WhatTheTexture/App.config
+++ b/InstanceTiles/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/WhatTheTexture/WhatTheTexture.csproj b/InstanceTiles/InstanceTiles.csproj
similarity index 85%
rename from WhatTheTexture/WhatTheTexture.csproj
rename to InstanceTiles/InstanceTiles.csproj
index 2368221..cfcf1e3 100644
--- a/WhatTheTexture/WhatTheTexture.csproj
+++ b/InstanceTiles/InstanceTiles.csproj
@@ -4,13 +4,14 @@
Debug
AnyCPU
- {E7B84735-45AA-439A-A64B-2AF248447660}
+ {282D9C70-9531-4960-A84B-E314D68DABFF}
Exe
- WhatTheTexture
- WhatTheTexture
- v4.5.2
+ InstanceTiles
+ InstanceTiles
+ v4.6.1
512
true
+
AnyCPU
@@ -37,7 +38,6 @@
-
@@ -54,10 +54,5 @@
-
-
- Always
-
-
\ No newline at end of file
diff --git a/WhatTheTexture/OpenTK.dll.config b/InstanceTiles/OpenTK.dll.config
similarity index 100%
rename from WhatTheTexture/OpenTK.dll.config
rename to InstanceTiles/OpenTK.dll.config
diff --git a/InstanceTiles/Program.cs b/InstanceTiles/Program.cs
new file mode 100644
index 0000000..e8d0d73
--- /dev/null
+++ b/InstanceTiles/Program.cs
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK;
+
+namespace InstanceTiles
+{
+ internal class Program
+ {
+ private float[] points =
+ {
+ +.5f, +.5f, +.5f, -.5f, +.5f, +.5f, -.5f, -.5f, +.5f,
+ -.5f, -.5f, +.5f, +.5f, -.5f, +.5f, +.5f, +.5f, +.5f,
+ -.5f, +.5f, -.5f, +.5f, +.5f, -.5f, +.5f, -.5f, -.5f,
+ +.5f, -.5f, -.5f, -.5f, -.5f, -.5f, -.5f, +.5f, -.5f,
+ +.5f, +.5f, -.5f, +.5f, +.5f, +.5f, +.5f, -.5f, +.5f,
+ +.5f, -.5f, +.5f, +.5f, -.5f, -.5f, +.5f, +.5f, -.5f,
+ -.5f, +.5f, +.5f, -.5f, +.5f, -.5f, -.5f, -.5f, -.5f,
+ -.5f, -.5f, -.5f, -.5f, -.5f, +.5f, -.5f, +.5f, +.5f,
+ +.5f, +.5f, -.5f, -.5f, +.5f, -.5f, -.5f, +.5f, +.5f,
+ -.5f, +.5f, +.5f, +.5f, +.5f, +.5f, +.5f, +.5f, -.5f,
+ +.5f, -.5f, +.5f, -.5f, -.5f, +.5f, -.5f, -.5f, -.5f,
+ -.5f, -.5f, -.5f, +.5f, -.5f, -.5f, +.5f, -.5f, +.5f,
+ };
+
+ private float[] texCoords =
+ {
+ 1.0f, 0.0f, 5.0f, 0.0f, 5.0f, 1.0f,
+ 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 5.0f,
+ 1.0f, 0.5f, 0.0f, 0.5f, 0.0f, 1.0f,
+ 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f,
+ 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f,
+ 0.0f, 0.0f, 0.0f, 0.5f, 0.5f, 0.5f,
+ 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 0.5f, 0.5f, 0.5f, 0.5f, 0.0f,
+ 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f,
+ 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f,
+ 0.0f, 0.5f, 0.5f, 0.5f, 0.5f, 0.0f,
+ };
+
+ private float[] cubePoints =
+ {
+ 0, 0, 0,
+ 1, 0, 0,
+ 0, 1, 0,
+ };
+
+ private float[] cubeTexCoords =
+ {
+ 0.05f
+ };
+
+ private static void Main(string[] args)
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/WhatTheTexture/Properties/AssemblyInfo.cs b/InstanceTiles/Properties/AssemblyInfo.cs
similarity index 89%
rename from WhatTheTexture/Properties/AssemblyInfo.cs
rename to InstanceTiles/Properties/AssemblyInfo.cs
index 1259cde..5195eb1 100644
--- a/WhatTheTexture/Properties/AssemblyInfo.cs
+++ b/InstanceTiles/Properties/AssemblyInfo.cs
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("WhatTheTexture")]
+[assembly: AssemblyTitle("InstanceTiles")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("WhatTheTexture")]
+[assembly: AssemblyProduct("InstanceTiles")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("e7b84735-45aa-439a-a64b-2af248447660")]
+[assembly: Guid("282d9c70-9531-4960-a84b-e314d68dabff")]
// Version information for an assembly consists of the following four values:
//
diff --git a/WhatTheTexture/packages.config b/InstanceTiles/packages.config
similarity index 100%
rename from WhatTheTexture/packages.config
rename to InstanceTiles/packages.config
diff --git a/WhatTheTexture/Program.cs b/WhatTheTexture/Program.cs
deleted file mode 100644
index 2c615b9..0000000
--- a/WhatTheTexture/Program.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
-using PixelFormat = OpenTK.Graphics.OpenGL.PixelFormat;
-
-namespace WhatTheTexture
-{
- internal class Program : GameWindow
- {
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
-
- Width = 1920;
- Height = 1080;
- X = (DisplayDevice.Default.Width - Width) / 2;
- Y = (DisplayDevice.Default.Height - Height) / 2;
-
- GL.Enable(EnableCap.Texture2D);
-
- var image = new Bitmap("tex.png");
-
- var texID = GL.GenTexture();
-
- GL.ActiveTexture(TextureUnit.Texture0);
- GL.BindTexture(TextureTarget.Texture2D, texID);
- var bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
- ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
-
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
- (int) TextureMinFilter.Nearest);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
- (int) TextureMagFilter.Nearest);
-
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmapData.Width, bitmapData.Height, 0,
- PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0);
-
- image.UnlockBits(bitmapData);
-
- GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
-
- GL.Viewport(ClientRectangle);
-
- GL.Begin(PrimitiveType.Triangles);
-
- GL.TexCoord2(0, 0);
- GL.Vertex2(-.8, -.8);
- GL.TexCoord2(1, 0);
- GL.Vertex2(.8, -.8);
- GL.TexCoord2(0, 1);
- GL.Vertex2(-.8, .8);
-
- GL.TexCoord2(1, 1);
- GL.Vertex2(.8, .8);
- GL.TexCoord2(1, 0);
- GL.Vertex2(.8, -.8);
- GL.TexCoord2(0, 1);
- GL.Vertex2(-.8, .8);
-
- GL.End();
-
- SwapBuffers();
- }
-
- private static void Main(string[] args)
- {
- using (var p = new Program())
- {
- p.Run();
- }
- }
- }
-}
\ No newline at end of file
diff --git a/WhatTheTexture/tex.png b/WhatTheTexture/tex.png
deleted file mode 100644
index 4b43e1e..0000000
Binary files a/WhatTheTexture/tex.png and /dev/null differ
diff --git a/hexworld.sln b/hexworld.sln
index ded023d..7f56b50 100644
--- a/hexworld.sln
+++ b/hexworld.sln
@@ -1,11 +1,11 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26127.3
+VisualStudioVersion = 15.0.26206.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hexworld", "hexworld\hexworld.csproj", "{AD9ED057-FB47-44CB-8839-22924B409706}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhatTheTexture", "WhatTheTexture\WhatTheTexture.csproj", "{E7B84735-45AA-439A-A64B-2AF248447660}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InstanceTiles", "InstanceTiles\InstanceTiles.csproj", "{282D9C70-9531-4960-A84B-E314D68DABFF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -17,10 +17,10 @@ Global
{AD9ED057-FB47-44CB-8839-22924B409706}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD9ED057-FB47-44CB-8839-22924B409706}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD9ED057-FB47-44CB-8839-22924B409706}.Release|Any CPU.Build.0 = Release|Any CPU
- {E7B84735-45AA-439A-A64B-2AF248447660}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {E7B84735-45AA-439A-A64B-2AF248447660}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {E7B84735-45AA-439A-A64B-2AF248447660}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {E7B84735-45AA-439A-A64B-2AF248447660}.Release|Any CPU.Build.0 = Release|Any CPU
+ {282D9C70-9531-4960-A84B-E314D68DABFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {282D9C70-9531-4960-A84B-E314D68DABFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {282D9C70-9531-4960-A84B-E314D68DABFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {282D9C70-9531-4960-A84B-E314D68DABFF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/hexworld/App.config b/hexworld/App.config
index 88fa402..bae5d6d 100644
--- a/hexworld/App.config
+++ b/hexworld/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/hexworld/Cube.cs b/hexworld/Cube.cs
deleted file mode 100644
index 6dfbbba..0000000
--- a/hexworld/Cube.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Threading.Tasks;
-using OpenTK;
-
-namespace hexworld
-{
- [StructLayout(LayoutKind.Sequential)]
- public struct Cube
- {
- public Vector3 Position;
- public Vector3 Color;
-
- public Cube(Vector3 position, Vector3 color)
- {
- Position = position;
- Color = color;
- }
- }
-}
diff --git a/hexworld/Game.cs b/hexworld/Game.cs
new file mode 100644
index 0000000..76a2e2a
--- /dev/null
+++ b/hexworld/Game.cs
@@ -0,0 +1,172 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using OpenTK;
+using OpenTK.Graphics.OpenGL4;
+using PixelFormat = OpenTK.Graphics.OpenGL4.PixelFormat;
+
+namespace hexworld
+{
+ public struct Vert
+ {
+ public static readonly int SizeInBytes = sizeof(float) * 5;
+
+ public Vector3 Point;
+ public Vector2 TexCoord;
+
+ public Vert(Vector3 point, Vector2 texCoord)
+ {
+ Point = point;
+ TexCoord = texCoord;
+ }
+
+ public Vert(float px, float py, float pz, float tx, float ty)
+ : this(new Vector3(px, py, pz), new Vector2(tx, ty))
+ {
+ }
+ }
+
+ public class HexWindow : GameWindow
+ {
+ private readonly Vert[] _verts =
+ {
+ // +X
+ new Vert(+1, +1, -1, 1.0f, 0.5f), new Vert(+1, +1, +1, 1.0f, 0.0f), new Vert(+1, -1, +1, 0.5f, 0.0f),
+ new Vert(+1, -1, +1, 0.5f, 0.0f), new Vert(+1, -1, -1, 0.5f, 0.5f), new Vert(+1, +1, -1, 1.0f, 0.5f),
+ // -X
+ new Vert(-1, +1, +1, 0.5f, 0.0f), new Vert(-1, +1, -1, 0.5f, 0.5f), new Vert(-1, -1, -1, 1.0f, 0.5f),
+ new Vert(-1, -1, -1, 1.0f, 0.5f), new Vert(-1, -1, +1, 1.0f, 0.0f), new Vert(-1, +1, +1, 0.5f, 0.0f),
+ // +Y
+ new Vert(+1, +1, -1, 0.5f, 0.5f), new Vert(-1, +1, -1, 1.0f, 0.5f), new Vert(-1, +1, +1, 1.0f, 0.0f),
+ new Vert(-1, +1, +1, 1.0f, 0.0f), new Vert(+1, +1, +1, 0.5f, 0.0f), new Vert(+1, +1, -1, 0.5f, 0.5f),
+ // -Y
+ new Vert(+1, -1, +1, 1.0f, 0.0f), new Vert(-1, -1, +1, 0.5f, 0.0f), new Vert(-1, -1, -1, 0.5f, 0.5f),
+ new Vert(-1, -1, -1, 0.5f, 0.5f), new Vert(+1, -1, -1, 1.0f, 0.5f), new Vert(+1, -1, +1, 1.0f, 0.0f),
+ // +Z
+ new Vert(+1, +1, +1, 0.5f, 0.0f), new Vert(-1, +1, +1, 0.0f, 0.0f), new Vert(-1, -1, +1, 0.0f, 0.5f),
+ new Vert(-1, -1, +1, 0.0f, 0.5f), new Vert(+1, -1, +1, 0.5f, 0.5f), new Vert(+1, +1, +1, 0.5f, 0.0f),
+ // -Z
+ new Vert(+1, +1, -1, 0.5f, 0.5f), new Vert(-1, +1, -1, 0.0f, 0.5f), new Vert(-1, -1, -1, 0.0f, 1.0f),
+ new Vert(-1, -1, -1, 0.0f, 1.0f), new Vert(+1, -1, -1, 0.5f, 1.0f), new Vert(+1, +1, -1, 0.5f, 0.5f),
+ };
+
+ private Matrix4 _view = Matrix4.Identity;
+ private Matrix4 _proj = Matrix4.Identity;
+
+ private int _pgm;
+ private int _texLoc;
+ private int _tex2Loc;
+
+ public HexWindow(int width, int height)
+ : base(width, height)
+ {
+ Width = width;
+ Height = height;
+ X = (DisplayDevice.Default.Width - Width) / 2;
+ Y = (DisplayDevice.Default.Height - Height) / 2;
+ }
+
+ protected override void OnUpdateFrame(FrameEventArgs e)
+ {
+ base.OnUpdateFrame(e);
+
+ const float s = 200f;
+ _view = Matrix4.LookAt(10 * Vector3.One, Vector3.Zero, Vector3.UnitZ);
+ _proj = Matrix4.CreateOrthographic(Width / s, Height / s, 0, 100);
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+
+ var vertsVbo = GL.GenBuffer();
+ GL.BindBuffer(BufferTarget.ArrayBuffer, vertsVbo);
+ GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr) (_verts.Length * Vert.SizeInBytes), _verts,
+ BufferUsageHint.StaticDraw);
+
+ var vs = GL.CreateShader(ShaderType.VertexShader);
+ GL.ShaderSource(vs, File.ReadAllText("s.vs.glsl"));
+ GL.CompileShader(vs);
+ Console.Out.WriteLine("vs:" + GL.GetShaderInfoLog(vs));
+
+ var fs = GL.CreateShader(ShaderType.FragmentShader);
+ GL.ShaderSource(fs, File.ReadAllText("s.fs.glsl"));
+ GL.CompileShader(fs);
+ Console.Out.WriteLine("fs: " + GL.GetShaderInfoLog(fs));
+
+ _pgm = GL.CreateProgram();
+ GL.AttachShader(_pgm, vs);
+ GL.AttachShader(_pgm, fs);
+ GL.LinkProgram(_pgm);
+ Console.Out.WriteLine("pgm: " + GL.GetProgramInfoLog(_pgm));
+
+ GL.BindBuffer(BufferTarget.ArrayBuffer, vertsVbo);
+ GL.EnableVertexAttribArray(0);
+ GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vert.SizeInBytes, 0);
+ GL.EnableVertexAttribArray(1);
+ GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, Vert.SizeInBytes, Vector3.SizeInBytes);
+
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
+
+ var texBmp = new Bitmap("tex.png");
+ _texLoc = GL.GenTexture();
+ GL.BindTexture(TextureTarget.Texture2D, _texLoc);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
+ (int) TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
+ (int) TextureMagFilter.Nearest);
+ var texData = texBmp.LockBits(new Rectangle(0, 0, texBmp.Width, texBmp.Height),
+ ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texBmp.Width, texBmp.Height, 0,
+ PixelFormat.Bgra, PixelType.UnsignedByte, texData.Scan0);
+ texBmp.UnlockBits(texData);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+
+ GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
+
+ var tex2Bmp = new Bitmap("tex2.png");
+ _tex2Loc = GL.GenTexture();
+ GL.BindTexture(TextureTarget.Texture2D, _tex2Loc);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
+ (int) TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
+ (int) TextureMagFilter.Nearest);
+ var tex2Data = tex2Bmp.LockBits(new Rectangle(0, 0, tex2Bmp.Width, tex2Bmp.Height),
+ ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, tex2Bmp.Width, tex2Bmp.Height, 0,
+ PixelFormat.Bgra, PixelType.UnsignedByte, tex2Data.Scan0);
+ tex2Bmp.UnlockBits(tex2Data);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
+
+ protected override void OnRenderFrame(FrameEventArgs e)
+ {
+ base.OnRenderFrame(e);
+
+ GL.Viewport(ClientRectangle);
+ GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
+
+ GL.Enable(EnableCap.DepthTest);
+ GL.UseProgram(_pgm);
+
+ GL.ActiveTexture(TextureUnit.Texture0);
+ GL.BindTexture(TextureTarget.Texture2D, _tex2Loc);
+ GL.Uniform1(GL.GetUniformLocation(_pgm, "tex"), 0);
+
+ GL.UniformMatrix4(GL.GetUniformLocation(_pgm, "view"), false, ref _view);
+ GL.UniformMatrix4(GL.GetUniformLocation(_pgm, "proj"), false, ref _proj);
+
+ GL.DrawArrays(PrimitiveType.Triangles, 0, _verts.Length);
+
+ GL.ActiveTexture(TextureUnit.Texture0);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+
+ SwapBuffers();
+ }
+ }
+}
\ No newline at end of file
diff --git a/hexworld/Program.cs b/hexworld/Program.cs
index f3ce35c..c4946bc 100644
--- a/hexworld/Program.cs
+++ b/hexworld/Program.cs
@@ -1,203 +1,17 @@
using System;
-using System.IO;
-using OpenTK;
-using OpenTK.Graphics.OpenGL;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
namespace hexworld
{
- internal class Game : GameWindow
+ public class Program
{
- #region Constructors
-
- public Game()
- : this(1920, 1080)
- {
- }
-
- public Game(int width, int height)
- : base(width, height)
- {
- Width = width;
- Height = height;
- X = (DisplayDevice.Default.Width - Width) / 2;
- Y = (DisplayDevice.Default.Height - Height) / 2;
- }
-
- #endregion
-
- #region Shaders
-
- private int _pgmId;
- private int _vsId;
- private int _fsId;
-
- #region Handles
-
- #endregion
-
- private void LoadShader(string filename, ShaderType type, int program, out int address)
- {
- address = GL.CreateShader(type);
- using (var sr = new StreamReader(filename))
- {
- GL.ShaderSource(address, sr.ReadToEnd());
- }
- GL.CompileShader(address);
- GL.AttachShader(program, address);
- Console.WriteLine(GL.GetShaderInfoLog(address));
- }
-
- #endregion
-
- #region Buffers
-
- private int _vboPosition;
- private int _cubeVbo;
- private int _ibo;
-
-
- #endregion
-
- #region Data
-
- private float[] _vertdata;
- private Cube[] _cubes;
- private int[] _indices;
-
- private Matrix4 _view;
- private Matrix4 _projection;
-
- #endregion
-
- private void InitProgram()
- {
- _pgmId = GL.CreateProgram();
-
- LoadShader("vs.glsl", ShaderType.VertexShader, _pgmId, out _vsId);
- LoadShader("fs.glsl", ShaderType.FragmentShader, _pgmId, out _fsId);
-
- GL.LinkProgram(_pgmId);
- Console.WriteLine(GL.GetProgramInfoLog(_pgmId));
-
- GL.GenBuffers(1, out _vboPosition);
- GL.BindBuffer(BufferTarget.ArrayBuffer, _vboPosition);
- GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr) (_vertdata.Length * sizeof(float)), _vertdata,
- BufferUsageHint.StaticDraw);
- GL.EnableVertexAttribArray(0);
- GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
-
- GL.GenBuffers(1, out _cubeVbo);
- GL.BindBuffer(BufferTarget.ArrayBuffer, _cubeVbo);
- GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr) (_cubes.Length * sizeof(float) * 6), _cubes,
- BufferUsageHint.StaticDraw);
- GL.EnableVertexAttribArray(1);
- GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 0);
- GL.VertexAttribDivisor(1, 1);
-
- GL.EnableVertexAttribArray(2);
- GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, 6 * sizeof(float), 3 * sizeof(float));
- GL.VertexAttribDivisor(2, 1);
-
- GL.GenBuffers(1, out _ibo);
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ibo);
- GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr) (_indices.Length * sizeof(int)), _indices,
- BufferUsageHint.StaticDraw);
- }
-
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
-
-
- _vertdata = new[]
- {
- -.5f, -.5f, -.5f,
- -.5f, -.5f, .5f,
- -.5f, .5f, -.5f,
- -.5f, .5f, .5f,
- .5f, -.5f, -.5f,
- .5f, -.5f, .5f,
- .5f, .5f, -.5f,
- .5f, .5f, .5f,
- };
-
- _indices = new[]
- {
- 0, 1, 2, 1, 2, 3,
- 4, 5, 6, 5, 6, 7,
- 0, 1, 4, 1, 4, 5,
- 2, 3, 6, 3, 6, 7,
- 0, 2, 4, 2, 4, 6,
- 1, 3, 5, 3, 5, 7
- };
-
- _cubes = new[]
- {
- new Cube(new Vector3(2, 2, 0), new Vector3(0.9f, 0.1f, 0.1f)),
- new Cube(new Vector3(2, 1, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(2, 0, 0), new Vector3(0.1f, 0.9f, 0.1f)),
- new Cube(new Vector3(2, -1, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(2, -2, 0), new Vector3(0.9f, 0.1f, 0.1f)),
- new Cube(new Vector3(1, 2, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(1, -2, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(0, 2, 0), new Vector3(0.1f, 0.1f, 0.9f)),
- new Cube(new Vector3(0, -2, 0), new Vector3(0.1f, 0.1f, 0.9f)),
- new Cube(new Vector3(-1, 2, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(-1, -2, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(-2, 2, 0), new Vector3(0.9f, 0.1f, 0.1f)),
- new Cube(new Vector3(-2, 1, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(-2, 0, 0), new Vector3(0.1f, 0.9f, 0.1f)),
- new Cube(new Vector3(-2, -1, 0), new Vector3(0.1f, 0.1f, 0.1f)),
- new Cube(new Vector3(-2, -2, 0), new Vector3(0.9f, 0.1f, 0.1f)),
- };
-
- InitProgram();
-
- _view = _projection = Matrix4.Identity;
- }
-
- protected override void OnRenderFrame(FrameEventArgs e)
- {
- base.OnRenderFrame(e);
- GL.Viewport(ClientRectangle);
-
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.Enable(EnableCap.DepthTest);
-
-
- GL.DrawElementsInstanced(PrimitiveType.Triangles, _indices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero,
- _cubes.Length);
-
- GL.Flush();
- SwapBuffers();
- }
-
- protected override void OnUpdateFrame(FrameEventArgs e)
- {
- base.OnUpdateFrame(e);
-
- _view = Matrix4.LookAt(Vector3.Zero, -Vector3.One, Vector3.UnitZ);
-
- GL.UniformMatrix4(0, false, ref _view);
- GL.UniformMatrix4(1, false, ref _projection);
-
- GL.UseProgram(_pgmId);
-
- GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
- }
-
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
-
- float size = 100;
- _projection = Matrix4.CreateOrthographic(Width / size, Height / size, -50, 50);
- }
-
public static void Main(string[] args)
{
- Game gw;
- using (gw = new Game())
+ using (var gw = new HexWindow(1920, 1080))
{
gw.Run();
}
diff --git a/hexworld/fs.glsl b/hexworld/fs.glsl
deleted file mode 100644
index 1ba171f..0000000
--- a/hexworld/fs.glsl
+++ /dev/null
@@ -1,10 +0,0 @@
-#version 440
-
-in vec4 color;
-out vec4 outputColor;
-
-void
-main()
-{
- outputColor = color;
-}
\ No newline at end of file
diff --git a/hexworld/hexworld.csproj b/hexworld/hexworld.csproj
index d2f1510..fe96bd2 100644
--- a/hexworld/hexworld.csproj
+++ b/hexworld/hexworld.csproj
@@ -8,9 +8,10 @@
Exe
hexworld
hexworld
- v4.5.2
+ v4.6.1
512
true
+
AnyCPU
@@ -49,20 +50,18 @@
-
+
-
- Always
-
-
-
-
+
+ Always
+
+
Always
@@ -71,5 +70,10 @@
Always
+
+
+ Always
+
+
\ No newline at end of file
diff --git a/hexworld/s.fs.glsl b/hexworld/s.fs.glsl
new file mode 100644
index 0000000..40028a0
--- /dev/null
+++ b/hexworld/s.fs.glsl
@@ -0,0 +1,10 @@
+#version 440
+
+in vec2 vTexCoord;
+
+uniform sampler2D tex;
+
+void main ()
+{
+ gl_FragColor = texture(tex, vTexCoord) + vec4(.1);
+}
\ No newline at end of file
diff --git a/hexworld/s.vs.glsl b/hexworld/s.vs.glsl
new file mode 100644
index 0000000..39134a3
--- /dev/null
+++ b/hexworld/s.vs.glsl
@@ -0,0 +1,15 @@
+#version 440
+
+in vec3 pos;
+in vec2 texCoord;
+
+out vec2 vTexCoord;
+
+layout (location=1) uniform mat4 view;
+layout (location=2) uniform mat4 proj;
+
+void main ()
+{
+ gl_Position = proj*view*vec4(pos, 1);
+ vTexCoord = texCoord;
+}
\ No newline at end of file
diff --git a/hexworld/tex.png b/hexworld/tex.png
index 75eb357..21b5b4d 100644
Binary files a/hexworld/tex.png and b/hexworld/tex.png differ
diff --git a/hexworld/tex2.png b/hexworld/tex2.png
new file mode 100644
index 0000000..2f7e1ae
Binary files /dev/null and b/hexworld/tex2.png differ
diff --git a/hexworld/vs.glsl b/hexworld/vs.glsl
deleted file mode 100644
index 28d44a7..0000000
--- a/hexworld/vs.glsl
+++ /dev/null
@@ -1,17 +0,0 @@
-#version 440
-
-layout (location = 0) in vec3 vPosition;
-layout (location = 1) in vec3 vColor;
-layout (location = 2) in vec3 vOffset;
-
-out vec4 color;
-
-layout (location = 0) uniform mat4 view;
-layout (location = 1) uniform mat4 projection;
-
-void main()
-{
- vec3 pos = vPosition + vOffset;
- gl_Position = projection * view * vec4(pos, 1.0);
- color = vec4( vColor, 1.0);
-}
\ No newline at end of file