using LearnOpenTK.Common; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; namespace TheLabs; public class RenderObject { public Mesh Mesh; public Shader Shader; public Texture Texture; public Vector3 Position = Vector3.Zero; public Matrix4 Transform = Matrix4.Identity; public Quaternion Rotation = Quaternion.Identity; public Vector3 Scale = Vector3.One; public RenderObject(Mesh mesh, Shader shader, Texture texture) { Mesh = mesh; Shader = shader; Texture = texture; } public void Draw(Matrix4 view, Matrix4 projection) { // 1. Activate Shader Shader.Use(); Shader.SetInt("uTexture", 0); // 2. Bind Texture Texture.Use(); // 3. Calculate Model Matrix Matrix4 model = Matrix4.CreateScale(Scale) * Matrix4.CreateFromQuaternion(Rotation) * Matrix4.CreateTranslation(Position); int modelLoc = GL.GetUniformLocation(Shader.Handle, "model"); GL.UniformMatrix4(modelLoc, false, ref model); // Try TRUE here 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 Mesh.Draw(); } }