Ejemplo n.º 1
0
GBitmap* gbitmap_create_with_resource (uint32_t resource_id) {
    printf ("[DEBUG] Load resource ID:%d as image\n",resource_id);
    char name[MAX_RESOURCE_NAME];
    copyResName(name,resource_id);
    FILE* f=fopen(name,"rb");
    if (!f) {
        printf("[ERROR] Couldn't load \"%s\"(%s)!\n",name,SDL_GetError());
        return 0;
    }
    fseek(f,0,SEEK_END);
    size_t len=ftell(f);
    fseek(f,0,SEEK_SET);
    void* data=malloc(len);
    if (!data) {
        printf("[ERROR] Couldn't load \"%s\"(Memory allocation failed)!\n",name);
        return 0;
    }
    size_t readLen=fread(data,1,len,f);
    fclose(f);
    if (len!=readLen) {
        printf ("[ERROR] Read error!\n");
        free(data);
        return 0;
    }
    return gbitmap_create_with_data (data);
}
Ejemplo n.º 2
0
void* gbitmap_init_from_resource (GBitmap* bitmap,int resource_id) {
    printf ("[DEBUG] Load resource ID:%d as image\n",resource_id);
    char name[MAX_RESOURCE_NAME];
    copyResName(name,resource_id);
    FILE* f=fopen(name,"rb");
    if (!f) {
        printf("[ERROR] Couldn't load \"%s\"(%s)!\n",name,SDL_GetError());
        return 0;
    }
    fseek(f,0,SEEK_END);
    size_t len=ftell(f);
    fseek(f,0,SEEK_SET);
    void* data=malloc(len);
    if (!data) {
        printf("[ERROR] Couldn't load \"%s\"(Memory allocation failed)!\n",name);
        return 0;
    }
    fread(data,1,len,f);
    gbitmap_init_with_data (bitmap,data);
    return data;
}
Ejemplo n.º 3
0
GFont fonts_load_custom_font(ResHandle res) {
    char name[MAX_RESOURCE_NAME];
    copyResName(name,(int)res);
    FILE* f=fopen (name,"rb");
    if (!f) {
        printf ("[WARN] Couldn't load custom font!\n");
        return 0;
    }
    int height;
    if (fread(&height,1,sizeof(int),f)==0) {
        printf ("[WARN] Couldn't read custom font height!\n");
        return 0;
    }
    fclose(f);
    strcat(name,"_f");
    TTF_Font* font=TTF_OpenFont (name,height);
    if (!font) {
        printf ("[WARN] Couldn't load custom font (\"%s\",%d,%s)!\n",name,height,TTF_GetError());
        return 0;
    }
    return (GFont)font;
}