Java Code Examples for javax.microedition.khronos.opengles.GL10#glVertexPointer()

The following examples show how to use javax.microedition.khronos.opengles.GL10#glVertexPointer() . 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: GLVertexList.java    From homescreenarcade with GNU General Public License v3.0 6 votes vote down vote up
public void render(GL10 gl) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    if (colorIndex>4) {
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    }
    else {
        gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    }

    gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
    if (colorIndex>4) {
        gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
    }
    else if (colorIndex==4) {
        // single color
        gl.glColor4f(
                colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    }

    gl.glDrawArrays(glMode, 0, numVertices);
}
 
Example 2
Source File: GLDrawerES1.java    From Building-Android-UIs-with-Custom-Views with MIT License 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    gl.glClearColor(1.f, 0.f, 0.f, 1.f);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    gl.glLoadIdentity();
    gl.glTranslatef(0.f, 0.f, -50.f);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);
    gl.glRotatef(angle, 0.f, 0.f, 1.f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glColor4f(1.f, 1.f, 1.f, 1.f);
    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);
}
 
Example 3
Source File: CubeSmallGLUT.java    From opengl with Apache License 2.0 6 votes vote down vote up
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 4
Source File: Grid.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void draw(GL10 gl, boolean useTexture) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);

    if (useTexture) {
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexCoordBuffer);
        gl.glEnable(GL10.GL_TEXTURE_2D);
    } else {
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glDisable(GL10.GL_TEXTURE_2D);
    }

    gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount,
            GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
 
Example 5
Source File: GLBitmap.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public void draw(GL10 gl) {
    // bind the previously generated texture
    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_CW);

    // Point to our vertex buffer
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

    // Draw the vertices as triangle strip
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);

    // Disable the client state before leaving
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 6
Source File: Square.java    From opengl with Apache License 2.0 6 votes vote down vote up
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 7
Source File: CubeSmallGLUT.java    From opengl with Apache License 2.0 6 votes vote down vote up
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 8
Source File: Quad.java    From retrobreaker with MIT License 6 votes vote down vote up
public void draw(GL10 gl) {
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glPushMatrix();
	gl.glLoadIdentity();
	gl.glTranslatef(mPosX, mPosY, 0.0f);
	gl.glScalef(mScale, mScale, mScale);

	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

	gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mVertexBuffer);
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColorBuffer);

	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

	gl.glPopMatrix();
}
 
Example 9
Source File: HQFftVisualizerSurfaceView.java    From android-openslmediaplayer with Apache License 2.0 6 votes vote down vote up
private static void drawFFT(
        GL10 gl, int width, int height,
        FloatBuffer vertices, int n,
        int vposition, float yrange, FloatColor color) {

    gl.glPushMatrix();

    // viewport
    gl.glViewport(0, (height / 2) * (1 - vposition), width, (height / 2));

    // X: [0:1], Y: [0:1]
    gl.glOrthof(0.0f, 1.0f, 0.0f, yrange, -1.0f, 1.0f);

    gl.glColor4f(color.red, color.green, color.blue, color.alpha);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(2, GL10.GL_FLOAT, (2 * Float.SIZE / 8), vertices);
    gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, n);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glPopMatrix();
}
 
Example 10
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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 11
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
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 13
Source File: GLWorld.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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 14
Source File: Cube.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * 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 15
Source File: Cube.java    From opengl with Apache License 2.0 5 votes vote down vote up
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 16
Source File: TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
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 17
Source File: GLRender.java    From LiveBlurListView with Apache License 2.0 4 votes vote down vote up
private void process(Bitmap bitmap, boolean fast) {
	final GL10 gl = mGL;
	
	gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	gl.glShadeModel(GL10.GL_SMOOTH);
	gl.glEnable(GL10.GL_DEPTH_TEST);
	gl.glClearDepthf(1.0f);
	gl.glDepthFunc(GL10.GL_LEQUAL);
	gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
	gl.glEnable(GL10.GL_TEXTURE_2D);
	gl.glEnable(GL10.GL_LEQUAL);
	
	float[] color = new float[16];
	FloatBuffer colorBuffer;
	float[] texVertex = new float[12];
	FloatBuffer vertexBuffer;
	
	ByteBuffer texByteBuffer = ByteBuffer.allocateDirect(texVertex.length * 4);
	texByteBuffer.order(ByteOrder.nativeOrder());
	vertexBuffer = texByteBuffer.asFloatBuffer();
	vertexBuffer.put(texVertex);
	vertexBuffer.position(0);
	
	ByteBuffer colorByteBuffer = ByteBuffer.allocateDirect(color.length * 4);
	colorByteBuffer.order(ByteOrder.nativeOrder());
	colorBuffer = colorByteBuffer.asFloatBuffer();
	colorBuffer.put(color);
	colorBuffer.position(0);
	
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	gl.glPushMatrix();
	gl.glTranslatef(0.0f, 0.0f, 0.0f);
	

	
	colorBuffer.clear();
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	colorBuffer.put(1.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(0.0f);
	colorBuffer.put(1.0f);
	
	vertexBuffer.clear();
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	vertexBuffer.put(0);
	vertexBuffer.put(5f);
	vertexBuffer.put(0);
	
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
	

	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
	
	gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4);
	gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
	
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glPopMatrix();
}
 
Example 18
Source File: Page.java    From PlayLikeCurl with MIT License 4 votes vote down vote up
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);
	}
 
Example 19
Source File: QuadRenderSystem.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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: Planet.java    From opengl with Apache License 2.0 3 votes vote down vote up
public void draw(GL10 gl) 
{
 	
	gl.glFrontFace(GL10.GL_CW);					
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, m_VertexData);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	
	gl.glColorPointer(4, GL10.GL_FLOAT, 0, m_ColorData);		

    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, (m_Slices+1)*2*(m_Stacks-1)+2);
}