Java Code Examples for javax.microedition.khronos.opengles.GL10#glDrawElements()
The following examples show how to use
javax.microedition.khronos.opengles.GL10#glDrawElements() .
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: CubeSmallGLUT.java From opengl with Apache License 2.0 | 6 votes |
void drawSimpleCube (GL10 gl) { float vertices[] = { -1,1,1, 1,1,1, 1,-1,1, -1,-1,1, 1,1,-1, -1,1,-1, -1,-1,-1, 1,-1,-1 }; byte indices[] = { 0,1,2, 2,3,0, 1,4,7, 7,2,1, 0,3,6, 6,5,0, 3,2,7, 7,6,3, 0,1,4, 4,5,0, 5,6,7, 7,4,5 }; FloatBuffer vertexBuffer = getFloatBufferFromFloatArray(vertices); ByteBuffer indexBuffer = getByteBufferFromByteArray(indices); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); //gl.glDrawElements(GL10.GL_LINE_LOOP, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); }
Example 2
Source File: CubeSmallGLUT.java From opengl with Apache License 2.0 | 6 votes |
void draw(GL10 gl) { // need for correct culling gl.glFrontFace(GL10.GL_CW); // make sure our state is correct gl.glEnableClientState(GL10.GL_NORMAL_ARRAY); // set our vertexes gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); // set our normals for correct lighting gl.glNormalPointer(GL10.GL_FLOAT, 0, mNormalBuffer); // draw the elements gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); // GLUT disables the client state -- we don't. Why does it? .. // TODO: consider a preDraw, draw, postDraw ... }
Example 3
Source File: CubeSmallGLUT.java From opengl with Apache License 2.0 | 6 votes |
void drawSimpleCube (GL10 gl) { float vertices[] = { -1,1,1, 1,1,1, 1,-1,1, -1,-1,1, 1,1,-1, -1,1,-1, -1,-1,-1, 1,-1,-1 }; byte indices[] = { 0,1,2, 2,3,0, 1,4,7, 7,2,1, 0,3,6, 6,5,0, 3,2,7, 7,6,3, 0,1,4, 4,5,0, 5,6,7, 7,4,5 }; FloatBuffer vertexBuffer = getFloatBufferFromFloatArray(vertices); ByteBuffer indexBuffer = getByteBufferFromByteArray(indices); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); //gl.glDrawElements(GL10.GL_LINE_LOOP, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); }
Example 4
Source File: Square.java From opengl with Apache License 2.0 | 6 votes |
public void draw(GL10 gl) { //tell openGL how the vertices are ordering their faces //this is both for efficiently so openGL can ignore the "backside" and not attempt to draw it. gl.glFrontFace(GL11.GL_CCW); //counter clockwise, so any counter triangles are ignored. //send the buffers to the renderer //specific the number of elements per vertex, which there are 2. gl.glVertexPointer(2, GL11.GL_FLOAT, 0, mFVertexBuffer); //8 //color buffer is added, with the size of the 4 elements gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); //9 //finally draw the element, we the connectivity array, using triangles //could also be triangle lists, points or lines gl.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_BYTE, mIndexBuffer); //return the openGL back to the default value. gl.glFrontFace(GL11.GL_CCW); //11 }
Example 5
Source File: Cube.java From opengl with Apache License 2.0 | 5 votes |
public void draw(GL10 gl) { gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer); gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan1); gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan2); }
Example 6
Source File: ShadeRenderer.java From BobEngine with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void render(GL10 gl, int layer) { if (alpha[layer] > 0.0001f) { float x = 0; float y = 0; float width = getRoom().getViewWidth(); float height = getRoom().getViewHeight(); x += getRoom().getCameraLeftEdge() * getRoom().getGridUnitX(); y += getRoom().getCameraBottomEdge() * getRoom().getGridUnitY(); vertices[0] = x; // Bottom Left X vertices[1] = y; // Bottom Left Y vertices[2] = vertices[0]; // Top Left X (Same as Bottom X) vertices[3] = y + height; // Top Left Y vertices[4] = x + width; // Bottom Right X vertices[5] = vertices[1]; // Bottom Right Y (Same as Left Y) vertices[6] = vertices[4]; // Top Right X (Same as Bottom X) vertices[7] = vertices[3]; // Top Right Y (Same as Left Y) vertexBuffer.clear(); vertexBuffer.put(vertices); vertexBuffer.position(0); textureBuffer.position(0); indexBuffer.position(0); gl.glBindTexture(GL11.GL_TEXTURE_2D, 0); gl.glColor4f(red[layer] * alpha[layer], green[layer] * alpha[layer], blue[layer] * alpha[layer], alpha[layer]); // Point to our vertex and texture buffers gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); // Draw the vertices as triangles gl.glDrawElements(GL10.GL_TRIANGLES, INDICES.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); } }
Example 7
Source File: Cube.java From opengl with Apache License 2.0 | 5 votes |
public void draw(GL10 gl) { gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer); gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan1); gl.glDrawElements( gl.GL_TRIANGLE_FAN, 6 * 3, gl.GL_UNSIGNED_BYTE, mTfan2); }
Example 8
Source File: Cube.java From opengl with Apache License 2.0 | 5 votes |
public void draw(GL10 gl) { gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer); gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan1); gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan2); }
Example 9
Source File: RotationVectorDemo.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void draw(GL10 gl) { gl.glEnable(GL10.GL_CULL_FACE); gl.glFrontFace(GL10.GL_CW); gl.glShadeModel(GL10.GL_SMOOTH); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); }
Example 10
Source File: GLWorld.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void draw(GL10 gl) { mColorBuffer.position(0); mVertexBuffer.position(0); mIndexBuffer.position(0); gl.glFrontFace(GL10.GL_CW); gl.glShadeModel(GL10.GL_FLAT); gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer); gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); count++; }
Example 11
Source File: TriangleRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void draw(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBuffer); gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, VERTS, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); }
Example 12
Source File: Square.java From opengl with Apache License 2.0 | 5 votes |
/** * This function draws our square on screen. * @param gl */ public void draw(GL10 gl) { //set a color other then white, which is blue/purple gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f); // 0x8080FFFF // Counter-clockwise winding. gl.glFrontFace(GL10.GL_CCW); // OpenGL docs // Enable face culling. gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs // What faces to remove with the face culling. gl.glCullFace(GL10.GL_BACK); // OpenGL docs // Enabled the vertices buffer for writing and to be used during // rendering. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);// OpenGL docs. // Specifies the location and data format of an array of vertex // coordinates to use when rendering. gl.glVertexPointer(3, GL10.GL_FLOAT, 0, // OpenGL docs vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,// OpenGL docs GL10.GL_UNSIGNED_SHORT, indexBuffer); // Disable the vertices buffer. gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); // OpenGL docs // Disable face culling. gl.glDisable(GL10.GL_CULL_FACE); // OpenGL docs }
Example 13
Source File: SpriteTextRenderer.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
public void draw(GL10 gl) { gl.glFrontFace(GL10.GL_CCW); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexBuffer); gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, VERTS, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); }
Example 14
Source File: Cube.java From opengl with Apache License 2.0 | 5 votes |
public void draw(GL10 gl) { gl.glVertexPointer(3, GL11.GL_FLOAT, 0, mFVertexBuffer); gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, mColorBuffer); gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan1); gl.glDrawElements( GL11.GL_TRIANGLE_FAN, 6 * 3, GL11.GL_UNSIGNED_BYTE, mTfan2); }
Example 15
Source File: DemoHeartRateSensorActivity.java From BLE-Heart-rate-variability-demo with MIT License | 5 votes |
protected void draw(GL10 gl) { long curtime = SystemClock.uptimeMillis(); this.prepareBuffers(sides, interval[1]); gl.glColor4f(96/255.0f, 246/255.0f, 255/255.0f, 1.0f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, this.numOfIndecies, GL10.GL_UNSIGNED_SHORT, mIndexBuffer); }
Example 16
Source File: Square.java From opengl with Apache License 2.0 | 5 votes |
/** * This function draws our square on screen. * @param gl */ public void draw(GL10 gl) { //set a color other then white, which is blue/purple gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f); // 0x8080FFFF // Counter-clockwise winding. gl.glFrontFace(GL10.GL_CCW); // OpenGL docs // Enable face culling. gl.glEnable(GL10.GL_CULL_FACE); // OpenGL docs // What faces to remove with the face culling. gl.glCullFace(GL10.GL_BACK); // OpenGL docs // Enabled the vertices buffer for writing and to be used during // rendering. gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);// OpenGL docs. // Specifies the location and data format of an array of vertex // coordinates to use when rendering. gl.glVertexPointer(3, GL10.GL_FLOAT, 0, // OpenGL docs vertexBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length,// OpenGL docs GL10.GL_UNSIGNED_SHORT, indexBuffer); // Disable the vertices buffer. gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); // OpenGL docs // Disable face culling. gl.glDisable(GL10.GL_CULL_FACE); // OpenGL docs }
Example 17
Source File: Cube.java From tilt-game-android with MIT License | 5 votes |
/** * Draws this cube of the given GL-Surface * * @param gl The GL-Surface this cube should be drawn upon. */ public void draw(GL10 gl) { gl.glEnable(GL10.GL_CULL_FACE); gl.glFrontFace(GL10.GL_CW); gl.glShadeModel(GL10.GL_SMOOTH); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer); gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); }
Example 18
Source File: CubeSmallGLUT.java From opengl with Apache License 2.0 | 4 votes |
void drawAgain(GL10 gl) { // used to draw again when the vertex and normal pointers haven't changed -- won't work otherwise // draw the elements -- assuming all of the above prep has taken place gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, mIndexBuffer); }
Example 19
Source File: QuadRenderSystem.java From BobEngine with GNU Lesser General Public License v2.1 | 4 votes |
/** * Render the quads in this system. * * @param gl OpenGL ES 1 object. * @param layer layer to render. */ public void render(GL10 gl, int layer) { boolean obFound = false; int gID; int numIndices = 0; // The number of indices for all objects if (graphic == null) { gID = 0; } else { gID = graphic.id; } for (int i = 0; i < numQuads; i++) { Transformation t = quads.get(i).getTransformation(); GraphicAreaTransformation g = quads.get(i).getGraphicAreaTransformation(); if (t.getLayer() == layer && onScreen(t, getRoom()) && Transform.getRealVisibility(t)) { if (!obFound) { vertexBuffer.clear(); textureBuffer.clear(); vertexBuffer.position(0); textureBuffer.position(0); indexBuffer[layer].position(0); obFound = true; } vertexBuffer.put(getVertices(t)); textureBuffer.put(getVertices(g)); numIndices += INDICES; } } if (obFound) { if (numIndices != lastIndex[layer]) { if (numIndices > indices.length) { indices = new short[numIndices + 1]; } for (int i = 0; i < numIndices; i += 6) { indices[i + 0] = (short) (((i / 6) * 4) + 0); indices[i + 1] = (short) (((i / 6) * 4) + 1); indices[i + 2] = (short) (((i / 6) * 4) + 2); indices[i + 3] = (short) (((i / 6) * 4) + 1); indices[i + 4] = (short) (((i / 6) * 4) + 2); indices[i + 5] = (short) (((i / 6) * 4) + 3); } indexBuffer[layer].clear(); indexBuffer[layer].put(indices); lastIndex[layer] = numIndices; } vertexBuffer.position(0); textureBuffer.position(0); indexBuffer[layer].position(0); // Add color gl.glColor4f(red[layer] * alpha[layer], green[layer] * alpha[layer], blue[layer] * alpha[layer], alpha[layer]); // Bind the texture gl.glBindTexture(GL11.GL_TEXTURE_2D, gID); // Point to our vertex and texture buffers gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); // Draw the vertices as triangles gl.glDrawElements(GL10.GL_TRIANGLES, numIndices, GL10.GL_UNSIGNED_SHORT, indexBuffer[layer]); } }
Example 20
Source File: Page.java From PlayLikeCurl with MIT License | 4 votes |
public void draw(GL10 gl,Context context) { if(needtextureupdate) { needtextureupdate=false; loadGLTexture(gl, context); } calculateVerticesCoords(); gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY); gl.glFrontFace(GL10.GL_CCW); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer); gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer); gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY); }