Java Code Examples for javax.microedition.khronos.opengles.GL11#glBufferData()

The following examples show how to use javax.microedition.khronos.opengles.GL11#glBufferData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLES11Canvas.java    From PhotoMovie with Apache License 2.0 6 votes vote down vote up
public GLES11Canvas(GL11 gl) {
    mGL = gl;
    mGLState = new GLState(gl);
    // First create an nio buffer, then create a VBO from it.
    int size = BOX_COORDINATES.length * Float.SIZE / Byte.SIZE;
    FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(size).asFloatBuffer();
    xyBuffer.put(BOX_COORDINATES, 0, BOX_COORDINATES.length).position(0);

    int[] name = new int[1];
    mGLId.glGenBuffers(1, name, 0);
    mBoxCoords = name[0];

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glBufferData(GL11.GL_ARRAY_BUFFER, xyBuffer.capacity() * (Float.SIZE / Byte.SIZE), xyBuffer, GL11.GL_STATIC_DRAW);

    gl.glVertexPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    // Enable the texture coordinate array for Texture 1
    gl.glClientActiveTexture(GL11.GL_TEXTURE1);
    gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);
    gl.glClientActiveTexture(GL11.GL_TEXTURE0);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    // mMatrixValues and mAlpha will be initialized in setSize()
}
 
Example 2
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void createBufferObjects(GL gl) {
    // Generate a the vertex and element buffer IDs
    int[] vboIds = new int[2];
    GL11 gl11 = (GL11) gl;
    gl11.glGenBuffers(2, vboIds, 0);
    mVertexBufferObjectId = vboIds[0];
    mElementBufferObjectId = vboIds[1];

    // Upload the vertex data
    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertexBufferObjectId);
    mVertexByteBuffer.position(0);
    gl11.glBufferData(GL11.GL_ARRAY_BUFFER, mVertexByteBuffer.capacity(), mVertexByteBuffer, GL11.GL_STATIC_DRAW);

    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mElementBufferObjectId);
    mIndexBuffer.position(0);
    gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer.capacity() * CHAR_SIZE, mIndexBuffer, GL11.GL_STATIC_DRAW);

    // We don't need the in-memory data any more
    mVertexBuffer = null;
    mVertexByteBuffer = null;
    mIndexBuffer = null;
}
 
Example 3
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void createBufferObjects(GL gl) {
    checkGLError(gl);
    // Generate a the vertex and element buffer IDs
    int[] vboIds = new int[2];
    GL11 gl11 = (GL11) gl;
    gl11.glGenBuffers(2, vboIds, 0);
    mVertexBufferObjectId = vboIds[0];
    mElementBufferObjectId = vboIds[1];

    // Upload the vertex data
    gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertexBufferObjectId);
    mVertexByteBuffer.position(0);
    gl11.glBufferData(GL11.GL_ARRAY_BUFFER, mVertexByteBuffer.capacity(), mVertexByteBuffer, GL11.GL_STATIC_DRAW);

    gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mElementBufferObjectId);
    mIndexBuffer.position(0);
    gl11.glBufferData(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer.capacity() * CHAR_SIZE, mIndexBuffer, GL11.GL_STATIC_DRAW);

    // We don't need the in-memory data any more
    mVertexBuffer = null;
    mVertexByteBuffer = null;
    mIndexBuffer = null;
    checkGLError(gl);
}
 
Example 4
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
private void initialize() {
    final GL11 gl = mGL;

    // First create an nio buffer, then create a VBO from it.
    final int size = BOX_COORDINATES.length * Float.SIZE / Byte.SIZE;
    final FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(size).asFloatBuffer();
    xyBuffer.put(BOX_COORDINATES, 0, BOX_COORDINATES.length).position(0);

    final int[] name = new int[1];
    GLId.glGenBuffers(1, name, 0);
    mBoxCoords = name[0];

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glBufferData(GL11.GL_ARRAY_BUFFER, xyBuffer.capacity() * (Float.SIZE / Byte.SIZE), xyBuffer,
            GL11.GL_STATIC_DRAW);

    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, 0);

    // Enable the texture coordinate array for Texture 1
    gl.glClientActiveTexture(GL10.GL_TEXTURE1);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glClientActiveTexture(GL10.GL_TEXTURE0);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);
    gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);

    gl.glEnable(GL10.GL_LINE_SMOOTH);
    gl.glLineWidth(1.5f);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    // mMatrixValues and mAlpha will be initialized in setSize()
}
 
Example 5
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fillPoly(final int color, final PointF... path) {
    mGLState.setColorMode(color, mAlpha);
    final GL11 gl = mGL;

    final int bytes = 2 * path.length * Float.SIZE;
    final FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(bytes).asFloatBuffer();
    for (int i = 0; i < path.length; i++) {
        xyBuffer.put(path[i].x / mScreenWidth);
        xyBuffer.put(path[i].y / mScreenHeight);
    }
    xyBuffer.position(0);

    saveTransform();
    translate(0, 0);
    scale(mScreenWidth, mScreenHeight, 1);
    gl.glLoadMatrixf(mMatrixValues, 0);

    final int[] name = new int[1];
    GLId.glGenBuffers(1, name, 0);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, name[0]);
    gl.glBufferData(GL11.GL_ARRAY_BUFFER, bytes, xyBuffer, GL11.GL_DYNAMIC_DRAW);
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, path.length);

    restoreTransform();

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, 0);
}
 
Example 6
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void drawPoly(final int color, final PointF... path) {
    mGLState.setColorMode(color, mAlpha);
    mGLState.setLineWidth(1.5f);
    final GL11 gl = mGL;

    final int bytes = 2 * path.length * Float.SIZE;
    final FloatBuffer xyBuffer = allocateDirectNativeOrderBuffer(bytes).asFloatBuffer();
    for (int i = 0; i < path.length; i++) {
        xyBuffer.put(path[i].x / mScreenWidth);
        xyBuffer.put(path[i].y / mScreenHeight);
    }
    xyBuffer.position(0);

    saveTransform();
    translate(0, 0);
    scale(mScreenWidth, mScreenHeight, 1);
    gl.glLoadMatrixf(mMatrixValues, 0);

    final int[] name = new int[1];
    GLId.glGenBuffers(1, name, 0);

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, name[0]);
    gl.glBufferData(GL11.GL_ARRAY_BUFFER, bytes, xyBuffer, GL11.GL_DYNAMIC_DRAW);
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, path.length);

    restoreTransform();

    gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, mBoxCoords);
    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, 0);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, 0);
}