Code example for GL10

Methods: glActiveTexture, glBindTexture, glClear, glDrawElements, glEnable, glEnableClientState, glFrontFace, glLoadIdentity, glMatrixMode, glRotatef

0
            mTexBuffer.position(0);
            mIndexBuffer.position(0);
        } 
 
        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, 24, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
        } 
    } 
 
    /** 
     * A representation of the Z-axis in vector form. 
     */ 
    protected static final float[] Z_AXIS = new float[] {
            0, 0, 1 
    }; 
 
    /** 
     * Computes the cross product of two vectors, storing the resulting 
     * pseudovector in out. All arrays must be length 3 or more, and out is 
     * overwritten. 
     *  
     * @param left the left operand of the cross product 
     * @param right the right operand of the cross product 
     * @param out the array into which to store the cross-product pseudovector's 
     *            data 
     */ 
    public static void crossProduct(float[] left, float[] right, float[] out) {
        out[0] = left[1] * right[2] - left[2] * right[1];
        out[1] = left[2] * right[0] - left[0] * right[2];
        out[2] = left[0] * right[1] - left[1] * right[0];
    } 
 
    /** 
     * Computes the dot product of two vectors. 
     *  
     * @param left the first dot product operand 
     * @param right the second dot product operand 
     * @return the dot product of left and right 
     */ 
    public static float dotProduct(float[] left, float[] right) {
        return left[0] * right[0] + left[1] * right[1] + left[2] * right[2];
    } 
 
    /** 
     * Normalizes the input vector into a unit vector. 
     *  
     * @param vector the vector to normalize. Contents are overwritten. 
     */ 
    public static void normalize(float[] vector) {
        double mag = Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2]
                * vector[2]);
        vector[0] /= mag;
        vector[1] /= mag;
        vector[2] /= mag;
    } 
 
    /** 
     * The angle around mCrossProd to rotate to align Z-axis with gravity. 
     */ 
    protected float mAngle;
 
    private Context mContext;
 
    /** 
     * The (pseudo)vector around which to rotate to align Z-axis with gravity. 
     */ 
    protected float[] mCrossProd = new float[3];
 
    private int mTextureID;
 
    private Wedge mWedge;
 
    /** 
     * It's a constructor. Can you dig it? 
     *  
     * @param context the Android Context that owns this renderer 
     */ 
    public AccelerometerTestRenderer(Context context) {
        mContext = context;
        mWedge = new Wedge();
    } 
 
    public void onAccuracyChanged(Sensor arg0, int arg1) {
        // no-op 
    } 
 
    /** 
     * Actually draws the wedge. 
     */ 
    public void onDrawFrame(GL10 gl) {
        // set up the texture for drawing 
        gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
        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);
 
        // clear the screen and draw 
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glRotatef(-mAngle * 180 / (float) Math.PI, mCrossProd[0], mCrossProd[1], mCrossProd[2]);
        mWedge.draw(gl);
    } 
 
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {