Skip to content

Can somebody give a demo example about how to use STB's rect pack? #1050

Description

@Hubert-Yang

Question

Hi,

I try to understand how to user stb's STBRectPack, does it working, here I add a unit test like:

STBRPNode.Buffer nodes_buffer = STBRPNode.malloc(3);

STBRPRect.Buffer rect_buffer = STBRPRect.malloc(3);

int index = 0;
for(STBRPRect rect : rect_buffer)
{
rect.set(index++, 0, 0, 30, 40, false);
}

atlas.setup_atlas_map(nodes_buffer, rect_buffer);

public void setup_atlas_map(STBRPNode.Buffer buffers, STBRPRect.Buffer rects)
{

STBRPContext pc =  STBRPContext.malloc(); 
if(pc != null)
{
	STBRectPack.stbrp_init_target(pc, atlas_w, atlas_h, buffers);	
	STBRectPack.stbrp_setup_heuristic(pc, STBRectPack.STBRP_HEURISTIC_Skyline_BF_sortHeight); 
	STBRectPack.stbrp_setup_allow_out_of_mem(pc, true);			
					
	STBRectPack.stbrp_pack_rects(pc, rects); 
}
	
// first we get altas with uv. 

	
for(STBRPNode node : buffers)
{
	System.out.println("get nodes as " + node.x() + " " + node.Y); 
}

}

but seems the node result is nothing. any where is wrong?

Thanks

Hubert Yang

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions