/**Simple function to draw the sprites with Color Lookup tables**/
void render_CLUT_sprite(unsigned int id, int x, int y, int z)
{
FIXED pos[XYZS]; pos[X]=toFIXED(x); pos[Y]=toFIXED(y); pos[Z]=toFIXED(z); pos[S]=65536;
SPR_ATTR spr_attributes = SPR_ATTRIBUTE(id, LUTidx(id), No_Gouraud, CL16Look | ECdis | SPdis | HSSon , sprNoflip );
slPutSprite(pos , &spr_attributes , 0) ;
}
/**Simple function to draw the sprites with Color Bank from Color RAM**/
void render_CRAM_sprite(unsigned int id, int x, int y, int z)
{
FIXED pos[XYZS]; pos[X]=toFIXED(x); pos[Y]=toFIXED(y); pos[Z]=toFIXED(z); pos[S]=65536;
SPR_ATTR spr_attributes = SPR_ATTRIBUTE(id, LUTcramIdx(id), No_Gouraud, CL16Bnk | ECdis | SPdis | HSSon , sprNoflip );
slPutSprite(pos, &spr_attributes , 0) ;
}
/***************************
This sets palette
***************************/
void set_palette(Uint16 * palette, Uint16 TextureId)
{
//For SGL only use slDMACopy instead : slDMACopy( (void*)palette, (void*)adr, sizeof(palette) );
jo_dma_copy(palette, (void*)(returnLUTaddr(TextureId)), sizeof(Uint16)*16);
//Only if you want to use the VDP2 CRAM for your sprite, else skip this
jo_palette_to_cram(palette, (void*)(returnCRAMaddr(TextureId)), 16);
}
/******************************
Load binary image
CAUTION : Jo Engine might throw an error if the texture's width/4 < 8,
The alternative would be to divide the height instead, but since the height doesn't need to be a multiple of 8 (ex.:3),
dividing by 4 might break everything (Ex.: 3/4 = 0).
Turn off the debug options in your makefile if that's an issue
******************************/
int load_4bits_bin_image(char * sub_dir, char * name, unsigned short width, unsigned short height)
{
jo_img * img;
jo_texture_definition *texture;
void * currentAddr = (void*)LWRAM; //Makes it easier to track the address
/**CD functions**/
jo_file file;
if(sub_dir != JO_NULL)
{
jo_fs_cd(sub_dir);
}
jo_fs_open(&file, name);
jo_fs_read_next_bytes(&file, (void*)LWRAM, (8+(width*height>>1)+32)); //8 bytes for width, height and pointer, then the width*heigth/2 (since we use 4 bits data) + the size of the palette (always 16*sizeof(Uint16))
jo_fs_close(&file); //or use this : GFS_Load(GFS_NameToId(name), 0, (void *)LWRAM, (4+(width*height>>1)+32));
if(sub_dir != JO_NULL)
{
jo_fs_cd(JO_PARENT_DIR);
}
/**Set the pointers**/
img = (jo_img*)currentAddr; currentAddr=(void*)(currentAddr+sizeof(jo_img));
img->width=img->width>>2; //Quick and dirty way to get around the fact that Jo Engine doesn't support 4 bits pixel data.
img->data = (jo_color*)(currentAddr); currentAddr=(void*)(currentAddr+(sizeof(Uint16)*img->width * img->height));
/**Adds the img in memory**/
int id = jo_sprite_add(img);
/**Here we just fix the issue caused by using the add 8 bits image for 4 bits images**/
texture=&__jo_sprite_def[id];
texture->width=img->width<<2; //Ghetto technique for compatibility with Jo Engine, but trying to replace the sprite will throw an error
__jo_sprite_pic[id].color_mode=COL_16;
texture->size = JO_MULT_BY_32(texture->width & 0x1f8) | texture->height;
/**Here we set the palette**/
set_palette((unsigned short *)currentAddr, id);
return id;
}