Aquí está la versión más simple que podría hacer que efectivamente trabajadas:
de configuración (inmediatamente después de haber realizado la glVertexAttribPointer para sus 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 (última cosa antes de llamar a glDrawArrays o similar)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, [appleTexture name]);
glUniform1i(glGetUniformLocation(program, "s_texture"), 0); // No idea
textura 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;
}
Fragmento de sombreado:
uniform sampler2D s_texture;
varying mediump vec2 v_textureCoordinate;
void main(void)
{
gl_FragColor = texture2D(s_texture, v_textureCoordinate);
}
¿Qué quiere decir con "la vieja ES 1.1 del API ya no funcionan", estoy usando GL ES 1.1 y funciona perfectamente. – Goles
Lo que mencioné, no puede simplemente lanzar llamadas de función de ES 1.1 a un contexto inicializado de ES 2.0 ... Claro que puede inicializar ES 1.1 y usar eso, pero no podrá hacer uso de sombreadores – Kyle