Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About synopfab

  • Rank
  1. synopfab

    Repeat texture with GLKit

    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; = GLKTextureTarget2D; =; } [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,; 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, ); //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 !
  2. synopfab

    Repeat texture with GLKit

    Ok, but I think that the error is that I've tried to add properties in openGL to texture loaded in GLKit. To my mind, the is OK, because I successfully display it to my view. The problem is that when I add the line [color=#AAB2B8][size=2]glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); [color=#AAB2B8][size=2] before , between, or after the lines [color=#AAB2B8][size=2][color=#E2E2E2]glEnableVertexAttribArray[color=#B5973B]([color=#660066]GLKVertexAttribTexCoord0[color=#B5973B]);[color=#E2E2E2] glVertexAttribPointer[color=#B5973B]([color=#660066]GLKVertexAttribTexCoord0[color=#B5973B],[color=#E2E2E2] [color=#006666]2[color=#B5973B],[color=#E2E2E2] GL_FLOAT[color=#B5973B],[color=#E2E2E2] GL_FALSE[color=#B5973B],[color=#E2E2E2] [color=#006666]0[color=#B5973B],[color=#E2E2E2] [color=#3B77B5]self[color=#B5973B].[color=#E2E2E2]textureCoordinates[color=#B5973B]); the view is empty and no texture is loaded. So everything is cool without the glTextParameterf but not repeated, and it is empty with the glTextParameterf. Thanks
  3. synopfab

    Repeat texture with GLKit

    My code works without those lines, and don't work with those lines : [color=#AAB2B8][font=monospace][size=2][color=#E2E2E2]glEnable[color=#B5973B]([color=#E2E2E2]GL_TEXTURE_2D[color=#B5973B]);[/font] [font=monospace][size=2][color="#e2e2e2"]glTexParameterf[color=#B5973B]([color=#E2E2E2] GL_TEXTURE_2D[color=#B5973B],[color=#E2E2E2] GL_TEXTURE_WRAP_S[color=#B5973B],[color=#E2E2E2] GL_REPEAT [color=#B5973B]);[/font] [font=monospace][size=2][color=#E2E2E2]glBindTexture[color=#B5973B]([color=#E2E2E2] GL_TEXTURE_2D[color=#B5973B],[color=#E2E2E2] texture[color=#B5973B].[color=#E2E2E2]name [color=#B5973B]);[/font] This is the reason why I think there is a sort of conflict, and maybe a glkit way to repeat a texture, without glTexParameterf ?
  4. synopfab

    Repeat texture with GLKit

    Hi Caste, and thank you for your reply. [font="monospace"] [/font]Thank you for your link to the docs. [font="arial, sans-serif"]The fact is that I don't find in the class GLKTextureLoader how to change WRAP_S and WRAP_T to GL_REPEAT.[/font] [font="arial, sans-serif"]It seems like there is a conflict if I use :[/font] [font="arial, sans-serif"] [/font] glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); [font="arial, sans-serif"] [/font] [font="arial, sans-serif"]Thanks again,[/font] [font="arial, sans-serif"]Fabrice[/font]
  5. synopfab

    Repeat texture with GLKit

    Hi everybody, 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; = GLKTextureTarget2D; =; 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, ); 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} Thank you for your help, Fabrice
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!