1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-28 00:39:30 +00:00

Added missing dependicies

This commit is contained in:
Reuh 2015-08-17 21:10:54 +02:00
parent 03baa21c10
commit ebcd9f00ed
47 changed files with 18405 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,141 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/3ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := sftd
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
CFLAGS := -g -Wall -O2\
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB) $(PORTLIBS) \
$(CURDIR)/../../3ds_portlibs/build \
$(CURDIR)/../../sf2dlib/libsf2d
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
$(foreach dir,$(PORTLIBS),-I$(dir)/include/freetype2) \
-I$(CURDIR)/$(BUILD)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
lib:
@[ -d $@ ] || mkdir -p $@
$(BUILD): lib
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) lib latex html
#---------------------------------------------------------------------------------
install: $(BUILD)
@cp $(OUTPUT) $(CTRULIB)/lib
@cp include/sftd.h $(CTRULIB)/include
@echo "Installed!"
#---------------------------------------------------------------------------------
else
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
%_vsh.h %.vsh.o : %.vsh
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
@bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
@rm ../$(notdir $<).shbin
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View file

@ -0,0 +1,113 @@
/**
* @file sftd.h
* @author Sergi Granell (xerpi)
* @date 2 April 2015
* @brief sftdlib header
*/
#ifndef SFTD_H
#define SFTD_H
#include <3ds.h>
#ifdef __cplusplus
extern "C" {
#endif
// Structs
/**
* @brief Represents a font
*/
typedef struct sftd_font sftd_font;
// Basic functions
/**
* @brief Initializates the library
* @return Whether the initialization has been successful or not
*/
int sftd_init();
/**
* @brief Finishes the library
* @return Whether the finalization has been successful or not
*/
int sftd_fini();
/**
* @brief Loads a font from a file
* @param filename the path to the font
* @return a pointer to the loaded font (NULL on error)
*/
sftd_font *sftd_load_font_file(const char *filename);
/**
* @brief Loads a font from memory
* @param buffer the address of the font
* @param size the size of the font buffer
* @return a pointer to the loaded font (NULL on error)
*/
sftd_font *sftd_load_font_mem(const void *buffer, unsigned int size);
/**
* @brief Frees a font
* @param font pointer to the font to freeze
*/
void sftd_free_font(sftd_font *font);
// Draw functions
/**
* @brief Draws text using a font
* @param font the font to use
* @param x the x coordinate to draw the text to
* @param y the y coordinate to draw the text to
* @param color the color to draw the font
* @param size the font size
* @param text a pointer to the text to draw
*/
void sftd_draw_text(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text);
/**
* @brief Draws formatted text using a font
* @param font the font to use
* @param x the x coordinate to draw the text to
* @param y the y coordinate to draw the text to
* @param color the color to draw the font
* @param size the font size
* @param text a pointer to the text to draw
* @param ... variable arguments
*/
void sftd_draw_textf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text, ...);
/**
* @brief Draws wide text using a font
* @param font the font to use
* @param x the x coordinate to draw the text to
* @param y the y coordinate to draw the text to
* @param color the color to draw the font
* @param size the font size
* @param text a pointer to the wide text to draw
*/
void sftd_draw_wtext(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text);
/**
* @brief Draws formatted wide text using a font
* @param font the font to use
* @param x the x coordinate to draw the text to
* @param y the y coordinate to draw the text to
* @param color the color to draw the font
* @param size the font size
* @param text a pointer to the wide text to draw
* @param ... variable arguments
*/
void sftd_draw_wtextf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text, ...);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -0,0 +1,269 @@
#include "sftd.h"
#include <wchar.h>
#include <sf2d.h>
#include <ft2build.h>
#include FT_CACHE_H
#include FT_FREETYPE_H
static int sftd_initialized = 0;
static FT_Library ftlibrary;
static FTC_Manager ftcmanager;
typedef enum {
SFTD_LOAD_FROM_FILE,
SFTD_LOAD_FROM_MEM
} sftd_font_load_from;
struct sftd_font {
sftd_font_load_from from;
union {
char *filename;
struct {
const void *font_buffer;
unsigned int buffer_size;
};
};
FTC_CMapCache cmapcache;
FTC_ImageCache imagecache;
};
static FT_Error ftc_face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face)
{
sftd_font *font = (sftd_font *)face_id;
FT_Error error = FT_Err_Cannot_Open_Resource;
if (font->from == SFTD_LOAD_FROM_FILE) {
error = FT_New_Face(
library,
font->filename,
0,
face);
} else if (font->from == SFTD_LOAD_FROM_MEM) {
error = FT_New_Memory_Face(
library,
font->font_buffer,
font->buffer_size,
0,
face);
}
return error;
}
int sftd_init()
{
if (sftd_initialized) return 2;
FT_Error error = FT_Init_FreeType(&ftlibrary);
if (error != FT_Err_Ok) {
return 0;
}
error = FTC_Manager_New(
ftlibrary,
0, /* use default */
0, /* use default */
0, /* use default */
&ftc_face_requester, /* use our requester */
NULL, /* user data */
&ftcmanager);
if (error != FT_Err_Ok) {
FT_Done_FreeType(ftlibrary);
return 0;
}
sftd_initialized = 1;
return 1;
}
int sftd_fini()
{
if (!sftd_initialized) return 2;
FT_Error error = FT_Done_FreeType(ftlibrary);
if (error != FT_Err_Ok) {
return 0;
}
FTC_Manager_Done(ftcmanager);
sftd_initialized = 0;
return 1;
}
sftd_font *sftd_load_font_file(const char *filename)
{
sftd_font *font = malloc(sizeof(*font));
size_t len = strlen(filename);
font->filename = malloc(len + 1);
strcpy(font->filename, filename);
font->filename[len] = '\0';
FTC_CMapCache_New(ftcmanager, &font->cmapcache);
FTC_ImageCache_New(ftcmanager, &font->imagecache);
font->from = SFTD_LOAD_FROM_FILE;
return font;
}
sftd_font *sftd_load_font_mem(const void *buffer, unsigned int size)
{
sftd_font *font = malloc(sizeof(*font));
font->font_buffer = buffer;
font->buffer_size = size;
FTC_CMapCache_New(ftcmanager, &font->cmapcache);
FTC_ImageCache_New(ftcmanager, &font->imagecache);
font->from = SFTD_LOAD_FROM_MEM;
return font;
}
void sftd_free_font(sftd_font *font)
{
if (font) {
FTC_FaceID face_id = (FTC_FaceID)font;
FTC_Manager_RemoveFaceID(ftcmanager, face_id);
if (font->from == SFTD_LOAD_FROM_FILE) {
free(font->filename);
}
free(font);
}
}
static void draw_bitmap(FT_Bitmap *bitmap, int x, int y, unsigned int color)
{
//This is too ugly
sf2d_texture *tex = sf2d_create_texture(bitmap->width, bitmap->rows, GPU_RGBA8, SF2D_PLACE_TEMP);
int j, k;
for (j = 0; j < bitmap->rows; j++) {
for (k = 0; k < bitmap->width; k++) {
((u32 *)tex->data)[j*tex->pow2_w + k] = __builtin_bswap32((color & ~0xFF) | bitmap->buffer[j*bitmap->width + k]);
}
}
sf2d_texture_tile32(tex);
sf2d_draw_texture(tex, x, y);
sf2d_free_texture(tex);
}
void sftd_draw_text(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text)
{
FTC_FaceID face_id = (FTC_FaceID)font;
FT_Face face;
FTC_Manager_LookupFace(ftcmanager, face_id, &face);
FT_Int charmap_index;
charmap_index = FT_Get_Charmap_Index(face->charmap);
FT_Glyph glyph;
FT_Bool use_kerning = FT_HAS_KERNING(face);
FT_UInt glyph_index, previous = 0;
int pen_x = x;
int pen_y = y;
FTC_ScalerRec scaler;
scaler.face_id = face_id;
scaler.width = size;
scaler.height = size;
scaler.pixel = 1;
FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL;
while (*text) {
glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text);
if (use_kerning && previous && glyph_index) {
FT_Vector delta;
FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
pen_x += delta.x >> 6;
}
FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL);
if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
draw_bitmap(&bitmap_glyph->bitmap, pen_x + bitmap_glyph->left + x, pen_y - bitmap_glyph->top + y, color);
pen_x += bitmap_glyph->root.advance.x >> 16;
pen_y += bitmap_glyph->root.advance.y >> 16;
}
previous = glyph_index;
text++;
}
}
void sftd_draw_textf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const char *text, ...)
{
char buffer[256];
va_list args;
va_start(args, text);
vsnprintf(buffer, 256, text, args);
sftd_draw_text(font, x, y, color, size, buffer);
va_end(args);
}
void sftd_draw_wtext(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text)
{
FTC_FaceID face_id = (FTC_FaceID)font;
FT_Face face;
FTC_Manager_LookupFace(ftcmanager, face_id, &face);
FT_Int charmap_index;
charmap_index = FT_Get_Charmap_Index(face->charmap);
FT_Glyph glyph;
FT_Bool use_kerning = FT_HAS_KERNING(face);
FT_UInt glyph_index, previous = 0;
int pen_x = x;
int pen_y = y;
FTC_ScalerRec scaler;
scaler.face_id = face_id;
scaler.width = size;
scaler.height = size;
scaler.pixel = 1;
FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL;
while (*text) {
glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text);
if (use_kerning && previous && glyph_index) {
FT_Vector delta;
FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta);
pen_x += delta.x >> 6;
}
FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL);
if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph;
draw_bitmap(&bitmap_glyph->bitmap, pen_x + bitmap_glyph->left + x, pen_y - bitmap_glyph->top + y, color);
pen_x += bitmap_glyph->root.advance.x >> 16;
pen_y += bitmap_glyph->root.advance.y >> 16;
}
previous = glyph_index;
text++;
}
}
void sftd_draw_wtextf(sftd_font *font, int x, int y, unsigned int color, unsigned int size, const wchar_t *text, ...)
{
wchar_t buffer[256];
va_list args;
va_start(args, text);
vswprintf(buffer, 256, text, args);
sftd_draw_wtext(font, x, y, color, size, buffer);
va_end(args);
}