public void flush() { flushNum += 1; vao.registerAttribute(0, vertBuffer, Vector3.SizeInBytes, 3); vao.registerAttribute(1, texBuffer, Vector2.SizeInBytes, 2); vao.bind(); Shader.start(); Matrix4 translationToOrigin = Matrix4.CreateTranslation(-1 * vertBuffer[0].X, -1 * vertBuffer[0].Y, 0); Matrix4 scale = Matrix4.CreateScale(2 * Camera.Zoom / (float)Window.Width, 2 * Camera.Zoom / (float)Window.Height, 1); Matrix4 translationToFinalSpot = Matrix4.CreateTranslation(2 * Camera.Zoom * (vertBuffer[0].X - Camera.Position.X - Window.Width / 2) / Window.Width, 2 * Camera.Zoom * (vertBuffer[0].Y - Camera.Position.Y - Window.Height / 2) / Window.Height, 0); Matrix4 world = Matrix4.Mult(translationToOrigin, scale); world = Matrix4.Mult(world, translationToFinalSpot); Shader.loadWorldRef(world); GL.BindTexture(TextureTarget.Texture2D, tex); GL.DrawArrays(PrimitiveType.Quads, 0, idx); Shader.stop(); vao.unbind(); idx = 0; }
public DefaultEntityRenderer(GameWindow window, Camera camera, Shader shader) : base(window, camera, shader) { vao = new VAO(); vertBuffer = new Vector3[4] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0, 1, 0), }; texBuffer = new Vector2[4] { new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 0), new Vector2(0, 0), }; Console.WriteLine((Vector2.SizeInBytes * 8 * 000) / 1024); vao.registerAttribute(0, vertBuffer, Vector3.SizeInBytes, 3); vao.registerAttribute(1, texBuffer, Vector2.SizeInBytes, 2); /* * VBO = GL.GenBuffer(); * GL.BindBuffer(BufferTarget.ArrayBuffer, VBO); * GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * vertBuffer.Length), vertBuffer, BufferUsageHint.StaticDraw); * GL.VertexPointer(2, VertexPointerType.Float, Vector2.SizeInBytes * 2, 0); * GL.TexCoordPointer(2, TexCoordPointerType.Float, Vector2.SizeInBytes * 2, Vector2.SizeInBytes); * GL.BindBuffer(BufferTarget.ArrayBuffer, 0);*/ }