Wpf System test
This commit is contained in:
parent
af9c782c1e
commit
9ad4bc1c69
17 changed files with 746 additions and 12 deletions
77
Map3DRendering/WorldMapRender.cs
Normal file
77
Map3DRendering/WorldMapRender.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using LandblockExtraction.AtlasMaker;
|
||||
using LandblockExtraction.DatEngine;
|
||||
using LandblockExtraction.LandBlockExtractor;
|
||||
using LandblockExtraction.WorldMap;
|
||||
using Map3DRendering.Common;
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
|
||||
namespace Map3DRendering {
|
||||
public class WorldMapRender {
|
||||
|
||||
private WorldMap worldMap;
|
||||
private int[,] _vertexArrayObject;
|
||||
private int[,] _vertexBufferObject;
|
||||
private int[,] _elementBufferObject;
|
||||
private int[,] _indiceLength;
|
||||
|
||||
public WorldMapRender() {
|
||||
worldMap = new WorldMap();
|
||||
_vertexArrayObject = new int[10, 10];
|
||||
_vertexBufferObject = new int[10, 10];
|
||||
_elementBufferObject = new int[10, 10];
|
||||
_indiceLength = new int[10, 10];
|
||||
}
|
||||
|
||||
public void OnLoad(Shader _shader) {
|
||||
for(int i = 0; i < 10; i++) {
|
||||
for(int j = 0; j < 10; j++) {
|
||||
InitializeBlock(j, i, worldMap.lands[j, i], _shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void InitializeBlock(int x, int y, Land block, Shader _shader) {
|
||||
int lenghPacket = 7;
|
||||
|
||||
var vertices = block.getVertices();
|
||||
var indices = block.getIndices();
|
||||
_indiceLength[x, y] = indices.Length;
|
||||
|
||||
// Initialisez le VAO, VBO et EBO pour le bloc à (x, y)...
|
||||
// Utilisez le code de votre méthode OnLoad originale pour configurer le VAO, VBO et EBO.
|
||||
int tempVertexArray = GL.GenVertexArray();
|
||||
GL.BindVertexArray(tempVertexArray);
|
||||
_vertexArrayObject[x, y] = tempVertexArray;
|
||||
|
||||
int tmpVertexBuffer = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, tmpVertexBuffer);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
|
||||
_vertexBufferObject[x, y] = tmpVertexBuffer;
|
||||
|
||||
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 0);
|
||||
|
||||
int tmpElementBuffer = GL.GenBuffer();
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, tmpElementBuffer);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(int), indices, BufferUsageHint.StaticDraw);
|
||||
_elementBufferObject[x, y] = tmpElementBuffer;
|
||||
|
||||
var vertexLocation = _shader.GetAttribLocation("aPos");
|
||||
GL.EnableVertexAttribArray(vertexLocation);
|
||||
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 0);
|
||||
|
||||
var colorLocation = _shader.GetAttribLocation("aColor");
|
||||
GL.EnableVertexAttribArray(colorLocation);
|
||||
GL.VertexAttribPointer(colorLocation, 4, VertexAttribPointerType.Float, false, lenghPacket * sizeof(float), 3 * sizeof(float));
|
||||
}
|
||||
public void Render(Shader shader) {
|
||||
for (int y = 0; y < 10; y++) {
|
||||
for (int x = 0; x < 10; x++) {
|
||||
var model = Matrix4.Identity;//CreateTranslation(x * BlockSize, 0, y * BlockSize); // Ajustez selon votre système de coordonnées
|
||||
shader.SetMatrix4("model", model);
|
||||
GL.BindVertexArray(_vertexArrayObject[x, y]);
|
||||
GL.DrawElements(PrimitiveType.Triangles, _indiceLength[x, y], DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue