Wpf System test
This commit is contained in:
parent
af9c782c1e
commit
9ad4bc1c69
17 changed files with 746 additions and 12 deletions
|
|
@ -30,6 +30,9 @@
|
|||
<None Update="Shaders\lighting.frag">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shaders\shadertest.frag">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Shaders\shader.frag">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
|
|
|||
13
Map3DRendering/Shaders/shadertest.frag
Normal file
13
Map3DRendering/Shaders/shadertest.frag
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#version 330
|
||||
|
||||
out vec4 outputColor;
|
||||
|
||||
uniform vec3 viewPos;
|
||||
uniform sampler2DArray texture0;
|
||||
|
||||
in vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
outputColor = Color;
|
||||
}
|
||||
|
|
@ -10,7 +10,8 @@ namespace Map3DRendering {
|
|||
|
||||
private readonly Vector3 _lightPos = new Vector3(0x10, 0, 0x10);
|
||||
|
||||
private MapRender mapRender;
|
||||
//private MapRender mapRender;
|
||||
private WorldMapRender _render;
|
||||
private AxesGizmo axesGizmo;
|
||||
|
||||
private Shader _shader;
|
||||
|
|
@ -33,7 +34,8 @@ namespace Map3DRendering {
|
|||
public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings)
|
||||
: base(gameWindowSettings, nativeWindowSettings) {
|
||||
|
||||
mapRender = new MapRender();
|
||||
//mapRender = new MapRender();
|
||||
_render = new WorldMapRender();
|
||||
|
||||
GL.GetInteger(GetPName.MaxTextureImageUnits, out maxTextures);
|
||||
}
|
||||
|
|
@ -49,10 +51,11 @@ namespace Map3DRendering {
|
|||
GL.GetInteger(GetPName.MaxTextureImageUnits, out maxTextureUnits);
|
||||
Console.WriteLine($"Maximum number of texture units for fragment shaders: {maxTextureUnits}");
|
||||
|
||||
_shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
|
||||
_shader = new Shader("Shaders/shader.vert", "Shaders/shadertest.frag");
|
||||
_shader.Use();
|
||||
|
||||
mapRender.OnLoad(_shader);
|
||||
//mapRender.OnLoad(_shader);
|
||||
_render.OnLoad(_shader);
|
||||
|
||||
var file = Directory.EnumerateFiles(@"./terrains");
|
||||
_texture = Texture.LoadFromArray(file.ToArray());
|
||||
|
|
@ -82,14 +85,15 @@ namespace Map3DRendering {
|
|||
_shader.SetMatrix4("projection", _camera.GetProjectionMatrix());
|
||||
|
||||
//_shader.SetVector3("objectColor", new Vector3(0.5f, 0.5f, 0.5f));
|
||||
_shader.SetVector3("lightColor", new Vector3(1.0f, 1.0f, 1.0f));
|
||||
_shader.SetVector3("lightPos", _camera.Position);
|
||||
//_shader.SetVector3("lightColor", new Vector3(1.0f, 1.0f, 1.0f));
|
||||
//_shader.SetVector3("lightPos", _camera.Position);
|
||||
|
||||
GL.LineWidth(5.0f);
|
||||
|
||||
_shader.SetVector3("viewPos", _camera.Position);
|
||||
mapRender.UpdateBlocks(_camera.Position, _shader);
|
||||
mapRender.Render(_shader);
|
||||
//_shader.SetVector3("viewPos", _camera.Position);
|
||||
//mapRender.UpdateBlocks(_camera.Position, _shader);
|
||||
//mapRender.Render(_shader);
|
||||
_render.Render(_shader);
|
||||
|
||||
axesGizmo.Render(Size.X, Size.Y, _camera);
|
||||
|
||||
|
|
|
|||
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