Iphone 应在NPOT纹理中使用GL_夹具_至_边缘

Iphone 应在NPOT纹理中使用GL_夹具_至_边缘,iphone,cocos2d-iphone,opengl-es-2.0,Iphone,Cocos2d Iphone,Opengl Es 2.0,我有两张照片: PNG(sRGB)64x64(从网络加载) PNG(sRGB),从fla移植到PNG,然后使用sRGB从PNG移植到jpg,然后再移植到PNG(sRGB) 我正在尝试用纹理填充多边形,该纹理由以下图像创建: CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:spriteName]; polygon = [[[PhisicsFilledPoligon alloc] initWithPo

我有两张照片:

  • PNG(sRGB)64x64(从网络加载)
  • PNG(sRGB),从fla移植到PNG,然后使用sRGB从PNG移植到jpg,然后再移植到PNG(sRGB)
  • 我正在尝试用纹理填充多边形,该纹理由以下图像创建:

    CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:spriteName];
    
        polygon = [[[PhisicsFilledPoligon alloc] initWithPoints:points
                             andTexture:texture] autorelease];
    
    PhysicsFilledPolygon是box2d的PhysicsSprite类型,但使用替代的“draw”方法:

    -(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);
    }
    
    当我尝试使用第一个图像作为纹理时,一切都很好。但由于我使用的是第二个,应用程序因错误而崩溃:

    *** 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'
    
    无论我尝试使用哪种图像,结果都是相同的错误。Cocos2d版本是2.0 rc0。以下是启动cocos2d的信息:

    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
    

    我的问题在哪里?

    你使用的纹理不是二维的力量。

    我认为问题在于:

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    
    GL_REPEAT不是NPOT纹理的核心OpenGL ES 2.0规范的一部分,只有GL_CLAMP_TO_EDGE是,因此不支持GL_REPEAT


    您需要将GL\u-CLAMP\u-to-EDGE设置为GL\u-EDGE,而不是GL\u-REPEAT,或者使用POT纹理。

    将GL\u-REPEAT切换为GL\u-CLAMP\u-to-EDGE将删除错误并在我的项目中重新构建,但我失去了重复效果。升级到cocos2d2.x后,我不得不这样做。最好的选择是,将你的图像尺寸设为2的幂。。。(2、4、8、16、32、64、128、256、512、1024、2048)

    神奇的词语是: CCConfiguration.m: //122号线附近

    supportsNPOT_ = NO; // before it said YES
    

    如何在项目中运行64X47和其他映像。。?