Trying to draw liquid on floor in 2d (Opengl directly write array of byte into stencil buffer)

Currently I’m making 2d game with java libgdx.
In my game I need to have multiple kinds of liquid to occupy floor of room. (somthing like splatoon but in 2d)
Each liquid need track of what entity it is in touch with and should be able to change where they occupy in runtime based on what players do.
So approach I took was, give number to each liquid and create array of byte with same size of room’s width*height to fill liquid into.
It works well in its function but, I have some problem in graphic side.
I need to fill in area of liquid with texture for each liquid. but I’m kinda lost on how to do it.

From searching, closest thing I’ve achieved so far was to create texture from array of byte through pixmap.
Then use these textures as stencil buffer mask. It works fine for visual side, but it is extremely slow.

so my question is
Is there any better way to draw and check collision for dynamic changing objects in 2D than using array of byte?
If not, Is there any better way to ‘fill in’ only selected area than stencil buffer?
If not, Is there more direct/faster way to use array of byte as stencil buffer mask?

Probably the best way would be to use a shader to generate the water texture. Do the collision checking and pass the collision info to the shader. If you look up interactive water shaders on shadertoy you might find some examples where the user can interact with the water using their mouse. Your collision detection would probably do something similar.

1 Like