private static float[] VDataBlock = new float[] {
-1.0f, 0.0f, // 0
1.0f, 1.0f, // 2
1.0f, -1.0f, // 4
3.0f, 0.0f // 6
};
public class NChunk
{
public float[] vertices = new float[CHUNK_SIZE * CHUNK_SIZE * 8];
public float[] UVs = new float[CHUNK_SIZE * CHUNK_SIZE * 8];
public int[] buffers = new int[CHUNK_SIZE * CHUNK_SIZE];
public NChunk()
{
float x, y;
for (int k = 0; k < CHUNK_SIZE; k++)
{
for (int l = 0; l < CHUNK_SIZE; l++)
{
x = (l - k) * 1.939f;
y = (l + k) * 0.969f;
int w = (k * 8) + (l * 8 * CHUNK_SIZE);
vertices[w + 0] = VDataBlock[0] + x;
vertices[w + 1] = VDataBlock[1] + y;
vertices[w + 2] = VDataBlock[2] + x;
vertices[w + 3] = VDataBlock[3] + y;
vertices[w + 4] = VDataBlock[4] + x;
vertices[w + 5] = VDataBlock[5] + y;
vertices[w + 6] = VDataBlock[6] + x;
vertices[w + 7] = VDataBlock[7] + y;
UVs[w + 0] = 0.0f;
UVs[w + 1] = 0.5f;
UVs[w + 2] = 0.5f;
UVs[w + 3] = 1.0f;
UVs[w + 4] = 0.5f;
UVs[w + 5] = 0.0f;
UVs[w + 6] = 1.0f;
UVs[w + 7] = 0.5f;
int bh = GL.GenVertexArray();
GL.BindVertexArray(bh);
GL.EnableVertexAttribArray(0);
GL.EnableVertexAttribArray(1);
Util.PrintGLError();
int wvbh = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, wvbh);
float[] blockVertices = new float[8];
Array.Copy(vertices, w, blockVertices, 0, 8);
GL.BufferData<float>(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 8), blockVertices, BufferUsageHint.StaticDraw);
Util.PrintGLError();
GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);
Util.PrintGLError();
int wuvspb = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, wuvspb);
float[] blockUVs = new float[8];
Array.Copy(UVs, w, blockUVs, 0, 8);
GL.BufferData<float>(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 8), blockUVs, BufferUsageHint.StaticDraw);
Util.PrintGLError();
GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 0, IntPtr.Zero);
Util.PrintGLError();
buffers[k * CHUNK_SIZE + l] = bh;
}
}
}
}
private static void RenderChunk(NChunk c)
{
for (int k = 0; k < CHUNK_SIZE; k++)
{
for (int l = 0; l < CHUNK_SIZE; l++)
{
GL.BindVertexArray(c.buffers[k * CHUNK_SIZE + l]);
GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
}
}