Finished refractor

This commit is contained in:
zyb3rwolfi 2025-11-13 02:28:09 +00:00
parent 8d46d85df0
commit 9bdb641096
4 changed files with 26 additions and 26 deletions

View File

@ -56,7 +56,6 @@ public class Mesh : IDisposable
GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, stride, 3 * sizeof(float)); GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, stride, 3 * sizeof(float));
GL.EnableVertexAttribArray(1); GL.EnableVertexAttribArray(1);
} }
// ... (you could add more layouts)
GL.BindVertexArray(0); GL.BindVertexArray(0);
} }

View File

@ -36,28 +36,19 @@ namespace TheLabs
{ {
// This is called when the window is created and is where we can set up OpenGL resources. // This is called when the window is created and is where we can set up OpenGL resources.
base.OnLoad(); base.OnLoad();
string shaderVertPath = "Shaders/shader.vert"; //GL.Disable(EnableCap.CullFace);
string texturePath = "Textures/placeholder.png";
if (!File.Exists(shaderVertPath))
{
throw new FileNotFoundException($"The shader file was not found at: {Path.GetFullPath(shaderVertPath)}");
}
if (!File.Exists(texturePath))
{
throw new FileNotFoundException($"The texture file was not found at: {Path.GetFullPath(texturePath)}");
}
//GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
// Set The background color to a nice blue. // Set The background color to a nice blue.
GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f); GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.DepthTest);
_shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag"); _shader = new Shader("Shaders/shader.vert", "Shaders/shader.frag");
_cubeMesh = ShapeFactory.CreateTexturedCube(); _cubeMesh = ShapeFactory.CreateTexturedCube();
_cubeTexture = new Texture("Textures/placeholder.png"); _cubeTexture = new Texture("Textures/placeholder.png");
_cubeObject = new RenderObject(_cubeMesh, _shader, _cubeTexture); _cubeObject = new RenderObject(_cubeMesh, _shader, _cubeTexture);
_cubeObject.Position = new Vector3(-0.75f, 0.0f, 0.0f); _cubeObject.Position = new Vector3(0.0f, 0.0f, -1.0f);
_cubeObject.Scale = new Vector3(0.5f, 0.5f, 0.5f);
} }
@ -72,9 +63,16 @@ namespace TheLabs
// --- Set up Camera --- // --- Set up Camera ---
Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f); Matrix4 view = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f);
float aspectRatio = (float)Size.X / Size.Y;
// 2. Add a safety check for divide-by-zero
if (Size.Y == 0 || Size.X == 0)
{
aspectRatio = 1.0f; // Default to 1:1 if window is minimized
}
Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView( Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(
MathHelper.DegreesToRadians(45f), MathHelper.DegreesToRadians(45f),
Size.X / (float)Size.Y, aspectRatio,
0.1f, 0.1f,
100.0f 100.0f
); );

View File

@ -28,13 +28,16 @@ public class RenderObject
Shader.SetInt("uTexture", 0); Shader.SetInt("uTexture", 0);
// 2. Bind Texture // 2. Bind Texture
Texture.Use(); // Assumes you have a Texture class Texture.Use(); // Assumes you have a Texture class
// 3. Calculate Model Matrix // 3. Calculate Model Matrix
Matrix4 model = Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Position); Matrix4 model = Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Position);
// 4. Set Uniforms int modelLoc = GL.GetUniformLocation(Shader.Handle, "model");
Shader.SetMatrix4("model", model); GL.UniformMatrix4(modelLoc, false, ref model); // Try TRUE here
Shader.SetMatrix4("view", view);
Shader.SetMatrix4("projection", projection); int viewLoc = GL.GetUniformLocation(Shader.Handle, "view");
GL.UniformMatrix4(viewLoc, false, ref view); // Try TRUE here
int projLoc = GL.GetUniformLocation(Shader.Handle, "projection");
GL.UniformMatrix4(projLoc, false, ref projection); // Try TRUE here
// 5. Tell the Mesh to draw itself // 5. Tell the Mesh to draw itself
Mesh.Draw(); Mesh.Draw();

View File

@ -44,7 +44,7 @@ public static class ShapeFactory
uint[] indices = { uint[] indices = {
// Front face // Front face
0, 1, 2, 0, 2, 1,
0, 2, 3, 0, 2, 3,
// Back face // Back face
4, 5, 6, 4, 5, 6,
@ -53,13 +53,13 @@ public static class ShapeFactory
8, 9, 10, 8, 9, 10,
8, 10, 11, 8, 10, 11,
// Right face // Right face
12, 13, 14, 12, 14, 13,
12, 14, 15, 12, 14, 15,
// Top face // Top face
16, 17, 18, 16, 17, 18,
16, 18, 19, 16, 18, 19,
// Bottom face // Bottom face
20, 21, 22, 20, 22, 21,
20, 22, 23 20, 22, 23
}; };