Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am new to <a href="/questions/tagged/android" class="post-tag" title="show questions tagged &#39;android&#39;" rel="tag"><img src="https://i.stack.imgur.com/tKsDb.png" height="16" width="18" alt="" class="sponsor-tag-img">android</a> programming so I am sure there is probably a better way to do this. But I was following the OpenGL ES 1.0 tutorial on the android developers site <a href="http://developer.android.com/resources/tutorials/opengl/opengl-es10.html" rel="nofollow noreferrer">http://developer.android.com/resources/tutorials/opengl/opengl-es10.html</a> which walks you through drawing a green triangle. You can follow the link and you will see most of the code I used there. I wanted to draw a circle on the triangle. The code I added is based on the above example posted by datenwolf. And is shown in snippets below:</p> <pre><code>public class HelloOpenGLES10Renderer implements GLSurfaceView.Renderer { // the number small triangles used to make a circle public int segments = 100; public float mAngle; private FloatBuffer triangleVB; // array to hold the FloatBuffer for the small triangles private FloatBuffer [] segmentsArray = new FloatBuffer[segments]; private void initShapes(){ . . . // stuff to draw holes in the board int i = 0; float angle_start = 0.0f; float angle_stop = 2.0f * (float) java.lang.Math.PI; float angle_step = (angle_stop - angle_start)/segments; for(i=0; i&lt;segments; i++) { float[] holeCoords; FloatBuffer holeVB; holeCoords = new float [ 9 ]; // initialize vertex Buffer for triangle // (# of coordinate values * 4 bytes per float) ByteBuffer vbb2 = ByteBuffer.allocateDirect(holeCoords.length * 4); vbb2.order(ByteOrder.nativeOrder());// use the device hardware's native byte order holeVB = vbb2.asFloatBuffer(); // create a floating point buffer from the ByteBuffer float x1 = 0.05f * (float) java.lang.Math.cos(angle_start + i*angle_step); float y1 = 0.05f * (float) java.lang.Math.sin(angle_start + i*angle_step); float z1 = 0.1f; float x2 = 0.05f * (float) java.lang.Math.cos(angle_start + i+1*angle_step); float y2 = 0.05f * (float) java.lang.Math.sin(angle_start + i+1*angle_step); float z2 = 0.1f; holeCoords[0] = 0.0f; holeCoords[1] = 0.0f; holeCoords[2] = 0.1f; holeCoords[3] = x1; holeCoords[4] = y1; holeCoords[5] = z1; holeCoords[6] = x2; holeCoords[7] = y2; holeCoords[8] = z2; holeVB.put(holeCoords); // add the coordinates to the FloatBuffer holeVB.position(0); // set the buffer to read the first coordinate segmentsArray[i] = holeVB; } } . . . public void onDrawFrame(GL10 gl) { . . . // Draw hole gl.glColor4f( 1.0f - 0.63671875f, 1.0f - 0.76953125f, 1.0f - 0.22265625f, 0.0f); for ( int i=0; i&lt;segments; i++ ) { gl.glVertexPointer(3, GL10.GL_FLOAT, 0, segmentsArray[i]); gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3); } } </code></pre> <p><img src="https://i.stack.imgur.com/8wGls.png" alt="Here&#39;s a screen shot in the emulator"></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. This table or related slice is empty.
    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