Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Initializing the Buffers in your onDrawFrame method doesn't look right.</p> <p>I suggest you create a basic Rectangle class with vertices and indices as fields:</p> <pre><code>public class Rectangle { private float vertices[]={ -1.0f, 1.0f, 0.0f, -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 1.0f,1.0f,0.0f }; private short[] indices = {0,1,2,0,2,3}; private FloatBuffer vertexBuffer; private ShortBuffer indexBuffer; public Rectangle(){ ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4); vbb.order(ByteOrder.nativeOrder()); vertexBuffer = vbb.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2); ibb.order(ByteOrder.nativeOrder()); indexBuffer = ibb.asShortBuffer(); indexBuffer.put(indices); indexBuffer.position(0); } public void draw(GL10 gl){ gl.glFrontFace(GL10.GL_CCW); gl.glEnable(GL10.GL_CULL_FACE); gl.glCullFace(GL10.GL_BACK); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisable(GL10.GL_CULL_FACE); } } </code></pre> <p>Add a Rectangle field to your Renderer and initialize it in the Renderer's constructor:</p> <pre><code>public MyOpenGLRenderer() { mRectangle = new Rectangle(); } </code></pre> <p>and call the Rectangle's draw method in your Renderer's onDrawFrame method:</p> <pre><code> public void onDrawFrame(GL10 gl) { //... mRectangle.draw(gl); } </code></pre> <p>Follow the first 3 parts of <a href="http://www.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/">this tutorial</a> for a complete solution to how it can be done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload