Oh well. I removed the culling vertices code(Although it didnt seem to be used, I looked for any call to the vertex culling function but there werent any) atleast now it doesn't return millions of shapes it returns just dozens but it still doesnt work. It still gives me an unreferenceable vector iterator. I changed a bit the routine.
Maybe the image format is the problem? I used a .png. Or maybe it's trying to get it from the LPDIRECT3DTEXTURE9?
I made a test for the image, I painted the corner red and then I took 'bits'(After copying the bits from the LPDIRECT3DTEXTURE9) and set 4 int variables to bit[0], bit[1], bit[2], bit[3]. The first one gave me 0, second one game me 255 third one gave me 0 and last one gave me 0 as would be expected I think.
Maybe the image format is the problem? I used a .png. Or maybe it's trying to get it from the LPDIRECT3DTEXTURE9?
I made a test for the image, I painted the corner red and then I took 'bits'(After copying the bits from the LPDIRECT3DTEXTURE9) and set 4 int variables to bit[0], bit[1], bit[2], bit[3]. The first one gave me 0, second one game me 255 third one gave me 0 and last one gave me 0 as would be expected I think.
Code:
void PlayState::CreateShapes(Object *obj)
{
D3DLOCKED_RECT rect;
LPDIRECT3DTEXTURE9 mTexture = obj->mSpriteInstance->mSprite->mTexture;
int width = 64;//obj->mSpriteInstance->mSprite->mTextureWidth;
int height = 64;//obj->mSpriteInstance->mSprite->mTextureHeight;
int size = width*height;
uchar *bits = new uchar[size*sizeof(DWORD)];
mTexture->LockRect(0, &rect, 0, 0);
memcpy(bits, rect.pBits, size*sizeof(DWORD));
mTexture->UnlockRect(0);
uchar *ex_color = new uchar[sizeof(DWORD)];
ex_color[0] = 0;
ex_color[1] = 0;
ex_color[2] = 0;
ex_color[3] = 0;
std::vector<Shape> out_shapes;
traceImage(bits,
width, //width
height, //hmTextureHeight
4, //channel count //4 channels? ARGB?
ex_color, //Alpha
0, //Alpha
out_shapes,
128,
true);
std::vector<Shape>::iterator shapeIt = out_shapes.begin();
for(; shapeIt != out_shapes.end(); shapeIt++)
{
b2PolygonDef shapeDef;
shapeDef.vertexCount = shapeIt->size();
std::list<Vertex>::iterator vertexIt = shapeIt->begin();
int x = 0;
while(vertexIt != shapeIt->end()){
shapeDef.vertices[x].Set(vertexIt->pos[0], vertexIt->pos[1]);
x++;
vertexIt++;
}
obj->mBody->CreateShape(&shapeDef);
}
}
{
D3DLOCKED_RECT rect;
LPDIRECT3DTEXTURE9 mTexture = obj->mSpriteInstance->mSprite->mTexture;
int width = 64;//obj->mSpriteInstance->mSprite->mTextureWidth;
int height = 64;//obj->mSpriteInstance->mSprite->mTextureHeight;
int size = width*height;
uchar *bits = new uchar[size*sizeof(DWORD)];
mTexture->LockRect(0, &rect, 0, 0);
memcpy(bits, rect.pBits, size*sizeof(DWORD));
mTexture->UnlockRect(0);
uchar *ex_color = new uchar[sizeof(DWORD)];
ex_color[0] = 0;
ex_color[1] = 0;
ex_color[2] = 0;
ex_color[3] = 0;
std::vector<Shape> out_shapes;
traceImage(bits,
width, //width
height, //hmTextureHeight
4, //channel count //4 channels? ARGB?
ex_color, //Alpha
0, //Alpha
out_shapes,
128,
true);
std::vector<Shape>::iterator shapeIt = out_shapes.begin();
for(; shapeIt != out_shapes.end(); shapeIt++)
{
b2PolygonDef shapeDef;
shapeDef.vertexCount = shapeIt->size();
std::list<Vertex>::iterator vertexIt = shapeIt->begin();
int x = 0;
while(vertexIt != shapeIt->end()){
shapeDef.vertices[x].Set(vertexIt->pos[0], vertexIt->pos[1]);
x++;
vertexIt++;
}
obj->mBody->CreateShape(&shapeDef);
}
}