Merge branch 'working'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 8f9be5a, 8b144eb · Browse files · 2 files·+42 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+42 added−12 removed
- other:+42 added−12 removed
Provenance
- Commit
e0dafae- Tree
2e69a3b- Author
Sean Barrett <sean2@nothings.org>- Committer
Sean Barrett <sean2@nothings.org>- Parent 1
8f9be5a- Parent 2
8b144eb
2 files changed+42 added−12 removed
modified:stb_easy_font.h+37 added-11 removed
1-// stb_easy_font.h - v0.6 - bitmap font for 3D rendering - public domain1+// stb_easy_font.h - v0.7 - bitmap font for 3D rendering - public domain2 // Sean Barrett, Feb 20153 //4 // Easy-to-deploy,5 // reasonably compact,9 unmodified lines15 //16 // DOCUMENTATION:17 //18 // int stb_easy_font_width(char *text)19+// int stb_easy_font_height(char *text)20 //20-// Takes a string without newlines and returns the horizontal size.21+// Takes a string and returns the horizontal size and the22+// vertical size (which can vary if 'text' has newlines).23 //24 // int stb_easy_font_print(float x, float y,25 // char *text, unsigned char color[4],26 // void *vertex_buffer, int vbuf_size)14 unmodified lines41 // color:uint8[4]42 //43 // You can ignore z and color if you get them from elsewhere44 // This format was chosen in the hopes it would make it43-// easier for you to reuse existing buffer-drawing code.45+// easier for you to reuse existing vertex-buffer-drawing code.46 //47 // If you pass in NULL for color, it becomes 255,255,255,255.48 //49 // Returns the number of quads.14 unmodified lines64 // characters. spacing = -1 is reasonable but feels a bit too65 // compact to me; -0.5 is a reasonable compromise as long as66 // you're scaling the font up.67 //66-// SAMPLE CODE:67-//68-// Here's sample code for old OpenGL; it's a lot more complicated69-// to make work on modern APIs, and that's your problem.70-//68 // LICENSE69 //70 // This software is in the public domain. Where that dedication is not71 // recognized, you are granted a perpetual, irrevocable license to copy,72 // distribute, and modify this file as you see fit.73 //74 // VERSION HISTORY75 //76+// (2016-01-22) 0.7 width() supports multiline text; add height()77 // (2015-09-13) 0.6 #include <math.h>; updated license78 // (2015-02-01) 0.5 First release79 80 #if 081+// SAMPLE CODE:82+//83+// Here's sample code for old OpenGL; it's a lot more complicated84+// to make work on modern APIs, and that's your problem.85+//86 void print_string(float x, float y, char *text, float r, float g, float b)87 {88 static char buffer[99999]; // ~500 chars89 int num_quads;134 unmodified lines224 225 static int stb_easy_font_width(char *text)226 {227 float len = 0;228+ float max_len = 0;229 while (*text) {230+ if (*text == '\n') {231+ if (len > max_len) max_len = len;232+ len = 0;233+ } else {226- len += stb_easy_font_charinfo[*text-32].advance & 15;227- len += stb_easy_font_spacing_val;234+ len += stb_easy_font_charinfo[*text-32].advance & 15;235+ len += stb_easy_font_spacing_val;236+ }237 ++text;238 }239+ if (len > max_len) max_len = len;230- return (int) ceil(len);240+ return (int) ceil(max_len);241 }242+243+static int stb_easy_font_height(char *text)244+{245+ float y = 0;246+ int nonempty_line=0;247+ while (*text) {248+ if (*text == '\n') {249+ y += 12;250+ nonempty_line = 0;251+ } else {252+ nonempty_line = 1;253+ }254+ ++text;255+ }256+ return (int) ceil(y + (nonempty_line ? 12 : 0));257+}258 #endifmodified:stb_image.h+5 added-1 removed
1-/* stb_image - v2.09 - public domain image loader - http://nothings.org/stb_image.h1+/* stb_image - v2.10 - public domain image loader - http://nothings.org/stb_image.h2 no warranty implied; use at your own risk3 4 Do this:5 #define STB_IMAGE_IMPLEMENTATION139 unmodified lines145 near-term back-compatibility use.146 147 148 Latest revision history:149+ 2.10 (2016-01-22) avoid warning introduced in 2.09150 2.09 (2016-01-16) 16-bit TGA; comments in PNM files; STBI_REALLOC_SIZED151 2.08 (2015-09-13) fix to 2.07 cleanup, reading RGB PSD as RGBA152 2.07 (2015-09-13) partial animated GIF support153 limited 16-bit PSD support3467 unmodified lines3621 limit = old_limit = (int) (z->zout_end - z->zout_start);3622 while (cur + n > limit)3623 limit *= 2;3624 q = (char *) STBI_REALLOC_SIZED(z->zout_start, old_limit, limit);3625+ STBI_NOTUSED(old_limit);3626 if (q == NULL) return stbi__err("outofmem", "Out of memory");3627 z->zout_start = q;3628 z->zout = q + cur;3629 z->zout_end = q + limit;781 unmodified lines4411 stbi_uc *p;4412 if (idata_limit == 0) idata_limit = c.length > 4096 ? c.length : 4096;4413 while (ioff + c.length > idata_limit)4414 idata_limit *= 2;4415+ STBI_NOTUSED(idata_limit_old);4416 p = (stbi_uc *) STBI_REALLOC_SIZED(z->idata, idata_limit_old, idata_limit); if (p == NULL) return stbi__err("outofmem", "Out of memory");4417 z->idata = p;4418 }4419 if (!stbi__getn(s, z->idata+ioff,c.length)) return stbi__err("outofdata","Corrupt PNG");2038 unmodified lines6458 #endif // STB_IMAGE_IMPLEMENTATION6459 6460 /*6461 revision history:6462+ 2.10 (2016-01-22) avoid warning introduced in 2.09 by STBI_REALLOC_SIZED6463 2.09 (2016-01-16) allow comments in PNM files6464 16-bit-per-pixel TGA (not bit-per-component)6465 info() for TGA could break due to .hdr handling6466 info() for BMP to shares code instead of sloppy parse148 unmodified lines