Note that there are some explanatory texts on larger screens.

plurals
  1. POworking with multiple Textures in OpenGL ES 2.0
    primarykey
    data
    text
    <p>I ran into a problem latley.</p> <p>I have a class DrawableTexturedPlane. This class specifies a simple Plane with a byte array as Texture. The array data can be changed by a simple function call. Well, the class takes a specific shader program as parameter. In my OpenGL View, i need 2 of those planes. Well, the first renders correctly, but the second does not show up at all. Im quite sure im missing something, but i am not sure which part of my code is incorrect. I would appreciate any help ;)</p> <p>TexturedPlaneClass (relevant parts):</p> <pre><code>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!" ); } </code></pre> <p>the Draw Method:</p> <pre><code> @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); } </code></pre> <p>Here is how the textures and the 2 planes are created:</p> <pre><code> 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] ); </code></pre> <p>Well the point is, if i initialize BOTH wirh GL_TEXTURE0, it works fine. (Although heavy flickering occurs after 10 - 20 seconds, i dont know why ).</p> <p>If i initialize them the way i did it above, only the one with TEXTURE_0 is shown correctly, the other one apperas to be black. </p> <p>I know i should write a TextureManager class, but for 2 Textures, this is a simple overkill.</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload