問題が発生しました。
クラス DrawableTexturedPlane があります。このクラスは、Texture としてバイト配列を持つ単純な Plane を指定します。配列データは、単純な関数呼び出しで変更できます。クラスは特定のシェーダー プログラムをパラメーターとして受け取ります。私の OpenGL ビューでは、これらのプレーンが 2 つ必要です。1 つ目は正しくレンダリングされますが、2 つ目はまったく表示されません。何かが足りないと確信していますが、コードのどの部分が間違っているのかわかりません。助けていただければ幸いです;)
TexturedPlaneClass (関連部分):
public DrawableTexturedPlane( float[] fVertices, int nProgrammHandle, int nGLTextureChannel, int nGLTextureID )
{
super( nProgrammHandle );
m_bHasBorder = bHasBorder;
m_nGLTextureChannel = nGLTextureChannel;
m_oVertexBuffer = _GetVertexBuffer( fVertices );
m_oTextureBuffer = _GetTextureCoordinates();
GLES20.glActiveTexture( m_nGLTextureChannel );
// Set filtering
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST );
GLES20.glTexParameterf( GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST );
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 );
m_cTexture = new byte[ 640 * 480 ];
Log.i( "Java/DrawableTexturedPlane", "Drawable Textured Plane created!" );
}
描画方法:
@Override
public void Draw( float[] mvpMatrix )
{
GLES20.glActiveTexture( m_nGLTextureChannel );
GLES20.glEnable(GLES20.GL_TEXTURE_2D);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
GLES20.glUseProgram( m_nProgramHandle );
m_HTextureUniform = GLES20.glGetUniformLocation( m_nProgramHandle, "uTexture" );
m_HTextureCoordinate = GLES20.glGetAttribLocation( m_nProgramHandle, "TexCoordinate" );
// get handle to the vertex shader's vPosition member
m_nPositionHandle = GLES20.glGetAttribLocation( m_nProgramHandle, "vPosition" );
ByteBuffer oDataBuf = ByteBuffer.wrap( m_cTexture );
// Prepare the triangle data
GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE, 640, 480,
0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, oDataBuf );
// Prepare the triangle data
GLES20.glVertexAttribPointer( m_nPositionHandle, 3, GLES20.GL_FLOAT, false, 12, m_oVertexBuffer );
GLES20.glEnableVertexAttribArray( m_nPositionHandle );
GLES20.glVertexAttribPointer( m_HTextureCoordinate, 2, GLES20.GL_FLOAT, false, 12, m_oTextureBuffer);
GLES20.glEnableVertexAttribArray( m_HTextureCoordinate );
m_nMVPMatrixHandle = GLES20.glGetUniformLocation( m_nProgramHandle, "uMVPMatrix");
// Apply the projection and view transformation
GLES20.glUniformMatrix4fv( m_nMVPMatrixHandle, 1, false, mvpMatrix, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6);
}
テクスチャと 2 つのプレーンを作成する方法は次のとおりです。
GLES20.glGenTextures( m_nTextureStorage.length, m_nTextureStorage, 0);
for( int i : m_nTextureStorage )
{
GLES20.glBindTexture( GLES20.GL_TEXTURE_2D, i );
}
m_oInfoPlane = new DrawableTexturedPlane( oInfoRect.GetAsFloatArray(), true, m_nShaderPrograms[0], GLES20.GL_TEXTURE0, m_nTextureStorage[0] );
m_oMainPlane = new DrawableTexturedPlane( oMainRect.GetAsFloatArray(), true, m_nShaderPrograms[0], GLES20.GL_TEXTURE1, m_nTextureStorage[1] );
ポイントは、GL_TEXTURE0 で両方を初期化すると、正常に動作することです。(10 ~ 20 秒後に激しいちらつきが発生しますが、その理由はわかりません)。
上記の方法でそれらを初期化すると、TEXTURE_0 を持つものだけが正しく表示され、他のものは黒く見えます。
TextureManager クラスを作成する必要があることはわかっていますが、2 つのテクスチャの場合、これは単純なやり過ぎです。
前もって感謝します