Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am using GLKit in order to show textures on my project. The code is like this:

-(void)setTextureImage:(UIImage *)image {
  NSError *error;
  texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&error];
  if (error) {
      NSLog(@"Error loading texture from image: %@",error);
  }
}

effect.texture2d0.envMode = GLKTextureEnvModeReplace;
effect.texture2d0.target = GLKTextureTarget2D;
effect.texture2d0.name = texture.name;

glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0, self.textureCoordinates);

Now I want to repeat this texture on a rectangle. Is there any way use GLKit for this behavior? I've tried to use opengl function in addition to the glkit ones, but it raises errors:

glEnable(GL_TEXTURE_2D);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glBindTexture( GL_TEXTURE_2D, texture.name );

2011-11-09 20:10:28.614 **[16309:207] GL ERROR: 0x0500

2011-11-09 20:10:30.840 **[16309:207] Error loading texture from image: Error Domain=GLKTextureLoaderErrorDomain Code=8

"The operation couldn’t be completed. (GLKTextureLoaderErrorDomain error 8.)" UserInfo=0x68545c0 {GLKTextureLoaderGLErrorKey=1280, GLKTextureLoaderErrorKey=OpenGL error}

share|improve this question
2  
This has nothing to do with wrapping. The error seems to indicate a texture loading problem, not a texture wrapping problem. –  Nicol Bolas Nov 9 '11 at 19:50
add comment

3 Answers 3

Probably a bit out-dated, But you need to set NSError *error; to NSError *error = nil; Already broke my head around this.

share|improve this answer
add comment

Your images have to be powers of 2, you shouldn't call glEnable(GL_TEXTURE_2D), and you need to call

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

after

[_baseEffect prepareToDraw];
share|improve this answer
add comment

Not sure if you ever solved it, but this is what worked for me:

texture = [GLKTextureLoader textureWithCGImage:image.CGImage options:nil error:&error];
if(error) {
    NSLog(@"Error loading texture from image: %@", error);
} else {
    glEnable(GL_TEXTURE_2D);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.