I am trying to make a simple textured square in OpenGL ES 2.0 on an iPhone. The geometry is beautiful and I get the expected square if I use solid color in my shader:
gl_FragColor = vec4 (1.0, 0.0, 0.0, 1.0);
And I get the expected gradients if I directly render the texture coordinates:
gl_FragColor = vec4 (texCoord.x, texCoord.y, 0.0, 1.0);
Image data is loaded from UIImage, scaled to 1024x1024 and loaded into the texture as follows:
glGenTextures (1, & _texture);
glBindTexture (GL_TEXTURE_2D, _texture);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
GL_UNSIGNED_BYTE, data);
width , height , and the contents of data all correct, as described in the debugger.
When I change my fragment shader to use a texture:
gl_FragColor = texture2D (tex, texCoord);
... and bind the texture and do this:
glActiveTexture (GL_TEXTURE0);
glBindTexture (GL_TEXTURE_2D, _texture);
// this is unnecessary, as it defaults to 0, but for completeness ...
GLuint texLoc = glGetUniformLocation (_program, "tex");
glUniform1i (texLoc, 0);
glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
... I get nothing. Black square. glGetError() does not return an error, and glIsTexture(_texture) returns true.
What am I doing wrong here? I was aware of all the examples that I could find on the Internet, but everyone does it exactly the same as I do, and the debugger shows my parameters for various GL functions - this is what I expect from them.