using System; using OpenTK.Graphics.OpenGL; using OpenTK; namespace org.niclasundharald.engine.graphics { public class Model3D { protected int vao, vbo, // Vertex Buffer cbo, // Color Buffer nbo; // Normals Buffer protected int nTriangles; protected Model3D(){ vao = GL.GenVertexArray(); nTriangles = 0; prepare(); } protected void prepare(){ vbo = GL.GenBuffer(); cbo = GL.GenBuffer(); nbo = GL.GenBuffer(); GL.BindVertexArray(vao); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, cbo); GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, 0, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, nbo); GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, 0, 0); GL.BindVertexArray(0); } protected void bind(Vector3[] vertexes){ bind( vertexes, null, null, null ); } protected void bind(Vector3[] vertexes,Vector4[] colors){ bind( vertexes, colors, null, null ); } protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals){ bind( vertexes, colors, normals, null ); } protected void bind(Vector3[] vertexes,Vector4[] colors,Vector3[] normals,Vector2[] uvs){ float[] fv = new float[vertexes.Length * 3]; for (int n=0;n