mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
[CHG] GRRLIB_LoadBMF is working, problem with palette is fixed but some cleaning is still required
[CHG] GRRLIB_FreeBMF is working too
This commit is contained in:
parent
4d9046eade
commit
8cc6db8605
5 changed files with 3258 additions and 40 deletions
|
@ -266,19 +266,19 @@ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const
|
|||
for(i=0; i<size; i++) {
|
||||
for(j=0; j<bmf.nbChar; j++) {
|
||||
if(tmp[i] == bmf.charDef[j].character) {
|
||||
|
||||
n=0;
|
||||
for(y=0; y<bmf.charDef[j].height; y++) {
|
||||
for(x=0; x<bmf.charDef[j].width; x++) {
|
||||
if(bmf.charDef[j].data[n]) {
|
||||
GRRLIB_SetPixelTotexImg(xpos + x, ypos + y, tex_BMfont,
|
||||
bmf.palette[bmf.charDef[j].data[n]]);
|
||||
GRRLIB_SetPixelTotexImg(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely,
|
||||
tex_BMfont, bmf.palette[bmf.charDef[j].data[n]]);
|
||||
//GRRLIB_Plot(xpos + x + bmf.charDef[j].relx, ypos + y + bmf.charDef[j].rely,
|
||||
// bmf.palette[bmf.charDef[j].data[n]]);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
}
|
||||
xpos += bmf.charDef[j].width + 1;
|
||||
|
||||
xpos += bmf.charDef[j].shift + bmf.addSpace;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -287,47 +287,47 @@ void GRRLIB_PrintBMF(f32 xpos, f32 ypos, GRRLIB_bytemapFont bmf, f32 zoom, const
|
|||
|
||||
GRRLIB_DrawImg(0, 0, tex_BMfont, 0, 1, 1, 0xFFFFFFFF);
|
||||
|
||||
|
||||
free(tex_BMfont.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a texture from a buffer.
|
||||
* Load a ByteMap font structure from a buffer.
|
||||
* @param my_bmf the ByteMap font buffer to load.
|
||||
* @return A GRRLIB_bytemapFont structure filled with BMF informations.
|
||||
*/
|
||||
GRRLIB_bytemapFont GRRLIB_LoadTextureBMF(const unsigned char my_bmf[]) {
|
||||
GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]) {
|
||||
GRRLIB_bytemapFont fontArray;
|
||||
fontArray.nbChar = 0;
|
||||
fontArray.charDef = NULL;
|
||||
|
||||
int i, j = 1;
|
||||
u8 lineheight;
|
||||
u8 usedcolors, highestcolor;
|
||||
short int sizeover, sizeunder, addspace, sizeinner, numcolpal;
|
||||
u8 lineheight, usedcolors, highestcolor, nbPalette;
|
||||
short int sizeover, sizeunder, sizeinner, numcolpal;
|
||||
u16 nbPixels;
|
||||
|
||||
// Initialize everything to zero
|
||||
memset(&fontArray, 0, sizeof(fontArray));
|
||||
|
||||
if(my_bmf[0]==0xE1 && my_bmf[1]==0xE6 && my_bmf[2]==0xD5 && my_bmf[3]==0x1A) {
|
||||
fontArray.version = my_bmf[4];
|
||||
lineheight = my_bmf[5];
|
||||
sizeover = my_bmf[6];
|
||||
sizeunder = my_bmf[7];
|
||||
addspace = my_bmf[8];
|
||||
fontArray.addSpace = my_bmf[8];
|
||||
sizeinner = my_bmf[9];
|
||||
usedcolors = my_bmf[10];
|
||||
highestcolor = my_bmf[11];
|
||||
numcolpal = 3 * my_bmf[16];
|
||||
memset(fontArray.palette, 0, sizeof(*fontArray.palette));
|
||||
for(i=0; i < numcolpal; i+=3)
|
||||
{ // Font palette
|
||||
fontArray.palette[j++] = ((my_bmf[i+17]<<24) | (my_bmf[i+18]<<16) | (my_bmf[i+19]<<8) | 0xFF);
|
||||
nbPalette = my_bmf[16];
|
||||
numcolpal = 3 * nbPalette;
|
||||
fontArray.palette = (u32 *)calloc(nbPalette + 1, sizeof(u32));
|
||||
for(i=0; i < numcolpal; i+=3) {
|
||||
fontArray.palette[j++] = ((((my_bmf[i+17]<<2)+3)<<24) | (((my_bmf[i+18]<<2)+3)<<16) | (((my_bmf[i+19]<<2)+3)<<8) | 0xFF);
|
||||
}
|
||||
j = 18 + numcolpal + my_bmf[17 + numcolpal];
|
||||
j = my_bmf[17 + numcolpal];
|
||||
fontArray.name = (char *)calloc(j + 1, sizeof(char));
|
||||
memcpy(fontArray.name, &my_bmf[18 + numcolpal], j);
|
||||
j = 18 + numcolpal + j;
|
||||
fontArray.nbChar = (my_bmf[j] | my_bmf[j+1]<<8);
|
||||
fontArray.charDef = (GRRLIB_bytemapChar *)calloc(fontArray.nbChar, sizeof(GRRLIB_bytemapChar));
|
||||
|
||||
j++;
|
||||
for(i=0; i < fontArray.nbChar; i++) //fontArray.nbChar
|
||||
{ // Bitmap character definitions
|
||||
for(i=0; i < fontArray.nbChar; i++) {
|
||||
fontArray.charDef[i].character = my_bmf[++j];
|
||||
fontArray.charDef[i].width = my_bmf[++j];
|
||||
fontArray.charDef[i].height = my_bmf[++j];
|
||||
|
@ -335,8 +335,7 @@ GRRLIB_bytemapFont GRRLIB_LoadTextureBMF(const unsigned char my_bmf[]) {
|
|||
fontArray.charDef[i].rely = my_bmf[++j];
|
||||
fontArray.charDef[i].shift = my_bmf[++j];
|
||||
nbPixels = fontArray.charDef[i].width * fontArray.charDef[i].height;
|
||||
//fontArray.charDef[i].data = malloc(nbPixels);
|
||||
fontArray.charDef[i].data = (u8 *)calloc(nbPixels, 8);
|
||||
fontArray.charDef[i].data = malloc(nbPixels);
|
||||
if(nbPixels && fontArray.charDef[i].data) {
|
||||
memcpy(fontArray.charDef[i].data, &my_bmf[++j], nbPixels);
|
||||
j += (nbPixels - 1);
|
||||
|
@ -352,7 +351,14 @@ GRRLIB_bytemapFont GRRLIB_LoadTextureBMF(const unsigned char my_bmf[]) {
|
|||
*/
|
||||
void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i=0; i<bmf.nbChar; i++) {
|
||||
free(bmf.charDef[i].data);
|
||||
}
|
||||
free(bmf.charDef);
|
||||
free(bmf.palette);
|
||||
free(bmf.name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -365,11 +371,6 @@ GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_img[]) {
|
|||
if(my_img[0]==0xFF && my_img[1]==0xD8 && my_img[2]==0xFF) {
|
||||
return(GRRLIB_LoadTextureJPG(my_img));
|
||||
}
|
||||
/*
|
||||
else if(my_img[0]==0x42 && my_img[1]==0x4D) {
|
||||
// Bitmap not supported
|
||||
}
|
||||
*/
|
||||
else {
|
||||
return(GRRLIB_LoadTexturePNG(my_img));
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ typedef struct GRRLIB_bytemapChar{
|
|||
u8 character; /**< Which character. */
|
||||
u8 width; /**< Character width. */
|
||||
u8 height; /**< Character height. */
|
||||
u8 relx; /**< Horizontal offset according to cursor (-128..127). */
|
||||
u8 rely; /**< Vertical offset according to cursor (-128..127). */
|
||||
s8 relx; /**< Horizontal offset according to cursor (-128..127). */
|
||||
s8 rely; /**< Vertical offset according to cursor (-128..127). */
|
||||
u8 shift; /**< Horizontal cursor shift after drawing the character. */
|
||||
u8 *data; /**< Character data itself (uncompressed, 8 bits per pixel). */
|
||||
} GRRLIB_bytemapChar;
|
||||
|
@ -50,9 +50,12 @@ typedef struct GRRLIB_bytemapChar{
|
|||
* Structure to hold the bytemap font informations.
|
||||
*/
|
||||
typedef struct GRRLIB_bytemapFont{
|
||||
u32 palette[64];
|
||||
u16 nbChar;
|
||||
GRRLIB_bytemapChar *charDef;
|
||||
u8 version; /**< Version . */
|
||||
s8 addSpace; /**< Add-space after each char (-128..127). */
|
||||
u32 *palette; /**< Font palette. */
|
||||
char *name; /**< Font name. */
|
||||
u16 nbChar; /**< Number of characters in font. */
|
||||
GRRLIB_bytemapChar *charDef; /**< List of bitmap character definitions. */
|
||||
} GRRLIB_bytemapFont;
|
||||
|
||||
|
||||
|
@ -72,7 +75,7 @@ void GRRLIB_NGoneFilled(Vector v[], u32 color, long n);
|
|||
GRRLIB_texImg GRRLIB_CreateEmptyTexture(unsigned int, unsigned int);
|
||||
GRRLIB_texImg GRRLIB_LoadTexture(const unsigned char my_img[]);
|
||||
|
||||
GRRLIB_bytemapFont GRRLIB_LoadTextureBMF(const unsigned char my_bmf[]);
|
||||
GRRLIB_bytemapFont GRRLIB_LoadBMF(const unsigned char my_bmf[]);
|
||||
void GRRLIB_FreeBMF(GRRLIB_bytemapFont bmf);
|
||||
|
||||
void GRRLIB_InitTileSet(struct GRRLIB_texImg *tex, unsigned int tilew, unsigned int tileh, unsigned int tilestart);
|
||||
|
|
BIN
examples/lesson1/source/gfx/frontal.bmf
Normal file
BIN
examples/lesson1/source/gfx/frontal.bmf
Normal file
Binary file not shown.
3211
examples/lesson1/source/gfx/frontal.h
Normal file
3211
examples/lesson1/source/gfx/frontal.h
Normal file
File diff suppressed because it is too large
Load diff
|
@ -20,6 +20,7 @@
|
|||
#include "gfx/BMfont5.h"
|
||||
#include "gfx/test_jpg.h"
|
||||
#include "gfx/ocean.h"
|
||||
#include "gfx/frontal.h"
|
||||
#include "gfx/sprite.h"
|
||||
|
||||
// Tile stuff
|
||||
|
@ -72,7 +73,8 @@ int main() {
|
|||
|
||||
GRRLIB_texImg tex_test_jpg = GRRLIB_LoadTexture(test_jpg);
|
||||
|
||||
GRRLIB_bytemapFont bmf_Font = GRRLIB_LoadTextureBMF(ocean);
|
||||
GRRLIB_bytemapFont bmf_Font1 = GRRLIB_LoadBMF(ocean);
|
||||
GRRLIB_bytemapFont bmf_Font2 = GRRLIB_LoadBMF(frontal);
|
||||
|
||||
GRRLIB_texImg tex_sprite_png = GRRLIB_LoadTexture(sprite);
|
||||
GRRLIB_InitTileSet(&tex_sprite_png, 24, 32, 0);
|
||||
|
@ -162,7 +164,7 @@ int main() {
|
|||
GRRLIB_Printf(left, top+300, tex_BMfont3, GRRLIB_WHITE, 1, "IR Y VALUE: %d", (int)ir1.y);
|
||||
GRRLIB_Printf(left, top+350, tex_BMfont3, 0XFFFFFF50, 1, "TEXT WITH ALPHA");
|
||||
GRRLIB_Printf(left, top+400, tex_BMfont5, GRRLIB_LIME, 1, "This font has the 128 ASCII characters");
|
||||
GRRLIB_PrintBMF(left, top+420, bmf_Font, 1, "OCEAN");
|
||||
GRRLIB_PrintBMF(left, top+420, bmf_Font2, 1, "%s", bmf_Font2.name);
|
||||
}
|
||||
GRRLIB_Printf(500, 27, tex_BMfont5, GRRLIB_WHITE, 1, "Current FPS: %d", FPS);
|
||||
GRRLIB_Render();
|
||||
|
@ -221,7 +223,8 @@ int main() {
|
|||
free(tex_BMfont3.data);
|
||||
free(tex_BMfont4.data);
|
||||
free(tex_BMfont5.data);
|
||||
GRRLIB_FreeBMF(bmf_Font);
|
||||
GRRLIB_FreeBMF(bmf_Font1);
|
||||
GRRLIB_FreeBMF(bmf_Font2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue