private static boolean initByteOrder() { ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order IntBuffer tst_i = tst_b.asIntBuffer(); ShortBuffer tst_s = tst_b.asShortBuffer(); tst_i.put(0, 0x0A0B0C0D); return 0x0C0D == tst_s.get(0); }
/** * Creates the buffers we use to store information about the 3D world. OpenGL doesn't use Java * arrays, but rather needs data in a format it can understand. Hence we use ByteBuffers. * * @param config The EGL configuration used when creating the surface. */ @Override public void onSurfaceCreated(EGLConfig config) { Log.i(TAG, "In onSurfaceCreated"); GLES20.glClearColor(0.1f, 0.1f, 0.1f, 0.5f); // Dark background so camera stuff show up. ByteBuffer bb = ByteBuffer.allocateDirect(squareVertices.length * 4); bb.order(ByteOrder.nativeOrder()); vertexBuffer = bb.asFloatBuffer(); vertexBuffer.put(squareVertices); vertexBuffer.position(0); ByteBuffer dlb = ByteBuffer.allocateDirect(drawOrder.length * 2); dlb.order(ByteOrder.nativeOrder()); drawListBuffer = dlb.asShortBuffer(); drawListBuffer.put(drawOrder); drawListBuffer.position(0); ByteBuffer bb2 = ByteBuffer.allocateDirect(textureVertices.length * 4); bb2.order(ByteOrder.nativeOrder()); textureVerticesBuffer = bb2.asFloatBuffer(); textureVerticesBuffer.put(textureVertices); textureVerticesBuffer.position(0); int vertexShader = loadGLShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = loadGLShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES Program GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES20.glLinkProgram(mProgram); // Create a texture and start mirroring the camera on the texture: texture = createTexture(); startCamera(texture); }
@Override protected int getFromBuffer( ByteBuffer buffer, DeserializableControl control, int offset, int length) { buffer.asShortBuffer().get(value, offset, length); buffer.position(buffer.position() + length * 2); return length; }
@Override public int read(ByteBuffer buf) throws IOException { ShortBuffer sbuf = buf.asShortBuffer(); int total = 0; while (sbuf.hasRemaining() && _header != null) { if (_buffer == null) { try { _buffer = (SampleBuffer) _decoder.decodeFrame(_header, _istream); _istream.closeFrame(); _header = _istream.readFrame(); } catch (JavaLayerException e) { throw new IOException(e.toString()); } } int blen = _buffer.getBufferLength(), length = Math.min(sbuf.remaining(), blen - _offset); sbuf.put(_buffer.getBuffer(), _offset, length); if ((_offset += length) >= blen) { _offset = 0; _buffer = null; } total += (length * 2); } buf.position(buf.position() + total); return total; }
private void init(BobView view, int layers) { this.view = view; obs = new ArrayList<GameObject>(OBJECTS); instances = 0; // Set up vertex buffer ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect( VERTEX_BYTES); // a float has 4 bytes so we allocate for each coordinate 4 bytes vertexByteBuffer.order(ByteOrder.nativeOrder()); vertexBuffer = vertexByteBuffer .order(ByteOrder.nativeOrder()) .asFloatBuffer(); // allocates the memory from the bytebuffer vertexBuffer.position(0); // puts the curser position at the beginning of the buffer // Set up texture buffer vertexByteBuffer = ByteBuffer.allocateDirect(TEX_BYTES); vertexByteBuffer.order(ByteOrder.nativeOrder()); textureBuffer = vertexByteBuffer.asFloatBuffer(); textureBuffer.position(0); // Set up index buffer vertexByteBuffer = ByteBuffer.allocateDirect(INDEX_BYTES); vertexByteBuffer.order(ByteOrder.nativeOrder()); indexBuffer = new ShortBuffer[layers]; for (int i = 0; i < layers; i++) { indexBuffer[i] = vertexByteBuffer.asShortBuffer(); indexBuffer[i].position(0); } this.layers = layers; lastIndex = new int[layers]; red = new float[layers]; green = new float[layers]; blue = new float[layers]; alpha = new float[layers]; for (int i = 0; i < layers; i++) { red[i] = green[i] = blue[i] = alpha[i] = 1f; } for (int i = 0; i < buttonNewpress.length; i++) { buttonNewpress[i] = -1; } for (int i = 0; i < buttonReleased.length; i++) { buttonReleased[i] = -1; } // Camera initialization camX = 0; camY = 0; camZoom = 1; cAnchorX = 0; cAnchorY = 0; }
public Square() { // initialize vertex byte buffer for shape coordinates ByteBuffer bb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) squareCoords.length * 4); bb.order(ByteOrder.nativeOrder()); vertexBuffer = bb.asFloatBuffer(); vertexBuffer.put(squareCoords); vertexBuffer.position(0); // initialize byte buffer for the draw list ByteBuffer dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) drawOrder.length * 2); dlb.order(ByteOrder.nativeOrder()); drawListBuffer = dlb.asShortBuffer(); drawListBuffer.put(drawOrder); drawListBuffer.position(0); // prepare shaders and OpenGL program int vertexShader = MyGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = MyGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program GLES20.glLinkProgram(mProgram); // create OpenGL program executables }
/* * Reads SHORT image data organized as separate image planes. * */ public short[][] readPlanar16( int width, int height, int samplesPerPixel, long[] stripOffsets, long[] stripCounts, long rowsPerStrip) throws IOException { short[][] data = new short[samplesPerPixel][width * height]; int band = 0; int numRows = 0; ByteBuffer buff = ByteBuffer.allocateDirect(width * height * SHORT_SIZEOF); buff.order(this.getByteOrder()); for (int i = 0; i < stripOffsets.length; i++) { this.theChannel.position(stripOffsets[i]); int len = (int) stripCounts[i]; if ((buff.position() + len) > data[band].length * SHORT_SIZEOF) len = data[band].length * SHORT_SIZEOF - buff.position(); buff.limit(buff.position() + len); this.theChannel.read(buff); numRows += rowsPerStrip; if (numRows >= height) { buff.flip(); ShortBuffer sbuff = buff.asShortBuffer(); sbuff.get(data[band]); buff.clear(); ++band; numRows = 0; } } return data; }
public Tessellator(int p_i52_1_) { renderingChunk = false; defaultTexture = true; autoGrow = true; subTessellators = new Tessellator[0]; subTextures = new int[0]; terrainTexture = 0; textureUpdateTime = 0L; field_1505_h = 0; field_1501_l = false; field_1500_m = false; field_35838_p = false; field_1499_n = false; field_1498_o = 0; field_1497_p = 0; field_1495_q = false; field_1488_w = false; field_1487_x = false; field_1485_z = 0; field_1496_A = 10; field_1494_B = p_i52_1_; field_1509_d = GLAllocation.func_1127_b(p_i52_1_ * 4); field_1508_e = field_1509_d.asIntBuffer(); field_1507_f = field_1509_d.asFloatBuffer(); field_35836_g = field_1509_d.asShortBuffer(); field_1506_g = new int[p_i52_1_]; field_1487_x = field_1510_c && GLContext.getCapabilities().GL_ARB_vertex_buffer_object; if (field_1487_x) { field_1486_y = GLAllocation.func_1125_c(field_1496_A); ARBVertexBufferObject.glGenBuffersARB(field_1486_y); } }
public Vertices( GLGraphics glGraphics, int maxVertices, int maxIndices, boolean hasColor, boolean hasTexCoords) { this.glGraphics = glGraphics; this.hasColor = hasColor; this.hasTexCoords = hasTexCoords; this.vertexSize = (2 + (hasColor ? 4 : 0) + (hasTexCoords ? 2 : 0)) * 4; // golemina na bajtite za tockite ByteBuffer buffer = ByteBuffer.allocateDirect(maxVertices * vertexSize); buffer.order(ByteOrder.nativeOrder()); vertices = buffer.asFloatBuffer(); if (maxIndices > 0) { buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8); buffer.order(ByteOrder.nativeOrder()); indices = buffer.asShortBuffer(); } else { indices = null; } }
Tessellator(int par1) { vertexCount = 0; hasColor = false; hasTexture = false; hasBrightness = false; hasNormals = false; rawBufferIndex = 0; addedVertices = 0; isColorDisabled = false; isDrawing = false; useVBO = false; vboIndex = 0; vboCount = 10; bufferSize = par1; byteBuffer = GLAllocation.createDirectByteBuffer(par1 * 4); intBuffer = byteBuffer.asIntBuffer(); floatBuffer = byteBuffer.asFloatBuffer(); shortBuffer = byteBuffer.asShortBuffer(); rawBuffer = new int[par1]; useVBO = tryVBO && GLContext.getCapabilities().GL_ARB_vertex_buffer_object; if (useVBO) { vertexBuffers = GLAllocation.createDirectIntBuffer(vboCount); ARBVertexBufferObject.glGenBuffersARB(vertexBuffers); } }
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); // Allocation automatically zeroes the ByteBuffer: int i = 0; while (i++ < bb.limit()) if (bb.get() != 0) print("nonzero"); print("i = " + i); bb.rewind(); // Store and read a char array: bb.asCharBuffer().put("Howdy!"); char c; while ((c = bb.getChar()) != 0) printnb(c + " "); print(); bb.rewind(); // Store and read a short: bb.asShortBuffer().put((short) 471142); print(bb.getShort()); bb.rewind(); // Store and read an int: bb.asIntBuffer().put(99471142); print(bb.getInt()); bb.rewind(); // Store and read a long: bb.asLongBuffer().put(99471142); print(bb.getLong()); bb.rewind(); // Store and read a float: bb.asFloatBuffer().put(99471142); print(bb.getFloat()); bb.rewind(); // Store and read a double: bb.asDoubleBuffer().put(99471142); print(bb.getDouble()); bb.rewind(); }
public void allocateIndex() { ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2); ibb.order(ByteOrder.nativeOrder()); ib = ibb.asShortBuffer(); ib.put(indices); ib.position(0); }
/** * Create a roaring array based on a previously serialized ByteBuffer. As much as possible, the * ByteBuffer is used as the backend, however if you modify the content, the result is * unspecified. * * @param bb The source ByteBuffer */ protected RoaringArray(ByteBuffer bb) { bb.order(ByteOrder.LITTLE_ENDIAN); if (bb.getInt() != SERIAL_COOKIE) throw new RuntimeException("I failed to find the right cookie."); this.size = bb.getInt(); // we fully read the meta-data array to RAM, but the containers // themselves are memory-mapped this.array = new Element[this.size]; final short keys[] = new short[this.size]; final int cardinalities[] = new int[this.size]; final boolean isBitmap[] = new boolean[this.size]; for (int k = 0; k < this.size; ++k) { keys[k] = bb.getShort(); cardinalities[k] = Util.toIntUnsigned(bb.getShort()) + 1; isBitmap[k] = cardinalities[k] > ArrayContainer.DEFAULT_MAX_SIZE; } for (int k = 0; k < this.size; ++k) { if (cardinalities[k] == 0) throw new RuntimeException("no"); Container val; if (isBitmap[k]) { final LongBuffer bitmapArray = bb.asLongBuffer().slice(); bitmapArray.limit(BitmapContainer.MAX_CAPACITY / 64); bb.position(bb.position() + BitmapContainer.MAX_CAPACITY / 8); val = new BitmapContainer(bitmapArray, cardinalities[k]); } else { final ShortBuffer shortArray = bb.asShortBuffer().slice(); shortArray.limit(cardinalities[k]); bb.position(bb.position() + cardinalities[k] * 2); val = new ArrayContainer(shortArray, cardinalities[k]); } this.array[k] = new Element(keys[k], val); } }
public void onSurfaceCreated(GL10 gl, EGLConfig config) { if (buffer == null) { ByteBuffer bb = ByteBuffer.allocateDirect(512 * 256 * 2); buffer = bb.asShortBuffer(); bitmap = new GLBitmap(0, 0, 1, bufferWidth, bufferHeight); bitmap.setBuffer(buffer); textureReInit = true; if (nativeThread == null) { nativeThread = new Thread(this); nativeThread.start(); } } gl.glDisable(GL10.GL_DITHER); gl.glDisable(GL10.GL_LIGHTING); gl.glDisable(GL10.GL_CULL_FACE); gl.glDisable(GL10.GL_MULTISAMPLE); // gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); gl.glClearColor(0, 0, 0, 0); // gl.glShadeModel(GL10.GL_SMOOTH); gl.glDisable(GL10.GL_DEPTH_TEST); // gl.glEnable(GL10.GL_TEXTURE_2D); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); textureReInit = true; }
public static ShortBuffer newShortBuffer(int numElements) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements * 2); bb.order(ByteOrder.nativeOrder()); ShortBuffer sb = bb.asShortBuffer(); sb.position(0); return sb; }
@Override protected void initModel() { final short[] _indicesArray = {0, 1, 2, 0, 2, 3}; // float has 4 bytes ByteBuffer vbb = ByteBuffer.allocateDirect(_indicesArray.length * 3 * 4); vbb.order(ByteOrder.nativeOrder()); vertexBuffer = vbb.asFloatBuffer(); // short has 2 bytes ByteBuffer ibb = ByteBuffer.allocateDirect(_indicesArray.length * 2); ibb.order(ByteOrder.nativeOrder()); indexBuffer = ibb.asShortBuffer(); final float[] coords = { 0.0f, -0.1f, 0.0f, // 0 0.1f, 0.0f, 0.0f, // 1 0.0f, 0.6f, 0.0f, // 2 -0.1f, 0.0f, 0.0f, // 3 }; vertexBuffer.put(coords); indexBuffer.put(_indicesArray); vertexBuffer.position(0); indexBuffer.position(0); }
/** * Creates a direct short buffer, and copy coords into it. * * @param coords - data to be copied. */ public static ShortBuffer allocateShortBuffer(short[] coords) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(coords.length * BYTES_PER_SHORT); byteBuffer.order(ByteOrder.nativeOrder()); ShortBuffer shortBuffer = byteBuffer.asShortBuffer(); shortBuffer.put(coords); shortBuffer.position(0); return shortBuffer; }
private void createViewBuffers(int numColumns) { buffer.position(0); headerBuffer = buffer.asIntBuffer(); buffer.position(3 * 4); idBuffer = buffer.asIntBuffer(); buffer.position(3 * 4 + numColumns * 4); valBuffer = buffer.asShortBuffer(); }
public static ShortBuffer toShortBuffer(short[] v) { ByteBuffer buf = ByteBuffer.allocateDirect(v.length * 2); buf.order(ByteOrder.nativeOrder()); ShortBuffer buffer = buf.asShortBuffer(); buffer.put(v); buffer.position(0); return buffer; }
public RockOnCover() { // public RockOnCover(int[] textureId, int[] textureAlphabetId) { /** cover coordinates */ float[] coords = { // X, Y, Z -1.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f, -1.f, 0.f, -1.f, -1.f, 0.f }; /** Texture coordinates */ float[] textCoords = { 0.f, 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f }; /** * Generate our openGL buffers with the vertice and texture coordinates and drawing indexes * VERTICAL */ // Buffers to be passed to gl*Pointer() functions // must be direct, i.e., they must be placed on the // native heap where the garbage collector cannot // move them. // // Buffers with multi-byte datatypes (e.g., short, int, float) // must have their byte order set to native order ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4); // verts * ncoords * bytes per vert?? vbb.order(ByteOrder.nativeOrder()); mFVertexBuffer = vbb.asFloatBuffer(); ByteBuffer tbb = ByteBuffer.allocateDirect(VERTS * 2 * 4); tbb.order(ByteOrder.nativeOrder()); mTexBuffer = tbb.asFloatBuffer(); ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2); ibb.order(ByteOrder.nativeOrder()); mIndexBuffer = ibb.asShortBuffer(); for (int i = 0; i < VERTS; i++) { for (int j = 0; j < 3; j++) { mFVertexBuffer.put(coords[i * 3 + j]); } } mTexBuffer.put(textCoords); for (int i = 0; i < VERTS; i++) { mIndexBuffer.put((short) i); } mFVertexBuffer.position(0); mTexBuffer.position(0); mIndexBuffer.position(0); }
/** * Set the indices. * * @param indices */ protected void setIndices(short[] indices) { // short is 2 bytes, therefore we multiply the number if // vertices with 2. ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2); ibb.order(ByteOrder.nativeOrder()); mIndicesBuffer = ibb.asShortBuffer(); mIndicesBuffer.put(indices); mIndicesBuffer.position(0); mNumOfIndices = indices.length; }
public ShortBuffer ibuf() { ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2); ibb.order(ByteOrder.nativeOrder()); _ibuf = ibb.asShortBuffer(); short[] indexs = {0, 1, 2}; for (int i = 0; i < VERTS; i++) _ibuf.put(indexs[i]); _ibuf.position(0); return _ibuf; }
/** Optional, throws GLException if not available in profile */ public final int gluScaleImage( int format, int widthin, int heightin, int typein, java.nio.Buffer datain, int widthout, int heightout, int typeout, java.nio.Buffer dataout) { validateMipmap(); java.nio.ByteBuffer in = null; java.nio.ByteBuffer out = null; in = copyToByteBuffer(datain); if (dataout instanceof java.nio.ByteBuffer) { out = (java.nio.ByteBuffer) dataout; } else if (dataout instanceof java.nio.ShortBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_SHORT); } else if (dataout instanceof java.nio.IntBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_INT); } else if (dataout instanceof java.nio.FloatBuffer) { out = Buffers.newDirectByteBuffer(dataout.remaining() * Buffers.SIZEOF_FLOAT); } else { throw new IllegalArgumentException( "Unsupported destination buffer type (must be byte, short, int, or float)"); } int errno = Mipmap.gluScaleImage( getCurrentGL2ES1(), format, widthin, heightin, typein, in, widthout, heightout, typeout, out); if (errno == 0) { out.rewind(); if (out != dataout) { if (dataout instanceof java.nio.ShortBuffer) { ((java.nio.ShortBuffer) dataout).put(out.asShortBuffer()); } else if (dataout instanceof java.nio.IntBuffer) { ((java.nio.IntBuffer) dataout).put(out.asIntBuffer()); } else if (dataout instanceof java.nio.FloatBuffer) { ((java.nio.FloatBuffer) dataout).put(out.asFloatBuffer()); } else { throw new RuntimeException("Should not reach here"); } } } return (errno); }
public void initGL(GL10 gl, Context context) { Bitmap texture = Util.getTextureFromBitmapResource(context, _textureResource); _width = texture.getWidth(); _height = texture.getHeight(); // scale the vertex buffer coords for (int i = 0; i < _vertices.length; i += 3) { _vertices[i] *= _width; _vertices[i + 1] *= _height; } // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer vbb = ByteBuffer.allocateDirect(_vertices.length * 4); vbb.order(ByteOrder.nativeOrder()); _vertexBuffer = vbb.asFloatBuffer(); _vertexBuffer.put(_vertices); _vertexBuffer.position(0); // short is 2 bytes, therefore we multiply the number if // vertices with 2. ByteBuffer ibb = ByteBuffer.allocateDirect(_indices.length * 2); ibb.order(ByteOrder.nativeOrder()); _indexBuffer = ibb.asShortBuffer(); _indexBuffer.put(_indices); _indexBuffer.position(0); // a float is 4 bytes, therefore we multiply the number if // vertices with 4. ByteBuffer tbb = ByteBuffer.allocateDirect(_textureCoords.length * 4); tbb.order(ByteOrder.nativeOrder()); _textureCoordsBuffer = tbb.asFloatBuffer(); _textureCoordsBuffer.put(_textureCoords); _textureCoordsBuffer.position(0); // create texture gl.glEnable(GL10.GL_TEXTURE_2D); _texturesBuffer = IntBuffer.allocate(1); gl.glGenTextures(1, _texturesBuffer); gl.glBindTexture(GL10.GL_TEXTURE_2D, _texturesBuffer.get(0)); // set the texture gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0); texture.recycle(); }
public LevelObjectRenderer() { final float vrect[] = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f}; final short irect[] = {0, 1, 3, 3, 1, 2}; final double step = Math.PI / 4.0f; final float vcircle[] = new float[16]; final short icircle[] = {5, 3, 7, 7, 3, 1, 1, 3, 2, 7, 1, 0, 5, 4, 3, 5, 7, 6}; double curangle = 0; for (int i = 0; i < 16; i += 2) { vcircle[i] = (float) Math.cos(curangle); vcircle[i + 1] = (float) Math.sin(curangle); curangle += step; } ByteBuffer vrbb = ByteBuffer.allocateDirect(4 * 2 * 4); vrbb.order(ByteOrder.nativeOrder()); m_RectangleVB = vrbb.asFloatBuffer(); m_RectangleVB.put(vrect, 0, 8); m_RectangleVB.position(0); ByteBuffer irbb = ByteBuffer.allocateDirect(2 * 6); irbb.order(ByteOrder.nativeOrder()); m_RectangleIB = irbb.asShortBuffer(); m_RectangleIB.put(irect, 0, 6); m_RectangleIB.position(0); ByteBuffer vcbb = ByteBuffer.allocateDirect(4 * 2 * 8); vcbb.order(ByteOrder.nativeOrder()); m_CircleVB = vcbb.asFloatBuffer(); m_CircleVB.put(vcircle, 0, 16); m_CircleVB.position(0); ByteBuffer icbb = ByteBuffer.allocateDirect(2 * 18); icbb.order(ByteOrder.nativeOrder()); m_CircleIB = icbb.asShortBuffer(); m_CircleIB.put(icircle, 0, 18); m_CircleIB.position(0); }
/** * @param vertices an array of vertices as defined by OpenGL's GL_TRIANGLE_FAN method * @param color the {@link Color} of the {@link Shape} */ public TriangleStripShape(float[] vertices, short[] indices, float[] normals, Color color) { this.vertices = Vertices.toFloatBuffer(vertices); this.normals = Vertices.toFloatBuffer(normals); ByteBuffer bb_idx = ByteBuffer.allocateDirect(indices.length * 2); bb_idx.order(ByteOrder.nativeOrder()); this.indices = bb_idx.asShortBuffer(); this.indices.put(indices); this.indices.position(0); setColor(color); setTransform(new Transform(new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 1))); }
public Cube(Bitmap b) { // initialize buffer for vertex coordinates ByteBuffer vpb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) faceCoords.length * 4); vpb.order(ByteOrder.nativeOrder()); vertexBuffer = vpb.asFloatBuffer(); vertexBuffer.put(faceCoords); vertexBuffer.position(0); // initialize buffer for vertex normals ByteBuffer vnb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) normals.length * 4); vnb.order(ByteOrder.nativeOrder()); normalBuffer = vnb.asFloatBuffer(); normalBuffer.put(normals); normalBuffer.position(0); // initialize buffer for UV Coordinates ByteBuffer uvb = ByteBuffer.allocateDirect( // (# of coordinate values * 4 bytes per float) uvs.length * 4); uvb.order(ByteOrder.nativeOrder()); uvBuffer = uvb.asFloatBuffer(); uvBuffer.put(uvs); uvBuffer.position(0); // initialize byte buffer for the draw list ByteBuffer dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) drawOrder.length * 2); dlb.order(ByteOrder.nativeOrder()); drawListBuffer = dlb.asShortBuffer(); drawListBuffer.put(drawOrder); drawListBuffer.position(0); int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); shaderProgram = GLES20.glCreateProgram(); GLES20.glAttachShader(shaderProgram, vertexShader); GLES20.glAttachShader(shaderProgram, fragmentShader); GLES20.glLinkProgram(shaderProgram); loadTexture(b); }
public MarkerTile(float mx, float my, float sx, float sy, int texture) { midx = mx; midy = my; sizx = sx; sizy = sy; midOx = mx; midOy = my; sizOx = sx; sizOy = sy; midTx = mx; midTy = my; sizTx = sx; sizTy = sy; textureRef = texture; int vertexInfoShader = XQGLRenderer.loadShader(GLES20.GL_VERTEX_SHADER, vertexInfoTileShaderCode); int fragmentInfoShader = XQGLRenderer.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentInfoTileShaderCode); mProgram = GLES20.glCreateProgram(); // add the vertex shader to program GLES20.glAttachShader(mProgram, vertexInfoShader); // add the fragment shader to program GLES20.glAttachShader(mProgram, fragmentInfoShader); // creates OpenGL ES program executables GLES20.glLinkProgram(mProgram); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(tileCoords.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); vertexBuffer = byteBuffer.asFloatBuffer(); vertexBuffer.put(tileCoords); vertexBuffer.position(0); byteBuffer = ByteBuffer.allocateDirect(drawOrder.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); indexBuffer = byteBuffer.asShortBuffer(); indexBuffer.put(drawOrder); indexBuffer.position(0); byteBuffer = ByteBuffer.allocateDirect(TextureCoords.length * 4); byteBuffer.order(ByteOrder.nativeOrder()); textureBuffer = byteBuffer.asFloatBuffer(); textureBuffer.put(TextureCoords); textureBuffer.position(0); }
public NioWrapLittleConversion() { // big/little endian difference one liner order = ByteOrder.LITTLE_ENDIAN; byteBuffer = ByteBuffer.allocateDirect(BUFFER_SIZE).order(order); // views on the bytebuffer to fill/drain it efficiently charBuffer = byteBuffer.asCharBuffer(); shortBuffer = byteBuffer.asShortBuffer(); intBuffer = byteBuffer.asIntBuffer(); longBuffer = byteBuffer.asLongBuffer(); floatBuffer = byteBuffer.asFloatBuffer(); doubleBuffer = byteBuffer.asDoubleBuffer(); }
public Triangle() { // Buffers to be passed to gl*Pointer() functions // must be direct, i.e., they must be placed on the // native heap where the garbage collector cannot // move them. // // Buffers with multi-byte datatypes (e.g., short, int, float) // must have their byte order set to native order ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4); vbb.order(ByteOrder.nativeOrder()); mFVertexBuffer = vbb.asFloatBuffer(); ByteBuffer tbb = ByteBuffer.allocateDirect(VERTS * 2 * 4); tbb.order(ByteOrder.nativeOrder()); mTexBuffer = tbb.asFloatBuffer(); ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2); ibb.order(ByteOrder.nativeOrder()); mIndexBuffer = ibb.asShortBuffer(); // A unit-sided equilateral triangle centered on the origin. float[] coords = { // X, Y, Z -0.5f, -0.25f, 0, 0.5f, -0.25f, 0, 0.0f, 0.559016994f, 0 }; for (int i = 0; i < VERTS; i++) { for (int j = 0; j < 3; j++) { mFVertexBuffer.put(coords[i * 3 + j] * 2.0f); } } for (int i = 0; i < VERTS; i++) { for (int j = 0; j < 2; j++) { mTexBuffer.put(coords[i * 3 + j] * 2.0f + 0.5f); } } for (int i = 0; i < VERTS; i++) { mIndexBuffer.put((short) i); } mFVertexBuffer.position(0); mTexBuffer.position(0); mIndexBuffer.position(0); }