2011-10-27 54 views
2

我一直在玩OpenGL ES Android,不知何故,我的紋理總是充滿最左上角像素的顏色。我想這些標誌是錯誤的,但我嘗試了很多邏輯組合,它似乎沒有任何區別。Android上的OpenGL - 紋理映射 - 只有左上角的像素可見

issue example

爲什麼質感表現得像這樣嗎?我錯過了什麼(標誌位)?由於

public void loadGLTexture(GL10 gl, Context context) { 
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId); 

    gl.glGenTextures(1, textures, 0); 
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); 

    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); 

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 

    bitmap.recycle(); 
} 

public void draw(GL10 gl) { 
    // bind the previously generated texture 
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); 

    ((GL11Ext) gl).glDrawTexfOES(position.getX(), position.getY(), 0, width, height); 
} 

表面設置爲

gl.glEnable(GL10.GL_TEXTURE_2D); 
gl.glShadeModel(GL10.GL_SMOOTH); 
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); 
gl.glClearDepthf(1.0f); 
gl.glEnable(GL10.GL_DEPTH_TEST); 
gl.glDepthFunc(GL10.GL_LEQUAL); 
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 

回答

0

顯然質地裁剪矩形已被明確設置:

int cropWorkspace[] = new int[4]; 
final BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inPreferredConfig = Bitmap.Config.RGB_565; 
cropWorkspace[0] = 0; 
cropWorkspace[1] = height; 
cropWorkspace[2] = width; 
cropWorkspace[3] = -height; 

((GL11) gl).glTexParameteriv(GL10.GL_TEXTURE_2D, GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropWorkspace, 0);