【问题标题】:OpenGL error 0x0500 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556OpenGL 错误 0x0500 在 -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556
【发布时间】:2013-03-17 18:18:47
【问题描述】:

我正在学习《学习 COCOS2D》一书中的 BOX2D 教程,我开始在控制台上看到此错误,例如每秒 10 次。我用谷歌搜索了这个错误,但找不到任何相关信息。有些人在谈论着色器文件,但我不知道那些是什么。有些人说不要使用多个 GLVIEW,但我不认为我正在这样做。下面是整个实现文件的代码。

错误信息: OpenGL 错误 0x0500 在 -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556

- (void)dealloc
{
    if(world){
        delete world;
        world = NULL;
    }
    if(debugDraw){
        delete debugDraw;
        debugDraw = nil;
    }
    [super dealloc];
}

+(id)scene{
    CCScene *scene = [CCScene node];
    PuzzleLayer *layer = [self node];
    [scene addChild:layer];
    return scene;
}

-(void)setupWorld{
    b2Vec2 gravity = b2Vec2(0.0f, -10.0f);
    //bool doSleep = true;
    world = new b2World(gravity);
}

-(void)createBoxAtLocation: (CGPoint)location withSize:(CGSize)size{
    CCLOG(@"Box location: %.0f, %.0f", location.x, location.y);
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);
    b2Body *body = world->CreateBody(&bodyDef);

    b2PolygonShape shape;
    shape.SetAsBox(size.width/2/PTM_RATIO, size.height/2/PTM_RATIO);
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &shape;
    fixtureDef.density = 1.0;
    body->CreateFixture(&fixtureDef);
}

-(void)setupDebugDraw{
    debugDraw = new GLESDebugDraw(PTM_RATIO * [[CCDirector sharedDirector] contentScaleFactor]);
    world->SetDebugDraw(debugDraw);
}

-(void)draw{
    glDisable(GL_TEXTURE_2D);
    world->DrawDebugData();
    glEnable(GL_TEXTURE_2D);
}

-(id)init{
    if(self = [super init]){
        [self setupWorld];
        [self setupDebugDraw];
        [self scheduleUpdate];
        self.isTouchEnabled = YES;
    }
    return self;
}

-(void)registerWithTouchDispatcher{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}

-(void)update:(ccTime)dt{
    int32 velocityIterations = 3;
    int32 positionIterations = 2;
    world->Step(dt, velocityIterations, positionIterations);
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
    CGPoint touchLocation = [touch locationInView:[touch view]];
    touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
    touchLocation = [self convertToNodeSpace:touchLocation];
    b2Vec2 locationWorld = b2Vec2(touchLocation.x/PTM_RATIO, touchLocation.y/PTM_RATIO);
    [self createBoxAtLocation:touchLocation withSize:CGSizeMake(50, 50)];
    return TRUE;
}

【问题讨论】:

    标签: ios opengl-es cocos2d-iphone


    【解决方案1】:

    OpenGL 错误 0x0500 = GL_INVALID_ENUM,有关 openGL 错误的详细信息:Check Here

    我猜你的 cocos2d 版本是 2.0 或更高。 Cocos2d 2.0 使用 openGLES2.0,因为 opengl 立即模式调用是不允许的......看你的代码 glEnable 被使用。

    将您的绘图功能替换为

    -(void) draw
    {
        [super draw];
        ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
        kmGLPushMatrix();
        self.world->DrawDebugData();    
        kmGLPopMatrix();
    }
    

    这是一个other thread, refer my answer in same for more details

    【讨论】:

    • 你说得对,是 GLES 版本的问题。非常感谢给我正确的绘制方法。但是我仍然没有看到任何框被绘制在屏幕上,尽管 createBoxAtLocation 方法被调用得很好。对此有什么想法吗?
    • 来自 Cocos2D 2.0 的 GLES-Render.h 和 GLES-Render.m
    • 如果您能详细说明为什么 createBoxAtLocation 仍然没有绘制块,因为我仍然出现空白屏幕,将不胜感激?
    • 只是让您知道,我的 .h 文件顶部有 #import "GLES-Render.h"。所以包括在内。但是 BOX2D 仍然没有在屏幕上绘制任何内容。
    • 我发现了问题:我错过了将 debugDraw 上的标志设置为 debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 2013-04-16
    相关资源
    最近更新 更多