Code example for GL10

Methods: glClear, glLoadIdentity, glMatrixMode, glPopMatrix, glPushMatrix, glRotatef, glTexEnvx, glTranslatef

0
        /* Do not create GLViews twice */ 
        mGLViewsCreated = true;
    } 
 
    private void drawTouchSurface(GL10 gl) {
	gl.glPushMatrix();
	gl.glTranslatef(
		convertToLevel(LEVEL_TOUCH, PROJ_LEFT)
		, convertToLevel(LEVEL_TOUCH, PROJ_BOTTOM )
		, 0f);// move to Left-Top 
	gl.glTranslatef(0f, 0f, LEVEL_0);   // after rotating, the Z-axis upside down
 
	mTouchSurface.draw(gl);
	gl.glPopMatrix();
    } 
 
    public void drawGLViews(GL10 gl) {
	GLObject obj;
 
	gl.glMatrixMode(gl.GL_MODELVIEW);
 
	gl.glLoadIdentity();
 
	/* the coordinate of OpenGL is different from normal computer system 
	 * We may rotate the coordinate so we don't have to worry about that. 
	 */ 
	gl.glRotatef(180f, 1f, 0f, 0f); // now the +x is heading for right
					//         +y is heading for bottom 
 
        mWorldLayer.onDraw(gl);
 
	/* Draw Level 1, the Bar and Pets */ 
        mBarLayer.onDraw(gl);
 
        mEditLayer.onDraw(gl);
	/* Draw the TouchSurface */ 
	drawTouchSurface(gl);
    } 
 
    class WallRenderer implements GLSurfaceView.Renderer {
 
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
 
	    mTextureManager.setGLContext(gl);
 
	    String version = gl.glGetString(gl.GL_VERSION);
	    String test = gl.glGetString(gl.GL_EXTENSIONS);
	    String result[] = test.split(" ");
	    Log.i(TAG, "Version: " + version);
	    for (int i = 0; i < result.length; i++) {
		Log.i(TAG, "Extension: " + result[i]);
	    } 
 
	    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
		    GL10.GL_FASTEST);
	    gl.glClearColor(.5f, .1f, .1f, 1);
	    gl.glShadeModel(GL10.GL_SMOOTH);
	    gl.glEnable(GL10.GL_DEPTH_TEST);
	    gl.glEnable(GL10.GL_TEXTURE_2D);
 
	    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
 
	    gl.glEnable(gl.GL_BLEND);
	    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);
	} 
 
	public void onSurfaceChanged(GL10 gl, int w, int h) {
	    mScreenWidth  = w;
	    mScreenHeight = h;
 
            Layer.sRatioH = PROJ_WIDTH / mScreenWidth;
            Layer.sRatioV = PROJ_HEIGHT / mScreenHeight;
 
            if (mEditSurface != null) {
                mEditSurface.resize(mScreenWidth, mScreenHeight);
                mEditLayer.measure();
            } 
 
	    GestureManager.getInstance().updateScreenSize(mScreenWidth, mScreenHeight);
 
	    gl.glLoadIdentity();
	    gl.glViewport(0, 0, w, h);
 
	    gl.glMatrixMode(gl.GL_PROJECTION);
	    gl.glLoadIdentity();
	    if (USE_ORTHO) {
		gl.glOrthof(PROJ_LEFT, PROJ_RIGHT
			, PROJ_BOTTOM, PROJ_TOP
			, PROJ_NEAR, PROJ_FAR);
	    } else { 
		gl.glFrustumf(PROJ_LEFT, PROJ_RIGHT
			, PROJ_BOTTOM, PROJ_TOP
			, PROJ_NEAR, PROJ_FAR);
	    } 
 
	    if (!mGLViewsCreated) {
		initGLViews(); 
	    } 
	} 
 
	public void onDrawFrame(GL10 gl) {
	    gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
		    GL10.GL_MODULATE);
	    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
 
	    if (mTextureManager.hasPendingTextures()) {
		mTextureManager.updateTexture();
	    }