WIP on moving emgui into rocket subdir

This commit is contained in:
Daniel Collin 2013-01-07 08:19:44 +01:00
parent 5371921900
commit 7a6f085965
20 changed files with 11385 additions and 0 deletions

View File

@ -0,0 +1,182 @@
#ifndef EMGUI_H_
#define EMGUI_H_
#include "Types.h"
#include "FontLayout.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiSliderDirection
{
EMGUI_SLIDERDIR_HORIZONTAL,
EMGUI_SLIDERDIR_VERTICAL,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiSpecialKey
{
EMGUI_KEY_ARROW_DOWN = 0x100,
EMGUI_KEY_ARROW_UP,
EMGUI_KEY_ARROW_RIGHT,
EMGUI_KEY_ARROW_LEFT,
EMGUI_KEY_ESC,
EMGUI_KEY_TAB,
EMGUI_KEY_BACKSPACE,
EMGUI_KEY_ENTER,
EMGUI_KEY_SPACE,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiKeyModifier
{
EMGUI_KEY_WIN = 1, // windows key on Windows
EMGUI_KEY_COMMAND = 1, // Command key on Mac OS X
EMGUI_KEY_ALT = 2,
EMGUI_KEY_CTRL = 4,
EMGUI_KEY_SHIFT = 8,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiMemoryLocation
{
EMGUI_LOCATION_MEMORY,
EMGUI_LOCATION_FILE,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define EMGUI_COLOR32(r, g, b, a) (unsigned int)((a << 24) | (b << 16) | (g << 8) | r)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
return (a << 24) | (b << 16) | (g << 8) | r;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getR(uint32_t color)
{
return color & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getG(uint32_t color)
{
return (color >> 8) & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getB(uint32_t color)
{
return (color >> 16) & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Creation and state changes the application needs to call
bool Emgui_create();
void Emgui_destroy();
void Emgui_setMousePos(int posX, int posY);
void Emgui_setMouseLmb(int state);
void Emgui_begin();
void Emgui_end();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Emgui_beginVerticalPanelXY(int x, int y);
void Emgui_beginHorizontalPanelXY(int x, int y);
void Emgui_beginVerticalPanel();
void Emgui_beginHorizontalPanel();
void Emgui_setLayer(int layer);
void Emgui_setScissor(int x, int y, int w, int h);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Font functions
void Emgui_setFont(uint32_t fontId);
void Emgui_setDefaultFont();
bool Emgui_setFontByName(const char* ttfFontname);
int Emgui_loadFontTTF(const char* ttfFontname, float fontHeight);
int Emgui_loadFontBitmap(const char* buffer, int len, enum EmguiMemoryLocation location,
int rangeStart, int rangeEnd, EmguiFontLayout* layout);
uint32_t Emgui_getTextSize(const char* text);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EditBox controlls
void Emgui_editBoxXY(int x, int y, int width, int height, int bufferLength, char* buffer);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Different controlls and gui functions
void Emgui_sendKeyinput(int keyCode, int modifier);
void Emgui_textLabel(const char* text);
void Emgui_drawLine(uint32_t color, int x0, int y0, int x1, int y1);
void Emgui_drawText(const char* text, int x, int y, uint32_t color);
void Emgui_drawTextFlipped(const char* text, int x, int y, uint32_t color);
void Emgui_staticImage(const char* filename);
void Emgui_fill(uint32_t color, int x, int y, int w, int h);
void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h);
void Emgui_drawBorder(uint32_t color0, uint32_t color1, int x, int y, int w, int h);
void Emgui_drawDots(uint32_t color, int* coords, int count);
void Emgui_textLabelXY(const char* text, int x, int y);
bool Emgui_slider(int x, int y, int w, int h, int start, int end, int largeVal,
enum EmguiSliderDirection dir, int itemSpace, int* value);
bool Emgui_buttonCoords(const char* text, uint32_t color, int x, int y, int width, int height);
bool Emgui_buttonCoordsImage(const char* text, int x, int y);
bool Emgui_button(const char* text);
bool Emgui_buttonImage(const char* filename);
void Emgui_setFirstControlFocus();
bool Emgui_hasKeyboardFocus();
void Emgui_radioButtonImage(void* image0, int size0, void* image1, int size1, enum EmguiMemoryLocation location,
uint32_t color, int x, int y, bool* stateIn);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper functions
static EMGUI_INLINE int emini(int a, int b)
{
if (a < b)
return a;
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE int emaxi(int a, int b)
{
if (a > b)
return a;
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE int eclampi(int v, int low, int high)
{
return emini(high, emaxi(v, low));
}
#endif // EMGUI_H_

View File

@ -0,0 +1,15 @@
#ifndef EMGFXBACKEND_H_
#define EMGFXBACKEND_H_
#include "Types.h"
bool EMGFXBackend_create();
bool EMGFXBackend_destroy();
void EMGFXBackend_updateViewPort(int width, int height);
void EMGFXBackend_render();
uint64_t EMGFXBackend_createFontTexture(void* imageBuffer, int w, int h);
uint64_t EMGFXBackend_createTexture(void* imageBuffer, int w, int h, int comp);
#endif

View File

@ -0,0 +1,95 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EMGUITYPES_H
#define EMGUITYPES_H
#include <stddef.h>
typedef unsigned int uint;
#if defined(_WIN32)
#if defined(__GNUC__)
#include <stdint.h>
#else
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned __int64 uint64_t;
typedef signed __int64 int64_t;
typedef unsigned char bool;
typedef wchar_t text_t;
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#pragma warning(disable: 4100 4127 4201 4706)
#endif
#define EMGUI_LIKELY(exp) exp
#define EMGUI_UNLIKELY(exp) exp
#define EMGUI_INLINE __forceinline
#define EMGUI_RESTRICT __restrict
#define EMGUI_ALIGN(x) __declspec(align(x))
#define EMGUI_UNCACHEDAC_PTR(x) x
#define EMGUI_UNCACHED_PTR(x) x
#define EMGUI_CACHED_PTR(x) x
#define EMGUI_ALIGNOF(t) __alignof(t)
#define EMGUI_BREAK __debugbreak()
#if defined(_WIN64)
#define EMGUI_X64
#endif
#elif defined(EMGUI_UNIX) || defined(EMGUI_MACOSX)
#include <stdint.h>
#define EMGUI_LIKELY(exp) __builtin_expect(exp, 1)
#define EMGUI_UNLIKELY(exp) __builtin_expect(exp, 0)
#define EMGUI_INLINE inline
#define EMGUI_RESTRICT __restrict
#define EMGUI_ALIGN(x) __attribute__((aligned(x)))
#define EMGUI_UNCACHEDAC_PTR(x) x
#define EMGUI_UNCACHED_PTR(x) x
#define EMGUI_CACHED_PTR(x) x
#define EMGUI_ALIGNOF(t) __alignof__(t)
#define EMGUI_BREAK ((*(volatile uint32_t *)(0)) = 0x666)
typedef char text_t;
#include <stdbool.h>
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#if defined(__LP64__)
#define EMGUI_X64
#endif
#else
#error Platform not supported
#endif
#define sizeof_array(array) (int)(sizeof(array) / sizeof(array[0]))
#endif

1104
ogl_editor/emgui/src/Emgui.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,182 @@
#ifndef EMGUI_H_
#define EMGUI_H_
#include "Types.h"
#include "FontLayout.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiSliderDirection
{
EMGUI_SLIDERDIR_HORIZONTAL,
EMGUI_SLIDERDIR_VERTICAL,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiSpecialKey
{
EMGUI_KEY_ARROW_DOWN = 0x100,
EMGUI_KEY_ARROW_UP,
EMGUI_KEY_ARROW_RIGHT,
EMGUI_KEY_ARROW_LEFT,
EMGUI_KEY_ESC,
EMGUI_KEY_TAB,
EMGUI_KEY_BACKSPACE,
EMGUI_KEY_ENTER,
EMGUI_KEY_SPACE,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiKeyModifier
{
EMGUI_KEY_WIN = 1, // windows key on Windows
EMGUI_KEY_COMMAND = 1, // Command key on Mac OS X
EMGUI_KEY_ALT = 2,
EMGUI_KEY_CTRL = 4,
EMGUI_KEY_SHIFT = 8,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiMemoryLocation
{
EMGUI_LOCATION_MEMORY,
EMGUI_LOCATION_FILE,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define EMGUI_COLOR32(r, g, b, a) (unsigned int)((a << 24) | (b << 16) | (g << 8) | r)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
return (a << 24) | (b << 16) | (g << 8) | r;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getR(uint32_t color)
{
return color & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getG(uint32_t color)
{
return (color >> 8) & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE uint32_t Emgui_color32_getB(uint32_t color)
{
return (color >> 16) & 0xff;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Creation and state changes the application needs to call
bool Emgui_create();
void Emgui_destroy();
void Emgui_setMousePos(int posX, int posY);
void Emgui_setMouseLmb(int state);
void Emgui_begin();
void Emgui_end();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Emgui_beginVerticalPanelXY(int x, int y);
void Emgui_beginHorizontalPanelXY(int x, int y);
void Emgui_beginVerticalPanel();
void Emgui_beginHorizontalPanel();
void Emgui_setLayer(int layer);
void Emgui_setScissor(int x, int y, int w, int h);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Font functions
void Emgui_setFont(uint32_t fontId);
void Emgui_setDefaultFont();
bool Emgui_setFontByName(const char* ttfFontname);
int Emgui_loadFontTTF(const char* ttfFontname, float fontHeight);
int Emgui_loadFontBitmap(const char* buffer, int len, enum EmguiMemoryLocation location,
int rangeStart, int rangeEnd, EmguiFontLayout* layout);
uint32_t Emgui_getTextSize(const char* text);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// EditBox controlls
void Emgui_editBoxXY(int x, int y, int width, int height, int bufferLength, char* buffer);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Different controlls and gui functions
void Emgui_sendKeyinput(int keyCode, int modifier);
void Emgui_textLabel(const char* text);
void Emgui_drawLine(uint32_t color, int x0, int y0, int x1, int y1);
void Emgui_drawText(const char* text, int x, int y, uint32_t color);
void Emgui_drawTextFlipped(const char* text, int x, int y, uint32_t color);
void Emgui_staticImage(const char* filename);
void Emgui_fill(uint32_t color, int x, int y, int w, int h);
void Emgui_fillGrad(uint32_t color0, uint32_t color1, int x, int y, int w, int h);
void Emgui_drawBorder(uint32_t color0, uint32_t color1, int x, int y, int w, int h);
void Emgui_drawDots(uint32_t color, int* coords, int count);
void Emgui_textLabelXY(const char* text, int x, int y);
bool Emgui_slider(int x, int y, int w, int h, int start, int end, int largeVal,
enum EmguiSliderDirection dir, int itemSpace, int* value);
bool Emgui_buttonCoords(const char* text, uint32_t color, int x, int y, int width, int height);
bool Emgui_buttonCoordsImage(const char* text, int x, int y);
bool Emgui_button(const char* text);
bool Emgui_buttonImage(const char* filename);
void Emgui_setFirstControlFocus();
bool Emgui_hasKeyboardFocus();
void Emgui_radioButtonImage(void* image0, int size0, void* image1, int size1, enum EmguiMemoryLocation location,
uint32_t color, int x, int y, bool* stateIn);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper functions
static EMGUI_INLINE int emini(int a, int b)
{
if (a < b)
return a;
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE int emaxi(int a, int b)
{
if (a > b)
return a;
return b;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE int eclampi(int v, int low, int high)
{
return emini(high, emaxi(v, low));
}
#endif // EMGUI_H_

View File

@ -0,0 +1,152 @@
#ifndef EMGUI_INTERNAL_H_
#define EMGUI_INTERNAL_H_
#include "Types.h"
#include "emgui_internal.h"
#include "FontLayout.h"
#include "External/stb_truetype.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum EmguiDrawType
{
EMGUI_DRAWTYPE_NONE,
EMGUI_DRAWTYPE_FILL,
EMGUI_DRAWTYPE_IMAGE,
EMGUI_DRAWTYPE_TEXT,
EMGUI_DRAWTYPE_SLIDER,
EMGUI_DRAWTYPE_DOTS,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct EmguiControlInfo
{
enum EmguiDrawType type;
int x;
int y;
int width;
int height;
uint32_t color;
uint32_t color1;
char* text;
// todo: Use union with all data instead
int sliderThumbX;
int sliderThumbY;
int sliderThumbWidth;
int sliderThumbHeight;
int fontId;
int* dots;
int dotsCount;
} EmguiControlInfo;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum
{
EMGUI_MAX_FONTS = 16,
EMGUI_LAYER_COUNT = 8,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct DrawTextCommand
{
struct DrawTextCommand* next;
char* text;
int x;
int y;
uint32_t color;
bool flipped;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct DrawFillCommand
{
struct DrawFillCommand* next;
uint32_t color0;
uint32_t color1;
int x;
int y;
int width;
int height;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct DrawImageCommand
{
struct DrawImageCommand* next;
int64_t imageId;
uint32_t color;
int x;
int y;
int width;
int height;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct Scissor
{
int x, y, width, height;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct DrawLayer
{
struct Scissor scissor;
struct DrawTextCommand* textCommands[EMGUI_MAX_FONTS];
struct DrawImageCommand* imageCommands;
struct DrawImageCommand* imageCommandsTail;
struct DrawFillCommand* fillCommands;
struct DrawFillCommand* fillCommandsTail;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct RenderData
{
struct DrawLayer layers[EMGUI_LAYER_COUNT];
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct LoadedFont
{
stbtt_bakedchar cData[96];
uint64_t handle;
char name[1024];
int rangeStart;
int rangeEnd;
uint16_t width;
uint16_t height;
unsigned short* altLookup;
EmguiFontLayout* layout;
} LoadedFont;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum
{
MAX_CONTROLS = 8192,
MAX_FONTS = 32,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern uint32_t g_controlId;
extern EmguiControlInfo g_controls[MAX_CONTROLS];
extern LoadedFont g_loadedFonts[MAX_FONTS];
extern uint32_t g_currentFont;
#endif

4407
ogl_editor/emgui/src/External/stb_image.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,269 @@
#ifndef STBI_INCLUDE_STB_IMAGE_H
#define STBI_INCLUDE_STB_IMAGE_H
// To get a header file for this, either cut and paste the header,
// or create stb_image.h, #define STBI_HEADER_FILE_ONLY, and
// then include stb_image.c from it.
//// begin header file ////////////////////////////////////////////////////
//
// Limitations:
// - no jpeg progressive support
// - non-HDR formats support 8-bit samples only (jpeg, png)
// - no delayed line count (jpeg) -- IJG doesn't support either
// - no 1-bit BMP
// - GIF always returns *comp=4
//
// Basic usage (see HDR discussion below):
// int x,y,n;
// unsigned char *data = stbi_load(filename, &x, &y, &n, 0);
// // ... process data if not NULL ...
// // ... x = width, y = height, n = # 8-bit components per pixel ...
// // ... replace '0' with '1'..'4' to force that many components per pixel
// // ... but 'n' will always be the number that it would have been if you said 0
// stbi_image_free(data)
//
// Standard parameters:
// int *x -- outputs image width in pixels
// int *y -- outputs image height in pixels
// int *comp -- outputs # of image components in image file
// int req_comp -- if non-zero, # of image components requested in result
//
// The return value from an image loader is an 'unsigned char *' which points
// to the pixel data. The pixel data consists of *y scanlines of *x pixels,
// with each pixel consisting of N interleaved 8-bit components; the first
// pixel pointed to is top-left-most in the image. There is no padding between
// image scanlines or between pixels, regardless of format. The number of
// components N is 'req_comp' if req_comp is non-zero, or *comp otherwise.
// If req_comp is non-zero, *comp has the number of components that _would_
// have been output otherwise. E.g. if you set req_comp to 4, you will always
// get RGBA output, but you can check *comp to easily see if it's opaque.
//
// An output image with N components has the following components interleaved
// in this order in each pixel:
//
// N=#comp components
// 1 grey
// 2 grey, alpha
// 3 red, green, blue
// 4 red, green, blue, alpha
//
// If image loading fails for any reason, the return value will be NULL,
// and *x, *y, *comp will be unchanged. The function stbi_failure_reason()
// can be queried for an extremely brief, end-user unfriendly explanation
// of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid
// compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly
// more user-friendly ones.
//
// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
//
// ===========================================================================
//
// iPhone PNG support:
//
// By default we convert iphone-formatted PNGs back to RGB; nominally they
// would silently load as BGR, except the existing code should have just
// failed on such iPhone PNGs. But you can disable this conversion by
// by calling stbi_convert_iphone_png_to_rgb(0), in which case
// you will always just get the native iphone "format" through.
//
// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
// pixel to remove any premultiplied alpha *only* if the image file explicitly
// says there's premultiplied data (currently only happens in iPhone images,
// and only if iPhone convert-to-rgb processing is on).
//
// ===========================================================================
//
// HDR image support (disable by defining STBI_NO_HDR)
//
// stb_image now supports loading HDR images in general, and currently
// the Radiance .HDR file format, although the support is provided
// generically. You can still load any file through the existing interface;
// if you attempt to load an HDR file, it will be automatically remapped to
// LDR, assuming gamma 2.2 and an arbitrary scale factor defaulting to 1;
// both of these constants can be reconfigured through this interface:
//
// stbi_hdr_to_ldr_gamma(2.2f);
// stbi_hdr_to_ldr_scale(1.0f);
//
// (note, do not use _inverse_ constants; stbi_image will invert them
// appropriately).
//
// Additionally, there is a new, parallel interface for loading files as
// (linear) floats to preserve the full dynamic range:
//
// float *data = stbi_loadf(filename, &x, &y, &n, 0);
//
// If you load LDR images through this interface, those images will
// be promoted to floating point values, run through the inverse of
// constants corresponding to the above:
//
// stbi_ldr_to_hdr_scale(1.0f);
// stbi_ldr_to_hdr_gamma(2.2f);
//
// Finally, given a filename (or an open file or memory block--see header
// file for details) containing image data, you can query for the "most
// appropriate" interface to use (that is, whether the image is HDR or
// not), using:
//
// stbi_is_hdr(char *filename);
//
// ===========================================================================
//
// I/O callbacks
//
// I/O callbacks allow you to read from arbitrary sources, like packaged
// files or some other source. Data read from callbacks are processed
// through a small internal buffer (currently 128 bytes) to try to reduce
// overhead.
//
// The three functions you must define are "read" (reads some bytes of data),
// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end).
#ifndef STBI_NO_STDIO
#if defined(_MSC_VER) && _MSC_VER >= 0x1400
#define _CRT_SECURE_NO_WARNINGS // suppress bogus warnings about fopen()
#endif
#include <stdio.h>
#endif
#define STBI_VERSION 1
enum
{
STBI_default = 0, // only used for req_comp
STBI_grey = 1,
STBI_grey_alpha = 2,
STBI_rgb = 3,
STBI_rgb_alpha = 4
};
typedef unsigned char stbi_uc;
#ifdef __cplusplus
extern "C" {
#endif
//////////////////////////////////////////////////////////////////////////////
//
// PRIMARY API - works on images of any type
//
//
// load image by filename, open file, or memory buffer
//
extern stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
#ifndef STBI_NO_STDIO
extern stbi_uc *stbi_load (char const *filename, int *x, int *y, int *comp, int req_comp);
extern stbi_uc *stbi_load_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
// for stbi_load_from_file, file pointer is left pointing immediately after image
#endif
typedef struct
{
int (*read) (void *user,char *data,int size); // fill 'data' with 'size' bytes. return number of bytes actually read
void (*skip) (void *user,unsigned n); // skip the next 'n' bytes
int (*eof) (void *user); // returns nonzero if we are at end of file/data
} stbi_io_callbacks;
extern stbi_uc *stbi_load_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
#ifndef STBI_NO_HDR
extern float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp);
#ifndef STBI_NO_STDIO
extern float *stbi_loadf (char const *filename, int *x, int *y, int *comp, int req_comp);
extern float *stbi_loadf_from_file (FILE *f, int *x, int *y, int *comp, int req_comp);
#endif
extern float *stbi_loadf_from_callbacks (stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp);
extern void stbi_hdr_to_ldr_gamma(float gamma);
extern void stbi_hdr_to_ldr_scale(float scale);
extern void stbi_ldr_to_hdr_gamma(float gamma);
extern void stbi_ldr_to_hdr_scale(float scale);
#endif // STBI_NO_HDR
// stbi_is_hdr is always defined
extern int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user);
extern int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len);
#ifndef STBI_NO_STDIO
extern int stbi_is_hdr (char const *filename);
extern int stbi_is_hdr_from_file(FILE *f);
#endif // STBI_NO_STDIO
// get a VERY brief reason for failure
// NOT THREADSAFE
extern const char *stbi_failure_reason (void);
// free the loaded image -- this is just free()
extern void stbi_image_free (void *retval_from_stbi_load);
// get image dimensions & components without fully decoding
extern int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp);
extern int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp);
#ifndef STBI_NO_STDIO
extern int stbi_info (char const *filename, int *x, int *y, int *comp);
extern int stbi_info_from_file (FILE *f, int *x, int *y, int *comp);
#endif
// for image formats that explicitly notate that they have premultiplied alpha,
// we just return the colors as stored in the file. set this flag to force
// unpremultiplication. results are undefined if the unpremultiply overflow.
extern void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply);
// indicate whether we should process iphone images back to canonical format,
// or just pass them through "as-is"
extern void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert);
// ZLIB client - used by PNG, available for other purposes
extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen);
extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen);
extern int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen);
extern int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen);
// define faster low-level operations (typically SIMD support)
#ifdef STBI_SIMD
typedef void (*stbi_idct_8x8)(stbi_uc *out, int out_stride, short data[64], unsigned short *dequantize);
// compute an integer IDCT on "input"
// input[x] = data[x] * dequantize[x]
// write results to 'out': 64 samples, each run of 8 spaced by 'out_stride'
// CLAMP results to 0..255
typedef void (*stbi_YCbCr_to_RGB_run)(stbi_uc *output, stbi_uc const *y, stbi_uc const *cb, stbi_uc const *cr, int count, int step);
// compute a conversion from YCbCr to RGB
// 'count' pixels
// write pixels to 'output'; each pixel is 'step' bytes (either 3 or 4; if 4, write '255' as 4th), order R,G,B
// y: Y input channel
// cb: Cb input channel; scale/biased to be 0..255
// cr: Cr input channel; scale/biased to be 0..255
extern void stbi_install_idct(stbi_idct_8x8 func);
extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func);
#endif // STBI_SIMD
#ifdef __cplusplus
}
#endif
//
//
//// end header file /////////////////////////////////////////////////////
#endif // STBI_INCLUDE_STB_IMAGE_H

View File

@ -0,0 +1,656 @@
// stb_truetype.h - v0.5 - public domain - 2009 Sean Barrett / RAD Game Tools
//
// This library processes TrueType files:
// parse files
// extract glyph metrics
// extract glyph shapes
// render glyphs to one-channel bitmaps with antialiasing (box filter)
//
// Todo:
// non-MS cmaps
// crashproof on bad data
// hinting? (no longer patented)
// cleartype-style AA?
// optimize: use simple memory allocator for intermediates
// optimize: build edge-list directly from curves
// optimize: rasterize directly from curves?
//
// ADDITIONAL CONTRIBUTORS
//
// Mikko Mononen: compound shape support, more cmap formats
// Tor Andersson: kerning, subpixel rendering
//
// Bug/warning reports:
// "Zer" on mollyrocket (with fix)
// Cass Everitt
// stoiko (Haemimont Games)
// Brian Hook
// Walter van Niftrik
//
// VERSION HISTORY
//
// 0.5 (2011-12-09) bugfixes:
// subpixel glyph renderer computed wrong bounding box
// first vertex of shape can be off-curve (FreeSans)
// 0.4b(2011-12-03) fixed an error in the font baking example
// 0.4 (2011-12-01) kerning, subpixel rendering (tor)
// bugfixes for:
// codepoint-to-glyph conversion using table fmt=12
// codepoint-to-glyph conversion using table fmt=4
// stbtt_GetBakedQuad with non-square texture (Zer)
// updated Hello World! sample to use kerning and subpixel
// fixed some warnings
// 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM)
// userdata, malloc-from-userdata, non-zero fill (STB)
// 0.2 (2009-03-11) Fix unsigned/signed char warnings
// 0.1 (2009-03-09) First public release
//
// USAGE
//
// Include this file in whatever places neeed to refer to it. In ONE C/C++
// file, write:
// #define STB_TRUETYPE_IMPLEMENTATION
// before the #include of this file. This expands out the actual
// implementation into that C/C++ file.
//
// Look at the header-file sections below for the API, but here's a quick skim:
//
// Simple 3D API (don't ship this, but it's fine for tools and quick start,
// and you can cut and paste from it to move to more advanced)
// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture
// stbtt_GetBakedQuad() -- compute quad to draw for a given char
//
// "Load" a font file from a memory buffer (you have to keep the buffer loaded)
// stbtt_InitFont()
// stbtt_GetFontOffsetForIndex() -- use for TTC font collections
//
// Render a unicode codepoint to a bitmap
// stbtt_GetCodepointBitmap() -- allocates and returns a bitmap
// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide
// stbtt_GetCodepointBitmapBox() -- how big the bitmap must be
//
// Character advance/positioning
// stbtt_GetCodepointHMetrics()
// stbtt_GetFontVMetrics()
// stbtt_GetCodepointKernAdvance()
//
// ADVANCED USAGE
//
// Quality:
//
// - Use the functions with Subpixel at the end to allow your characters
// to have subpixel positioning. Since the font is anti-aliased, not
// hinted, this is very import for quality.
//
// - Kerning is now supported, and if you're supporting subpixel rendering
// then kerning is worth using to give your text a polished look.
//
// Performance:
//
// - Convert Unicode codepoints to "glyphs" and operate on the glyphs; if
// you don't do this, stb_truetype is forced to do the conversion on
// every call.
//
// - There are a lot of memory allocations. We should modify it to take
// a temp buffer and allocate from the temp buffer (without freeing),
// should help performance a lot.
//
// NOTES
//
// The system uses the raw data found in the .ttf file without changing it
// and without building auxiliary data structures. This is a bit inefficient
// on little-endian systems (the data is big-endian), but assuming you're
// caching the bitmaps or glyph shapes this shouldn't be a big deal.
//
// It appears to be very hard to programmatically determine what font a
// given file is in a general way. I provide an API for this, but I don't
// recommend it.
//
//
// SOURCE STATISTICS (based on v0.5, 1980 LOC)
//
// Documentation & header file 450 LOC \___ 550 LOC documentation
// Sample code 140 LOC /
// Truetype parsing 590 LOC ---- 600 LOC TrueType
// Software rasterization 240 LOC \ .
// Curve tesselation 120 LOC \__ 550 LOC Bitmap creation
// Bitmap management 100 LOC /
// Baked bitmap interface 70 LOC /
// Font name matching & access 150 LOC ---- 150
// C runtime library abstraction 60 LOC ---- 60
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// SAMPLE PROGRAMS
////
//
// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless
//
#if 0
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
#include "stb_truetype.h"
char ttf_buffer[1<<20];
unsigned char temp_bitmap[512*512];
stbtt_bakedchar cdata[96]; // ASCII 32..126 is 95 glyphs
GLstbtt_uint ftex;
void my_stbtt_initfont(void)
{
fread(ttf_buffer, 1, 1<<20, fopen("c:/windows/fonts/times.ttf", "rb"));
stbtt_BakeFontBitmap(data,0, 32.0, temp_bitmap,512,512, 32,96, cdata); // no guarantee this fits!
// can free ttf_buffer at this point
glGenTextures(1, &ftex);
glBindTexture(GL_TEXTURE_2D, ftex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 512,512, 0, GL_ALPHA, GL_UNSIGNED_BYTE, temp_bitmap);
// can free temp_bitmap at this point
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
void my_stbtt_print(float x, float y, char *text)
{
// assume orthographic projection with units = screen pixels, origin at top left
glBindTexture(GL_TEXTURE_2D, ftex);
glBegin(GL_QUADS);
while (*text) {
if (*text >= 32 && *text < 128) {
stbtt_aligned_quad q;
stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl,0=old d3d
glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0);
glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0);
glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1);
glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y1);
}
++text;
}
glEnd();
}
#endif
//
//
//////////////////////////////////////////////////////////////////////////////
//
// Complete program (this compiles): get a single bitmap, print as ASCII art
//
#if 0
#include <stdio.h>
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
#include "stb_truetype.h"
char ttf_buffer[1<<25];
int main(int argc, char **argv)
{
stbtt_fontinfo font;
unsigned char *bitmap;
int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20);
fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb"));
stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0));
bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0);
for (j=0; j < h; ++j) {
for (i=0; i < w; ++i)
putchar(" .:ioVM@"[bitmap[j*w+i]>>5]);
putchar('\n');
}
return 0;
}
#endif
//
// Output:
//
// .ii.
// @@@@@@.
// V@Mio@@o
// :i. V@V
// :oM@@M
// :@@@MM@M
// @@o o@M
// :@@. M@M
// @@@o@@@@
// :M@@V:@@.
//
//////////////////////////////////////////////////////////////////////////////
//
// Complete program: print "Hello World!" banner, with bugs
//
#if 0
char buffer[24<<20];
unsigned char screen[20][79];
int main(int arg, char **argv)
{
stbtt_fontinfo font;
int i,j,ascent,baseline,ch=0;
float scale, xpos=0;
char *text = "Heljo World!";
fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb"));
stbtt_InitFont(&font, buffer, 0);
scale = stbtt_ScaleForPixelHeight(&font, 15);
stbtt_GetFontVMetrics(&font, &ascent,0,0);
baseline = (int) (ascent*scale);
while (text[ch]) {
int advance,lsb,x0,y0,x1,y1;
float x_shift = xpos - (float) floor(xpos);
stbtt_GetCodepointHMetrics(&font, text[ch], &advance, &lsb);
stbtt_GetCodepointBitmapBoxSubpixel(&font, text[ch], scale,scale,x_shift,0, &x0,&y0,&x1,&y1);
stbtt_MakeCodepointBitmapSubpixel(&font, &screen[baseline + y0][(int) xpos + x0], x1-x0,y1-y0, 79, scale,scale,x_shift,0, text[ch]);
// note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong
// because this API is really for baking character bitmaps into textures. if you want to do this,
// you need to render the bitmap to a temp buffer, then "alpha blend" that into the working buffer
xpos += (advance * scale);
if (text[ch+1])
xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch],text[ch+1]);
++ch;
}
for (j=0; j < 20; ++j) {
for (i=0; i < 78; ++i)
putchar(" .:ioVM@"[screen[j][i]>>5]);
putchar('\n');
}
return 0;
}
#endif
#ifndef STB_TRUETYPE_H_
#define STB_TRUETYPE_H_
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////
//// INTEGRATION WITH RUNTIME LIBRARIES
////
// #define your own (u)stbtt_int8/16/32 before including to override this
#ifndef stbtt_uint8
typedef unsigned char stbtt_uint8;
typedef signed char stbtt_int8;
typedef unsigned short stbtt_uint16;
typedef signed short stbtt_int16;
typedef unsigned int stbtt_uint32;
typedef signed int stbtt_int32;
#endif
typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1];
typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1];
// #define your own STBTT_sort() to override this to avoid qsort
#ifndef STBTT_sort
#include <stdlib.h>
#define STBTT_sort(data,num_items,item_size,compare_func) qsort(data,num_items,item_size,compare_func)
#endif
// #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h
#ifndef STBTT_ifloor
#include <math.h>
#define STBTT_ifloor(x) ((int) floor(x))
#define STBTT_iceil(x) ((int) ceil(x))
#endif
// #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h
#ifndef STBTT_malloc
//#include <malloc.h>
#define STBTT_malloc(x,u) malloc(x)
#define STBTT_free(x,u) free(x)
#endif
#ifndef STBTT_assert
#include <assert.h>
#define STBTT_assert(x) assert(x)
#endif
#ifndef STBTT_strlen
#include <string.h>
#define STBTT_strlen(x) strlen(x)
#endif
#ifndef STBTT_memcpy
#include <memory.h>
#define STBTT_memcpy memcpy
#define STBTT_memset memset
#endif
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////
//// INTERFACE
////
////
#ifndef __STB_INCLUDE_STB_TRUETYPE_H__
#define __STB_INCLUDE_STB_TRUETYPE_H__
#ifdef __cplusplus
extern "C" {
#endif
//////////////////////////////////////////////////////////////////////////////
//
// TEXTURE BAKING API
//
// If you use this API, you only have to call two functions ever.
//
typedef struct
{
unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap
float xoff,yoff,xadvance;
} stbtt_bakedchar;
extern int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf)
float pixel_height, // height of font in pixels
unsigned char *pixels, int pw, int ph, // bitmap to be filled in
int first_char, int num_chars, // characters to bake
stbtt_bakedchar *chardata); // you allocate this, it's num_chars long
// if return is positive, the first unused row of the bitmap
// if return is negative, returns the negative of the number of characters that fit
// if return is 0, no characters fit and no rows were used
// This uses a very crappy packing.
typedef struct
{
float x0,y0,s0,t0; // top-left
float x1,y1,s1,t1; // bottom-right
} stbtt_aligned_quad;
extern void stbtt_GetBakedQuad(stbtt_bakedchar *chardata, int pw, int ph, // same data as above
int char_index, // character to display
float *xpos, float *ypos, // pointers to current position in screen pixel space
stbtt_aligned_quad *q, // output: quad to draw
int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier
// Call GetBakedQuad with char_index = 'character - first_char', and it
// creates the quad you need to draw and advances the current position.
// It's inefficient; you might want to c&p it and optimize it.
//////////////////////////////////////////////////////////////////////////////
//
// FONT LOADING
//
//
extern int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
// Each .ttf file may have more than one font. Each has a sequential index
// number starting from 0. Call this function to get the font offset for a
// given index; it returns -1 if the index is out of range. A regular .ttf
// file will only define one font and it always be at offset 0, so it will
// return '0' for index 0, and -1 for all other indices. You can just skip
// this step if you know it's that kind of font.
// The following structure is defined publically so you can declare one on
// the stack or as a global or etc.
typedef struct
{
void * userdata;
unsigned char * data; // pointer to .ttf file
int fontstart; // offset of start of font
int numGlyphs; // number of glyphs, needed for range checking
int loca,head,glyf,hhea,hmtx,kern; // table locations as offset from start of .ttf
int index_map; // a cmap mapping for our chosen character encoding
int indexToLocFormat; // format needed to map from glyph index to glyph
} stbtt_fontinfo;
extern int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset);
// Given an offset into the file that defines a font, this function builds
// the necessary cached info for the rest of the system. You must allocate
// the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't
// need to do anything special to free it, because the contents are a pure
// cache with no additional data structures. Returns 0 on failure.
//////////////////////////////////////////////////////////////////////////////
//
// CHARACTER TO GLYPH-INDEX CONVERSIOn
int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint);
// If you're going to perform multiple operations on the same character
// and you want a speed-up, call this function with the character you're
// going to process, then use glyph-based functions instead of the
// codepoint-based functions.
//////////////////////////////////////////////////////////////////////////////
//
// CHARACTER PROPERTIES
//
extern float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels);
// computes a scale factor to produce a font whose "height" is 'pixels' tall.
// Height is measured as the distance from the highest ascender to the lowest
// descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics
// and computing:
// scale = pixels / (ascent - descent)
// so if you prefer to measure height by the ascent only, use a similar calculation.
extern void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap);
// ascent is the coordinate above the baseline the font extends; descent
// is the coordinate below the baseline the font extends (i.e. it is typically negative)
// lineGap is the spacing between one row's descent and the next row's ascent...
// so you should advance the vertical position by "*ascent - *descent + *lineGap"
// these are expressed in unscaled coordinates
extern void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing);
// leftSideBearing is the offset from the current horizontal position to the left edge of the character
// advanceWidth is the offset from the current horizontal position to the next horizontal position
// these are expressed in unscaled coordinates
extern int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2);
// an additional amount to add to the 'advance' value between ch1 and ch2
// @TODO; for now always returns 0!
extern int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1);
// Gets the bounding box of the visible part of the glyph, in unscaled coordinates
extern void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing);
extern int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2);
extern int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1);
// as above, but takes one or more glyph indices for greater efficiency
//////////////////////////////////////////////////////////////////////////////
//
// GLYPH SHAPES (you probably don't need these, but they have to go before
// the bitmaps for C declaration-order reasons)
//
#ifndef STBTT_vmove // you can predefine these to use different values (but why?)
enum {
STBTT_vmove=1,
STBTT_vline,
STBTT_vcurve
};
#endif
#ifndef stbtt_vertex // you can predefine this to use different values
// (we share this with other code at RAD)
#define stbtt_vertex_type short // can't use stbtt_int16 because that's not visible in the header file
typedef struct
{
stbtt_vertex_type x,y,cx,cy;
unsigned char type,padding;
} stbtt_vertex;
#endif
extern int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices);
extern int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices);
// returns # of vertices and fills *vertices with the pointer to them
// these are expressed in "unscaled" coordinates
extern void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
// frees the data allocated above
//////////////////////////////////////////////////////////////////////////////
//
// BITMAP RENDERING
//
extern void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata);
// frees the bitmap allocated below
extern unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
// allocates a large-enough single-channel 8bpp bitmap and renders the
// specified character/glyph at the specified scale into it, with
// antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque).
// *width & *height are filled out with the width & height of the bitmap,
// which is stored left-to-right, top-to-bottom.
//
// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap
extern unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff);
// the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel
// shift for the character
extern void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint);
// the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap
// in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap
// is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the
// width and height and positioning info for it first.
extern void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint);
// same as stbtt_MakeCodepointBitmap, but you can specify a subpixel
// shift for the character
extern void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
// get the bbox of the bitmap centered around the glyph origin; so the
// bitmap width is ix1-ix0, height is iy1-iy0, and location to place
// the bitmap top left is (leftSideBearing*scale,iy0).
// (Note that the bitmap uses y-increases-down, but the shape uses
// y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.)
extern void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
// same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel
// shift for the character
// the following functions are equivalent to the above functions, but operate
// on glyph indices instead of Unicode codepoints (for efficiency)
extern unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff);
extern unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff);
extern void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph);
extern void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph);
extern void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1);
extern void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1);
// @TODO: don't expose this structure
typedef struct
{
int w,h,stride;
unsigned char *pixels;
} stbtt__bitmap;
extern void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata);
//////////////////////////////////////////////////////////////////////////////
//
// Finding the right font...
//
// You should really just solve this offline, keep your own tables
// of what font is what, and don't try to get it out of the .ttf file.
// That's because getting it out of the .ttf file is really hard, because
// the names in the file can appear in many possible encodings, in many
// possible languages, and e.g. if you need a case-insensitive comparison,
// the details of that depend on the encoding & language in a complex way
// (actually underspecified in truetype, but also gigantic).
//
// But you can use the provided functions in two possible ways:
// stbtt_FindMatchingFont() will use *case-sensitive* comparisons on
// unicode-encoded names to try to find the font you want;
// you can run this before calling stbtt_InitFont()
//
// stbtt_GetFontNameString() lets you get any of the various strings
// from the file yourself and do your own comparisons on them.
// You have to have called stbtt_InitFont() first.
extern int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags);
// returns the offset (not index) of the font that matches, or -1 if none
// if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold".
// if you use any other flag, use a font name like "Arial"; this checks
// the 'macStyle' header field; i don't know if fonts set this consistently
#define STBTT_MACSTYLE_DONTCARE 0
#define STBTT_MACSTYLE_BOLD 1
#define STBTT_MACSTYLE_ITALIC 2
#define STBTT_MACSTYLE_UNDERSCORE 4
#define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0
extern int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2);
// returns 1/0 whether the first string interpreted as utf8 is identical to
// the second string interpreted as big-endian utf16... useful for strings from next func
extern const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID);
// returns the string (which may be big-endian double byte, e.g. for unicode)
// and puts the length in bytes in *length.
//
// some of the values for the IDs are below; for more see the truetype spec:
// http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html
// http://www.microsoft.com/typography/otspec/name.htm
enum { // platformID
STBTT_PLATFORM_ID_UNICODE =0,
STBTT_PLATFORM_ID_MAC =1,
STBTT_PLATFORM_ID_ISO =2,
STBTT_PLATFORM_ID_MICROSOFT =3
};
enum { // encodingID for STBTT_PLATFORM_ID_UNICODE
STBTT_UNICODE_EID_UNICODE_1_0 =0,
STBTT_UNICODE_EID_UNICODE_1_1 =1,
STBTT_UNICODE_EID_ISO_10646 =2,
STBTT_UNICODE_EID_UNICODE_2_0_BMP=3,
STBTT_UNICODE_EID_UNICODE_2_0_FULL=4
};
enum { // encodingID for STBTT_PLATFORM_ID_MICROSOFT
STBTT_MS_EID_SYMBOL =0,
STBTT_MS_EID_UNICODE_BMP =1,
STBTT_MS_EID_SHIFTJIS =2,
STBTT_MS_EID_UNICODE_FULL =10
};
enum { // encodingID for STBTT_PLATFORM_ID_MAC; same as Script Manager codes
STBTT_MAC_EID_ROMAN =0, STBTT_MAC_EID_ARABIC =4,
STBTT_MAC_EID_JAPANESE =1, STBTT_MAC_EID_HEBREW =5,
STBTT_MAC_EID_CHINESE_TRAD =2, STBTT_MAC_EID_GREEK =6,
STBTT_MAC_EID_KOREAN =3, STBTT_MAC_EID_RUSSIAN =7
};
enum { // languageID for STBTT_PLATFORM_ID_MICROSOFT; same as LCID...
// problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs
STBTT_MS_LANG_ENGLISH =0x0409, STBTT_MS_LANG_ITALIAN =0x0410,
STBTT_MS_LANG_CHINESE =0x0804, STBTT_MS_LANG_JAPANESE =0x0411,
STBTT_MS_LANG_DUTCH =0x0413, STBTT_MS_LANG_KOREAN =0x0412,
STBTT_MS_LANG_FRENCH =0x040c, STBTT_MS_LANG_RUSSIAN =0x0419,
STBTT_MS_LANG_GERMAN =0x0407, STBTT_MS_LANG_SPANISH =0x0409,
STBTT_MS_LANG_HEBREW =0x040d, STBTT_MS_LANG_SWEDISH =0x041D
};
enum { // languageID for STBTT_PLATFORM_ID_MAC
STBTT_MAC_LANG_ENGLISH =0 , STBTT_MAC_LANG_JAPANESE =11,
STBTT_MAC_LANG_ARABIC =12, STBTT_MAC_LANG_KOREAN =23,
STBTT_MAC_LANG_DUTCH =4 , STBTT_MAC_LANG_RUSSIAN =32,
STBTT_MAC_LANG_FRENCH =1 , STBTT_MAC_LANG_SPANISH =6 ,
STBTT_MAC_LANG_GERMAN =2 , STBTT_MAC_LANG_SWEDISH =5 ,
STBTT_MAC_LANG_HEBREW =10, STBTT_MAC_LANG_CHINESE_SIMPLIFIED =33,
STBTT_MAC_LANG_ITALIAN =3 , STBTT_MAC_LANG_CHINESE_TRAD =19
};
#ifdef __cplusplus
}
#endif
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,19 @@
#pragma once
#include "Types.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct EmguiFontLayout
{
int16_t id;
int16_t x;
int16_t y;
int16_t width;
int16_t height;
int16_t xoffset;
int16_t yoffset;
int16_t xadvance;
} EmguiFontLayout;

