Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You might want to take a look at the NeHe Android Tutorials. They go into this in detail and show you what you need to do. </p> <p>Specifically, the lesson you are looking for is here: <a href="http://insanitydesign.com/wp/projects/nehe-android-ports/" rel="nofollow">http://insanitydesign.com/wp/projects/nehe-android-ports/</a></p> <p>Lesson 6</p> <p>You might not be binding and enabling the buffers, here's a snippet from the tutorial:</p> <pre><code>public void draw(GL10 gl) { //Bind our only previously generated texture in this case gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); //Point to our buffers gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); //Set the face rotation gl.glFrontFace(GL10.GL_CCW); //Enable the vertex and texture state gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); //Draw the vertices as triangles, based on the Index Buffer information gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); //Disable the client state before leaving gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); } </code></pre> <p>Credit: Insanity Design - <a href="http://insanitydesign.com/" rel="nofollow">http://insanitydesign.com/</a></p> <p>Edit: I see what you're asking. Here's more code that should be able to help you then. If you look into the SpriteMethodTest app for android: <a href="http://apps-for-android.googlecode.com/svn/trunk/SpriteMethodTest" rel="nofollow">http://apps-for-android.googlecode.com/svn/trunk/SpriteMethodTest</a></p> <p>You'll notice that Chris Pruett (The developer of this app) shows you the multitude of ways to draw textures to the screen. Below is the code (I believe) you're looking for.</p> <h2>Grid.java</h2> <pre><code>public void beginDrawingStrips(GL10 gl, boolean useTexture) { beginDrawing(gl, useTexture); if (!mUseHardwareBuffers) { gl.glVertexPointer(3, mCoordinateType, 0, mVertexBuffer); if (useTexture) { gl.glTexCoordPointer(2, mCoordinateType, 0, mTexCoordBuffer); } } else { GL11 gl11 = (GL11)gl; // draw using hardware buffers gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mVertBufferIndex); gl11.glVertexPointer(3, mCoordinateType, 0, 0); gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, mTextureCoordBufferIndex); gl11.glTexCoordPointer(2, mCoordinateType, 0, 0); gl11.glBindBuffer(GL11.GL_ELEMENT_ARRAY_BUFFER, mIndexBufferIndex); } } // Assumes beginDrawingStrips() has been called before this. public void drawStrip(GL10 gl, boolean useTexture, int startIndex, int indexCount) { int count = indexCount; if (startIndex + indexCount &gt;= mIndexCount) { count = mIndexCount - startIndex; } if (!mUseHardwareBuffers) { gl.glDrawElements(GL10.GL_TRIANGLES, count, GL10.GL_UNSIGNED_SHORT, mIndexBuffer.position(startIndex)); } else { GL11 gl11 = (GL11)gl; gl11.glDrawElements(GL11.GL_TRIANGLES, count, GL11.GL_UNSIGNED_SHORT, startIndex * CHAR_SIZE); } } </code></pre> <p>Specifically, you'll want to look at the code where it takes the false branch of !mUseHardwareBuffers. I suggest you look at the full Grid.java file for a better representation of how to do it because he also sets up the texture pointers and enables OpenGL to start drawing. </p> <p>On a Side Note: I suggest reading this from Chris also: <a href="http://www.scribd.com/doc/16917369/Writing-Real-Time-Games-for-Android" rel="nofollow">http://www.scribd.com/doc/16917369/Writing-Real-Time-Games-for-Android</a></p> <p>He goes into what this app does and what he found the most effective way of drawing textures was.</p>
 

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