How can I use SetDebugDraw if my z-buffer is disabled?

Hi friends!

My 2D game does not use z-buffer (I'm using the iPhone) for perfomance reasons, actually I don't need it because I render all my objects from back to front.

How can I use SetDebugDraw if my z-buffer is disabled? Because this render is done on STEP, befeore my render call.

Is it possible to force b2DebugDraw render a bit later? (exactly, after my own render).

Thanks in advance.
You need to tweak your DebugDraw implementation so that instead of immediately rendering the shapes, it saves their information and renders them later.
That is how I do it. I take it a step farther. I buffer all render commands and sort them (if needed, i optimized so that I only resort a 'dirty' buffer), and then render back to front. That way my game logic isn't tied to my render order in any way.

-nick
caspin wrote:That is how I do it. I take it a step farther. I buffer all render commands and sort them (if needed, i optimized so that I only resort a 'dirty' buffer), and then render back to front. That way my game logic isn't tied to my render order in any way.

-nick


It seems interesting what you said.
How do you buffer them? I have some ideas, but I'd prefer to know more about your approach.
I mean, do you use a class for a circle, anorone for a line.... or just data structures?


Thanks for replies.
There are some details missing but the spirit of the solution is the same.

Code: Select all

// the base class for all graphics in my game
class Graphic
{
public:
   // use this for sorting, and testing if graphic list is dirty
   // during update pass
   virtual float zOrder( void ) const =0;

   // accessors for position, rotation, etc.

private:
   friend class Graphic_manager;
   // called every frame.  if returns false remove
   // from graphic list, delete it.
   virtual bool update( float dt ) =0;

   // called each frame
   virtual void render( /*graphic context if needed*/ ) =0;
};

class Sprite : public Graphic
{
   // stores reference to texture, as well as quad coords.
};

class GLPrimative : public Graphic
{
public:
   const unsigned* world_generation;
   const unsigned my_world_generation;
   GLenum gl_begin_param;
   std::vector<b2Vec2> vertices;
   std::vector<b2Vec2> texture_coords;
   Color c;
   glTexture_id texture;

private:

   void render( )
   {
      // do open gl stuff
      // optionally use textures if texture id is not 0.
   }

   bool update( float dt )
   {
      // besure you don't have an off by one error here.
      return my_world_generation == *world_generation;
   }
};


I have a graphic manager that essentially manages a list of graphic pointers.
It loops over the graphic list calling update on each, testing if a resort
is needed, and removing expired graphic objects. If the resort is needed
it performs a sort. And finally it again loops over the graphic list calling
render on each

I increment an integer in my b2World wrapper everytime I call step. The b2Debugdraw
callback passes the address of this integer into the GlPrimative when it
is allocated. I call this integer world generation. The Glprimative remembers
what generation it was created, so it can stop rendering when a new set of
debug primatives are rendered.

I implement this with shared pointers to help with graphic lifetime management.

You can see all the gory details at http://ammo.googlecode.com

-nick

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