OpenGLは2.0マルチテクスチャの問題をES

Lesti001:

私はシェーダに2つのテクスチャをロードする必要がありますが、アプリケーションの起動時に、最初のテクスチャが正しく表示され、第二は、ちょうど黒の正方形であります

テクスチャをロードします

GLES20.glGenTextures(1, textures, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);

GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);

アクティベーションテクスチャ

GLES20.glEnableVertexAttribArray(ShaderProgram.posHandle);
GLES20.glEnableVertexAttribArray(ShaderProgram.texcordHandle);

GLES20.glVertexAttribPointer(ShaderProgram.posHandle,3, GLES20.GL_FLOAT, false, 0, vbuffer);
GLES20.glVertexAttribPointer(ShaderProgram.texcordHandle,2, GLES20.GL_FLOAT, false, 0, tbuffer);

GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture.getTexid());
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glUniform1i(ShaderProgram.texHandle, texture.getTexid());

GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, blend.getTexid());
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
GLES20.glUniform1i(ShaderProgram.tex01Handle, blend.getTexid());

GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_BYTE, ibuffer);

フラグメントシェーダ

precision mediump float;
uniform sampler2D tex;
uniform sampler2D tx;
uniform vec4 u_color;
uniform float alpha;
varying vec2 v_tex;
void main(){
    vec4 t = texture2D(tex, v_tex);
    vec4 te = texture2D(tx, v_tex);
    gl_FragColor = te;
}

まずsampler2Dテックス

第二sampler2D TX

Rabbid76:

glBindTexture現在のテクスチャユニットで指定されたターゲットにテクスチャをバインドします。現在のテクスチャユニットは、グローバル状態とすることによって選択されますglActiveTexture
あなたはテクスチャをバインドする前にテクスチャを選択する必要があります。テクスチャユニットを変更すると、現在バインドされているテクスチャに影響を与えません。

# bind "texture" to texture unit 0
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture.getTexid());

# bind "blend" to texture unit 1
GLES20.glActiveTexture(GLES20.GL_TEXTURE1);    
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, blend.getTexid());

Furthermore, the binding point between the texture object and the texture sampler uniform is the texture unit. Thus the texture object has to be bound to the texture unit and the number of the texture unit has to be assigned to the texture sampler uniform (0 for GL_TEXTURE0, 1 for GL_TEXTURE1). e.g:

GLES20.glUniform1i(ShaderProgram.texHandle, 0);   // 0 means GL_TEXTURE0
GLES20.glUniform1i(ShaderProgram.tex01Handle, 1); // 1 means GL_TEXTURE1 

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=374908&siteId=1