LiquidFun Physics Engine Integration

LiquidFun Physics Engine Integration
0.0 0


Hello, I stumbled apon a really neat extension of Box2d developed by Google called LiquidFun. I was able to successfully swap out Box2d with LiquidFun. However, I am unsure of how to render the particles in a “particlesystem” with cocos2d-x from the physics engine. The programmers guide states the following:

Each type of particle property lives in a contiguous memory buffer. For example, all particles’ position data live next door to one another, all color data live next door to one another, and so forth. Table 1 provides a visual representation of this storage.

Table 1. Memory Map of Particle Buffers

Particle 1 Particle 2 Particle 3
Position x1,y1 x2,y2 x3,y3
Address 0x00001000 0x00001008 0x00001010
Color r1,g1,b1,a1 r2,g2,b2,a2 r3,g3,b3,a3
Address 0x00002000 0x00002004 0x00002008
OpenGL can use these buffers directly in rendering.
In this example, OpenGL 1.1 would use glVertexPointer and glColorPointer to get the values from memory. OpenGL 2.0 would use glVertexAttribPointer.
OpenGL can be used to render either individual particles or particle groups.

However, I have never worked directly with the OpenGL API and I have no idea how to integrate this with cocos2d-x’s rendering. Can someone please post an example of how to render a particle system?

I greatly appreciate this.


hey good news man,
I kinda know 1 or 2 things about openGL/cocos2dx but what version are you using? bec. 2.x is different than 3.x

By the way i actually ask in the forum how to integrate liquidfun but to no avail so would you be kind enough to share how did you integrate it? like a tutorial or something?

Thanks man, cheers.



I am using the 3.0 beta. Basically, this was what I did:

  1. In my project folder, I went to the cocos2d library folder. Then, I deleted the cocos, extensions, and external folders and created symbolic links to cocos2d-x folder’s cocos, extensions, and external folder. This allows for the changes you make in the cocos2d-x library folder to be reflected in your project.

  2. In the cocos2d-x library folder, go to External/Box2d and delete all of it’s contents. Then copy all of the LiquidFun source code into that Box2d directory. The only thing that should be new is a “Particle” folder. In addition, you will have to use the Android Make File I uploaded in order to build correctly on Android.

  3. In order to build correctly with xCode, you will need to expand the cocos_lib project and navigate to external/Box2d. Most likely the Particle folder is missing so you will have to go to File->Add Files and add the Particle folder to the Box2d directory.

All these instructions are for cocos2d-x 3.0 and they may be different for earlier versions.

I wish you luck and I would greatly appreciate if you could post your working code for the rendering of the particle system.


hey man,
sorry i wasn’t able to reply right away im doing something else actually, thanks for sharing your knowledge. i’ll try to play with liquidfun and openGL but i can’t assure you when i can post a sample project, but allow me to give you some pointers:

1.this might be very simple and obvious but, learn openGL 2.0/3.0 (that’s it… no pun intended) openGL 1.1 is outdated and fixed/no-shaders, if you want cool effects go with openGL 2.0/3.0
2.the table you posted is the attribute management they use, there is this called array-of-structure and structure-of-array thing that you can use when sending vertex data to openGL. you can pack all vertex attributes like position, color, texture coordinates into one and tell openGL how you packed them or you can just segregate them like all position in 1group and all color in 1group(which is what they did)… so on
3.then after you learn openGL visit this (or before you study openGL read this to give you some inspiration, i guess) it’s a good example i think bec. it’s also about soft-body physics (which is what liquidfun is offering us) but the methods used might be outdated i don’t know what version of cocos2d the author was using but the concept i believe is still the same. this is where i got inspired to learn openGL back then.
Have fun learning openGL man, i know you’ll thank me after so… you’re welcome, in advance, cheers!!!


hi… i have been trying to get liquid fun to work… but before that I get error with debug draw saying that “allocating an object of abstract class GLESdebugdraw” and doesnt let debug draw to start… if I build the project without making any changed to the box 2d folder debug draw works fine… did you guys face any such issues too???


make sure that you have an derived class from that abstract GLESdebugdraw class.
i think box2d has its own implementation of an derived class, you can just copy that to your project.
i believed that’s the rendering part of box2d for its primitives, correct me guys if im wrong, its been a long time since i play with it. this might help you


ya but there is no implementation of the drawparticle virtual function in the regular debugdraw… there is a render class in the liquidfun project which implements it which uses opengl i think so and also i think they give just point for the particle group to the renderer in the renderer it cycles throuh all the particles and updates the draw… I atleast think that is what is happening… so i modified the draw particle call in the b2world class so suit this and I get a bunch of particles but they dont move… neeed toooo sleeeeeeeeZzzzzzzzz…


have you tried the liquidfun implementation of debugdraw? i think it has its own.
try to look from 1 of its demo proj

i love it, code til you drop :wink:


ya… I saw that it is in the frameworks folder and file is called render. The implementation is just mind boggling. Drawing a solid sphere the code is like 15 lines and that for dreawing a particle is like 150 lines it is all pure openGL. My knowledge of openGL and GLES are a bit limited so I did go about making some changes to the GLES-Renderer class that I am using in cocos2d-x… the particles do display on the screen but it is all packed together and are not getting updated. Like it should fall as I have gravity enabled.

Could you share your debugdraw code?


sorry sid, ive not played with it yet as im doing something else. for now i can only share some ideas but again im no expert and my ideas may not be right. after these i’ll definitely play with it and share some codes with you/guys.
by the way have you ask the liquidfun forum?


thanks … will check it out… :slight_smile:


i would just like to inform you guys that on the liquidfun site they’ve updated the api or should i say integrated it with cocos2dx-2.2.2 (if im not mistaken) so all you have to do is compile everything with all the sample codes using liquidfun for the physics part and cocos2dx for the rendering side.
have fun with liquids… :wink: got that? liquid? fun? … aaaahhhhhh … i think not :;ok