// Wrap a float[] in a direct FloatBuffer using native byte order. private static FloatBuffer directNativeFloatBuffer(float[] array) { FloatBuffer buffer = ByteBuffer.AllocateDirect(array.Length * 4).Order(ByteOrder.NativeOrder()).AsFloatBuffer(); buffer.Put(array); buffer.Flip(); return(buffer); }
public FirstTriangleScreen(IGame g) : base(g) { _glGraphics = ((AndroidGLGame)g).GLGraphics; ByteBuffer bb = ByteBuffer.AllocateDirect(3 * _vertexSize); bb.Order(ByteOrder.NativeOrder()); _vertices = bb.AsFloatBuffer(); _vertices.Put(new float[] { 0.0f, 0.0f, 539.0f, 0.0f, 270.0f, 959.0f }); _vertices.Flip(); }
public TexturedTriangleScreen(IGame g) : base(g) { _glGraphics = ((AndroidGLGame)g).GLGraphics; ByteBuffer bb = ByteBuffer.AllocateDirect(_vertexSize * 3); bb.Order(ByteOrder.NativeOrder()); _vertices = bb.AsFloatBuffer(); _vertices.Put(new float[] { 0f, 0f, 0f, 1f, 540f, 0f, 1f, 1f, 270f, 960f, 0.5f, 0f }); _vertices.Flip(); _textureId = LoadTexture("bobargb8888.png"); }
public ColoredTriangleScreen(IGame g) : base(g) { _glGraphics = ((AndroidGLGame)g).GLGraphics; ByteBuffer bb = ByteBuffer.AllocateDirect(3 * _vertexSize); bb.Order(ByteOrder.NativeOrder()); _vertices = bb.AsFloatBuffer(); _vertices.Put(new float[] { 0, 0, 1, 0, 0, 1, 540, 0, 0, 1, 0, 1, 270, 960, 0, 0, 1, 1 }); _vertices.Flip(); }
public IndexedVerticesScreen(IGame g) : base(g) { _glGraphics = ((AndroidGLGame)g).GLGraphics; ByteBuffer bb = ByteBuffer.AllocateDirect(_vertexSize * 4); bb.Order(ByteOrder.NativeOrder()); _vertices = bb.AsFloatBuffer(); _vertices.Put(new float[] { 100f, 100f, 0f, 1f, 428f, 100f, 1f, 1f, 428f, 428f, 1f, 0f, 100f, 428f, 0f, 0f }); _vertices.Flip(); bb = ByteBuffer.AllocateDirect(6 * 2); bb.Order(ByteOrder.NativeOrder()); _indices = bb.AsShortBuffer(); _indices.Put(new short[] { 0, 1, 2, 2, 3, 0 }); _indices.Flip(); _texture = new AndroidTexture((AndroidGLGame)g, "bobrgb888.png"); }
public void SetVertices(float[] vertices, int offset, int length) { _vertices.Clear(); _vertices.Put(vertices, offset, length); _vertices.Flip(); }
public bool loadingBinModel(String fileName) { float[] floatArray; long size; try { // Vertex vertexBuffer = null; System.GC.Collect(); int resourceId = context.Resources.GetIdentifier(fileName + "_vert", "raw", context.PackageName); Stream fileIn = context.Resources.OpenRawResource(resourceId) as Stream; MemoryStream m = new MemoryStream(); fileIn.CopyTo(m); size = m.Length; floatArray = new float[size / 4]; System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size); vertexBuffer = FloatBuffer.Allocate((int)size / 4); // float array to vertexBuffer.Put(floatArray, 0, (int)size / 4); vertexBuffer.Flip(); VBOManager.setSize(fileName, vertexBuffer.Capacity() / 4); //is size of vertex count = 1 vertex 4 float x,y,z, 1 floatArray = null; fileIn.Close(); m.Close(); //---------------------------------------------------------------------------------------------------- normalBuffer = null; System.GC.Collect(); resourceId = context.Resources.GetIdentifier(fileName + "_norm", "raw", context.PackageName); fileIn = context.Resources.OpenRawResource(resourceId) as Stream; m = new MemoryStream(); fileIn.CopyTo(m); size = m.Length; floatArray = new float[size / 4]; System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size); normalBuffer = FloatBuffer.Allocate((int)size / 4); // float array to normalBuffer.Put(floatArray, 0, (int)size / 4); normalBuffer.Flip(); floatArray = null; fileIn.Close(); m.Close(); //---------------------------------------------------------------------------------------------------- textureBuffer = null; System.GC.Collect(); resourceId = context.Resources.GetIdentifier(fileName + "_texture", "raw", context.PackageName); fileIn = context.Resources.OpenRawResource(resourceId) as Stream; m = new MemoryStream(); fileIn.CopyTo(m); size = m.Length; floatArray = new float[size / 4]; System.Buffer.BlockCopy(m.ToArray(), 0, floatArray, 0, (int)size); textureBuffer = FloatBuffer.Allocate((int)size / 4); // float array to textureBuffer.Put(floatArray, 0, (int)size / 4); textureBuffer.Flip(); floatArray = null; fileIn.Close(); m.Close(); return(true); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } }