Here's the simplest version I could make that actually worked:
Setup (immediately after you've done the glVertexAttribPointer for your vertex arrays)
GLint program; // your shader-program, pre-filled
...
// AFTER you've created *and set* the EAGLContext
GLKTextureInfo* appleTexture = [GLKTextureLoader
textureWithContentsOfFile:... options:... error:...];
// NB: make sure that the returned texture is not nil!
// if it's nil, you'll get black objects, and need to check
// your path to your texture file
...
// INSIDE your VAO setup (usually "setupGL" in Apple's template),
// assuming you're using VAO,
// i.e. after "glBindVertexArrayOES"
GLint _textureBuffer; // an empty buffer that we'll create and fill
glEnableVertexAttribArray( glGetAttribLocation(program, "a_textureCoordinate") );
glGenBuffers(1, &_textureBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _textureBuffer);
glBufferData(GL_ARRAY_BUFFER,
self.currentScene.meshNumVertices * sizeof( (*self->sharedMeshTextureCoords) ),
self->sharedMeshTextureCoords, GL_DYNAMIC_DRAW);
glVertexAttribPointer( glGetAttribLocation(program, "a_textureCoordinate"),
2, GL_FLOAT, GL_FALSE, 0, 0);
glActiveTexture(GL_TEXTURE0);
Render (last thing before calling glDrawArrays or similar)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [appleTexture name]);
glUniform1i( glGetUniformLocation( program, "s_texture"), 0); // No idea
Texture shader:
attribute vec4 position;
attribute vec2 a_textureCoordinate;
varying vec2 v_textureCoordinate;
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
void main()
{
v_textureCoordinate = a_textureCoordinate;
gl_Position = modelViewProjectionMatrix * position;
}
Fragment shader:
uniform sampler2D s_texture;
varying mediump vec2 v_textureCoordinate;
void main(void)
{
gl_FragColor = texture2D( s_texture, v_textureCoordinate );
}