Slowly getting things working
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
@@ -4,13 +4,14 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E7B84735-45AA-439A-A64B-2AF248447660}</ProjectGuid>
|
||||
<ProjectGuid>{282D9C70-9531-4960-A84B-E314D68DABFF}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WhatTheTexture</RootNamespace>
|
||||
<AssemblyName>WhatTheTexture</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<RootNamespace>InstanceTiles</RootNamespace>
|
||||
<AssemblyName>InstanceTiles</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -37,7 +38,6 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -54,10 +54,5 @@
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="tex.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
61
InstanceTiles/Program.cs
Normal file
61
InstanceTiles/Program.cs
Normal file
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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:
|
||||
//
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB |
12
hexworld.sln
12
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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
172
hexworld/Game.cs
Normal file
172
hexworld/Game.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#version 440
|
||||
|
||||
in vec4 color;
|
||||
out vec4 outputColor;
|
||||
|
||||
void
|
||||
main()
|
||||
{
|
||||
outputColor = color;
|
||||
}
|
||||
@@ -8,9 +8,10 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>hexworld</RootNamespace>
|
||||
<AssemblyName>hexworld</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -49,20 +50,18 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Cube.cs" />
|
||||
<Compile Include="Game.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="vs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="fs.glsl">
|
||||
<None Include="s.fs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="s.vs.glsl">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
@@ -71,5 +70,10 @@
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="tex2.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
10
hexworld/s.fs.glsl
Normal file
10
hexworld/s.fs.glsl
Normal file
@@ -0,0 +1,10 @@
|
||||
#version 440
|
||||
|
||||
in vec2 vTexCoord;
|
||||
|
||||
uniform sampler2D tex;
|
||||
|
||||
void main ()
|
||||
{
|
||||
gl_FragColor = texture(tex, vTexCoord) + vec4(.1);
|
||||
}
|
||||
15
hexworld/s.vs.glsl
Normal file
15
hexworld/s.vs.glsl
Normal file
@@ -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;
|
||||
}
|
||||
BIN
hexworld/tex.png
BIN
hexworld/tex.png
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
hexworld/tex2.png
Normal file
BIN
hexworld/tex2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 490 B |
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user