Thanks for your proposal, but same result with i or f, a black screen.
Here is big part of my class Shape.m, maybe it helps ? This code works and show a texture, but I don't find the way to repeat.
//Set the texture image
-(void)setTextureImage:(UIImage *)image { NSError *error;
texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&error];
if (error) {
NSLog(@"Error loading texture from image: %@",error);
}
}
// Set the texture coordinates
- (GLKVector2 *)textureCoordinates {
if (textureCoordinateData == nil)
textureCoordinateData = [NSMutableData dataWithLength:sizeof(GLKVector2)*self.numVertices];
return [textureCoordinateData mutableBytes];
}
// called on each shape
-(void)renderInScene:(P3Scene *)scene {
effect = [[GLKBaseEffect alloc] init];
if (useConstantColor) {
effect.useConstantColor = YES;
effect.constantColor = color;
}
//set the scene with the projectionMatrix we need
effect.transform.projectionMatrix = scene.projectionMatrix;
//translate, rotate and then scale
modelviewMatrix = GLKMatrix4Multiply(GLKMatrix4MakeTranslation(position.x, position.y, 0), GLKMatrix4MakeRotation(rotation, 0, 0, 1));
modelviewMatrix = GLKMatrix4Multiply(modelviewMatrix, GLKMatrix4MakeScale(scale.x, scale.y, 1));
effect.transform.modelviewMatrix = modelviewMatrix;
//set a texture if exists
if (texture != nil) {
effect.texture2d0.envMode = GLKTextureEnvModeReplace;
effect.texture2d0.target = GLKTextureTarget2D;
effect.texture2d0.name = texture.name;
}
[effect prepareToDraw];
[self render];
}
//called in the renderInScene method
-(void)render {
//enable transparency for sprites
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//tells the shader that we are going to use vertex position data.
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 0, self.vertices);
//set the color of each vertices
if (!useConstantColor) {
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, 0, self.vertexColors);
}
if (texture != nil) {
//ALL MY TESTS ARE HERE
/*glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture.name);
glTexCoordPointer(3, GL_FLOAT, 0, self.textureCoordinates);
glDisable(GL_TEXTURE_2D);*/
//glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
//glBindTexture( GL_TEXTURE_2D, texture.name );
//glEnable(GL_TEXTURE_2D);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates);
//glDisable(GL_TEXTURE_2D);
}
glDrawArrays(GL_TRIANGLE_FAN, 0, self.numVertices);
//is cleanup code that tells the shader that we’re done using vertex position data.
glDisableVertexAttribArray(GLKVertexAttribPosition);
if (!useConstantColor)
glDisableVertexAttribArray(GLKVertexAttribColor);
if (texture != nil)
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
glDisable(GL_BLEND);
}
Is that code helping ? Thank you very much !
Caste, on 11 November 2011 - 02:15 AM, said:
Ah I just spotted that you're using glTexParameterf which indicates that you will pass a float (hence the f at the end) to the function as a parameter. But the parameter GL_REPEAT is an enum (or an int) and thus you should use glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);