mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 05:13:59 +02:00
- added freetype-gl rendered and set as default font renderer (see: http://code.google.com/p/freetype-gl/)
This commit is contained in:
96
source/shared_lib/include/graphics/freetype-gl/edtaa3func.h
Normal file
96
source/shared_lib/include/graphics/freetype-gl/edtaa3func.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2009 Stefan Gustavson (stefan.gustavson@gmail.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY STEFAN GUSTAVSON ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL STEFAN GUSTAVSON OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Stefan Gustavson.
|
||||
*
|
||||
*
|
||||
* edtaa3()
|
||||
*
|
||||
* Sweep-and-update Euclidean distance transform of an
|
||||
* image. Positive pixels are treated as object pixels,
|
||||
* zero or negative pixels are treated as background.
|
||||
* An attempt is made to treat antialiased edges correctly.
|
||||
* The input image must have pixels in the range [0,1],
|
||||
* and the antialiased image should be a box-filter
|
||||
* sampling of the ideal, crisp edge.
|
||||
* If the antialias region is more than 1 pixel wide,
|
||||
* the result from this transform will be inaccurate.
|
||||
*
|
||||
* By Stefan Gustavson (stefan.gustavson@gmail.com).
|
||||
*
|
||||
* Originally written in 1994, based on a verbal
|
||||
* description of the SSED8 algorithm published in the
|
||||
* PhD dissertation of Ingemar Ragnemalm. This is his
|
||||
* algorithm, I only implemented it in C.
|
||||
*
|
||||
* Updated in 2004 to treat border pixels correctly,
|
||||
* and cleaned up the code to improve readability.
|
||||
*
|
||||
* Updated in 2009 to handle anti-aliased edges.
|
||||
*
|
||||
* Updated in 2011 to avoid a corner case infinite loop.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Compute the local gradient at edge pixels using convolution filters.
|
||||
* The gradient is computed only at edge pixels. At other places in the
|
||||
* image, it is never used, and it's mostly zero anyway.
|
||||
*/
|
||||
void computegradient(double *img, int w, int h, double *gx, double *gy);
|
||||
|
||||
/*
|
||||
* A somewhat tricky function to approximate the distance to an edge in a
|
||||
* certain pixel, with consideration to either the local gradient (gx,gy)
|
||||
* or the direction to the pixel (dx,dy) and the pixel greyscale value a.
|
||||
* The latter alternative, using (dx,dy), is the metric used by edtaa2().
|
||||
* Using a local estimate of the edge gradient (gx,gy) yields much better
|
||||
* accuracy at and near edges, and reduces the error even at distant pixels
|
||||
* provided that the gradient direction is accurately estimated.
|
||||
*/
|
||||
double edgedf(double gx, double gy, double a);
|
||||
|
||||
|
||||
double distaa3(double *img, double *gximg, double *gyimg, int w, int c, int xc, int yc, int xi, int yi);
|
||||
|
||||
// Shorthand macro: add ubiquitous parameters dist, gx, gy, img and w and call distaa3()
|
||||
#define DISTAA(c,xc,yc,xi,yi) (distaa3(img, gx, gy, w, c, xc, yc, xi, yi))
|
||||
|
||||
void edtaa3(double *img, double *gx, double *gy, int w, int h, short *distx, short *disty, double *dist);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
131
source/shared_lib/include/graphics/freetype-gl/font-manager.h
Normal file
131
source/shared_lib/include/graphics/freetype-gl/font-manager.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#pragma once
|
||||
#ifndef __FONT_MANAGER_H__
|
||||
#define __FONT_MANAGER_H__
|
||||
|
||||
#include "vector.h"
|
||||
#include "markup.h"
|
||||
#include "texture-font.h"
|
||||
#include "texture-atlas.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
TextureAtlas * atlas;
|
||||
Vector * fonts;
|
||||
wchar_t * cache;
|
||||
Region black;
|
||||
} FontManager;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
FontManager *
|
||||
font_manager_new( size_t width, size_t height, size_t depth );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
font_manager_delete( FontManager *self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureFont *
|
||||
font_manager_get_from_filename( FontManager * self,
|
||||
const char * filename,
|
||||
const float size );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureFont *
|
||||
font_manager_get_from_description( FontManager * self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureFont *
|
||||
font_manager_get_from_markup( FontManager *self,
|
||||
const Markup *markup );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
char *
|
||||
font_manager_match_description( FontManager * self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
const wchar_t *
|
||||
font_manager_get_cache( FontManager * self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
font_manager_set_cache( FontManager * self,
|
||||
const wchar_t * cache );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FONT_MANAGER_H__ */
|
||||
|
128
source/shared_lib/include/graphics/freetype-gl/markup.h
Normal file
128
source/shared_lib/include/graphics/freetype-gl/markup.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#pragma once
|
||||
#ifndef __MARKUP_H__
|
||||
#define __MARKUP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
float r,g,b,a;
|
||||
} Color;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * family;
|
||||
float size;
|
||||
int bold;
|
||||
int italic;
|
||||
float rise;
|
||||
float spacing;
|
||||
Color foreground_color;
|
||||
Color background_color;
|
||||
int outline;
|
||||
Color outline_color;
|
||||
int underline;
|
||||
Color underline_color;
|
||||
int overline;
|
||||
Color overline_color;
|
||||
int strikethrough;
|
||||
Color strikethrough_color;
|
||||
struct TextureFont_ * font;
|
||||
} Markup;
|
||||
|
||||
|
||||
Markup * markup_new( void );
|
||||
Markup * markup_copy( const Markup *other );
|
||||
|
||||
|
||||
int markup_cmp( const Markup *self,
|
||||
const Markup *other );
|
||||
|
||||
void markup_delete( Markup *self );
|
||||
const char * markup_get_family( Markup *self );
|
||||
void markup_set_family( Markup *self,
|
||||
const char *family );
|
||||
int markup_get_italic( Markup *self );
|
||||
void markup_set_italic( Markup *self,
|
||||
const int italic );
|
||||
int markup_get_bold( Markup *self );
|
||||
void markup_set_bold( Markup *self,
|
||||
const int bold );
|
||||
float markup_get_size( Markup *self );
|
||||
void markup_set_size( Markup *self,
|
||||
const float size );
|
||||
float markup_get_rise( Markup *self );
|
||||
void markup_set_rise( Markup *self,
|
||||
const float rise );
|
||||
float markup_get_spacing( Markup *self );
|
||||
void markup_set_spacing( Markup *self,
|
||||
const float spacing );
|
||||
Color markup_get_foreground_color( Markup *self );
|
||||
void markup_set_foreground_color( Markup *self,
|
||||
const Color * color );
|
||||
Color markup_get_background_color( Markup *self );
|
||||
void markup_set_background_color( Markup *self,
|
||||
const Color * color );
|
||||
int markup_get_outline( Markup *self );
|
||||
void markup_set_outline( Markup *self,
|
||||
const int outline );
|
||||
Color markup_get_outline_color( Markup *self );
|
||||
void markup_set_outline_color( Markup *self,
|
||||
const Color * color );
|
||||
int markup_get_underline( Markup *self );
|
||||
void markup_set_underline( Markup *self,
|
||||
const int underline );
|
||||
Color markup_get_underline_color( Markup *self );
|
||||
void markup_set_underline_color( Markup *self,
|
||||
const Color * color );
|
||||
int markup_get_overline( Markup *self );
|
||||
void markup_set_overline( Markup *self,
|
||||
const int overline );
|
||||
Color markup_get_overline_color( Markup *self );
|
||||
void markup_set_overline_color( Markup *self,
|
||||
const Color * color );
|
||||
int markup_get_strikethrough( Markup *self );
|
||||
void markup_set_strikethrough( Markup *self,
|
||||
const int strikethrough );
|
||||
Color markup_get_strikethrough_color( Markup *self );
|
||||
void markup_set_strikethrough_color( Markup *self,
|
||||
const Color * color );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MARKUP_H__ */
|
156
source/shared_lib/include/graphics/freetype-gl/texture-atlas.h
Normal file
156
source/shared_lib/include/graphics/freetype-gl/texture-atlas.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* =========================================================================
|
||||
|
||||
This source is based on the article by Jukka Jylänki :
|
||||
"A Thousand Ways to Pack the Bin - A Practical Approach to
|
||||
Two-Dimensional Rectangle Bin Packing", February 27, 2010.
|
||||
|
||||
More precisely, this is an implementation of the Skyline Bottom-Left
|
||||
algorithm based on C++ sources provided by Jukka Jylänki at:
|
||||
http://clb.demon.fi/files/RectangleBinPack/
|
||||
|
||||
========================================================================= */
|
||||
#pragma once
|
||||
#ifndef __TEXTURE_ATLAS_H__
|
||||
#define __TEXTURE_ATLAS_H__
|
||||
#include "vector.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A Region describes
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
} Region;
|
||||
|
||||
|
||||
typedef struct { float x,y,z,w; } vec4;
|
||||
typedef struct { float x,y,z; } vec3;
|
||||
typedef struct { float x,y; } vec2;
|
||||
typedef struct { int x,y,z,w; } ivec4;
|
||||
typedef struct { int x,y,z; } ivec3;
|
||||
typedef struct { int x,y; } ivec2;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/** Current allocated nodes */
|
||||
Vector *nodes;
|
||||
|
||||
/** Width (in pixels) of the underlying texture */
|
||||
size_t width;
|
||||
|
||||
/** Height (in pixels) of the underlying texture */
|
||||
size_t height;
|
||||
|
||||
/** Texture format (1, 3 or 4) */
|
||||
size_t depth;
|
||||
|
||||
/** Allocated surface */
|
||||
size_t used;
|
||||
|
||||
/** Texture identity (OpenGL) */
|
||||
unsigned int texid;
|
||||
|
||||
unsigned char *data;
|
||||
|
||||
/** A special region */
|
||||
Region black;
|
||||
|
||||
} TextureAtlas;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureAtlas *
|
||||
texture_atlas_new( size_t width,
|
||||
size_t height,
|
||||
size_t depth );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_atlas_delete( TextureAtlas *self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_atlas_upload( TextureAtlas *self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Region
|
||||
texture_atlas_get_region( TextureAtlas *self,
|
||||
size_t width,
|
||||
size_t height );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_atlas_set_region( TextureAtlas *self,
|
||||
size_t x,
|
||||
size_t y,
|
||||
size_t width,
|
||||
size_t height,
|
||||
unsigned char *data,
|
||||
size_t stride );
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_atlas_clear( TextureAtlas *self );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TEXTURE_ATLAS_H__ */
|
120
source/shared_lib/include/graphics/freetype-gl/texture-font.h
Normal file
120
source/shared_lib/include/graphics/freetype-gl/texture-font.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#pragma once
|
||||
#ifndef __TEXTURE_FONT_H__
|
||||
#define __TEXTURE_FONT_H__
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
#include "vector.h"
|
||||
#include "texture-atlas.h"
|
||||
#include "texture-glyph.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
struct TextureFont_
|
||||
{
|
||||
Vector * glyphs;
|
||||
TextureAtlas * atlas;
|
||||
char * filename;
|
||||
int bold;
|
||||
int italic;
|
||||
float size;
|
||||
float gamma;
|
||||
Region black;
|
||||
int antialias;
|
||||
int subpixel;
|
||||
int hinting;
|
||||
float height;
|
||||
float linegap;
|
||||
float ascender;
|
||||
float descender;
|
||||
int lcd_filter;
|
||||
unsigned char lcd_weights[5];
|
||||
};
|
||||
typedef struct TextureFont_ TextureFont;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureFont *
|
||||
texture_font_new( TextureAtlas * atlas,
|
||||
const char * filename,
|
||||
const float size );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_font_delete( TextureFont * self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureGlyph *
|
||||
texture_font_get_glyph( TextureFont * self,
|
||||
wchar_t charcode );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
size_t
|
||||
texture_font_cache_glyphs( TextureFont * self,
|
||||
const wchar_t * charcodes );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
int
|
||||
texture_font_load_face( FT_Library * library,
|
||||
const char * filename,
|
||||
const float size,
|
||||
FT_Face * face );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TEXTURE_FONT_H__ */
|
||||
|
131
source/shared_lib/include/graphics/freetype-gl/texture-glyph.h
Normal file
131
source/shared_lib/include/graphics/freetype-gl/texture-glyph.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#pragma once
|
||||
#ifndef __TEXTURE_GLYPH_H__
|
||||
#define __TEXTURE_GLYPH_H__
|
||||
|
||||
#include <wchar.h>
|
||||
#include "markup.h"
|
||||
#include "vertex-buffer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
wchar_t charcode;
|
||||
float kerning;
|
||||
} KerningPair;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} Pen;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
wchar_t charcode;
|
||||
int width, height;
|
||||
int offset_x, offset_y;
|
||||
float advance_x, advance_y;
|
||||
float u0, v0, u1, v1;
|
||||
KerningPair * kerning;
|
||||
size_t kerning_count;
|
||||
struct TextureFont_ *font;
|
||||
} TextureGlyph;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
float u, v;
|
||||
float r, g, b, a;
|
||||
} TextureGlyphVertex;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
TextureGlyph *
|
||||
texture_glyph_new( void );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_glyph_delete( TextureGlyph * self );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_glyph_render( TextureGlyph * self,
|
||||
Markup * markup,
|
||||
Pen * pen );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void
|
||||
texture_glyph_add_to_vertex_buffer( const TextureGlyph * self,
|
||||
VertexBuffer * buffer,
|
||||
const Markup * markup,
|
||||
Pen * pen, int kerning );
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
float
|
||||
texture_glyph_get_kerning( TextureGlyph * self,
|
||||
wchar_t charcode );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TEXTURE_GLYPH_H__ */
|
289
source/shared_lib/include/graphics/freetype-gl/vector.h
Normal file
289
source/shared_lib/include/graphics/freetype-gl/vector.h
Normal file
@@ -0,0 +1,289 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#ifndef __VECTOR_H__
|
||||
#define __VECTOR_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Generic vector structure.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Pointer to dynamically allocated items. */
|
||||
void * items;
|
||||
|
||||
/** Number of items that can be held in currently allocated storage. */
|
||||
size_t capacity;
|
||||
|
||||
/** Number of items. */
|
||||
size_t size;
|
||||
|
||||
/** Size (in bytes) of a single item. */
|
||||
size_t item_size;
|
||||
} Vector;
|
||||
|
||||
/**
|
||||
* Creates a vector.
|
||||
*
|
||||
* @param item_size item size in bytes
|
||||
* @return a new empty vector
|
||||
*/
|
||||
Vector *
|
||||
vector_new( size_t item_size );
|
||||
|
||||
/**
|
||||
* Deletes a vector.
|
||||
*
|
||||
* @param self a vector structure
|
||||
*/
|
||||
void
|
||||
vector_delete( Vector *self );
|
||||
|
||||
/**
|
||||
* Returns a pointer to the item located at specified index.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param index the index of the item to be returned
|
||||
* @return pointer on the specified item
|
||||
*/
|
||||
const void *
|
||||
vector_get( const Vector *self,
|
||||
size_t index );
|
||||
|
||||
/**
|
||||
* Returns a pointer to the first item.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @return pointer on the first item
|
||||
*/
|
||||
const void *
|
||||
vector_front( const Vector *self );
|
||||
|
||||
/**
|
||||
* Returns a pointer to the last item
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @return pointer on the last item
|
||||
*/
|
||||
const void *
|
||||
vector_back( const Vector *self );
|
||||
|
||||
/**
|
||||
* Check if an item is contained within the vector.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param item item to be searched in the vector
|
||||
* @param cmp a pointer a comparison function
|
||||
* @return 1 if item is contained within the vector, 0 otherwise
|
||||
*/
|
||||
int
|
||||
vector_contains( const Vector *self,
|
||||
const void *item,
|
||||
int (*cmp)(const void *, const void *) );
|
||||
|
||||
/**
|
||||
* Checks whether the vector is empty.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @return 1 if the vector is empty, 0 otherwise
|
||||
*/
|
||||
int
|
||||
vector_empty( const Vector *self );
|
||||
|
||||
/**
|
||||
* Returns the number of items
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @return number of items
|
||||
*/
|
||||
size_t
|
||||
vector_size( const Vector *self );
|
||||
|
||||
/**
|
||||
* Reserve storage such that it can hold at last size items.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param size the new storage capacity
|
||||
*/
|
||||
void
|
||||
vector_reserve( Vector *self,
|
||||
const size_t size );
|
||||
|
||||
/**
|
||||
* Returns current storage capacity
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @return storage capacity
|
||||
*/
|
||||
size_t
|
||||
vector_capacity( const Vector *self );
|
||||
|
||||
/**
|
||||
* Decrease capacity to fit actual size.
|
||||
*
|
||||
* @param self a vector structure
|
||||
*/
|
||||
void
|
||||
vector_shrink( Vector *self );
|
||||
|
||||
/**
|
||||
* Removes all items.
|
||||
*
|
||||
* @param self a vector structure
|
||||
*/
|
||||
void
|
||||
vector_clear( Vector *self );
|
||||
|
||||
/**
|
||||
* Replace an item.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param index the index of the item to be replaced
|
||||
* @param item the new item
|
||||
*/
|
||||
void
|
||||
vector_set( Vector *self,
|
||||
const size_t index,
|
||||
const void *item );
|
||||
|
||||
/**
|
||||
* Erase an item.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param index the index of the item to be erased
|
||||
*/
|
||||
void
|
||||
vector_erase( Vector *self,
|
||||
const size_t index );
|
||||
|
||||
/**
|
||||
* Erase a range of items.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param first the index of the first item to be erased
|
||||
* @param last the index of the last item to be erased
|
||||
*/
|
||||
void
|
||||
vector_erase_range( Vector *self,
|
||||
const size_t first,
|
||||
const size_t last );
|
||||
|
||||
/**
|
||||
* Appends given item to the end of the vector.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param item the item to be inserted
|
||||
*/
|
||||
void
|
||||
vector_push_back( Vector *self,
|
||||
const void *item );
|
||||
|
||||
/**
|
||||
* Removes the last item of the vector.
|
||||
*
|
||||
* @param self a vector structure
|
||||
*/
|
||||
void
|
||||
vector_pop_back( Vector *self );
|
||||
|
||||
/**
|
||||
* Resizes the vector to contain size items
|
||||
*
|
||||
* If the current size is less than size, additional items are appended and
|
||||
* initialized with value. If the current size is greater than size, the
|
||||
* vector is reduced to its first size elements.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param size the new size
|
||||
*/
|
||||
void
|
||||
vector_resize( Vector *self,
|
||||
const size_t size );
|
||||
|
||||
/**
|
||||
* Insert a single item at specified index.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param index location before which to insert item
|
||||
* @param item the item to be inserted
|
||||
*/
|
||||
void
|
||||
vector_insert( Vector *self,
|
||||
const size_t index,
|
||||
const void *item );
|
||||
|
||||
/**
|
||||
* Insert raw data at specified index.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param index location before which to insert item
|
||||
* @param data a pointer to the items to be inserted
|
||||
* @param count the number of items to be inserted
|
||||
*/
|
||||
void
|
||||
vector_insert_data( Vector *self,
|
||||
const size_t index,
|
||||
const void * data,
|
||||
const size_t count );
|
||||
|
||||
/**
|
||||
* Append raw data to the end of the vector.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param data a pointer to the items to be inserted
|
||||
* @param count the number of items to be inserted
|
||||
*/
|
||||
void
|
||||
vector_push_back_data( Vector *self,
|
||||
const void * data,
|
||||
const size_t count );
|
||||
|
||||
/**
|
||||
* Sort vector items according to cmp function.
|
||||
*
|
||||
* @param self a vector structure
|
||||
* @param cmp a pointer a comparison function
|
||||
*/
|
||||
void
|
||||
vector_sort( Vector *self,
|
||||
int (*cmp)(const void *, const void *) );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __VECTOR_H__ */
|
477
source/shared_lib/include/graphics/freetype-gl/vertex-buffer.h
Normal file
477
source/shared_lib/include/graphics/freetype-gl/vertex-buffer.h
Normal file
@@ -0,0 +1,477 @@
|
||||
/* =========================================================================
|
||||
* Freetype GL - A C OpenGL Freetype engine
|
||||
* Platform: Any
|
||||
* WWW: http://code.google.com/p/freetype-gl/
|
||||
* -------------------------------------------------------------------------
|
||||
* Copyright 2011 Nicolas P. Rougier. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are
|
||||
* those of the authors and should not be interpreted as representing official
|
||||
* policies, either expressed or implied, of Nicolas P. Rougier.
|
||||
* ========================================================================= */
|
||||
#ifndef __VERTEX_BUFFER_H__
|
||||
#define __VERTEX_BUFFER_H__
|
||||
#if defined(__APPLE__)
|
||||
#include <Glut/glut.h>
|
||||
#else
|
||||
#include <GL/glut.h>
|
||||
#endif
|
||||
#include "vector.h"
|
||||
|
||||
#define MAX_VERTEX_ATTRIBUTE 64
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Generic vertex attribute.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/**
|
||||
* a client-side capability.
|
||||
*/
|
||||
GLenum target;
|
||||
|
||||
/**
|
||||
* a translated client-side capability.
|
||||
*/
|
||||
GLchar ctarget;
|
||||
|
||||
/**
|
||||
* index of the generic vertex attribute to be modified.
|
||||
*/
|
||||
GLuint index;
|
||||
|
||||
/**
|
||||
* Number of components per generic vertex attribute. Must be 1, 2, 3, or
|
||||
* 4. The initial value is 4.
|
||||
*/
|
||||
GLint size;
|
||||
|
||||
/**
|
||||
* Data type of each component in the array. Symbolic constants GL_BYTE,
|
||||
* GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT,
|
||||
* GL_FLOAT, or GL_DOUBLE are accepted. The initial value is GL_FLOAT.
|
||||
*/
|
||||
GLenum type;
|
||||
|
||||
/**
|
||||
* Whether fixed-point data values should be normalized (GL_TRUE) or
|
||||
* converted directly as fixed-point values (GL_FALSE) when they are
|
||||
* accessed.
|
||||
*/
|
||||
GLboolean normalized;
|
||||
|
||||
/**
|
||||
* Byte offset between consecutive generic vertex attributes. If stride is
|
||||
* 0, the generic vertex attributes are understood to be tightly packed in
|
||||
* the array. The initial value is 0.
|
||||
*/
|
||||
GLsizei stride;
|
||||
|
||||
/**
|
||||
* Pointer to the first component of the first attribute element in the
|
||||
* array.
|
||||
*/
|
||||
GLvoid * pointer;
|
||||
|
||||
/** Pointer to the function that enable this attribute. */
|
||||
void ( * enable )(void *);
|
||||
|
||||
} VertexAttribute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generic vertex buffer.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Format of the vertex buffer. */
|
||||
char * format;
|
||||
|
||||
/** Vector of vertices. */
|
||||
Vector * vertices;
|
||||
|
||||
/** GL identity of the vertices buffer. */
|
||||
GLuint vertices_id;
|
||||
|
||||
/** Vector of indices. */
|
||||
Vector * indices;
|
||||
|
||||
/** GL identity of the indices buffer. */
|
||||
GLuint indices_id;
|
||||
|
||||
/** Whether the vertex buffer needs to be uploaded to GPU memory. */
|
||||
char dirty;
|
||||
|
||||
/** Array of attributes. */
|
||||
VertexAttribute *attributes[MAX_VERTEX_ATTRIBUTE];
|
||||
} VertexBuffer;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates an empty vertex buffer.
|
||||
*
|
||||
* @param format a string describing vertex format.
|
||||
* @return an empty vertex buffer.
|
||||
*/
|
||||
VertexBuffer *
|
||||
vertex_buffer_new( const char *format );
|
||||
|
||||
|
||||
/**
|
||||
* Creates a vertex buffer from data.
|
||||
*
|
||||
* @param format a string describing vertex format.
|
||||
* @param vcount number of vertices
|
||||
* @param vertices raw vertices data
|
||||
* @param icount number of vertices
|
||||
* @param indices raw indices data
|
||||
* @return an empty vertex buffer.
|
||||
*/
|
||||
VertexBuffer *
|
||||
vertex_buffer_new_from_data( char *format,
|
||||
size_t vcount,
|
||||
void * vertices,
|
||||
size_t icount,
|
||||
GLuint * indices );
|
||||
|
||||
|
||||
/**
|
||||
* Deletes vertex buffer and releases GPU memory.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
*/
|
||||
void
|
||||
vertex_buffer_delete( VertexBuffer * self );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print information about a vertex buffer
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
*/
|
||||
void
|
||||
vertex_buffer_print( VertexBuffer * self );
|
||||
|
||||
|
||||
/**
|
||||
* Immediate draw
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param mode render mode
|
||||
* @param what attributes to be rendered
|
||||
*/
|
||||
void
|
||||
vertex_buffer_draw ( const char * format,
|
||||
const GLenum mode,
|
||||
const void * vertices,
|
||||
const size_t count );
|
||||
|
||||
|
||||
/**
|
||||
* Immediate draw with indexed vertices
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param mode render mode
|
||||
* @param what attributes to be rendered
|
||||
*/
|
||||
void
|
||||
vertex_buffer_draw_indexed ( const char * format,
|
||||
const GLenum mode,
|
||||
const void * vertices,
|
||||
const size_t vcount,
|
||||
const GLuint * indices,
|
||||
const size_t icount );
|
||||
|
||||
|
||||
/**
|
||||
* Render vertex buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param mode render mode
|
||||
* @param what attributes to be rendered
|
||||
*/
|
||||
void
|
||||
vertex_buffer_render ( VertexBuffer *self,
|
||||
GLenum mode,
|
||||
const char *what );
|
||||
|
||||
|
||||
/**
|
||||
* Upload buffer to GPU memory.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
*/
|
||||
void
|
||||
vertex_buffer_upload( VertexBuffer *self );
|
||||
|
||||
|
||||
/**
|
||||
* Clear all vertices and indices
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
*/
|
||||
void
|
||||
vertex_buffer_clear( VertexBuffer *self );
|
||||
|
||||
|
||||
/**
|
||||
* Appends a single index at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param index index to be appended
|
||||
*/
|
||||
void
|
||||
vertex_buffer_push_back_index ( VertexBuffer *self,
|
||||
GLuint index );
|
||||
|
||||
|
||||
/**
|
||||
* Appends a single vertex at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param vertex vertex to be appended
|
||||
*/
|
||||
void
|
||||
vertex_buffer_push_back_vertex ( VertexBuffer *self,
|
||||
void *vertex );
|
||||
|
||||
|
||||
/**
|
||||
* Appends indices at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param indices indices to be appended
|
||||
* @param count number of indices to be appended
|
||||
*/
|
||||
void
|
||||
vertex_buffer_push_back_indices ( VertexBuffer *self,
|
||||
GLuint *indices,
|
||||
size_t count );
|
||||
|
||||
|
||||
/**
|
||||
* Appends vertices at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param vertices vertices to be appended
|
||||
* @param count number of vertices to be appended
|
||||
*/
|
||||
void
|
||||
vertex_buffer_push_back_vertices ( VertexBuffer *self,
|
||||
void *vertices,
|
||||
size_t count );
|
||||
|
||||
|
||||
/**
|
||||
* Appends indices at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param index location before which to insert indices
|
||||
* @param indices indices to be appended
|
||||
* @param count number of indices to be appended
|
||||
*/
|
||||
void
|
||||
vertex_buffer_insert_indices ( VertexBuffer *self,
|
||||
size_t index,
|
||||
GLuint *indices,
|
||||
size_t count );
|
||||
|
||||
|
||||
/**
|
||||
* Appends indices at the end of the buffer.
|
||||
*
|
||||
* @param self a vertex buffer
|
||||
* @param index location before which to insert vertices
|
||||
* @param vertices vertices to be appended
|
||||
* @param count number of vertices to be appended
|
||||
*
|
||||
* @note
|
||||
* Indices after index will be increased by count.
|
||||
*/
|
||||
void
|
||||
vertex_buffer_add_vertices ( VertexBuffer *self,
|
||||
size_t index,
|
||||
void *vertices,
|
||||
size_t count );
|
||||
|
||||
|
||||
/**
|
||||
* Create an attribute from the given parameters.
|
||||
*
|
||||
* @param target client-side capability
|
||||
* @param index index of the generic vertex attribute to be modified.
|
||||
* @param size number of component
|
||||
* @param type data type
|
||||
* @param normalized Whether fixed-point data values should be normalized
|
||||
(GL_TRUE) or converted directly as fixed-point values
|
||||
(GL_FALSE) when they are accessed.
|
||||
* @param stride byte offset between consecutive attributes.
|
||||
* @param pointer pointer to the first component of the first attribute
|
||||
* element in the array.
|
||||
* @return a new initialized vertex attribute.
|
||||
*/
|
||||
VertexAttribute *
|
||||
vertex_attribute_new( GLenum target,
|
||||
GLuint index,
|
||||
GLint size,
|
||||
GLenum type,
|
||||
GLboolean normalized,
|
||||
GLsizei stride,
|
||||
GLvoid *pointer );
|
||||
|
||||
|
||||
/**
|
||||
* Create an attribute from the given description.
|
||||
*
|
||||
* @param format Format string specifies the format of a vertex attribute.
|
||||
* @return an initialized vertex attribute
|
||||
*
|
||||
*/
|
||||
VertexAttribute *
|
||||
vertex_attribute_parse( char *format );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the position vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_position_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the normal vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_normal_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the color vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_color_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the texture vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_tex_coord_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the fog vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_fog_coord_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the edge flag vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_edge_flag_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Enable the secondary color vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_secondary_color_enable( VertexAttribute *attr );
|
||||
|
||||
/**
|
||||
* Enable a generic vertex attribute.
|
||||
*
|
||||
* @param attr a vertex attribute
|
||||
*/
|
||||
void
|
||||
vertex_attribute_generic_attribute_enable( VertexAttribute *attr );
|
||||
|
||||
|
||||
/**
|
||||
* Returns the GL enum type correspond to given character.
|
||||
*
|
||||
* @param ctype character type
|
||||
* @return GL enum type
|
||||
*/
|
||||
GLenum
|
||||
GL_TYPE( char ctype );
|
||||
|
||||
|
||||
/**
|
||||
* Get the GL name of the given target.
|
||||
*
|
||||
* @param ctarget a char describing target ( one of v,c,e,f,n,s,t)
|
||||
* @return the associated GL target
|
||||
*/
|
||||
GLenum
|
||||
GL_VERTEX_ATTRIBUTE_TARGET( char ctarget );
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of a given GL enum type.
|
||||
*
|
||||
* @param gtype a GL enum type
|
||||
* @return the size of the given type
|
||||
*/
|
||||
GLuint
|
||||
GL_TYPE_SIZE( GLenum gtype );
|
||||
|
||||
|
||||
/**
|
||||
* Returns the literal string of given GL enum type.
|
||||
*
|
||||
* @param gtype a GL enum type
|
||||
* @return the literal string describing the type
|
||||
*/
|
||||
char *
|
||||
GL_TYPE_STRING( GLenum gtype );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __VERTEX_BUFFER_H__ */
|
280
source/shared_lib/include/graphics/gl/font_text_freetypegl.h
Normal file
280
source/shared_lib/include/graphics/gl/font_text_freetypegl.h
Normal file
@@ -0,0 +1,280 @@
|
||||
// ==============================================================
|
||||
// This file is part of the MegaGlest Shared Library (www.megaglest.org)
|
||||
//
|
||||
// Copyright (C) 2011 Mark Vejvoda and others
|
||||
//
|
||||
// You can redistribute this code and/or modify it under
|
||||
// the terms of the GNU General Public License as published
|
||||
// by the Free Software Foundation; either version 3 of the
|
||||
// License, or (at your option) any later version
|
||||
// ==============================================================
|
||||
|
||||
#ifndef TextFreetypeGL_h
|
||||
#define TextFreetypeGL_h
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
//#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
//#include "vector.h"
|
||||
#include "texture-font.h"
|
||||
#include "texture-atlas.h"
|
||||
#include "vertex-buffer.h"
|
||||
#include "font-manager.h"
|
||||
|
||||
#include "font_text.h"
|
||||
|
||||
namespace Shared { namespace Graphics { namespace Gl {
|
||||
|
||||
/**
|
||||
* Use Freetype-GL for rendering text in OpenGL
|
||||
*/
|
||||
//====================================================================
|
||||
class TextFreetypeGL : public Text
|
||||
{
|
||||
public:
|
||||
|
||||
static string langHeightText;
|
||||
static int faceResolution;
|
||||
|
||||
TextFreetypeGL(FontTextHandlerType type);
|
||||
virtual ~TextFreetypeGL();
|
||||
virtual void init(string fontName, int fontSize);
|
||||
|
||||
virtual void SetFaceSize(int);
|
||||
virtual int GetFaceSize();
|
||||
|
||||
virtual void Render(const char*, const int = -1);
|
||||
virtual float Advance(const char*, const int = -1);
|
||||
virtual float LineHeight(const char*, const int = -1);
|
||||
|
||||
virtual void Render(const wchar_t*, const int = -1);
|
||||
virtual float Advance(const wchar_t*, const int = -1);
|
||||
virtual float LineHeight(const wchar_t* = L" ", const int = -1);
|
||||
|
||||
private:
|
||||
//FTFont *ftFont;
|
||||
VertexBuffer *buffer;
|
||||
TextureAtlas *atlas;
|
||||
TextureFont *font;
|
||||
//TextureGlyph *glyph;
|
||||
FontManager *manager;
|
||||
//Markup markup;
|
||||
int fontFaceSize;
|
||||
|
||||
string fontName;
|
||||
const char* fontFile;
|
||||
|
||||
const char* findFont(const char *firstFontToTry=NULL);
|
||||
|
||||
void cleanupFont();
|
||||
};
|
||||
|
||||
}}}//end namespace
|
||||
|
||||
/**
|
||||
* Provides a way to easily walk multibyte unicode strings in the various
|
||||
* Unicode encodings (UTF-8, UTF-16, UTF-32, UCS-2, and UCS-4). Encodings
|
||||
* with elements larger than one byte must already be in the correct endian
|
||||
* order for the current architecture.
|
||||
*/
|
||||
template <typename T>
|
||||
class FreetypeGLUnicodeStringItr
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor. Also reads the first character and stores it.
|
||||
*
|
||||
* @param string The buffer to iterate. No copy is made.
|
||||
*/
|
||||
FreetypeGLUnicodeStringItr(const T* string) : curPos(string), nextPos(string)
|
||||
{
|
||||
(*this)++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Pre-increment operator. Reads the next unicode character and sets
|
||||
* the state appropriately.
|
||||
* Note - not protected against overruns.
|
||||
*/
|
||||
FreetypeGLUnicodeStringItr& operator++()
|
||||
{
|
||||
curPos = nextPos;
|
||||
// unicode handling
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 1: // UTF-8
|
||||
// get this character
|
||||
readUTF8(); break;
|
||||
case 2: // UTF-16
|
||||
readUTF16(); break;
|
||||
case 4: // UTF-32
|
||||
// fall through
|
||||
default: // error condition really, but give it a shot anyway
|
||||
curChar = *nextPos++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-increment operator. Reads the next character and sets
|
||||
* the state appropriately.
|
||||
* Note - not protected against overruns.
|
||||
*/
|
||||
FreetypeGLUnicodeStringItr operator++(int)
|
||||
{
|
||||
FreetypeGLUnicodeStringItr temp = *this;
|
||||
++*this;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Equality operator. Two FreetypeGLUnicodeStringItrs are considered equal
|
||||
* if they have the same current buffer and buffer position.
|
||||
*/
|
||||
bool operator==(const FreetypeGLUnicodeStringItr& right) const
|
||||
{
|
||||
if (curPos == right.getBufferFromHere())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dereference operator.
|
||||
*
|
||||
* @return The unicode codepoint of the character currently pointed
|
||||
* to by the FreetypeGLUnicodeStringItr.
|
||||
*/
|
||||
unsigned int operator*() const
|
||||
{
|
||||
return curChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Buffer-fetching getter. You can use this to retreive the buffer
|
||||
* starting at the currently-iterated character for functions which
|
||||
* require a Unicode string as input.
|
||||
*/
|
||||
const T* getBufferFromHere() const { return curPos; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* Helper function for reading a single UTF8 character from the string.
|
||||
* Updates internal state appropriately.
|
||||
*/
|
||||
void readUTF8();
|
||||
|
||||
/**
|
||||
* Helper function for reading a single UTF16 character from the string.
|
||||
* Updates internal state appropriately.
|
||||
*/
|
||||
void readUTF16();
|
||||
|
||||
/**
|
||||
* The buffer position of the first element in the current character.
|
||||
*/
|
||||
const T* curPos;
|
||||
|
||||
/**
|
||||
* The character stored at the current buffer position (prefetched on
|
||||
* increment, so there's no penalty for dereferencing more than once).
|
||||
*/
|
||||
unsigned int curChar;
|
||||
|
||||
/**
|
||||
* The buffer position of the first element in the next character.
|
||||
*/
|
||||
const T* nextPos;
|
||||
|
||||
// unicode magic numbers
|
||||
static const unsigned char utf8bytes[256];
|
||||
static const unsigned long offsetsFromUTF8[6];
|
||||
static const unsigned long highSurrogateStart;
|
||||
static const unsigned long highSurrogateEnd;
|
||||
static const unsigned long lowSurrogateStart;
|
||||
static const unsigned long lowSurrogateEnd;
|
||||
static const unsigned long highSurrogateShift;
|
||||
static const unsigned long lowSurrogateBase;
|
||||
};
|
||||
|
||||
/* The first character in a UTF8 sequence indicates how many bytes
|
||||
* to read (among other things) */
|
||||
template <typename T>
|
||||
const unsigned char FreetypeGLUnicodeStringItr<T>::utf8bytes[256] = {
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
|
||||
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,5,5,5,5,6,6,6,6
|
||||
};
|
||||
|
||||
/* Magic values subtracted from a buffer value during UTF8 conversion.
|
||||
* This table contains as many values as there might be trailing bytes
|
||||
* in a UTF-8 sequence. */
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
||||
0x03C82080UL, 0xFA082080UL, 0x82082080UL };
|
||||
|
||||
// get a UTF8 character; leave the tracking pointer at the start of the
|
||||
// next character
|
||||
// not protected against invalid UTF8
|
||||
template <typename T>
|
||||
inline void FreetypeGLUnicodeStringItr<T>::readUTF8()
|
||||
{
|
||||
unsigned int ch = 0;
|
||||
unsigned int extraBytesToRead = utf8bytes[(unsigned char)(*nextPos)];
|
||||
// falls through
|
||||
switch (extraBytesToRead)
|
||||
{
|
||||
case 6: ch += *nextPos++; ch <<= 6; /* remember, illegal UTF-8 */
|
||||
case 5: ch += *nextPos++; ch <<= 6; /* remember, illegal UTF-8 */
|
||||
case 4: ch += *nextPos++; ch <<= 6;
|
||||
case 3: ch += *nextPos++; ch <<= 6;
|
||||
case 2: ch += *nextPos++; ch <<= 6;
|
||||
case 1: ch += *nextPos++;
|
||||
}
|
||||
ch -= offsetsFromUTF8[extraBytesToRead-1];
|
||||
curChar = ch;
|
||||
}
|
||||
|
||||
// Magic numbers for UTF-16 conversions
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::highSurrogateStart = 0xD800;
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::highSurrogateEnd = 0xDBFF;
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::lowSurrogateStart = 0xDC00;
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::lowSurrogateEnd = 0xDFFF;
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::highSurrogateShift = 10;
|
||||
template <typename T>
|
||||
const unsigned long FreetypeGLUnicodeStringItr<T>::lowSurrogateBase = 0x0010000UL;
|
||||
|
||||
template <typename T>
|
||||
inline void FreetypeGLUnicodeStringItr<T>::readUTF16()
|
||||
{
|
||||
unsigned int ch = *nextPos++;
|
||||
// if we have the first half of the surrogate pair
|
||||
if (ch >= highSurrogateStart && ch <= highSurrogateEnd)
|
||||
{
|
||||
unsigned int ch2 = *curPos;
|
||||
// complete the surrogate pair
|
||||
if (ch2 >= lowSurrogateStart && ch2 <= lowSurrogateEnd)
|
||||
{
|
||||
ch = ((ch - highSurrogateStart) << highSurrogateShift)
|
||||
+ (ch2 - lowSurrogateStart) + lowSurrogateBase;
|
||||
++nextPos;
|
||||
}
|
||||
}
|
||||
curChar = ch;
|
||||
}
|
||||
|
||||
|
||||
#endif // USE_FREETYPEGL
|
||||
|
||||
#endif // TextFreetypeGL_h
|
Reference in New Issue
Block a user