Colors added
parent
8ae20b7159
commit
52da9e584b
|
@ -54,9 +54,6 @@ namespace nhengine
|
||||||
|
|
||||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||||
|
|
||||||
//camera.ArcX = -MathHelper.PiOver2 * 0.8f;
|
|
||||||
//camera.ArcZ += MathHelper.Pi / 180;
|
|
||||||
|
|
||||||
camera.setup();
|
camera.setup();
|
||||||
|
|
||||||
boot.SquaredMap.paint(camera);
|
boot.SquaredMap.paint(camera);
|
||||||
|
|
|
@ -43,6 +43,11 @@ namespace nhengine
|
||||||
|
|
||||||
GL.AttachShader(this.id, vertexShader.ID);
|
GL.AttachShader(this.id, vertexShader.ID);
|
||||||
GL.AttachShader(this.id, fragmentShader.ID);
|
GL.AttachShader(this.id, fragmentShader.ID);
|
||||||
|
|
||||||
|
GL.BindAttribLocation(this.id, 0, "position");
|
||||||
|
GL.BindAttribLocation(this.id, 1, "v_color");
|
||||||
|
|
||||||
|
|
||||||
GL.LinkProgram(this.id);
|
GL.LinkProgram(this.id);
|
||||||
Console.WriteLine("Shader Program Result: {0}", GL.GetProgramInfoLog(this.id));
|
Console.WriteLine("Shader Program Result: {0}", GL.GetProgramInfoLog(this.id));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,15 @@ namespace nhengine
|
||||||
private int[] tileTypes;
|
private int[] tileTypes;
|
||||||
|
|
||||||
/* GL shared resources */
|
/* GL shared resources */
|
||||||
private int vao, ebo;
|
private int vao, cao, nao, ebo;
|
||||||
|
|
||||||
private int bufVertices;
|
private int bufVertices;
|
||||||
private float[]
|
private float[]
|
||||||
vertices;
|
vertices;
|
||||||
|
private float[]
|
||||||
|
colors,
|
||||||
|
normals;
|
||||||
|
|
||||||
private int[] elements;
|
private int[] elements;
|
||||||
|
|
||||||
private ShaderProgram
|
private ShaderProgram
|
||||||
|
@ -46,6 +50,8 @@ namespace nhengine
|
||||||
|
|
||||||
private void prepareGL(){
|
private void prepareGL(){
|
||||||
vao = GL.GenVertexArray();
|
vao = GL.GenVertexArray();
|
||||||
|
cao = GL.GenBuffer();
|
||||||
|
nao = GL.GenBuffer();
|
||||||
ebo = GL.GenBuffer();
|
ebo = GL.GenBuffer();
|
||||||
bufVertices = GL.GenBuffer();
|
bufVertices = GL.GenBuffer();
|
||||||
}
|
}
|
||||||
|
@ -61,6 +67,11 @@ namespace nhengine
|
||||||
elements = new int[width * height * 6];
|
elements = new int[width * height * 6];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (colors == null){
|
||||||
|
colors = new float[heightMap.Length * 3];
|
||||||
|
normals = new float[colors.Length];
|
||||||
|
}
|
||||||
|
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
|
|
||||||
for (int x = 0; x <= width;x++)
|
for (int x = 0; x <= width;x++)
|
||||||
|
@ -70,7 +81,13 @@ namespace nhengine
|
||||||
|
|
||||||
vertices[b + 0] = 128 * x;
|
vertices[b + 0] = 128 * x;
|
||||||
vertices[b + 1] = 128 * y;
|
vertices[b + 1] = 128 * y;
|
||||||
vertices[b + 2] = (float)(128 * rand.NextDouble());
|
|
||||||
|
float h = (float)rand.NextDouble();
|
||||||
|
vertices[b + 2] = (float)(256 * (h * h));
|
||||||
|
|
||||||
|
colors[b + 0] = 0.3f + 0.7f * (float)vertices[b + 2] / 256.0f;
|
||||||
|
colors[b + 1] = 0.2f + 0.8f * (float)vertices[b + 2] / 256.0f;
|
||||||
|
colors[b + 2] = 0.4f + 0.6f * (float)vertices[b + 2] / 256.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +100,9 @@ namespace nhengine
|
||||||
elements[b + 1] = x + (y * (width + 1)) + 1;
|
elements[b + 1] = x + (y * (width + 1)) + 1;
|
||||||
elements[b + 2] = x + ((y + 1) * (width + 1));
|
elements[b + 2] = x + ((y + 1) * (width + 1));
|
||||||
|
|
||||||
/*
|
|
||||||
elements[b + 3] = x + ((y + 1) * (width + 1));
|
elements[b + 3] = x + ((y + 1) * (width + 1));
|
||||||
elements[b + 4] = x + (y * (width + 1)) + 1;
|
elements[b + 4] = x + (y * (width + 1)) + 1;
|
||||||
elements[b + 5] = x + ((y + 1) * (width + 1)) + 1;
|
elements[b + 5] = x + ((y + 1) * (width + 1)) + 1;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +117,20 @@ namespace nhengine
|
||||||
false,
|
false,
|
||||||
0,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
GL.BindBuffer(BufferTarget.ArrayBuffer, cao);
|
||||||
|
GL.BufferData(BufferTarget.ArrayBuffer, 4 * colors.Length, colors, BufferUsageHint.StaticDraw);
|
||||||
|
|
||||||
|
GL.VertexAttribPointer(1,
|
||||||
|
3,
|
||||||
|
VertexAttribPointerType.Float,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
0);
|
||||||
|
|
||||||
GL.EnableVertexAttribArray(0);
|
GL.EnableVertexAttribArray(0);
|
||||||
|
GL.EnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
|
||||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer,ebo);
|
GL.BindBuffer(BufferTarget.ElementArrayBuffer,ebo);
|
||||||
GL.BufferData(BufferTarget.ElementArrayBuffer, 4 * elements.Length, elements, BufferUsageHint.StaticDraw);
|
GL.BufferData(BufferTarget.ElementArrayBuffer, 4 * elements.Length, elements, BufferUsageHint.StaticDraw);
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
out vec4 color;
|
in vec4 color;
|
||||||
|
in vec3 norm;
|
||||||
|
in vec2 uv;
|
||||||
|
|
||||||
|
out vec4 _color;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
_color = color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
layout (location = 0) in vec3 position;
|
in vec3 position;
|
||||||
|
in vec3 v_color;
|
||||||
|
in vec3 v_norm;
|
||||||
|
in vec2 v_uv;
|
||||||
|
|
||||||
uniform mat4 proj_matrix2;
|
|
||||||
uniform mat4 proj_matrix;
|
uniform mat4 proj_matrix;
|
||||||
|
|
||||||
|
out vec4 color;
|
||||||
|
out vec3 norm;
|
||||||
|
out vec2 uv;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = proj_matrix * vec4(position.x, position.y, position.z, 1.0) ;
|
color = vec4( v_color, 0.6);
|
||||||
|
norm = v_norm;
|
||||||
|
uv = v_uv;
|
||||||
|
gl_Position = proj_matrix * vec4(position, 1.0) ;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue