Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid OPENGL2 not drawing texture to quad
    text
    copied!<p>I'm trying to get some textures rendered on quads, but the screen turns out empty. (Open GL 2.0) I formerly used a static color shader on the quads, and the quads did appear on screen, so the positioning is fine.</p> <p>UPDATE: Now I can see black textures only...</p> <p>Here is my code:</p> <p>Vertex Shader:</p> <pre><code>uniform mat4 uTMatrix; uniform mat4 uMVPMatrix; attribute vec4 vPosition; attribute vec4 vTex; attribute vec4 inputTextureCoordinate; varying vec2 TexCoord0; void main(){ TexCoord0 = inputTextureCoordinate.xy; gl_Position = uMVPMatrix * uTMatrix * vPosition; } </code></pre> <p>Frag Shader:</p> <pre><code>varying highp vec2 TexCoord0; uniform sampler2D colorMap; void main(){ gl_FragColor = texture2D(colorMap, TexCoord0); } </code></pre> <p>onDrawFrame():</p> <pre><code> Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glUseProgram(mProgram); final float halfw = mWidth / 2f; final int rowHeight = mRowHeight; final float r = (float) rowHeight / halfw; int i = mFirstRow; final float initial = (float) ((i * rowHeight) - mScroll) / halfw; Matrix.setIdentityM(mTMatrix, 0); Matrix.translateM(mTMatrix, 0, 0, -initial, 0); GLES20.glFrontFace(GLES20.GL_CW); GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 0, mVertBuffer); GLES20.glEnableVertexAttribArray(maPositionHandle); GLES20.glVertexAttribPointer(maTexHandle, 3, GLES20.GL_FLOAT, false, 0, mTexBuffer); GLES20.glEnableVertexAttribArray(maTexHandle); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glEnable(GLES20.GL_TEXTURE_2D); final int l = mLastRow; for (; i &lt;= l; i++) { if (\*A check to see if the bitmap is cached*\) { GLES20.glUniform1i(muTextureHandle, i); GLES20.glUniformMatrix4fv(muTMatrixHandle, 1, false, mTMatrix, 0); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); } Matrix.translateM(mTMatrix, 0, 0, -r, 0); } GLES20.glDisableVertexAttribArray(maPositionHandle); GLES20.glDisableVertexAttribArray(maTexHandle); </code></pre> <p>loadTexture:</p> <pre><code> public void loadTexture(GL10 gl, Context c) { int[] texture = new int[1]; texture[0] = mRow; GLES20.glDeleteTextures(1, texture, 0); texture[0] = mRow; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture[0]); // Create Nearest Filtered Texture 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_LINEAR); // Different possible texture parameters, e.g. // GLES20.GL_CLAMP_TO_EDGE GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); Bitmap bitmap = mBitmap; if (bitmap == null) { bitmap = mEmptyBitmap; } GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); } </code></pre>
 

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