View File

@ -0,0 +1,15 @@
#ifndef EMGFXBACKEND_H_
#define EMGFXBACKEND_H_
#include "Types.h"
bool EMGFXBackend_create();
bool EMGFXBackend_destroy();
void EMGFXBackend_updateViewPort(int width, int height);
void EMGFXBackend_render();
uint64_t EMGFXBackend_createFontTexture(void* imageBuffer, int w, int h);
uint64_t EMGFXBackend_createTexture(void* imageBuffer, int w, int h, int comp);
#endif

View File

@ -0,0 +1,387 @@
#include "../GFXBackend.h"
#include "../emgui_internal.h"
#if defined(__APPLE__)
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <gl/gl.h>
#endif
#include <stdlib.h>
#include <stdio.h>
/*
#define GL_CHECK(x) do { \
x; \
GLenum glerr = glGetError(); \
if (glerr != GL_NO_ERROR) { \
printf("EMGUI: OpenGL error: %d, file: %s, line: %d", glerr, __FILE__, __LINE__); \
} \
} while (0)
*/
#define GL_CHECK(x) x;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void setColor(uint32_t color)
{
// TODO: Figure out why glColor4b doesn't work here :/
glColor4f(((color >> 0) & 0xff) * 1.0f / 255.0f,
((color >> 8) & 0xff) * 1.0f / 255.0f,
((color >> 16) & 0xff) * 1.0f / 255.0f,
((color >> 24) & 0xff) * 1.0f / 255.0f);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool EMGFXBackend_create()
{
// set the background colour
glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0);
glDisable(GL_DEPTH_TEST);
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool EMGFXBackend_destroy()
{
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void EMGFXBackend_updateViewPort(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, 0, 1);
}
static GLuint texId;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint64_t EMGFXBackend_createFontTexture(void* fontBuffer, int width, int height)
{
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, fontBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return (uint64_t)texId;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
uint64_t EMGFXBackend_createTexture(void* imageBuffer, int w, int h, int comp)
{
int format = GL_RGBA;
GL_CHECK(glGenTextures(1, &texId));
GL_CHECK(glBindTexture(GL_TEXTURE_2D, texId));
switch (comp)
{
case 1 : format = GL_ALPHA; break;
case 3 : format = GL_RGB; break;
case 4 : format = GL_RGBA; break;
}
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, format, GL_UNSIGNED_BYTE, imageBuffer));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
GL_CHECK(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
return (uint64_t)texId;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE LoadedFont* getLoadedFont()
{
return &g_loadedFonts[g_currentFont];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void drawText(struct DrawTextCommand* commands, int fontId)
{
const LoadedFont* font = &g_loadedFonts[fontId];
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, (GLuint)font->handle);
//glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
while (commands)
{
const char* text = commands->text;
float x = (float)commands->x;
float y = (float)commands->y;
const bool flipped = commands->flipped;
setColor(commands->color);
if (font->altLookup)
{
char c = *text++;
while (c != 0)
{
int offset = c - 32;
float s0 = (float)font->altLookup[(offset * 2) + 0];
float t0 = (float)font->altLookup[(offset * 2) + 1];
float s1 = s0 + 8.0f;
float t1 = t0 + 8.0f;
float x0 = x;
float y0 = y;
float x1 = x + 8.0f;
float y1 = y + 8.0f;
s0 *= 1.0f / 128.0f;
t0 *= 1.0f / 128.0f;
s1 *= 1.0f / 128.0f;
t1 *= 1.0f / 128.0f;
glTexCoord2f(s0, t0); glVertex2f(x0, y0);
glTexCoord2f(s1, t0); glVertex2f(x1, y0);
glTexCoord2f(s1, t1); glVertex2f(x1, y1);
glTexCoord2f(s0, t1); glVertex2f(x0, y1);
c = *text++;
x += 8.0f;
}
}
else if (font->layout)
{
float s_scale = 1.0f / (float)font->width;
float t_scale = 1.0f / (float)font->height;
const int range_start = font->rangeStart;
const int range_end = font->rangeEnd;
int c = (unsigned char)*text++;
while (c != 0)
{
if (c >= range_start && c < range_end)
{
int offset = c - range_start;
EmguiFontLayout* info = &font->layout[offset];
float s0 = info->x;
float t0 = info->y;
float s1 = (float)(info->x + info->width);
float t1 = (float)(info->y + info->height);
if (flipped)
{
float x0 = x + (float)info->yoffset;
float y0 = y + (float)info->xoffset - info->xadvance;
float x1 = x0 + (float)info->height;
float y1 = y0 + (float)info->width;
s0 *= s_scale;
s1 *= s_scale;
t0 *= t_scale;
t1 *= t_scale;
glTexCoord2f(s1, t0); glVertex2f(x0, y0);
glTexCoord2f(s1, t1); glVertex2f(x1, y0);
glTexCoord2f(s0, t1); glVertex2f(x1, y1);
glTexCoord2f(s0, t0); glVertex2f(x0, y1);
y -= (float)info->xadvance;
}
else
{
float x0 = x + (float)info->xoffset;
float y0 = y + (float)info->yoffset;
float x1 = x0 + (float)info->width;
float y1 = y0 + (float)info->height;
s0 *= s_scale;
s1 *= s_scale;
t0 *= t_scale;
t1 *= t_scale;
glTexCoord2f(s0, t0); glVertex2f(x0, y0);
glTexCoord2f(s1, t0); glVertex2f(x1, y0);
glTexCoord2f(s1, t1); glVertex2f(x1, y1);
glTexCoord2f(s0, t1); glVertex2f(x0, y1);
x += (float)info->xadvance;
}
}
c = *text++;
}
}
else
{
while (*text)
{
int c = (unsigned char)*text;
if (c >= 32 && c < 128)
{
stbtt_aligned_quad q;
stbtt_GetBakedQuad((stbtt_bakedchar*)font->cData, 512,512, c-32, &x, &y, &q, 1);
glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0);
glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0);
glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1);
glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1);
}
++text;
}
}
commands = commands->next;
}
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void drawFill(struct DrawFillCommand* command)
{
glEnable(GL_BLEND);
glBegin(GL_QUADS);
while (command)
{
const float x = (float)command->x;
const float y = (float)command->y;
const float w = (float)command->width;
const float h = (float)command->height;
setColor(command->color0);
glVertex2f(x, y);
glVertex2f(x + w, y);
setColor(command->color1);
glVertex2f(x + w, y + h);
glVertex2f(x, y + h);
command = command->next;
}
glEnd();
glDisable(GL_BLEND);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void drawImage(struct DrawImageCommand* command)
{
uint64_t lastTexture = command->imageId;
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, (GLuint)lastTexture);
glBegin(GL_QUADS);
// TODO: Sorting of images type up-front
while (command)
{
const float x = (float)command->x;
const float y = (float)command->y;
const float w = (float)command->width;
const float h = (float)command->height;
if (command->imageId != (int64_t)lastTexture)
{
glEnd();
glBindTexture(GL_TEXTURE_2D, (GLuint)command->imageId);
glBegin(GL_QUADS);
lastTexture = command->imageId;
}
setColor(command->color);
glTexCoord2f(0.0f, 0.0f); glVertex2f(x, y);
glTexCoord2f(1.0f, 0.0f); glVertex2f(x + w, y);
glTexCoord2f(1.0f, 1.0f); glVertex2f(x + w, y + h);
glTexCoord2f(0.0f, 1.0f); glVertex2f(x, y + h);
command = command->next;
}
glEnd();
glDisable(GL_TEXTURE_2D);
}
extern struct RenderData s_renderData;
extern void swapBuffers();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void EMGFXBackend_render()
{
int i = 0, layerIter = 0;
// Not sure how to handle the clears, maybe send ClearScreen flag to Emgui_end()?
glClear(GL_COLOR_BUFFER_BIT);
// prepare for primitive drawing
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
for (layerIter = 0; layerIter < EMGUI_LAYER_COUNT; ++layerIter)
{
struct DrawLayer* layer = &s_renderData.layers[layerIter];
if (layer->scissor.width > 0 && layer->scissor.height > 0)
{
glEnable(GL_SCISSOR_TEST);
glScissor(layer->scissor.x, layer->scissor.y,
layer->scissor.width, layer->scissor.height);
}
drawFill(layer->fillCommands);
for (i = 0; i < EMGUI_MAX_FONTS; ++i)
{
if (layer->textCommands[i])
drawText(layer->textCommands[i], i);
}
if (layer->imageCommands)
drawImage(layer->imageCommands);
if (layer->scissor.width > 0 && layer->scissor.height > 0)
{
glDisable(GL_SCISSOR_TEST);
}
}
swapBuffers();
}

