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

The following examples show how to use javax.microedition.khronos.opengles.GL10#glEnableClientState() . 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: 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 3
Source File: BobRenderer.java    From BobEngine with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the surface. <br />
 * <br />
 * This method will load the textures, enable effects we need, disable
 * effects we don't need, set up the client state for drawing the quads.
 */
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
	myOwner.getGraphicsHelper().handleGraphics((GL11) gl);             // Load textures for the view

	low = high = -1;

	gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);          // How to interpret transparency
	gl.glAlphaFunc(GL10.GL_GREATER, 0);
	gl.glEnable(GL10.GL_BLEND);                                        // Enable transparency
	gl.glEnable(GL10.GL_TEXTURE_2D);                                   // Enable Texture Mapping

	// Disable all the things we don't need.
	gl.glDisable(GL10.GL_DEPTH_TEST);
	gl.glDisable(GL10.GL_FOG);
	gl.glDisable(GL10.GL_LIGHTING);
	gl.glDisable(GL10.GL_STENCIL_TEST);
	gl.glDisable(GL10.GL_SCISSOR_TEST);
	gl.glDisable(GL10.GL_DITHER);
	gl.glDisable(GL10.GL_CULL_FACE);

	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);                      // We will use vertex arrays for quad vertices
	gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);               // We will need to use portions of textures
}
 
Example 4
Source File: BouncyCubeRenderer.java    From opengl with Apache License 2.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) 
{
	gl.glClearColor(0.0f,0.5f,0.5f,1.0f);
    gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL11.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -7.0f);

    gl.glRotatef(mAngle, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(mAngle, 1.0f, 0.0f, 0.0f);

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

    mCube.draw(gl);

    mTransY += .075f;
    mAngle+=.4;
}
 
Example 5
Source File: RotationVectorDemo.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    // clear screen
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    // set-up modelview matrix
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glMultMatrixf(mRotationMatrix, 0);

    // draw our object
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

    mCube.draw(gl);
}
 
Example 6
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 7
Source File: CubeRenderer.java    From tilt-game-android with MIT License 5 votes vote down vote up
/**
 * Draws a translated cube
 * 
 * @param gl the surface
 * @param translateX x-translation
 * @param translateY y-translation
 * @param translateZ z-translation
 */
private void drawTranslatedCube(GL10 gl, float translateX, float translateY, float translateZ) {
    gl.glPushMatrix();
    gl.glTranslatef(translateX, translateY, translateZ);

    // draw our object
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

    mCube.draw(gl);
    gl.glPopMatrix();
}
 
Example 8
Source File: TexCubeSmallGLUT.java    From opengl with Apache License 2.0 5 votes vote down vote up
void draw(GL10 gl) {
if (texEnabled) {
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mCoordBuffer);
}

super.draw(gl);

if (texEnabled) {
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_TEXTURE_2D);
}
   }
 
Example 9
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 10
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    // configure model space
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 10f, 0, 0, 0, 0, 1, 0f);
    gl.glColor4f(1f, 0f, 0f, 1f);
}
 
Example 11
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOnscreen(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);

    gl.glClearColor(0,0,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTargetTexture);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

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

    gl.glActiveTexture(GL10.GL_TEXTURE0);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    gl.glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);

    // Restore default state so the other renderer is not affected.

    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 12
Source File: AndroidOpenGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    // configure model space
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    GLU.gluLookAt(gl, 0, 0, 10f, 0, 0, 0, 0, 1, 0f);
    gl.glColor4f(1f, 0f, 0f, 1f);
}
 
Example 13
Source File: DemoHeartRateSensorActivity.java    From BLE-Heart-rate-variability-demo with MIT License 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {
	gl.glDisable(GL10.GL_DITHER);
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
	gl.glMatrixMode(GL10.GL_MODELVIEW);
	gl.glLoadIdentity();
	GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	draw(gl);
}
 
Example 14
Source File: SquareRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onDrawFrame(GL10 gl) {//4
	gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);//5
	gl.glMatrixMode(GL10.GL_MODELVIEW); //6
	gl.glLoadIdentity(); //7
	gl.glTranslatef(0.0f,(float)Math.sin(mTransY), -3.0f); //8
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //9
	gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
	mSquare.draw(gl); //10
	mTransY += .075f;
}
 
