Search code examples
iphonecocos2d-iphoneopengl-es-2.0

GL_CLAMP_TO_EDGE should be used in NPOT textures


I have two images:

  1. PNG (sRGB) 64x64 (dowloaded from network)
  2. PNG (sRGB), ported from fla to png, then, from png to jpg with sRGB, then to PNG (sRGB).

I'm trying to fill polygon with texture, created from this image:

CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:spriteName];

    polygon = [[[PhisicsFilledPoligon alloc] initWithPoints:points
                         andTexture:texture] autorelease];

PhysicsFilledPolygon is kind of PhysicsSprite for box2d, but with overrided 'draw' method:

-(void) draw 
{
    ccGLBindTexture2D( [self.texture name] );

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

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords );

    [prog use];
    [prog setUniformForModelViewProjectionMatrix];

    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, sizeof(CGPoint), areaTrianglePoints);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(CGPoint), textureCoordinates);

    glDrawArrays(GL_TRIANGLES, 0, areaTrianglePointCount);
}

when I'm tring to use 1st image for texture, all works fine. But since I'm using 2nd one, app crashes with error:

*** Assertion failure in -[CCTexture2D setTexParameters:], /Users/SentineL/Documents/squirrels ios/squirrels/libs/cocos2d/CCTexture2D.m:743
2012-05-18 14:42:26.603 squirrels[21436:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'GL_CLAMP_TO_EDGE should be used in NPOT textures'

What ever image I'm trying to use, result is same error. Cocos2d version is 2.0 rc0. Here is starting cocos2d info:

2012-05-18 14:42:25.038 squirrels[21436:707] cocos2d: OS version: 5.1 (0x05010000)
2012-05-18 14:42:25.041 squirrels[21436:707] cocos2d: GL_VENDOR:   Imagination Technologies
2012-05-18 14:42:25.042 squirrels[21436:707] cocos2d: GL_RENDERER: PowerVR SGX 543
2012-05-18 14:42:25.044 squirrels[21436:707] cocos2d: GL_VERSION:  OpenGL ES 2.0 IMGSGX543-63.24
2012-05-18 14:42:25.047 squirrels[21436:707] cocos2d: GL_MAX_TEXTURE_SIZE: 4096
2012-05-18 14:42:25.048 squirrels[21436:707] cocos2d: GL_MAX_TEXTURE_UNITS: 8
2012-05-18 14:42:25.049 squirrels[21436:707] cocos2d: GL_MAX_SAMPLES: 4
2012-05-18 14:42:25.051 squirrels[21436:707] cocos2d: GL supports PVRTC: YES
2012-05-18 14:42:25.053 squirrels[21436:707] cocos2d: GL supports BGRA8888 textures: YES
2012-05-18 14:42:25.054 squirrels[21436:707] cocos2d: GL supports NPOT textures: YES
2012-05-18 14:42:25.056 squirrels[21436:707] cocos2d: GL supports discard_framebuffer: YES
2012-05-18 14:42:25.057 squirrels[21436:707] cocos2d: compiled with Profiling Support: NO

2012-05-18 14:42:25.059 squirrels[21436:707] cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h

2012-05-18 14:42:25.061 squirrels[21436:707] cocos2d: cocos2d v2.0.0-rc0
2012-05-18 14:42:25.063 squirrels[21436:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2012-05-18 14:42:25:201 squirrels[21436:707] Retina Display Not supported
2012-05-18 14:42:25.214 squirrels[21436:707] cocos2d: animation started with frame interval: 60.00
2012-05-18 14:42:25.234 squirrels[21436:707] cocos2d: surface size: 1024x768

Where is my problem?


Solution

  • You're using texture with Not-Power-Of-Two dimensions.