How do I repeat a texture with GLKit?

Posted by Synopfab on Game Development See other posts from Game Development or by Synopfab
Published on 2011-11-09T19:21:54Z Indexed on 2012/06/11 22:48 UTC
Read the original article Hit count: 587

Filed under:
|

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}

© Game Development or respective owner

Related posts about opengl-es

Related posts about ios