Example 15
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOffscreenImage(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glEnable(GL10.GL_DEPTH_TEST);

    gl.glClearColor(0,0.5f,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glTranslatef(0, 0, -3.0f);
    gl.glRotatef(mAngle,        0, 1, 0);
    gl.glRotatef(mAngle*0.25f,  1, 0, 0);

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

    mCube.draw(gl);

    gl.glRotatef(mAngle*2.0f, 0, 1, 1);
    gl.glTranslatef(0.5f, 0.5f, 0.5f);

    mCube.draw(gl);

    mAngle += 1.2f;

    // Restore default state so the other renderer is not affected.

    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
 
Example 16
Source File: VortexRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    // preparation
    Log.i(LOG_TAG, "onSurfaceCreated()");
    gl.glMatrixMode(GL10.GL_PROJECTION);
    float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2); 
    float ratio = _width / _height;
    // perspective:
    gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
    // orthographic:
    //gl.glOrthof(-1, 1, -1 / ratio, 1 / ratio, 0.01f, 100.0f);
    gl.glViewport(0, 0, (int) _width, (int) _height);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    
// define the color we want to be displayed as the "clipping wall"
gl.glClearColor(0f, 0f, 0f, 1.0f);

// enable the differentiation of which side may be visible 
gl.glEnable(GL10.GL_CULL_FACE);
// which is the front? the one which is drawn counter clockwise
gl.glFrontFace(GL10.GL_CCW);
// which one should NOT be drawn
gl.glCullFace(GL10.GL_BACK);

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

initTriangle();
}
 
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: PLCubicPanorama.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    gl.glEnable(GL10.GL_TEXTURE_2D);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glCullFace(GL10.GL_FRONT);
    gl.glShadeModel(GL10.GL_SMOOTH);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sCubeBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, sTextureCoordsBuffer);

    // Front Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeFrontFaceIndex)) {
        gl.glNormal3f(0.0f, 0.0f, 1.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
    }

    // Back Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeBackFaceIndex)) {
        gl.glNormal3f(0.0f, 0.0f, -1.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
    }

    // Left Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeLeftFaceIndex)) {
        gl.glNormal3f(1.0f, 0.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
    }

    // Right Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeRightFaceIndex)) {
        gl.glNormal3f(-1.0f, 0.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);
    }

    // Up Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeUpFaceIndex)) {
        gl.glNormal3f(0.0f, 1.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
    }

    // Down Face
    if (this.bindTextureByIndex(gl, PLConstants.kCubeDownFaceIndex)) {
        gl.glNormal3f(0.0f, -1.0f, 0.0f);
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
    }

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_CULL_FACE);
    gl.glDisable(GL10.GL_TEXTURE_2D);
}
 
Example 19
Source File: PLCubicPanorama.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
/**render methods*/

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer)
{
	gl.glEnable(GL10.GL_TEXTURE_2D);
	
	gl.glEnable(GL10.GL_CULL_FACE);
	gl.glCullFace(GL10.GL_FRONT);
	gl.glShadeModel(GL10.GL_SMOOTH);
	
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, sCubeBuffer);
	gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, sTextureCoordsBuffer);
	
	// Front Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeFrontFaceIndex))
	{
		gl.glNormal3f(0.0f, 0.0f, 1.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	}
	
	// Back Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeBackFaceIndex))
	{
		gl.glNormal3f(0.0f, 0.0f, -1.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
	}
	
	// Left Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeLeftFaceIndex))
	{
		gl.glNormal3f(1.0f, 0.0f, 0.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 8, 4);
	}
	
	// Right Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeRightFaceIndex))
	{
		gl.glNormal3f(-1.0f, 0.0f, 0.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 12, 4);
	}
	
	// Up Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeUpFaceIndex))
	{
		gl.glNormal3f(0.0f, 1.0f, 0.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 16, 4);
	}
	
	// Down Face
	if(this.bindTextureByIndex(gl, PLConstants.kCubeDownFaceIndex))
	{
		gl.glNormal3f(0.0f, -1.0f, 0.0f);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 20, 4);
	}
	
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);	
	gl.glDisable(GL10.GL_CULL_FACE);
	gl.glDisable(GL10.GL_TEXTURE_2D);
}
 
Example 20
Source File: MatrixPaletteRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    gl.glEnable(GL10.GL_DEPTH_TEST);

    gl.glEnable(GL10.GL_CULL_FACE);

    /*
     * Now we're ready to draw some 3D objects
     */

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

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

    gl.glActiveTexture(GL10.GL_TEXTURE0);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_REPEAT);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT);

    long time = SystemClock.uptimeMillis() % 4000L;

    // Rock back and forth
    double animationUnit = ((double) time) / 4000;
    float unitAngle = (float) Math.cos(animationUnit * 2 * Math.PI);
    float angle = unitAngle * 135f;

    gl.glEnable(GL11Ext.GL_MATRIX_PALETTE_OES);
    gl.glMatrixMode(GL11Ext.GL_MATRIX_PALETTE_OES);

    GL11Ext gl11Ext = (GL11Ext) gl;

    // matrix 0: no transformation
    gl11Ext.glCurrentPaletteMatrixOES(0);
    gl11Ext.glLoadPaletteFromModelViewMatrixOES();


    // matrix 1: rotate by "angle"
    gl.glRotatef(angle, 0, 0, 1.0f);

    gl11Ext.glCurrentPaletteMatrixOES(1);
    gl11Ext.glLoadPaletteFromModelViewMatrixOES();

    mGrid.draw(gl);

    gl.glDisable(GL11Ext.GL_MATRIX_PALETTE_OES);
}