Specific colour per object

For debugging purposes, how can I change the draw colour for one specific object?

Thanks 🤓

Edit: Without modifying the API if possible
Look at PolyShapes.h.
Erin Catto wrote:
Look at PolyShapes.h.

Oh fantastic, anyway I can prevent drawing my sensors? I want to be able to draw those custom coloured objects on top 🙂
Still looking 🙂
It's fairly easy to make your own draw shape parser, and combined with the userdata pointer you could give each a unique color of choice.
Code:
b2World world;
...
// Go through all bodies in the world.
for( b2Body* body = world->GetBodyList();body; body = body->GetNext()){
  // Go through all fixtures in each body.
  for( b2Fixture* fixture = body->GetFixtureList(); fixture; fixture = fixture->GetNext() ){
     b2Shape* shape = fixture->GetShape();
     // Check if it's polygon or circle. Uses different methods.
     if( shape->GetType() == b2Shape::e_polygon ){
        b2PolygonShape* polygon = (b2PolygonShape*)shape;
        int numberOfVertices = polygon->GetVertexCount();
        // Loop through all the vertices.
        for(int i = 0; i < numberOfVertices; i++){
          const b2Vec2 vertex = polygon->GetVertex(i);
          b2Vec2 worldVertex = body->GetWorldPoint(vertex);
          yourGameObjClass* gameObject = body->userData;
          yourColorClass color = gameObject->GetColor();
     // Draw point worldVertex or put into array and then draw line or what have you, depending on your line draw methods.
      }
      if( shape->GetType() == b2Shape::e_circle ){
        // Draw circle...
      }
   }
}


Sometimes it's easier to just build your own. 😉 Ofcourse this doesn't draw joints and contacts, but you can get those through parsing other b2World functions the same way. It's a nice and simple way of drawing (atleast I think so) that gives you full control.
Good luck!

Original thread: https://box2d.org/forum/viewtopic.php?t=4846