I'll keep it simple: The code listed at the end of this post is in top-to-bottom order within my project. I have an OGLES2.0 framework in place which renders everything except textures perfectly. When rendering a single texture all I see is a black box of the correct dimensions.
Here's what I've verified:
Having output the texture bytes (it's format
GL_ALPHA) it's plain to see there are zero and none-zero values, so the data looks correct (or at least not all black!).The texture ids are correct, verified by using the following in the vertex shader:
gl_FragColor=vec4(v_texCoord.xy,0.0,1.0);..and observing the expectedblack->green->yellow->redcolour flow moving from(0,0)->(0,1)->(1,1)->(1,0)is seen.My texture has power of two dimensions:
256 x 64, correctly reflected in the data array.
I'd be tremendously grateful for help in determining what's wrong, as after several hours of googling and prodding I'm stumped!
glGenTextures(1, &_textureId); GLint savedId; glGetIntegerv(GL_TEXTURE_BINDING_2D, &savedId); glBindTexture(GL_TEXTURE_2D, _textureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); GLenum datatype = -1; GLenum format = -1; switch([self pixelFormat]) { case kGLTexturePixelFormat_RGBA8888: format=GL_RGBA; datatype=GL_UNSIGNED_BYTE; break; case kGLTexturePixelFormat_RGB565: format=GL_RGB; datatype=GL_UNSIGNED_SHORT_5_6_5; break; case kGLTexturePixelFormat_A8: // * This is current format, used for testing. format=GL_ALPHA; datatype=GL_UNSIGNED_BYTE; break; default: [NSException raise:NSInternalInconsistencyException format:@""]; } glTexImage2D(GL_TEXTURE_2D, 0, format, [self pixelsWide], [self pixelsHigh], 0, format, datatype, [self data]); glBindTexture(GL_TEXTURE_2D, savedId); //... GLint s_textureId = glGetUniformLocation(program, "s_texture"); //... glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, [_textureAtlas textureId]); glUniform1i(s_textureId, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // In vertex shader: attribute vec2 a_texCoord; varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { // ... v_texCoord = a_texCoord; } // In fragment shader: varying vec2 v_texCoord; uniform sampler2D s_texture; void main() { // ... gl_FragColor = texture2D(s_texture, v_texCoord); }