I am working on an application using OpenGL ES 2.0 for an embedded device.
This is my fragment shader:
varying vec2 v_texCoord;
uniform sampler2D s_texture;
void main() {
gl_FragColor = texture2D(s_texture, v_texCoord);
}
I set the textures correctly. For some reason, the call glTexImage2Ddoes not lead to the result I'm looking for. The texture is completely black, and not filled with the data that I provide it.
This is how I create the texture:
GLuint textureId;
GLubyte pixels[6 * 3] =
{
255, 0, 0,
0, 255, 0,
0, 0, 255,
255, 255, 0,
0, 255, 255,
255, 0, 255
};
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
glGenTextures ( 1, &textureId );
glBindTexture ( GL_TEXTURE_2D, textureId );
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, 3, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
Then I snap the texture like this:
samplerLoc = glGetUniformLocation ( userData->programObject, "s_texture" );
glActiveTexture ( GL_TEXTURE0 );
glBindTexture ( GL_TEXTURE_2D, textureId );
glUniform1i ( samplerLoc, 0 );
I confirmed that the vertex coordinates and textures are connected and passed to the shaders when debugging. So this should be a problem with the function s_textureor glTexImage2D.