View File

@ -0,0 +1,3 @@
#pragma once

View File

@ -0,0 +1,368 @@
#include "MicroknightFont.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Microknight font (128x128 packed with 1 bit per pixel)
unsigned char s_microkinghtFontData[] =
{
0x00,0x0c,0x1b,0x0d,0x81,0x03,0x01,0xc0,0x30,0x18,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x0c,0x1b,0x0d,0x87,0xc4,0xb3,0x60,0x30,0x30,0x0c,0x1b,0x03,0x00,0x00,0x00,
0x00,0x0c,0x09,0x1f,0xcd,0x03,0xe1,0xc0,0x10,0x60,0x06,0x0e,0x03,0x00,0x00,0x00,
0x00,0x0c,0x00,0x0d,0x87,0xc0,0xc3,0xd8,0x20,0x60,0x06,0x3f,0x8f,0xc0,0x03,0xe0,
0x00,0x0c,0x00,0x1f,0xc1,0x61,0x83,0x70,0x00,0x60,0x06,0x0e,0x03,0x01,0x80,0x00,
0x00,0x00,0x00,0x0d,0x81,0x63,0x63,0x60,0x00,0x30,0x0c,0x1b,0x03,0x01,0x80,0x00,
0x00,0x0c,0x00,0x0d,0x87,0xc6,0x91,0xf0,0x00,0x18,0x18,0x00,0x00,0x00,0x80,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x60,0x18,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x07,0xc1,0xe0,0x61,0xf0,0x70,0x7f,0x1e,0x0f,0x00,0x00,0x00,
0x00,0x03,0x1e,0x03,0x00,0x60,0x30,0x61,0x80,0xc0,0x03,0x33,0x19,0x81,0x80,0xc0,
0x00,0x06,0x33,0x07,0x03,0xc0,0xe0,0xc1,0xf8,0xfc,0x06,0x1f,0x18,0xc1,0x80,0xc0,
0x00,0x0c,0x37,0x83,0x06,0x00,0x31,0xb0,0x0c,0xc6,0x0c,0x31,0x98,0xc0,0x00,0x00,
0x00,0x18,0x3d,0x83,0x0c,0x02,0x33,0x30,0x8c,0xc6,0x0c,0x31,0x8f,0xc0,0x00,0x00,
0x18,0x30,0x39,0x83,0x0c,0x06,0x33,0xf9,0x98,0xcc,0x0c,0x33,0x00,0xc1,0x80,0xc0,
0x18,0x60,0x1f,0x0f,0xcf,0xe3,0xe0,0x30,0xf0,0x78,0x0c,0x1e,0x03,0x81,0x80,0x40,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0f,0x83,0x83,0xc3,0xe0,0xf0,0xf8,0x7f,0x3f,0x87,0x0c,0x63,0xf0,
0x18,0x00,0x0c,0x18,0xc6,0xc6,0x63,0x31,0x98,0xcc,0x60,0x30,0x0c,0x0c,0x60,0xc0,
0x30,0x3e,0x06,0x00,0xcd,0xe6,0x33,0xf1,0x80,0xc6,0x7e,0x3f,0x18,0x0c,0x60,0xc0,
0x60,0x00,0x03,0x07,0x8f,0x67,0xf3,0x19,0x80,0xc6,0x60,0x30,0x19,0xcf,0xe0,0xc0,
0x30,0x3e,0x06,0x06,0x0d,0xe6,0x33,0x19,0x80,0xc6,0x60,0x30,0x18,0xcc,0x60,0xc0,
0x18,0x00,0x0c,0x00,0x0c,0x06,0x33,0x31,0x8c,0xc6,0x60,0x30,0x18,0xcc,0x60,0xc0,
0x00,0x00,0x00,0x06,0x06,0x66,0x33,0xe0,0xf8,0xfc,0x7f,0x30,0x0f,0xcc,0x63,0xf0,
0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0e,0x63,0x30,0x18,0xcc,0x63,0xc3,0xe0,0xf0,0xf8,0x3c,0x1f,0x98,0xcc,0x66,0x30,
0x06,0x66,0x30,0x1d,0xce,0x66,0x63,0x31,0x98,0xcc,0x60,0x06,0x18,0xcc,0x66,0x30,
0x06,0x6c,0x30,0x1f,0xcf,0x66,0x33,0x19,0x8c,0xc6,0x3e,0x06,0x18,0xcc,0x66,0x30,
0x06,0x78,0x30,0x1a,0xcd,0xe6,0x33,0x19,0x8c,0xc6,0x03,0x06,0x18,0xc6,0xc6,0xb0,
0xc6,0x6c,0x30,0x18,0xcc,0xe6,0x33,0xf1,0x8c,0xfc,0x23,0x06,0x18,0xc6,0xc7,0xf0,
0xc6,0x66,0x30,0x18,0xcc,0x66,0x33,0x01,0xac,0xd8,0x63,0x06,0x18,0xc3,0x87,0x70,
0x7c,0x63,0x3f,0x98,0xcc,0x63,0xe3,0x00,0xf8,0xcc,0x3e,0x06,0x0f,0x83,0x86,0x30,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xc6,0x63,0x3f,0x87,0x00,0x01,0xc0,0x40,0x00,0x18,0x00,0x30,0x00,0x00,0x60,0x00,
0x6c,0x63,0x03,0x06,0x0c,0x00,0xc0,0xe0,0x00,0x18,0x1e,0x3e,0x0f,0x03,0xe3,0xc0,
0x38,0x63,0x06,0x06,0x06,0x00,0xc1,0xb0,0x00,0x10,0x03,0x33,0x19,0x86,0x66,0x60,
0x38,0x3e,0x0c,0x06,0x03,0x00,0xc0,0x00,0x00,0x08,0x3f,0x31,0x98,0x0c,0x67,0xe0,
0x6c,0x06,0x18,0x06,0x01,0x80,0xc0,0x00,0x00,0x00,0x63,0x31,0x98,0x0c,0x66,0x00,
0xc6,0x06,0x30,0x06,0x00,0xc0,0xc0,0x00,0x00,0x00,0x63,0x31,0x98,0xcc,0x66,0x30,
0xc6,0x06,0x3f,0x87,0x00,0x61,0xc0,0x00,0x00,0x00,0x3f,0x3f,0x0f,0x87,0xe3,0xe0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x00,0x30,0x03,0x00,0xc6,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x6c,0x3f,0x3e,0x00,0x00,0x06,0x60,0x61,0x88,0xf8,0x3c,0x3e,0x07,0xcf,0xc3,0xc0,
0x60,0x63,0x33,0x07,0x01,0xc6,0xc0,0x61,0xdc,0xcc,0x66,0x33,0x0c,0xcc,0x66,0x00,
0x78,0x63,0x31,0x83,0x00,0xc7,0x80,0x61,0xfc,0xc6,0x63,0x31,0x98,0xcc,0x03,0xe0,
0x60,0x63,0x31,0x83,0x00,0xc6,0xc0,0x61,0xac,0xc6,0x63,0x31,0x98,0xcc,0x00,0x30,
0x60,0x3f,0x31,0x83,0x00,0xc6,0x60,0x61,0x8c,0xc6,0x63,0x31,0x98,0xcc,0x06,0x30,
0x60,0x03,0x31,0x8f,0xc4,0xc6,0x31,0xf9,0x8c,0xc6,0x3e,0x3f,0x0f,0xcc,0x03,0xe0,
0x60,0x3e,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0xc0,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x1c,0x87,0x00,0x00,0xc0,
0x7c,0x63,0x31,0x98,0xcc,0x66,0x33,0xf8,0x30,0x18,0x0c,0x27,0x0e,0x00,0x00,0x00,
0x30,0x63,0x31,0x9a,0xc6,0xc6,0x30,0x30,0x30,0x18,0x0c,0x00,0x1c,0x00,0x00,0xc0,
0x30,0x63,0x1b,0x1f,0xc3,0x86,0x30,0x60,0x60,0x18,0x06,0x00,0x18,0x20,0x00,0xc0,
0x30,0x63,0x1b,0x0f,0x83,0x86,0x30,0xc0,0x30,0x18,0x0c,0x00,0x10,0x60,0x00,0xc0,
0x32,0x63,0x0e,0x0d,0x86,0xc3,0xf1,0x80,0x30,0x18,0x0c,0x00,0x00,0xe0,0x00,0xc0,
0x1c,0x3f,0x0e,0x08,0x8c,0x60,0x33,0xf8,0x18,0x18,0x18,0x00,0x01,0xc0,0x00,0xc0,
0x00,0x00,0x00,0x00,0x00,0x03,0xe0,0x00,0x00,0x18,0x00,0x00,0x03,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x1c,0x00,0x18,0xc1,0x83,0xc1,0xb0,0x78,0x00,0x00,0x1f,0x00,0x03,0xc3,0xe0,
0x78,0x36,0x31,0x98,0xc1,0x86,0x00,0x00,0x84,0x7e,0x1b,0x03,0x00,0x04,0x20,0x00,
0xcc,0x30,0x1f,0x18,0xc1,0x83,0xe0,0x01,0x32,0xc6,0x36,0x00,0x00,0x0b,0x90,0x00,
0xc0,0x7c,0x31,0x8f,0x80,0x06,0x30,0x01,0x42,0xc6,0x6c,0x00,0x0f,0x8a,0x50,0x00,
0xc0,0x30,0x31,0x81,0x81,0x86,0x30,0x01,0x42,0x7e,0x36,0x00,0x00,0x0b,0x90,0x00,
0xc6,0x30,0x1f,0x07,0xc1,0x83,0xe0,0x01,0x32,0x00,0x1b,0x00,0x00,0x0a,0x50,0x00,
0x7c,0x7f,0x31,0x81,0x81,0x80,0x30,0x00,0x84,0x7c,0x00,0x00,0x00,0x04,0x20,0x00,
0x30,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x78,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x38,0x00,0x1c,0x0e,0x01,0x80,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x06,0x03,0x00,
0x6c,0x08,0x06,0x03,0x03,0x06,0x31,0xf8,0x00,0x00,0x38,0x1f,0x1b,0x0e,0x67,0x30,
0x6c,0x3e,0x0c,0x06,0x06,0x06,0x33,0xd0,0x30,0x00,0x18,0x31,0x8d,0x86,0xc3,0x60,
0x38,0x08,0x18,0x03,0x00,0x06,0x31,0xd0,0x30,0x00,0x18,0x31,0x86,0xc7,0xa3,0xc0,
0x00,0x00,0x1e,0x0e,0x00,0x06,0x30,0x50,0x00,0x00,0x3c,0x1f,0x0d,0x83,0x61,0xf0,
0x00,0x3e,0x00,0x00,0x00,0x06,0x30,0x50,0x00,0x00,0x00,0x00,0x1b,0x06,0xf3,0x18,
0x00,0x00,0x00,0x00,0x00,0x07,0xe0,0x50,0x00,0x18,0x00,0x1f,0x00,0x0c,0xf6,0x70,
0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x30,0xf8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xe0,0x18,0x0c,0x03,0x03,0x03,0x91,0xb0,0xf0,0x3f,0x3c,0x0c,0x03,0x01,0x83,0x60,
0x36,0x00,0x02,0x04,0x0c,0xc4,0xe0,0x01,0x98,0x6c,0x66,0x02,0x04,0x06,0x60,0x00,
0x6c,0x18,0x1e,0x0f,0x07,0x83,0xc1,0xe0,0xf0,0xcf,0x60,0x3f,0x9f,0xcf,0xe7,0xf0,
0x3a,0x1e,0x33,0x19,0x8c,0xc6,0x63,0x31,0x98,0xfc,0x60,0x30,0x18,0x0c,0x06,0x00,
0xf6,0x03,0x3f,0x9f,0xcf,0xe7,0xf3,0xf9,0xfc,0xcc,0x60,0x3f,0x1f,0x8f,0xc7,0xe0,
0x6f,0x63,0x31,0x98,0xcc,0x66,0x33,0x19,0x8c,0xcc,0x63,0x30,0x18,0x0c,0x06,0x00,
0xcf,0x3e,0x31,0x98,0xcc,0x66,0x33,0x19,0x8c,0xcf,0x3e,0x3f,0x9f,0xcf,0xe7,0xf0,
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x0c,0x06,0x0d,0x8f,0x83,0x90,0xc0,0x30,0x30,0x39,0x1b,0x00,0x07,0x81,0x80,
0x08,0x10,0x19,0x80,0x0c,0xc4,0xe0,0x20,0x40,0xcc,0x4e,0x00,0x0f,0x8c,0xc0,0x40,
0x7e,0x3f,0x1f,0x8f,0xcc,0x67,0x31,0xe0,0xf0,0x78,0x3c,0x1e,0x1a,0xcd,0xe6,0x30,
0x18,0x0c,0x06,0x03,0x0e,0x67,0xb3,0x31,0x98,0xcc,0x66,0x33,0x1f,0xef,0x66,0x30,
0x18,0x0c,0x06,0x03,0x0c,0x66,0xf3,0x19,0x8c,0xc6,0x63,0x31,0x9b,0x6e,0x66,0x30,
0x18,0x0c,0x06,0x03,0x0c,0x66,0x73,0x19,0x8c,0xc6,0x63,0x31,0x98,0xec,0x66,0x30,
0x7e,0x3f,0x1f,0x8f,0xcf,0xc6,0x31,0xf0,0xf8,0x7c,0x3e,0x1f,0x0f,0xc7,0xc3,0xe0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x18,0x0c,0x1b,0x03,0x0c,0x00,0x00,0xc0,0x30,0x18,0x39,0x1b,0x07,0x80,0x00,0x00,
0x20,0x33,0x00,0x04,0x0f,0x83,0xc0,0x20,0x40,0x66,0x4e,0x00,0x0c,0xc7,0xe3,0xc0,
0xc6,0x63,0x31,0x98,0xcc,0xc6,0x60,0xf0,0x78,0x3c,0x1e,0x0f,0x07,0x81,0xb6,0x60,
0xc6,0x63,0x31,0x98,0xcc,0x66,0xe0,0x18,0x0c,0x06,0x03,0x01,0x80,0xc7,0xf6,0x00,
0xc6,0x63,0x31,0x8f,0x8f,0xc6,0x31,0xf8,0xfc,0x7e,0x3f,0x1f,0x8f,0xcd,0x86,0x00,
0xc6,0x63,0x31,0x81,0x8c,0x06,0x33,0x19,0x8c,0xc6,0x63,0x31,0x98,0xcd,0x86,0x30,
0x7c,0x3e,0x1f,0x01,0x8c,0x06,0xe1,0xf8,0xfc,0x7e,0x3f,0x1f,0x8f,0xc7,0xf3,0xe0,
0x00,0x00,0x00,0x00,0x0c,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x30,0x0c,0x0c,0x0d,0x83,0x00,0xc0,0x60,0xd8,0x0c,0x39,0x0c,0x03,0x01,0x83,0x90,
0x08,0x10,0x33,0x00,0x00,0x81,0x01,0x98,0x00,0x16,0x4e,0x02,0x04,0x06,0x64,0xe0,
0x78,0x3c,0x1e,0x0f,0x03,0x81,0xc0,0xe0,0x70,0x3e,0x7c,0x1e,0x0f,0x07,0x83,0xc0,
0xfc,0x7e,0x3f,0x1f,0x81,0x80,0xc0,0x60,0x30,0x66,0x66,0x33,0x19,0x8c,0xc6,0x60,
0xc0,0x60,0x30,0x18,0x01,0x80,0xc0,0x60,0x30,0xc6,0x63,0x31,0x98,0xcc,0x66,0x30,
0xc6,0x63,0x31,0x98,0xc1,0x80,0xc0,0x60,0x30,0xc6,0x63,0x31,0x98,0xcc,0x66,0x30,
0x7c,0x3e,0x1f,0x0f,0x87,0xe3,0xf1,0xf8,0xfc,0x7e,0x63,0x1f,0x0f,0x87,0xc3,0xe0,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x6c,0x00,0x00,0x06,0x01,0x80,0xc1,0xb0,0x30,0xc0,0x36,0x00,0x00,0x00,0x00,0x00,
0x00,0x0c,0x1e,0x01,0x02,0x03,0x30,0x00,0x40,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0x00,0x33,0x18,0xcc,0x66,0x33,0x19,0x8c,0xf8,0x63,0x00,0x00,0x00,0x00,0x00,
0xcc,0x3f,0x37,0x98,0xcc,0x66,0x33,0x19,0x8c,0xcc,0x63,0x00,0x00,0x00,0x00,0x00,
0xc6,0x00,0x3d,0x98,0xcc,0x66,0x33,0x19,0x8c,0xc6,0x63,0x00,0x00,0x00,0x00,0x00,
0xc6,0x0c,0x39,0x98,0xcc,0x66,0x33,0x18,0xfc,0xfc,0x3f,0x00,0x00,0x00,0x00,0x00,
0x7c,0x00,0x1f,0x0f,0xc7,0xe3,0xf1,0xf8,0x0c,0xc0,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xc0,0x3e,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Font layout (generated from Angelcode Bitmap Font generator)
struct MicroknightLayout s_microknightLayout[] =
{
{ 0, 0 },
{ 9, 0 },
{ 18, 0 },
{ 27, 0 },
{ 36, 0 },
{ 45, 0 },
{ 54, 0 },
{ 63, 0 },
{ 72, 0 },
{ 81, 0 },
{ 90, 0 },
{ 99, 0 },
{ 108, 0 },
{ 117, 0 },
{ 0, 9 },
{ 9, 9 },
{ 18, 9 },
{ 27, 9 },
{ 36, 9 },
{ 45, 9 },
{ 54, 9 },
{ 63, 9 },
{ 72, 9 },
{ 81, 9 },
{ 90, 9 },
{ 99, 9 },
{ 108, 9 },
{ 117, 9 },
{ 0, 18 },
{ 9, 18 },
{ 18, 18 },
{ 27, 18 },
{ 36, 18 },
{ 45, 18 },
{ 54, 18 },
{ 63, 18 },
{ 72, 18 },
{ 81, 18 },
{ 90, 18 },
{ 99, 18 },
{ 108, 18 },
{ 117, 18 },
{ 0, 27 },
{ 9, 27 },
{ 18, 27 },
{ 27, 27 },
{ 36, 27 },
{ 45, 27 },
{ 54, 27 },
{ 63, 27 },
{ 72, 27 },
{ 81, 27 },
{ 90, 27 },
{ 99, 27 },
{ 108, 27 },
{ 117, 27 },
{ 0, 36 },
{ 9, 36 },
{ 18, 36 },
{ 27, 36 },
{ 36, 36 },
{ 45, 36 },
{ 54, 36 },
{ 63, 36 },
{ 72, 36 },
{ 81, 36 },
{ 90, 36 },
{ 99, 36 },
{ 108, 36 },
{ 117, 36 },
{ 0, 45 },
{ 9, 45 },
{ 18, 45 },
{ 27, 45 },
{ 36, 45 },
{ 45, 45 },
{ 54, 45 },
{ 63, 45 },
{ 72, 45 },
{ 81, 45 },
{ 90, 45 },
{ 99, 45 },
{ 108, 45 },
{ 117, 45 },
{ 0, 54 },
{ 9, 54 },
{ 18, 54 },
{ 27, 54 },
{ 36, 54 },
{ 45, 54 },
{ 54, 54 },
{ 63, 54 },
{ 72, 54 },
{ 81, 54 },
{ 90, 54 },
{ 99, 54 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ 108, 54 },
{ 117, 54 },
{ 0, 63 },
{ 9, 63 },
{ 18, 63 },
{ 27, 63 },
{ 36, 63 },
{ 45, 63 },
{ 54, 63 },
{ 63, 63 },
{ 72, 63 },
{ 81, 63 },
{ 90, 63 },
{ 99, 63 },
{ 108, 63 },
{ 117, 63 },
{ 0, 72 },
{ 9, 72 },
{ 18, 72 },
{ 27, 72 },
{ 36, 72 },
{ 45, 72 },
{ 54, 72 },
{ 63, 72 },
{ 72, 72 },
{ 81, 72 },
{ 90, 72 },
{ 99, 72 },
{ 108, 72 },
{ 117, 72 },
{ 0, 81 },
{ 9, 81 },
{ 18, 81 },
{ 27, 81 },
{ 36, 81 },
{ 45, 81 },
{ 54, 81 },
{ 63, 81 },
{ 72, 81 },
{ 81, 81 },
{ 90, 81 },
{ 99, 81 },
{ 108, 81 },
{ 117, 81 },
{ 0, 90 },
{ 9, 90 },
{ 18, 90 },
{ 27, 90 },
{ 36, 90 },
{ 45, 90 },
{ 54, 90 },
{ 63, 90 },
{ 72, 90 },
{ 81, 90 },
{ 90, 90 },
{ 99, 90 },
{ 108, 90 },
{ 117, 90 },
{ 0, 99 },
{ 9, 99 },
{ 18, 99 },
{ 27, 99 },
{ 36, 99 },
{ 45, 99 },
{ 54, 99 },
{ 63, 99 },
{ 72, 99 },
{ 81, 99 },
{ 90, 99 },
{ 99, 99 },
{ 108, 99 },
{ 117, 99 },
{ 0, 108 },
{ 9, 108 },
{ 18, 108 },
{ 27, 108 },
{ 36, 108 },
{ 45, 108 },
{ 54, 108 },
{ 63, 108 },
{ 72, 108 },
{ 81, 108 },
{ 90, 108 },
{ 99, 108 },
{ 108, 108 },
{ 117, 108 },
{ 0, 117 },
{ 9, 117 },
{ 18, 117 },
{ 27, 117 },
{ 36, 117 },
{ 45, 117 },
{ 54, 117 },
{ 63, 117 },
{ 72, 117 },
{ 81, 117 },
};

View File

@ -0,0 +1,15 @@
#pragma once
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct MicroknightLayout
{
unsigned short x;
unsigned short y;
} MicroknightLayout;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern unsigned char s_microkinghtFontData[];
extern struct MicroknightLayout s_microknightLayout[];

View File

@ -0,0 +1,95 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef EMGUITYPES_H
#define EMGUITYPES_H
#include <stddef.h>
typedef unsigned int uint;
#if defined(_WIN32)
#if defined(__GNUC__)
#include <stdint.h>
#else
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned int uint32_t;
typedef signed int int32_t;
typedef unsigned __int64 uint64_t;
typedef signed __int64 int64_t;
typedef unsigned char bool;
typedef wchar_t text_t;
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#pragma warning(disable: 4100 4127 4201 4706)
#endif
#define EMGUI_LIKELY(exp) exp
#define EMGUI_UNLIKELY(exp) exp
#define EMGUI_INLINE __forceinline
#define EMGUI_RESTRICT __restrict
#define EMGUI_ALIGN(x) __declspec(align(x))
#define EMGUI_UNCACHEDAC_PTR(x) x
#define EMGUI_UNCACHED_PTR(x) x
#define EMGUI_CACHED_PTR(x) x
#define EMGUI_ALIGNOF(t) __alignof(t)
#define EMGUI_BREAK __debugbreak()
#if defined(_WIN64)
#define EMGUI_X64
#endif
#elif defined(EMGUI_UNIX) || defined(EMGUI_MACOSX)
#include <stdint.h>
#define EMGUI_LIKELY(exp) __builtin_expect(exp, 1)
#define EMGUI_UNLIKELY(exp) __builtin_expect(exp, 0)
#define EMGUI_INLINE inline
#define EMGUI_RESTRICT __restrict
#define EMGUI_ALIGN(x) __attribute__((aligned(x)))
#define EMGUI_UNCACHEDAC_PTR(x) x
#define EMGUI_UNCACHED_PTR(x) x
#define EMGUI_CACHED_PTR(x) x
#define EMGUI_ALIGNOF(t) __alignof__(t)
#define EMGUI_BREAK ((*(volatile uint32_t *)(0)) = 0x666)
typedef char text_t;
#include <stdbool.h>
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#if defined(__LP64__)
#define EMGUI_X64
#endif
#else
#error Platform not supported
#endif
#define sizeof_array(array) (int)(sizeof(array) / sizeof(array[0]))
#endif

View File

@ -0,0 +1,65 @@
#include "LinearAllocator.h"
#include <string.h>
#include <stdlib.h>
static LinearAllocator g_scratchPad;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void* LinearAllocator_allocAligned(LinearAllocator* state, uint32_t size, uint32_t alignment)
{
void* retData;
// Align the pointer to the current
intptr_t ptr = (intptr_t)state->current;
uint32_t bitMask = (alignment - 1);
uint32_t lowBits = ptr & bitMask;
uint32_t adjust = ((alignment - lowBits) & bitMask);
// adjust the pointer to correct alignment
state->current += adjust;
// TODO: Proper error handling here
// HIPPO_ASSERT(((intptr_t)state->current - (intptr_t)state->start) + size < state->maxSize);
retData = (void*)state->current;
state->current += size;
return retData;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void* LinearAllocator_allocAlignedZero(LinearAllocator* allocator, uint32_t size, uint32_t alignment)
{
void* mem = LinearAllocator_allocAligned(allocator, size, alignment);
memset(mem, 0, size);
return mem;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void LinearAllocator_setScratchPad(void* data, uint32_t size)
{
LinearAllocator_create(&g_scratchPad, data, size);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LinearAllocator* LinearAllocator_getScratchPad()
{
return &g_scratchPad;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
char* LinearAllocator_allocString(LinearAllocator* allocator, const char* value)
{
const size_t len = strlen(value) + 1;
char* mem = LinearAllocator_allocArray(allocator, char, (uint32_t)len);
memcpy(mem, value, len);
return mem;
}

View File

@ -0,0 +1,100 @@
#ifndef LINEARALLOCATOR_H
#define LINEARALLOCATOR_H
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "../Types.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct LinearAllocator
{
uint8_t* start;
uint8_t* current;
uint32_t maxSize;
} LinearAllocator;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct LinearAllocatorRewindPoint
{
uint8_t* pointer;
} LinearAllocatorRewindPoint;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EMGUI_INLINE void LinearAllocator_create(LinearAllocator* state, void* data, uint32_t size)
{
state->start = state->current = (uint8_t*)data;
state->maxSize = size;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//! \todo Document
static EMGUI_INLINE void LinearAllocator_reset(LinearAllocator* state)
{
state->current = state->start;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//! \todo Document
void* LinearAllocator_allocAligned(LinearAllocator* state, uint32_t size, uint32_t alignment);
void* LinearAllocator_allocAlignedZero(LinearAllocator* state, uint32_t size, uint32_t alignment);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//! \brief Makes it possible to get a rewindpoint to rewind the memory back to the memory position at the point
//! when the function was called (use LinerarAllocator_rewind) to rewind back.
//! Notice that "rewind" in this sense is just to move a pointer back. It actually doesn't do anything with the memory
//! \param[in] state the current instance of LinearAllocator (as setup by LinearAllocator_create)
//! \param[in] rewindPoint holds the restorpoint
static EMGUI_INLINE LinearAllocatorRewindPoint LinearAllocator_getRewindPoint(const LinearAllocator* allocator)
{
LinearAllocatorRewindPoint rewindPoint;
rewindPoint.pointer = allocator->current;
return rewindPoint;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// \brief Rewinds the allocator to a given rewindpoint
//! \param[in] rewindPoint Rewindpoint to rewind back to
//! \param[in] state the current instance of LinearAllocator (as setup by LinearAllocator_create)
static EMGUI_INLINE void LinearAllocator_rewind(LinearAllocator* state, LinearAllocatorRewindPoint rewindPoint)
{
state->current = rewindPoint.pointer;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// \brief Rewinds the allocator to a given rewindpoint
static EMGUI_INLINE ptrdiff_t LinearAllocator_getCursor(const LinearAllocator* allocator)
{
return ((intptr_t)allocator->current) - ((intptr_t)allocator->start);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// \brief Gets a "scratch" pad that the user can use to allocate temporary memory. Notice that its up to the user
// to rewind the allocator back \linkLinearAllocator_getRewindPoint\endlink and \linkLinearAllocator_rewind\endlink
LinearAllocator* LinearAllocator_getScratchPad();
void LinearAllocator_setScratchPad(void* data, uint32_t size);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Helper macros
#define LinearAllocator_alloc(state, type) (type*)LinearAllocator_allocAligned(state, sizeof(type), EMGUI_ALIGNOF(type))
#define LinearAllocator_allocZero(state, type) (type*)LinearAllocator_allocAlignedZero(state, sizeof(type), EMGUI_ALIGNOF(type))
#define LinearAllocator_allocArray(state, type, count) (type*)LinearAllocator_allocAlignedZero(state, sizeof(type) * count, \
EMGUI_ALIGNOF(type))
#define LinearAllocator_allocArrayZero(state, type, count) (type*)LinearAllocator_allocAlignedZero(state, sizeof(type) * count, EMGUI_ALIGNOF(type))
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
char* LinearAllocator_allocString(LinearAllocator* allocator, const char* name);
#endif