Initial Commit
commit
8ae20b7159
|
@ -0,0 +1,40 @@
|
|||
# Autosave files
|
||||
*~
|
||||
|
||||
# build
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
||||
packages/
|
||||
TestResults/
|
||||
|
||||
# globs
|
||||
Makefile.in
|
||||
*.DS_Store
|
||||
*.sln.cache
|
||||
*.suo
|
||||
*.cache
|
||||
*.pidb
|
||||
*.userprefs
|
||||
*.usertasks
|
||||
config.log
|
||||
config.make
|
||||
config.status
|
||||
aclocal.m4
|
||||
install-sh
|
||||
autom4te.cache/
|
||||
*.user
|
||||
*.tar.gz
|
||||
tarballs/
|
||||
test-results/
|
||||
Thumbs.db
|
||||
|
||||
# Mac bundle stuff
|
||||
*.dmg
|
||||
*.app
|
||||
|
||||
# resharper
|
||||
*_Resharper.*
|
||||
*.Resharper
|
||||
|
||||
# dotCover
|
||||
*.dotCover
|
|
@ -0,0 +1,58 @@
|
|||
using System;
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class BootStrap
|
||||
{
|
||||
public static BootStrap _instance;
|
||||
public static BootStrap instance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
OpenGLWindow glWindow;
|
||||
Graphics graphics;
|
||||
|
||||
SquaredMap map;
|
||||
|
||||
public static void Main(string[] args){
|
||||
_instance = new BootStrap();
|
||||
|
||||
_instance.run();
|
||||
|
||||
}
|
||||
|
||||
public BootStrap()
|
||||
{
|
||||
bootGraphics();
|
||||
bootMap();
|
||||
}
|
||||
|
||||
public SquaredMap SquaredMap {
|
||||
get { return this.map; }
|
||||
}
|
||||
|
||||
public void bootGraphics(){
|
||||
glWindow = new OpenGLWindow();
|
||||
graphics = new Graphics();
|
||||
}
|
||||
|
||||
public void bootMap(){
|
||||
map = new SquaredMap(25,25);
|
||||
}
|
||||
|
||||
|
||||
public void run(){
|
||||
glWindow.MakeCurrent();
|
||||
|
||||
glWindow.Run(30,30);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class GLCamera
|
||||
{
|
||||
Matrix4 position,
|
||||
projection,
|
||||
rotation,
|
||||
lookat;
|
||||
|
||||
Matrix4 result;
|
||||
|
||||
float arc_z,
|
||||
arc_x;
|
||||
float distance;
|
||||
|
||||
public GLCamera()
|
||||
{
|
||||
lookat = Matrix4.CreateTranslation(1600, 1600, 0);
|
||||
|
||||
distance = 2500.0f;
|
||||
|
||||
projection = Matrix4.CreatePerspectiveFieldOfView(
|
||||
MathHelper.PiOver4,
|
||||
1.6f,
|
||||
0.5f,
|
||||
100000.0f
|
||||
);
|
||||
rotation = Matrix4.CreateScale(1.0f);
|
||||
|
||||
setup();
|
||||
}
|
||||
|
||||
public void setViewport(int width,int height){
|
||||
projection = Matrix4.CreatePerspectiveFieldOfView(
|
||||
MathHelper.PiOver4,
|
||||
width / (float)height,
|
||||
0.5f,
|
||||
100000.0f
|
||||
);
|
||||
}
|
||||
|
||||
public Matrix4 Rotation {
|
||||
get { return this.rotation; }
|
||||
}
|
||||
|
||||
public float ArcZ
|
||||
{
|
||||
get { return this.arc_z; }
|
||||
set { this.arc_z = value; }
|
||||
}
|
||||
|
||||
public float ArcX
|
||||
{
|
||||
get { return this.arc_x; }
|
||||
set { this.arc_x = value; }
|
||||
}
|
||||
|
||||
public float Distance {
|
||||
get { return this.distance; }
|
||||
set { this.distance = value; }
|
||||
}
|
||||
|
||||
public void setup(){
|
||||
rotation = Matrix4.CreateRotationZ(this.arc_z) * Matrix4.CreateRotationX(this.arc_x);
|
||||
position = Matrix4.CreateTranslation(0, 0, distance);
|
||||
|
||||
result = Matrix4.Identity;
|
||||
result *= lookat.Inverted();
|
||||
result *= rotation;
|
||||
// result *= Matrix4.CreateRotationZ(this.arc_z);
|
||||
// result *= Matrix4.CreateRotationX(this.arc_x);
|
||||
result *= position.Inverted();
|
||||
result *= projection;
|
||||
}
|
||||
|
||||
public Matrix4 Matrix {
|
||||
get { return this.result; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class Graphics
|
||||
{
|
||||
private TextureManager textureManager;
|
||||
|
||||
public Graphics()
|
||||
{
|
||||
this.textureManager = new TextureManager();
|
||||
}
|
||||
|
||||
|
||||
TextureManager TextureManager {
|
||||
get { return this.textureManager; }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class OpenGLWindow : GameWindow
|
||||
{
|
||||
private GLCamera camera;
|
||||
|
||||
private Point mouseCapturePosition;
|
||||
private bool mouseCaptured;
|
||||
|
||||
public OpenGLWindow()
|
||||
:base(800, 600,
|
||||
GraphicsMode.Default,
|
||||
"nhEngine",
|
||||
GameWindowFlags.Default,
|
||||
DisplayDevice.Default,
|
||||
3, 3,
|
||||
GraphicsContextFlags.ForwardCompatible)
|
||||
{
|
||||
VSync = VSyncMode.On;
|
||||
camera = new GLCamera();
|
||||
camera.ArcX = -MathHelper.PiOver3;
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
GL.ClearColor(0.1f, 0.2f, 0.5f, 0.0f);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
|
||||
GL.Viewport(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);
|
||||
camera.setViewport(ClientRectangle.Width, ClientRectangle.Height);
|
||||
}
|
||||
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnRenderFrame(e);
|
||||
|
||||
BootStrap boot = BootStrap.instance();
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
//camera.ArcX = -MathHelper.PiOver2 * 0.8f;
|
||||
//camera.ArcZ += MathHelper.Pi / 180;
|
||||
|
||||
camera.setup();
|
||||
|
||||
boot.SquaredMap.paint(camera);
|
||||
|
||||
SwapBuffers();
|
||||
}
|
||||
|
||||
private void captureMouse(){
|
||||
mouseCapturePosition = new Point(Mouse.X, Mouse.Y);
|
||||
mouseCaptured = true;
|
||||
CursorVisible = false;
|
||||
}
|
||||
|
||||
private void releaseMouse(){
|
||||
mouseCaptured = false;
|
||||
CursorVisible = true;
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(OpenTK.Input.MouseMoveEventArgs e)
|
||||
{
|
||||
if (mouseCaptured){
|
||||
Point delta = new Point(e.X - mouseCapturePosition.X, e.Y - mouseCapturePosition.Y);
|
||||
onMouseCapturedMove(delta);
|
||||
mouseCapturePosition = e.Position;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void onMouseCapturedMove(Point delta){
|
||||
camera.ArcZ += ((float)delta.X) / 100.0f;
|
||||
camera.ArcX += ((float)delta.Y) / 100.0f;
|
||||
|
||||
if (camera.ArcX > 0.0f){
|
||||
camera.ArcX = 0.0f;
|
||||
}
|
||||
|
||||
if (camera.ArcX < -MathHelper.PiOver2){
|
||||
camera.ArcX = -MathHelper.PiOver2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(OpenTK.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
switch (e.Button){
|
||||
case OpenTK.Input.MouseButton.Left:
|
||||
break;
|
||||
case OpenTK.Input.MouseButton.Right:
|
||||
captureMouse();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(OpenTK.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
releaseMouse();
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(OpenTK.Input.MouseWheelEventArgs e)
|
||||
{
|
||||
camera.Distance += e.DeltaPrecise * 16.0f;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<configuration>
|
||||
<dllmap os="linux" dll="opengl32.dll" target="libGL.so.1"/>
|
||||
<dllmap os="linux" dll="glu32.dll" target="libGLU.so.1"/>
|
||||
<dllmap os="linux" dll="openal32.dll" target="libopenal.so.1"/>
|
||||
<dllmap os="linux" dll="alut.dll" target="libalut.so.0"/>
|
||||
<dllmap os="linux" dll="opencl.dll" target="libOpenCL.so"/>
|
||||
<dllmap os="linux" dll="libX11" target="libX11.so.6"/>
|
||||
<dllmap os="linux" dll="libXi" target="libXi.so.6"/>
|
||||
<dllmap os="linux" dll="SDL2.dll" target="libSDL2-2.0.so.0"/>
|
||||
<dllmap os="osx" dll="opengl32.dll" target="/System/Library/Frameworks/OpenGL.framework/OpenGL"/>
|
||||
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
|
||||
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
|
||||
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
|
||||
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
|
||||
<!-- XQuartz compatibility (X11 on Mac) -->
|
||||
<dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
|
||||
<dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
|
||||
<dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
|
||||
<dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
|
||||
<dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
|
||||
<dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
|
||||
</configuration>
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class Shader
|
||||
{
|
||||
private int id;
|
||||
|
||||
private ShaderType shaderType;
|
||||
private String source;
|
||||
|
||||
public Shader(ShaderType shaderType, String source)
|
||||
{
|
||||
this.id = GL.CreateShader(shaderType);
|
||||
|
||||
this.shaderType = shaderType;
|
||||
this.source = source;
|
||||
|
||||
compile();
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return this.id; }
|
||||
}
|
||||
|
||||
public Shader(ShaderType shaderType, FileStream file)
|
||||
{
|
||||
this.id = GL.CreateShader(shaderType);
|
||||
this.shaderType = shaderType;
|
||||
|
||||
StreamReader sr = new StreamReader(file);
|
||||
this.source = sr.ReadToEnd();
|
||||
|
||||
|
||||
compile();
|
||||
}
|
||||
|
||||
private void compile()
|
||||
{
|
||||
GL.ShaderSource(this.id, source);
|
||||
GL.CompileShader(this.id);
|
||||
|
||||
string msg = GL.GetShaderInfoLog((int)this.id);
|
||||
|
||||
Console.WriteLine("Supported Shader Version: {0}", GL.GetString(StringName.ShadingLanguageVersion));
|
||||
Console.WriteLine("Shader Compiled: {0}", msg);
|
||||
|
||||
}
|
||||
|
||||
public ShaderType ShaderType
|
||||
{
|
||||
get { return this.shaderType; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace nhengine {
|
||||
|
||||
public class ShaderManager {
|
||||
private static ShaderManager _instance;
|
||||
|
||||
private List<Shader> shaders;
|
||||
|
||||
public ShaderManager(){
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
this.shaders = new List<Shader>();
|
||||
}
|
||||
|
||||
void registerShader(Shader shader){
|
||||
this.shaders.Add(shader);
|
||||
}
|
||||
|
||||
public class Shader
|
||||
{
|
||||
|
||||
private int id;
|
||||
private ShaderType shaderType;
|
||||
private String source;
|
||||
|
||||
public Shader(ShaderType shaderType, String source)
|
||||
{
|
||||
this.id = GL.CreateShader(shaderType);
|
||||
|
||||
this.shaderType = shaderType;
|
||||
this.source = source;
|
||||
|
||||
_instance.registerShader(this);
|
||||
|
||||
compile();
|
||||
}
|
||||
|
||||
public int ID {
|
||||
get { return this.id; }
|
||||
}
|
||||
|
||||
public Shader(ShaderType shaderType,FileStream file){
|
||||
this.id = GL.CreateShader(shaderType);
|
||||
this.shaderType = shaderType;
|
||||
|
||||
StreamReader sr = new StreamReader(file);
|
||||
this.source = sr.ReadToEnd();
|
||||
|
||||
_instance.registerShader(this);
|
||||
|
||||
compile();
|
||||
}
|
||||
|
||||
private void compile(){
|
||||
GL.ShaderSource(this.id, source);
|
||||
GL.CompileShader(this.id);
|
||||
|
||||
string msg = GL.GetShaderInfoLog((int)this.id);
|
||||
|
||||
Console.WriteLine("Supported Shader Version: {0}", GL.GetString(StringName.ShadingLanguageVersion));
|
||||
Console.WriteLine("Shader Compiled: {0}", msg);
|
||||
|
||||
}
|
||||
|
||||
public ShaderType ShaderType {
|
||||
get { return this.shaderType; }
|
||||
}
|
||||
}
|
||||
|
||||
public class ShaderProgram {
|
||||
|
||||
Shader vertexShader;
|
||||
Shader fragmentShader;
|
||||
|
||||
int id;
|
||||
|
||||
public ShaderProgram(Shader vertexShader, Shader fragmentShader){
|
||||
|
||||
this.vertexShader = vertexShader;
|
||||
this.fragmentShader = fragmentShader;
|
||||
|
||||
this.id = GL.CreateProgram();
|
||||
|
||||
GL.AttachShader(this.id, vertexShader.ID);
|
||||
GL.AttachShader(this.id, fragmentShader.ID);
|
||||
GL.LinkProgram(this.id);
|
||||
Console.WriteLine("Shader Program Result:D {0}", GL.GetProgramInfoLog(this.id));
|
||||
}
|
||||
|
||||
public int ID {
|
||||
get { return this.id; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class ShaderProgram
|
||||
{
|
||||
|
||||
Shader vertexShader;
|
||||
Shader fragmentShader;
|
||||
|
||||
int id;
|
||||
|
||||
public ShaderProgram(Shader vertexShader, Shader fragmentShader)
|
||||
{
|
||||
init(vertexShader, fragmentShader);
|
||||
}
|
||||
|
||||
public ShaderProgram(String vertexShader, String fragmentShader)
|
||||
{
|
||||
init(
|
||||
new Shader(ShaderType.VertexShader, vertexShader),
|
||||
new Shader(ShaderType.FragmentShader, fragmentShader)
|
||||
);
|
||||
}
|
||||
|
||||
public ShaderProgram(Stream vertexShader, Stream fragmentShader)
|
||||
{
|
||||
init(
|
||||
new Shader(ShaderType.VertexShader, new StreamReader(vertexShader).ReadToEnd()),
|
||||
new Shader(ShaderType.FragmentShader, new StreamReader(fragmentShader).ReadToEnd())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private void init(Shader vertexShader, Shader fragmentShader){
|
||||
this.vertexShader = vertexShader;
|
||||
this.fragmentShader = fragmentShader;
|
||||
|
||||
this.id = GL.CreateProgram();
|
||||
|
||||
GL.AttachShader(this.id, vertexShader.ID);
|
||||
GL.AttachShader(this.id, fragmentShader.ID);
|
||||
GL.LinkProgram(this.id);
|
||||
Console.WriteLine("Shader Program Result: {0}", GL.GetProgramInfoLog(this.id));
|
||||
}
|
||||
|
||||
public int ID
|
||||
{
|
||||
get { return this.id; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,177 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class SquaredMap
|
||||
{
|
||||
private int width,
|
||||
height;
|
||||
|
||||
private double[] heightMap;
|
||||
private int[] tileTypes;
|
||||
|
||||
/* GL shared resources */
|
||||
private int vao, ebo;
|
||||
|
||||
private int bufVertices;
|
||||
private float[]
|
||||
vertices;
|
||||
private int[] elements;
|
||||
|
||||
private ShaderProgram
|
||||
shaderProgram;
|
||||
|
||||
public SquaredMap(int width,int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
this.heightMap = new double[getVertexIndex(width,height) + 1];
|
||||
this.tileTypes = new int[getTileIndex(width,height) + 1];
|
||||
|
||||
shaderProgram = new ShaderProgram(
|
||||
new FileStream("shader/simple_vertex.shader",FileMode.Open),
|
||||
new FileStream("shader/simple_fragment.shader",FileMode.Open)
|
||||
);
|
||||
|
||||
prepareGL();
|
||||
computeGL();
|
||||
|
||||
dumpGL();
|
||||
}
|
||||
|
||||
private void prepareGL(){
|
||||
vao = GL.GenVertexArray();
|
||||
ebo = GL.GenBuffer();
|
||||
bufVertices = GL.GenBuffer();
|
||||
}
|
||||
|
||||
public void computeGL(){
|
||||
int b;
|
||||
|
||||
if (vertices == null){
|
||||
vertices = new float[heightMap.Length * 3];
|
||||
}
|
||||
|
||||
if (elements == null){
|
||||
elements = new int[width * height * 6];
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
for (int x = 0; x <= width;x++)
|
||||
{
|
||||
for (int y = 0; y <= height;y++){
|
||||
b = 3 * getVertexIndex(x, y);
|
||||
|
||||
vertices[b + 0] = 128 * x;
|
||||
vertices[b + 1] = 128 * y;
|
||||
vertices[b + 2] = (float)(128 * rand.NextDouble());
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < width;x++)
|
||||
{
|
||||
for (int y = 0; y < height;y++){
|
||||
b = 6 * getTileIndex(x, y);
|
||||
|
||||
elements[b + 0] = x + (y * (width + 1));
|
||||
elements[b + 1] = x + (y * (width + 1)) + 1;
|
||||
elements[b + 2] = x + ((y + 1) * (width + 1));
|
||||
|
||||
/*
|
||||
elements[b + 3] = x + ((y + 1) * (width + 1));
|
||||
elements[b + 4] = x + (y * (width + 1)) + 1;
|
||||
elements[b + 5] = x + ((y + 1) * (width + 1)) + 1;
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, bufVertices);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, 4 * vertices.Length, vertices, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.VertexAttribPointer(0,
|
||||
3,
|
||||
VertexAttribPointerType.Float,
|
||||
false,
|
||||
0,
|
||||
0);
|
||||
GL.EnableVertexAttribArray(0);
|
||||
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer,ebo);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, 4 * elements.Length, elements, BufferUsageHint.StaticDraw);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
}
|
||||
|
||||
void dumpGL(){
|
||||
Console.WriteLine("Vertices:");
|
||||
for (int x = 0; x < 8;x++){
|
||||
Console.WriteLine("{0}", vertices[x]);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTileIndex(int x, int y)
|
||||
{
|
||||
return x + (y * this.width);
|
||||
}
|
||||
private int getVertexIndex(int x,int y){
|
||||
return x + (y * (this.width + 1));
|
||||
}
|
||||
|
||||
private int getTileType(int x, int y)
|
||||
{
|
||||
int ind = getTileIndex(x, y);
|
||||
if ((ind < 0) || (ind > tileTypes.Length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this.tileTypes[ind];
|
||||
}
|
||||
|
||||
private int getTileType(int ind)
|
||||
{
|
||||
if ((ind < 0) || (ind > tileTypes.Length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this.tileTypes[ind];
|
||||
}
|
||||
|
||||
private double getHeight(int ind)
|
||||
{
|
||||
if ((ind < 0) || (ind > heightMap.Length))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return this.heightMap[ind];
|
||||
}
|
||||
|
||||
public void paint(GLCamera camera){
|
||||
|
||||
|
||||
Matrix4 pmat = camera.Matrix;
|
||||
|
||||
GL.UseProgram(shaderProgram.ID);
|
||||
|
||||
int pm = GL.GetUniformLocation(shaderProgram.ID, "proj_matrix");
|
||||
GL.UniformMatrix4(pm, false, ref pmat);
|
||||
|
||||
GL.BindVertexArray(vao);
|
||||
|
||||
GL.DrawElements(BeginMode.Triangles, elements.Length, DrawElementsType.UnsignedInt, 0);
|
||||
|
||||
GL.BindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
|
||||
namespace nhengine
|
||||
{
|
||||
public class TextureManager
|
||||
{
|
||||
Dictionary<int, Texture> textures;
|
||||
|
||||
Texture defTexture;
|
||||
|
||||
public TextureManager()
|
||||
{
|
||||
textures = new Dictionary<int, Texture>();
|
||||
createDefaultTexture();
|
||||
}
|
||||
|
||||
private void createDefaultTexture()
|
||||
{
|
||||
defTexture = new Texture(128, 128);
|
||||
|
||||
for (int n = 0; n < 128;n++){
|
||||
defTexture.setPixel(0, n, 0x00FFFF00);
|
||||
defTexture.setPixel(n, 0, 0x00FFFF00);
|
||||
defTexture.setPixel(127, n, 0x00FFFF00);
|
||||
defTexture.setPixel(n, 127, 0x00FFFF00);
|
||||
}
|
||||
|
||||
addTexture(defTexture);
|
||||
}
|
||||
|
||||
public int addTexture(Texture t)
|
||||
{
|
||||
int id = GL.GenTexture();
|
||||
GL.BindTexture(TextureTarget.Texture2D, id);
|
||||
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, t.Width, t.Height, 0, PixelFormat.Rgba, PixelType.Byte, t.Data);
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
|
||||
textures.Add(id, t);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public class Texture
|
||||
{
|
||||
int width,
|
||||
height;
|
||||
UInt32[] data;
|
||||
|
||||
public Texture(int width,int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.data = new UInt32[width * height];
|
||||
}
|
||||
|
||||
public UInt32[] Data {
|
||||
get { return this.data; }
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get { return this.width; }
|
||||
}
|
||||
public int Height {
|
||||
get { return this.height; }
|
||||
}
|
||||
|
||||
public UInt32 getPixel(int x,int y){
|
||||
return data[x + (y * width)];
|
||||
}
|
||||
|
||||
public void setPixel(int x, int y, UInt32 rgba)
|
||||
{
|
||||
data[x + (y * width)] = rgba;
|
||||
}
|
||||
public void setPixel(int x, int y,uint r,uint g,uint b,uint a)
|
||||
{
|
||||
data[x + (y * width)] = (r << 0) | (g << 8) | (b << 16) | (a << 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||
<ProjectGuid>{48BC2215-027E-435F-B8DB-336BD9F678FC}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>nhengine</RootNamespace>
|
||||
<AssemblyName>nhengine</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
|
||||
<StartAction>Project</StartAction>
|
||||
<StartWorkingDirectory>bin\Debug</StartWorkingDirectory>
|
||||
<ExternalConsole>false</ExternalConsole>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BootStrap.cs" />
|
||||
<Compile Include="SquaredMap.cs" />
|
||||
<Compile Include="TextureManager.cs" />
|
||||
<Compile Include="Graphics.cs" />
|
||||
<Compile Include="OpenGLWindow.cs" />
|
||||
<Compile Include="Shader.cs" />
|
||||
<Compile Include="ShaderProgram.cs" />
|
||||
<Compile Include="GLCamera.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="shader\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shader\simple_vertex.shader">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="shader\simple_fragment.shader">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK">
|
||||
<HintPath>packages\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,43 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nhengine", "nhengine.csproj", "{48BC2215-027E-435F-B8DB-336BD9F678FC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pencil.Gaming", "..\Pencil.Gaming\Pencil.Gaming\Pencil.Gaming.csproj", "{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
Compatibility-GLFW2|Any CPU = Compatibility-GLFW2|Any CPU
|
||||
Core-GLFW2|Any CPU = Core-GLFW2|Any CPU
|
||||
Compatibility-GLFW3|Any CPU = Compatibility-GLFW3|Any CPU
|
||||
Core-GLFW3|Any CPU = Core-GLFW3|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Debug|x86.Build.0 = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Release|x86.ActiveCfg = Release|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Release|x86.Build.0 = Release|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Compatibility-GLFW2|Any CPU.ActiveCfg = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Compatibility-GLFW2|Any CPU.Build.0 = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Core-GLFW2|Any CPU.ActiveCfg = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Core-GLFW2|Any CPU.Build.0 = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Compatibility-GLFW3|Any CPU.ActiveCfg = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Compatibility-GLFW3|Any CPU.Build.0 = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Core-GLFW3|Any CPU.ActiveCfg = Debug|x86
|
||||
{48BC2215-027E-435F-B8DB-336BD9F678FC}.Core-GLFW3|Any CPU.Build.0 = Debug|x86
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Release|x86.Build.0 = Release|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Compatibility-GLFW2|Any CPU.ActiveCfg = Compatibility-GLFW2|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Compatibility-GLFW2|Any CPU.Build.0 = Compatibility-GLFW2|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Core-GLFW2|Any CPU.ActiveCfg = Core-GLFW2|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Core-GLFW2|Any CPU.Build.0 = Core-GLFW2|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Compatibility-GLFW3|Any CPU.ActiveCfg = Compatibility-GLFW3|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Compatibility-GLFW3|Any CPU.Build.0 = Compatibility-GLFW3|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Core-GLFW3|Any CPU.ActiveCfg = Core-GLFW3|Any CPU
|
||||
{DDB6DB6D-E5DE-4BDB-8AC8-26DF800E9FF0}.Core-GLFW3|Any CPU.Build.0 = Core-GLFW3|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="OpenTK" version="2.0.0" targetFramework="net451" />
|
||||
</packages>
|
|
@ -0,0 +1,8 @@
|
|||
#version 330
|
||||
|
||||
out vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#version 330
|
||||
|
||||
layout (location = 0) in vec3 position;
|
||||
|
||||
uniform mat4 proj_matrix2;
|
||||
uniform mat4 proj_matrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = proj_matrix * vec4(position.x, position.y, position.z, 1.0) ;
|
||||
}
|
Loading…
Reference in New Issue