2011-04-13 50 views
0

即時通訊嘗試繪製3d對象,然後在屏幕上繪製2D紋理。紋理在onSurfaceCreated(GL10 GL)使用此功能創建:android texture2D導致3d顏色丟失

public static int loadText(GL10 gl, float width, float height, String text) { 
     gl.glGenTextures(1, mTextureNameWorkspace, 0); 
     textureName = mTextureNameWorkspace[0]; 
     gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); 
     gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); 
     gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE); 
     bitmap = Bitmap.createBitmap((int) width, (int) height, Bitmap.Config.ARGB_4444); 
     canvas = new Canvas(bitmap); 
     canvas.drawText(text, width/2, 50, paint); 
     GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 
     mCropWorkspace[0] = 0; 
     mCropWorkspace[1] = bitmap.getHeight(); 
     mCropWorkspace[2] = bitmap.getWidth(); 
     mCropWorkspace[3] = -bitmap.getHeight(); 
     bitmap.recycle(); 
     ((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, mCropWorkspace, 0); 
     return textureName; 
    } 

的問題是,如果我畫幀,而無需調用此3D對象是橙色的,但顯然是2D紋理心不是繪製。但是如果我在調用該框架之後繪製框架,那麼3d對象將變爲黑色。代碼im用於繪圖:

 gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
     gl.glDisable(GL10.GL_BLEND); 
     gl.glShadeModel(GL10.GL_SMOOTH); 
     gl.glMatrixMode(GL10.GL_PROJECTION); 
     gl.glLoadIdentity(); 
     gl.glEnable(GL10.GL_DEPTH_TEST); 
     gl.glLoadIdentity(); 
     GLU.gluPerspective(gl, 45.0f, (float) width/(float) height, 0.1f, 500.0f); 
     gl.glMatrixMode(GL10.GL_MODELVIEW); 
     gl.glLoadIdentity(); 
     gl.glTranslatef(4, 2, -10); 
     gl.glRotatef(45, 0, 1, 0); 
     car.draw(gl); 

回答

3

您沒有在任何地方啓用紋理單元。在做任何其他與紋理相關的調用之前,先放置glEnable(GL_TEXTURE_2D)

+0

我把gl.glDisable(GL10.GL_TEXTURE_2D);在onDrawFrame(GL10 gl)開始時,它完美地工作,謝謝 – ng93 2011-04-13 11:05:25