ganesh
ganesh

Reputation: 166

OpenGL error 0x0500 in -[CCTextureAtlas drawNumberOfQuads:fromIndex:] 556

I am following BOX2D tutorial from Learn COCOS2D book and I started to see this error like 10 times every second on console. I googled this error but couldn't find any relevant information. Some people are talking about shader files but I don't know what are those. Some people are saying not to use multiple GLVIEWs but I don't see I am doing that. Below is the entire code of implemenation file.

ERROR MSG: OpenGL error 0x0500 in -[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;
}

Upvotes: 3

Views: 3287

Answers (1)

Guru
Guru

Reputation: 22042

OpenGL error 0x0500 = GL_INVALID_ENUM, For more details about openGL Error: Check Here

I guess your cocos2d version is 2.0 or higher. Cocos2d 2.0 uses openGLES2.0, in that opengl immediate mode calls are not allowed...see your code glEnable is used.

Replace your draw function with

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

Here is one other thread, refer my answer in same for more details:

Upvotes: 5

Related Questions