The problem I have is dealing with the graphic data. I haven't converted all the drawing functions (MapDrawBG, MapDrawBGT, MapDrawFG, etc) but I created a little function to draw one graphic block(tile) to see if I am decoding the raw graphics data in the mappy file (test.fmp) correctly. Here is my graphics decoding function:
Code: Select all
int DCMappy::MapDecodeBGFX (void) {
int i;
char *rawimagedata = NULL; // The raw graphics in whatever format the map is in [8bit;16bit]
pvr_ptr_t mapblockgfxpt = NULL;
// Allocated raw image data memory(one block at a time) depending on the mapdepth[8:1, 16:2]
if(mapdepth == 8) {
rawimagedata = (char *)malloc(mapblockwidth*mapblockheight);
} else if(mapdepth == 16) {
rawimagedata = (char *)malloc(mapblockwidth*mapblockheight*2);
}
if (rawimagedata == NULL) { maperror = MER_OUTOFMEM; return -1; }
// One block at a time filling up maplpDDSTiles
for(i = 0; i < mapnumblockgfx; i++) {
// Allocated PVR Memory(one block at a time) depending on the mapdepth
if(mapdepth == 8) {
fread(rawimagedata, mapblockwidth*mapblockheight, 1, mapfilept);
mapblockgfxpt = pvr_mem_malloc(mapblockwidth*mapblockheight);
if(mapblockgfxpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
pvr_txr_load_ex((void *)rawimagedata, mapblockgfxpt, mapblockwidth, mapblockheight, PVR_TXRLOAD_8BPP);
} else if(mapdepth == 16) {
fread(rawimagedata, mapblockwidth*mapblockheight*2, 1, mapfilept);
mapblockgfxpt = pvr_mem_malloc(mapblockwidth*mapblockheight*2);
if(mapblockgfxpt==NULL) { maperror = MER_OUTOFMEM; return -1; }
pvr_txr_load_ex((void *)rawimagedata, mapblockgfxpt, mapblockwidth, mapblockheight, PVR_TXRLOAD_16BPP);
}
// Setup a KOS Platform independent image struct to hold each gfx block
maplpDDSTiles[i] = (kos_img_t *)malloc(sizeof(kos_img_t));
maplpDDSTiles[i]->w = mapblockwidth;
maplpDDSTiles[i]->h = mapblockheight;
maplpDDSTiles[i]->data = (void *)mapblockgfxpt;
if(mapdepth == 8) {
maplpDDSTiles[i]->fmt = PVR_TXRFMT_PAL8BPP;
maplpDDSTiles[i]->byte_count = mapblockwidth*mapblockheight;
} else if(mapdepth == 16) {
maplpDDSTiles[i]->fmt = PVR_TXRFMT_RGB565;
maplpDDSTiles[i]->byte_count = mapblockwidth*mapblockheight*2;
}
mapblockgfxpt = NULL;
} // End of mapnumblockgfx
free(rawimagedata);
return 0;
}
So when I test this code on a map that contains graphics I imported I get some wrong colors but the design does come out(the colors are just different than they should be). When I test it with the one that comes with Will Sams's SDLMappy Version I get some funky colors and no design at all. The graphics are both 16 bits. I couldn't understand why it would work with one image but not the other. So I just changed PVR_TXRFMT_RGB565 -> PVR_TXRFMT_ARGB4444 which still gave me the right design and wrong colors for my graphic but the same thing still happened with the other graphic. Then I changed PVR_TXRFMT_ARGB4444 -> PVR_TXRFMT_ARGB1555 and I kinda of got the right colors and right design for my graphic but the same wrong thing still happens for the other. As I said before, both are 16bit images but one is not working. I do not know how to tell from raw image data (when the graphic in *.fmp is 16bit) if it is RGB565, ARGB4444, or ARGB1555.
According to this (Scroll down to "The FMP file format" and look at BGFX) documentation all 16 bit are RGB565 format if I am not mistaken.
Here is my drawing function:
Code: Select all
void DCMappy::DrawBlock(void) {
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, maplpDDSTiles[3]->fmt, maplpDDSTiles[3]->w, maplpDDSTiles[3]->h, (pvr_ptr_t)maplpDDSTiles[3]->data, PVR_FILTER_BILINEAR);
pvr_poly_compile(&hdr, &cxt);
pvr_prim(&hdr, sizeof(hdr));
vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
vert.oargb = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = 1;
vert.y = 1;
vert.z = 1;
vert.u = 0.0;
vert.v = 0.0;
pvr_prim(&vert, sizeof(vert));
vert.x = 32;
vert.y = 1;
vert.z = 1;
vert.u = 1.0;
vert.v = 0.0;
pvr_prim(&vert, sizeof(vert));
vert.x = 1;
vert.y = 32;
vert.z = 1;
vert.u = 0.0;
vert.v = 1.0;
pvr_prim(&vert, sizeof(vert));
vert.x = 32;
vert.y = 32;
vert.z = 1;
vert.u = 1.0;
vert.v = 1.0;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
}
http://www.tilemap.co.uk/mappy.php So you can test out the maps yourself