Mesh can now be rendered and therefore also the sphere
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 17s
All checks were successful
Gitea Actions Demo / Scan the project (push) Successful in 17s
This commit is contained in:
@ -32,7 +32,6 @@ public static class Program
|
||||
private static Vector2 _lastMousePosition;
|
||||
private static uint _vao, _vbo;
|
||||
private static Sphere sphere;
|
||||
private static Mesh testMesh;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@ -71,10 +70,10 @@ public static class Program
|
||||
input.Mice[i].MouseMove += OnMouseMove;
|
||||
input.Mice[i].Cursor.CursorMode = CursorMode.Disabled;
|
||||
}
|
||||
|
||||
|
||||
_vao = _gl.GenVertexArray();
|
||||
_gl.BindVertexArray(_vao);
|
||||
|
||||
|
||||
float[] vertices =
|
||||
{
|
||||
// positions // normals // texture coords
|
||||
@ -84,35 +83,35 @@ public static class Program
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
|
||||
|
||||
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
|
||||
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f,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
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
|
||||
@ -120,22 +119,22 @@ public static class Program
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
|
||||
ReadOnlySpan<float> verticesData = new(vertices);
|
||||
|
||||
|
||||
_vbo = _gl.GenBuffer();
|
||||
_gl.BindBuffer(BufferTargetARB.ArrayBuffer, _vbo);
|
||||
_gl.BufferData(BufferTargetARB.ArrayBuffer, (nuint)(verticesData.Length * sizeof(float)), verticesData, BufferUsageARB.StaticDraw);
|
||||
|
||||
_shader = new Nebulix.Rendering.Shader(_gl, "shader.vert", "shader.frag");
|
||||
|
||||
|
||||
_gl.EnableVertexAttribArray(0);
|
||||
_gl.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), (void*)0);
|
||||
_gl.EnableVertexAttribArray(1);
|
||||
_gl.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 8 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
_gl.EnableVertexAttribArray(2);
|
||||
_gl.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 8 * sizeof(float), (void*)(6 * sizeof(float)));
|
||||
|
||||
|
||||
_texture = new Texture2D(_gl, "images/container.png", ImageFormat.RGBA);
|
||||
|
||||
|
||||
@ -144,24 +143,6 @@ public static class Program
|
||||
sphere.CreateSphere();
|
||||
_sphereShader =
|
||||
new Nebulix.Rendering.Shader(_gl, "./Shaders/Sphere/sphere.vert", "./Shaders/Sphere/sphere.frag");
|
||||
|
||||
testMesh = new Mesh
|
||||
{
|
||||
Vertices =
|
||||
[
|
||||
new Vector3D<float>(0.5f, 0.5f, 0.0f),
|
||||
new Vector3D<float>(0.5f, -0.5f, 0.0f),
|
||||
new Vector3D<float>(-0.5f, -0.5f, 0.0f),
|
||||
new Vector3D<float>(-0.5f, 0.5f, 0.5f)
|
||||
],
|
||||
Indices =
|
||||
[
|
||||
0u, 1u, 3u,
|
||||
1u, 2u, 3u
|
||||
]
|
||||
};
|
||||
testMesh.CalculateNormals();
|
||||
|
||||
}
|
||||
|
||||
private static void OnUpdate(double deltaTime)
|
||||
@ -190,7 +171,7 @@ public static class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnRender(double deltaTime)
|
||||
private static unsafe void OnRender(double deltaTime)
|
||||
{
|
||||
_gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
@ -207,21 +188,18 @@ public static class Program
|
||||
_shader.SetInt("tex", 0);
|
||||
_texture.Bind();
|
||||
|
||||
// _gl.BindVertexArray(_vao);
|
||||
// _gl.DrawArrays(PrimitiveType.Triangles, 0, 36);
|
||||
_gl.BindVertexArray(_vao);
|
||||
_gl.DrawArrays(PrimitiveType.Triangles, 0, 36);
|
||||
|
||||
// Sphere
|
||||
modelMatrix = Matrix4x4.CreateTranslation(0, 0, 0);
|
||||
modelMatrix = Matrix4x4.CreateTranslation(1, 0, 0);
|
||||
|
||||
_sphereShader.Use();
|
||||
_sphereShader.SetMatrix("modelMatrix", modelMatrix);
|
||||
_sphereShader.SetMatrix("projectionMatrix", projectionMatrix);
|
||||
_sphereShader.SetMatrix("viewMatrix", viewMatrix);
|
||||
|
||||
// sphere.RenderSphere(_gl);
|
||||
testMesh.Render(_gl);
|
||||
|
||||
// var f = new Face(-Vector3D<float>.UnitX, 10);
|
||||
// f.GetMesh().Render(_gl);
|
||||
sphere.RenderSphere(_gl);
|
||||
}
|
||||
|
||||
private static void OnKeyDown(IKeyboard keyboard, Key key, int keyCode)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 colour;
|
||||
out vec4 FragColour;
|
||||
|
||||
in vec3 FragPos;
|
||||
//in vec3 Normal;
|
||||
@ -8,8 +8,5 @@ in vec3 FragPos;
|
||||
void main()
|
||||
{
|
||||
vec3 col = vec3(1.0, 0.5, 0.2) * FragPos;
|
||||
//vec3 col = texture(tex, TexCoords);
|
||||
//colour = vec4(texture(tex, TexCoords).rgb, 1.0);
|
||||
// colour = vec4(col, 1);
|
||||
colour = vec4(1);
|
||||
FragColour = vec4(col, 1);
|
||||
}
|
@ -6,9 +6,19 @@ using Silk.NET.OpenGL;
|
||||
namespace Engine_silk.NET
|
||||
{
|
||||
// also maybe make an ISphere and call this class "CubeSphere"?
|
||||
public class Sphere(uint resolution)
|
||||
public class Sphere
|
||||
{
|
||||
private readonly Face[] sphereFaces = new Face[6];
|
||||
private readonly uint resolution;
|
||||
|
||||
public Sphere(uint resolution)
|
||||
{
|
||||
if (resolution < 2)
|
||||
throw new ArgumentOutOfRangeException(nameof(resolution), resolution,
|
||||
"Resolution must be greater than 1");
|
||||
this.resolution = resolution;
|
||||
}
|
||||
|
||||
public void CreateSphere()
|
||||
{
|
||||
Vector3D<float>[] directions =
|
||||
@ -63,7 +73,7 @@ namespace Engine_silk.NET
|
||||
var vertices = new Vector3D<float>[_resolution * _resolution];
|
||||
// _resolution - 1 because the vertices index starts at 0
|
||||
// * 6 because each triangle needs 3 points and each small quad has 2 triangles 3*2 = 6
|
||||
var indices = new nuint[(_resolution - 1) * (_resolution - 1) * 6];
|
||||
var indices = new uint[(_resolution - 1) * (_resolution - 1) * 6];
|
||||
int triangleIndex = 0;
|
||||
|
||||
uint i;
|
||||
|
Reference in New Issue
Block a user