using LandblockExtraction.DatEngine; using LandblockExtraction.WorldMap; using Map3DRendering.Common; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; namespace Map3DRendering; public class WorldMapRender { private PortalEngine portalEngine; private CellEngine cellEngine; private WorldMap worldMap; public int _vertexArrayObject; public int _vertexBufferObject; public int _elementBufferObject; public int indicesLength; public WorldMapRender() { portalEngine = new PortalEngine(); cellEngine = new CellEngine(); worldMap = new WorldMap(portalEngine, cellEngine); worldMap.LoadRegion(0x5F, 0x9F); } public void OnLoad(Shader _shader) { InitializeMap(_shader); } private void InitializeMap(Shader _shader) { int lenghPacket = 7; var vertices = worldMap.GetAllVertices(); var indices = worldMap.GenerateRegionIndices(0x5F, 0x9F); indicesLength = 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 = tempVertexArray; int tmpVertexBuffer = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, tmpVertexBuffer); GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw); _vertexBufferObject = 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 = 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), 6 * sizeof(float)); } public void Render(Shader shader) { 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); GL.DrawElements(PrimitiveType.Triangles, indicesLength, DrawElementsType.UnsignedInt, 0); } }