diff --git a/.gitignore b/.gitignore index af96791..de95591 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vscode +.vs build +x64 diff --git a/README.md b/README.md index e230af3..353b7a2 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,19 @@ Wellspring uses stb_truetype to rasterize and pack fonts quickly. Dependencies ------------ -Wellspring depends on the C runtime, but SDL2 can be optionally depended upon instead if your application prefers it. +Wellspring depends on the C runtime, but SDL2 can be optionally depended upon instead if your application prefers it by defining USE_SDL2. Building Wellspring ------------------- -For *nix platforms, use Cmake: +For *nix platforms, use CMake: $ mkdir build/ $ cd build $ cmake ../ $ make +For Windows, see the 'visualc/' directory. + License ------- Wellspring is licensed under the zlib license. See LICENSE for details. diff --git a/include/Wellspring.h b/include/Wellspring.h index bcd01ed..8b12ff7 100644 --- a/include/Wellspring.h +++ b/include/Wellspring.h @@ -142,47 +142,6 @@ WELLSPRINGAPI void Wellspring_GetBufferData( WELLSPRINGAPI void Wellspring_DestroyTextBatch(Wellspring_TextBatch *textBatch); WELLSPRINGAPI void Wellspring_DestroyPacker(Wellspring_Packer *packer); -/* Function defines */ - -#ifdef USE_SDL2 - -#define Wellspring_malloc SDL_malloc -#define Wellspring_realloc SDL_realloc -#define Wellspring_free SDL_free -#define Wellspring_memcpy SDL_memcpy -#define Wellspring_memset SDL_memset -#define Wellspring_ifloor(x) ((int) SDL_floorf(x)) -#define Wellspring_iceil(x) ((int) SDL_ceilf(x)) -#define Wellspring_sqrt SDL_sqrt -#define Wellspring_pow SDL_pow -#define Wellspring_fmod SDL_fmod -#define Wellspring_cos SDL_cos -#define Wellspring_acos SDL_acos -#define Wellspring_fabs SDL_fabs -#define Wellspring_assert SDL_assert -#define Wellspring_strlen SDL_strlen -#define Wellspring_sort SDL_qsort - -#else - -#define Wellspring_malloc malloc -#define Wellspring_realloc realloc -#define Wellspring_free free -#define Wellspring_memcpy memcpy -#define Wellspring_ifloor(x) ((int) floor(x)) -#define Wellspring_iceil(x) ((int) ceil(x)) -#define Wellspring_sqrt sqrt -#define Wellspring_pow pow -#define Wellspring_fmod fmod -#define Wellspring_cos cos -#define Wellspring_acos acos -#define Wellspring_fabs fabs -#define Wellspring_assert assert -#define Wellspring_strlen strlen -#define Wellspring_sort qsort - -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/Wellspring.c b/src/Wellspring.c index 48feeb2..1e16127 100644 --- a/src/Wellspring.c +++ b/src/Wellspring.c @@ -26,6 +26,57 @@ #include "Wellspring.h" + /* Function defines */ + +#ifdef USE_SDL2 + +#define Wellspring_malloc SDL_malloc +#define Wellspring_realloc SDL_realloc +#define Wellspring_free SDL_free +#define Wellspring_memcpy SDL_memcpy +#define Wellspring_memset SDL_memset +#define Wellspring_ifloor(x) ((int) SDL_floorf(x)) +#define Wellspring_iceil(x) ((int) SDL_ceilf(x)) +#define Wellspring_sqrt SDL_sqrt +#define Wellspring_pow SDL_pow +#define Wellspring_fmod SDL_fmod +#define Wellspring_cos SDL_cos +#define Wellspring_acos SDL_acos +#define Wellspring_fabs SDL_fabs +#define Wellspring_assert SDL_assert +#define Wellspring_strlen SDL_strlen +#define Wellspring_sort SDL_qsort + +#else + +#ifdef _MSC_VER + +#include +#include +#include +#include +#include +#endif + +#define Wellspring_malloc malloc +#define Wellspring_realloc realloc +#define Wellspring_free free +#define Wellspring_memcpy memcpy +#define Wellspring_memset memset +#define Wellspring_ifloor(x) ((int) floor(x)) +#define Wellspring_iceil(x) ((int) ceil(x)) +#define Wellspring_sqrt sqrt +#define Wellspring_pow pow +#define Wellspring_fmod fmod +#define Wellspring_cos cos +#define Wellspring_acos acos +#define Wellspring_fabs fabs +#define Wellspring_assert assert +#define Wellspring_strlen strlen +#define Wellspring_sort qsort + +#endif + #define STBTT_malloc(x,u) ((void)(u),Wellspring_malloc(x)) #define STBTT_free(x,u) ((void)(u),Wellspring_free(x)) #define STBTT_memcpy Wellspring_memcpy @@ -70,7 +121,7 @@ typedef int32_t stbtt_int32; typedef struct CharRange { stbtt_packedchar *data; - int32_t firstCodepoint; + uint32_t firstCodepoint; uint32_t charCount; } CharRange; @@ -183,14 +234,14 @@ uint32_t Wellspring_PackFontRanges( ) { Packer *myPacker = (Packer*) packer; Wellspring_FontRange *currentFontRange; - stbtt_pack_range stbPackRanges[numRanges]; + stbtt_pack_range* stbPackRanges = Wellspring_malloc(sizeof(stbtt_pack_range) * numRanges); CharRange *currentCharRange; uint32_t i; for (i = 0; i < numRanges; i += 1) { currentFontRange = &ranges[i]; - stbPackRanges[i].font_size = currentFontRange->fontSize; + stbPackRanges[i].font_size = (float) currentFontRange->fontSize; stbPackRanges[i].first_unicode_codepoint_in_range = currentFontRange->firstCodepoint; stbPackRanges[i].array_of_unicode_codepoints = NULL; stbPackRanges[i].num_chars = currentFontRange->numChars; diff --git a/visualc/Wellspring.sln b/visualc/Wellspring.sln new file mode 100644 index 0000000..cb45ad7 --- /dev/null +++ b/visualc/Wellspring.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Wellspring", "Wellspring.vcxproj", "{6DB15344-E000-45CB-A48A-1D72F7D6E945}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + MinSizeRel|x64 = MinSizeRel|x64 + Release|x64 = Release|x64 + RelWithDebInfo|x64 = RelWithDebInfo|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.ActiveCfg = Debug|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Debug|x64.Build.0 = Debug|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.ActiveCfg = Release|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.Release|x64.Build.0 = Release|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {6DB15344-E000-45CB-A48A-1D72F7D6E945}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7B2DB465-0A55-3811-9EF4-A520B47653D2} + EndGlobalSection +EndGlobal diff --git a/visualc/Wellspring.vcxproj b/visualc/Wellspring.vcxproj new file mode 100644 index 0000000..1fbcb58 --- /dev/null +++ b/visualc/Wellspring.vcxproj @@ -0,0 +1,84 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {6DB15344-E000-45CB-A48A-1D72F7D6E945} + FNA3D + + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + false + true + MultiByte + + + v142 + + + v142 + + + + + + + + + + ..\lib\;..\..\SDL2\include;..\include;$(IncludePath) + ..\..\SDL2\lib\$(PlatformShortName);$(LibraryPath) + + + + Level3 + Disabled + USE_SDL2;%(PreprocessorDefinitions) + + + DebugFull + SDL2.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + USE_SDL2;%(PreprocessorDefinitions) + true + true + + + true + true + SDL2.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/visualc/Wellspring.vcxproj.user b/visualc/Wellspring.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/visualc/Wellspring.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file