@@ -27,9 +27,15 @@ OBJS = \ | |||
# freetype-gl | |||
OBJS += \ | |||
src/freetype-gl/font-manager.c.o \ | |||
src/freetype-gl/mat4.c.o \ | |||
src/freetype-gl/shader.c.o \ | |||
src/freetype-gl/text-buffer.c.o \ | |||
src/freetype-gl/texture-atlas.c.o \ | |||
src/freetype-gl/texture-font.c.o \ | |||
src/freetype-gl/vector.c.o | |||
src/freetype-gl/vector.c.o \ | |||
src/freetype-gl/vertex-attribute.c.o \ | |||
src/freetype-gl/vertex-buffer.c.o | |||
ifeq ($(MACOS),true) | |||
OBJS += src/pugl/pugl_osx_extended.m.o | |||
@@ -71,7 +77,7 @@ all: $(TARGET) | |||
# -------------------------------------------------------------- | |||
clean: | |||
$(RM) src/*.o src/pugl/*.o ../libdgl.* | |||
$(RM) src/*.o src/pugl/*.o src/freetype-gl/*.o ../libdgl.* | |||
debug: | |||
$(MAKE) DEBUG=true | |||
@@ -0,0 +1,270 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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. | |||
* ============================================================================ | |||
*/ | |||
#if 0 | |||
# if !defined(_WIN32) && !defined(_WIN64) | |||
# include <fontconfig/fontconfig.h> | |||
# endif | |||
#endif | |||
#include <assert.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <wchar.h> | |||
#include "font-manager.h" | |||
// ------------------------------------------------------------ file_exists --- | |||
int | |||
file_exists( const char * filename ) | |||
{ | |||
FILE * file = fopen( filename, "r" ); | |||
if ( file ) | |||
{ | |||
fclose(file); | |||
return 1; | |||
} | |||
return 0; | |||
} | |||
// ------------------------------------------------------- font_manager_new --- | |||
font_manager_t * | |||
font_manager_new( size_t width, size_t height, size_t depth ) | |||
{ | |||
font_manager_t *self; | |||
texture_atlas_t *atlas = texture_atlas_new( width, height, depth ); | |||
self = (font_manager_t *) malloc( sizeof(font_manager_t) ); | |||
if( !self ) | |||
{ | |||
fprintf( stderr, | |||
"line %d: No more memory for allocating data\n", __LINE__ ); | |||
exit( EXIT_FAILURE ); | |||
} | |||
self->atlas = atlas; | |||
self->fonts = vector_new( sizeof(texture_font_t *) ); | |||
self->cache = wcsdup( L" " ); | |||
return self; | |||
} | |||
// ---------------------------------------------------- font_manager_delete --- | |||
void | |||
font_manager_delete( font_manager_t * self ) | |||
{ | |||
size_t i; | |||
texture_font_t *font; | |||
assert( self ); | |||
for( i=0; i<vector_size( self->fonts ); ++i) | |||
{ | |||
font = *(texture_font_t **) vector_get( self->fonts, i ); | |||
texture_font_delete( font ); | |||
} | |||
vector_delete( self->fonts ); | |||
texture_atlas_delete( self->atlas ); | |||
if( self->cache ) | |||
{ | |||
free( self->cache ); | |||
} | |||
free( self ); | |||
} | |||
// ----------------------------------------------- font_manager_delete_font --- | |||
void | |||
font_manager_delete_font( font_manager_t * self, | |||
texture_font_t * font) | |||
{ | |||
size_t i; | |||
texture_font_t *other; | |||
assert( self ); | |||
assert( font ); | |||
for( i=0; i<self->fonts->size;++i ) | |||
{ | |||
other = (texture_font_t *) vector_get( self->fonts, i ); | |||
if ( (strcmp(font->filename, other->filename) == 0) | |||
&& ( font->size == other->size) ) | |||
{ | |||
vector_erase( self->fonts, i); | |||
break; | |||
} | |||
} | |||
texture_font_delete( font ); | |||
} | |||
// ----------------------------------------- font_manager_get_from_filename --- | |||
texture_font_t * | |||
font_manager_get_from_filename( font_manager_t *self, | |||
const char * filename, | |||
const float size ) | |||
{ | |||
size_t i; | |||
texture_font_t *font; | |||
assert( self ); | |||
for( i=0; i<vector_size(self->fonts); ++i ) | |||
{ | |||
font = * (texture_font_t **) vector_get( self->fonts, i ); | |||
if( (strcmp(font->filename, filename) == 0) && ( font->size == size) ) | |||
{ | |||
return font; | |||
} | |||
} | |||
font = texture_font_new_from_file( self->atlas, size, filename ); | |||
if( font ) | |||
{ | |||
vector_push_back( self->fonts, &font ); | |||
texture_font_load_glyphs( font, self->cache ); | |||
return font; | |||
} | |||
fprintf( stderr, "Unable to load \"%s\" (size=%.1f)\n", filename, size ); | |||
return 0; | |||
} | |||
// ----------------------------------------- font_manager_get_from_description --- | |||
texture_font_t * | |||
font_manager_get_from_description( font_manager_t *self, | |||
const char * family, | |||
const float size, | |||
const int bold, | |||
const int italic ) | |||
{ | |||
texture_font_t *font; | |||
char *filename = 0; | |||
assert( self ); | |||
if( file_exists( family ) ) | |||
{ | |||
filename = strdup( family ); | |||
} | |||
else | |||
{ | |||
#if defined(_WIN32) || defined(_WIN64) | |||
fprintf( stderr, "\"font_manager_get_from_description\" not implemented yet.\n" ); | |||
return 0; | |||
#endif | |||
filename = font_manager_match_description( self, family, size, bold, italic ); | |||
if( !filename ) | |||
{ | |||
fprintf( stderr, "No \"%s (size=%.1f, bold=%d, italic=%d)\" font available.\n", | |||
family, size, bold, italic ); | |||
return 0; | |||
} | |||
} | |||
font = font_manager_get_from_filename( self, filename, size ); | |||
free( filename ); | |||
return font; | |||
} | |||
// ------------------------------------------- font_manager_get_from_markup --- | |||
texture_font_t * | |||
font_manager_get_from_markup( font_manager_t *self, | |||
const markup_t *markup ) | |||
{ | |||
assert( self ); | |||
assert( markup ); | |||
return font_manager_get_from_description( self, markup->family, markup->size, | |||
markup->bold, markup->italic ); | |||
} | |||
// ----------------------------------------- font_manager_match_description --- | |||
char * | |||
font_manager_match_description( font_manager_t * self, | |||
const char * family, | |||
const float size, | |||
const int bold, | |||
const int italic ) | |||
{ | |||
// Use of fontconfig is disabled by default. | |||
#if 1 | |||
return 0; | |||
#else | |||
# if defined _WIN32 || defined _WIN64 | |||
fprintf( stderr, "\"font_manager_match_description\" not implemented for windows.\n" ); | |||
return 0; | |||
# endif | |||
char *filename = 0; | |||
int weight = FC_WEIGHT_REGULAR; | |||
int slant = FC_SLANT_ROMAN; | |||
if ( bold ) | |||
{ | |||
weight = FC_WEIGHT_BOLD; | |||
} | |||
if( italic ) | |||
{ | |||
slant = FC_SLANT_ITALIC; | |||
} | |||
FcInit(); | |||
FcPattern *pattern = FcPatternCreate(); | |||
FcPatternAddDouble( pattern, FC_SIZE, size ); | |||
FcPatternAddInteger( pattern, FC_WEIGHT, weight ); | |||
FcPatternAddInteger( pattern, FC_SLANT, slant ); | |||
FcPatternAddString( pattern, FC_FAMILY, (FcChar8*) family ); | |||
FcConfigSubstitute( 0, pattern, FcMatchPattern ); | |||
FcDefaultSubstitute( pattern ); | |||
FcResult result; | |||
FcPattern *match = FcFontMatch( 0, pattern, &result ); | |||
FcPatternDestroy( pattern ); | |||
if ( !match ) | |||
{ | |||
fprintf( stderr, "fontconfig error: could not match family '%s'", family ); | |||
return 0; | |||
} | |||
else | |||
{ | |||
FcValue value; | |||
FcResult result = FcPatternGet( match, FC_FILE, 0, &value ); | |||
if ( result ) | |||
{ | |||
fprintf( stderr, "fontconfig error: could not match family '%s'", family ); | |||
} | |||
else | |||
{ | |||
filename = strdup( (char *)(value.u.s) ); | |||
} | |||
} | |||
FcPatternDestroy( match ); | |||
return filename; | |||
#endif | |||
} |
@@ -0,0 +1,205 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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 __FONT_MANAGER_H__ | |||
#define __FONT_MANAGER_H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
#include "vector.h" | |||
#include "markup.h" | |||
#include "texture-font.h" | |||
#include "texture-atlas.h" | |||
/** | |||
* @file font-manager.h | |||
* @author Nicolas Rougier (Nicolas.Rougier@inria.fr) | |||
* | |||
* @defgroup font-manager Font manager | |||
* | |||
* Structure in charge of caching fonts. | |||
* | |||
* <b>Example Usage</b>: | |||
* @code | |||
* #include "font-manager.h" | |||
* | |||
* int main( int arrgc, char *argv[] ) | |||
* { | |||
* font_manager_t * manager = manager_new( 512, 512, 1 ); | |||
* texture_font_t * font = font_manager_get( manager, "Mono", 12, 0, 0 ); | |||
* | |||
* return 0; | |||
* } | |||
* @endcode | |||
* | |||
* @{ | |||
*/ | |||
/** | |||
* Structure in charge of caching fonts. | |||
*/ | |||
typedef struct font_manager_t { | |||
/** | |||
* Texture atlas to hold font glyphs. | |||
*/ | |||
texture_atlas_t * atlas; | |||
/** | |||
* Cached textures. | |||
*/ | |||
vector_t * fonts; | |||
/** | |||
* Default glyphs to be loaded when loading a new font. | |||
*/ | |||
wchar_t * cache; | |||
} font_manager_t; | |||
/** | |||
* Creates a new empty font manager. | |||
* | |||
* @param width width of the underlying atlas | |||
* @param height height of the underlying atlas | |||
* @param depth bit depth of the underlying atlas | |||
* | |||
* @return a new font manager. | |||
* | |||
*/ | |||
font_manager_t * | |||
font_manager_new( size_t width, | |||
size_t height, | |||
size_t depth ); | |||
/** | |||
* Deletes a font manager. | |||
* | |||
* @param self a font manager. | |||
*/ | |||
void | |||
font_manager_delete( font_manager_t *self ); | |||
/** | |||
* Deletes a font from the font manager. | |||
* | |||
* Note that font glyphs are not removed from the atlas. | |||
* | |||
* @param self a font manager. | |||
* @param font font to be deleted | |||
* | |||
*/ | |||
void | |||
font_manager_delete_font( font_manager_t * self, | |||
texture_font_t * font ); | |||
/** | |||
* Request for a font based on a filename. | |||
* | |||
* @param self a font manager. | |||
* @param filename font filename | |||
* @param size font size | |||
* | |||
* @return Requested font | |||
*/ | |||
texture_font_t * | |||
font_manager_get_from_filename( font_manager_t * self, | |||
const char * filename, | |||
const float size ); | |||
/** | |||
* Request for a font based on a description | |||
* | |||
* @param self a font manager | |||
* @param family font family | |||
* @param size font size | |||
* @param bold whether font is bold | |||
* @param italic whether font is italic | |||
* | |||
* @return Requested font | |||
*/ | |||
texture_font_t * | |||
font_manager_get_from_description( font_manager_t * self, | |||
const char * family, | |||
const float size, | |||
const int bold, | |||
const int italic ); | |||
/** | |||
* Request for a font based on a markup | |||
* | |||
* @param self a font manager | |||
* @param markup Markup describing a font | |||
* | |||
* @return Requested font | |||
*/ | |||
texture_font_t * | |||
font_manager_get_from_markup( font_manager_t *self, | |||
const markup_t *markup ); | |||
/** | |||
* Search for a font filename that match description. | |||
* | |||
* @param self a font manager | |||
* @param family font family | |||
* @param size font size | |||
* @param bold whether font is bold | |||
* @param italic whether font is italic | |||
* | |||
* @return Requested font filename | |||
*/ | |||
char * | |||
font_manager_match_description( font_manager_t * self, | |||
const char * family, | |||
const float size, | |||
const int bold, | |||
const int italic ); | |||
/** @} */ | |||
#ifdef __cplusplus | |||
} | |||
#endif // ifdef __cplusplus | |||
#endif /* __FONT_MANAGER_H__ */ | |||
@@ -0,0 +1,191 @@ | |||
/* ========================================================================= | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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 __MARKUP_H__ | |||
#define __MARKUP_H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
#include "texture-font.h" | |||
#include "vec234.h" | |||
/** | |||
* @file markup.h | |||
* @author Nicolas Rougier (Nicolas.Rougier@inria.fr) | |||
* | |||
* @defgroup markup Markup | |||
* | |||
* Simple structure that describes text properties. | |||
* | |||
* <b>Example Usage</b>: | |||
* @code | |||
* #include "markup.h" | |||
* | |||
* ... | |||
* | |||
* vec4 black = {{0.0, 0.0, 0.0, 1.0}}; | |||
* vec4 white = {{1.0, 1.0, 1.0, 1.0}}; | |||
* vec4 none = {{1.0, 1.0, 1.0, 0.0}}; | |||
* | |||
* markup_t normal = { | |||
* .family = "Droid Serif", | |||
* .size = 24.0, | |||
* .bold = 0, | |||
* .italic = 0, | |||
* .rise = 0.0, | |||
* .spacing = 1.0, | |||
* .gamma = 1.0, | |||
* .foreground_color = black, .background_color = none, | |||
* .underline = 0, .underline_color = black, | |||
* .overline = 0, .overline_color = black, | |||
* .strikethrough = 0, .strikethrough_color = black, | |||
* .font = 0, | |||
* }; | |||
* | |||
* ... | |||
* | |||
* @endcode | |||
* | |||
* @{ | |||
*/ | |||
/** | |||
* Simple structure that describes text properties. | |||
*/ | |||
typedef struct markup_t | |||
{ | |||
/** | |||
* A font family name such as "normal", "sans", "serif" or "monospace". | |||
*/ | |||
char * family; | |||
/** | |||
* Font size. | |||
*/ | |||
float size; | |||
/** | |||
* Whether text is bold. | |||
*/ | |||
int bold; | |||
/** | |||
* Whether text is italic. | |||
*/ | |||
int italic; | |||
/** | |||
* Vertical displacement from the baseline. | |||
*/ | |||
float rise; | |||
/** | |||
* Spacing between letters. | |||
*/ | |||
float spacing; | |||
/** | |||
* Gamma correction. | |||
*/ | |||
float gamma; | |||
/** | |||
* Text color. | |||
*/ | |||
vec4 foreground_color; | |||
/** | |||
* Background color. | |||
*/ | |||
vec4 background_color; | |||
/** | |||
* Whether outline is active. | |||
*/ | |||
int outline; | |||
/** | |||
* Outline color. | |||
*/ | |||
vec4 outline_color; | |||
/** | |||
* Whether underline is active. | |||
*/ | |||
int underline; | |||
/** | |||
* Underline color. | |||
*/ | |||
vec4 underline_color; | |||
/** | |||
* Whether overline is active. | |||
*/ | |||
int overline; | |||
/** | |||
* Overline color. | |||
*/ | |||
vec4 overline_color; | |||
/** | |||
* Whether strikethrough is active. | |||
*/ | |||
int strikethrough; | |||
/** | |||
* Strikethrough color. | |||
*/ | |||
vec4 strikethrough_color; | |||
/** | |||
* Pointer on the corresponding font (family/size/bold/italic) | |||
*/ | |||
texture_font_t * font; | |||
} markup_t; | |||
extern markup_t default_markup; | |||
/** @} */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __MARKUP_H__ */ |
@@ -0,0 +1,263 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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. | |||
* ============================================================================ | |||
*/ | |||
#include <assert.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <math.h> | |||
#include "mat4.h" | |||
#ifndef M_PI | |||
# define M_PI 3.14159265358979323846 | |||
#endif | |||
mat4 * | |||
mat4_new( void ) | |||
{ | |||
mat4 *self = (mat4 *) malloc( sizeof(mat4) ); | |||
return self; | |||
} | |||
void | |||
mat4_set_zero( mat4 *self ) | |||
{ | |||
assert( self ); | |||
memset( self, 0, sizeof( mat4 )); | |||
} | |||
void | |||
mat4_set_identity( mat4 *self ) | |||
{ | |||
assert( self ); | |||
memset( self, 0, sizeof( mat4 )); | |||
self->m00 = 1.0; | |||
self->m11 = 1.0; | |||
self->m22 = 1.0; | |||
self->m33 = 1.0; | |||
} | |||
void | |||
mat4_multiply( mat4 *self, mat4 *other ) | |||
{ | |||
mat4 m; | |||
size_t i; | |||
assert( self ); | |||
assert( other ); | |||
for( i=0; i<4; ++i ) | |||
{ | |||
m.data[i*4+0] = | |||
(self->data[i*4+0] * other->data[0*4+0]) + | |||
(self->data[i*4+1] * other->data[1*4+0]) + | |||
(self->data[i*4+2] * other->data[2*4+0]) + | |||
(self->data[i*4+3] * other->data[3*4+0]) ; | |||
m.data[i*4+1] = | |||
(self->data[i*4+0] * other->data[0*4+1]) + | |||
(self->data[i*4+1] * other->data[1*4+1]) + | |||
(self->data[i*4+2] * other->data[2*4+1]) + | |||
(self->data[i*4+3] * other->data[3*4+1]) ; | |||
m.data[i*4+2] = | |||
(self->data[i*4+0] * other->data[0*4+2]) + | |||
(self->data[i*4+1] * other->data[1*4+2]) + | |||
(self->data[i*4+2] * other->data[2*4+2]) + | |||
(self->data[i*4+3] * other->data[3*4+2]) ; | |||
m.data[i*4+3] = | |||
(self->data[i*4+0] * other->data[0*4+3]) + | |||
(self->data[i*4+1] * other->data[1*4+3]) + | |||
(self->data[i*4+2] * other->data[2*4+3]) + | |||
(self->data[i*4+3] * other->data[3*4+3]) ; | |||
} | |||
memcpy( self, &m, sizeof( mat4 ) ); | |||
} | |||
void | |||
mat4_set_orthographic( mat4 *self, | |||
float left, float right, | |||
float bottom, float top, | |||
float znear, float zfar ) | |||
{ | |||
assert( self ); | |||
assert( right != left ); | |||
assert( bottom != top ); | |||
assert( znear != zfar ); | |||
mat4_set_zero( self ); | |||
self->m00 = +2.0/(right-left); | |||
self->m30 = -(right+left)/(right-left); | |||
self->m11 = +2.0/(top-bottom); | |||
self->m31 = -(top+bottom)/(top-bottom); | |||
self->m22 = -2.0/(zfar-znear); | |||
self->m32 = -(zfar+znear)/(zfar-znear); | |||
self->m33 = 1.0; | |||
} | |||
void | |||
mat4_set_perspective( mat4 *self, | |||
float fovy, float aspect, | |||
float znear, float zfar) | |||
{ | |||
float h, w; | |||
assert( self ); | |||
assert( znear != zfar ); | |||
h = tan(fovy / 360.0 * M_PI) * znear; | |||
w = h * aspect; | |||
mat4_set_frustum( self, -w, w, -h, h, znear, zfar ); | |||
} | |||
void | |||
mat4_set_frustum( mat4 *self, | |||
float left, float right, | |||
float bottom, float top, | |||
float znear, float zfar ) | |||
{ | |||
assert( self ); | |||
assert( right != left ); | |||
assert( bottom != top ); | |||
assert( znear != zfar ); | |||
mat4_set_zero( self ); | |||
self->m00 = (2.0*znear)/(right-left); | |||
self->m20 = (right+left)/(right-left); | |||
self->m11 = (2.0*znear)/(top-bottom); | |||
self->m21 = (top+bottom)/(top-bottom); | |||
self->m22 = -(zfar+znear)/(zfar-znear); | |||
self->m32 = -(2.0*zfar*znear)/(zfar-znear); | |||
self->m23 = -1.0; | |||
} | |||
void | |||
mat4_set_rotation( mat4 *self, | |||
float angle, | |||
float x, float y, float z) | |||
{ | |||
float c, s, norm; | |||
assert( self ); | |||
c = cos( M_PI*angle/180.0 ); | |||
s = sin( M_PI*angle/180.0 ); | |||
norm = sqrt(x*x+y*y+z*z); | |||
x /= norm; y /= norm; z /= norm; | |||
mat4_set_identity( self ); | |||
self->m00 = x*x*(1-c)+c; | |||
self->m10 = y*x*(1-c)-z*s; | |||
self->m20 = z*x*(1-c)+y*s; | |||
self->m01 = x*y*(1-c)+z*s; | |||
self->m11 = y*y*(1-c)+c; | |||
self->m21 = z*y*(1-c)-x*s; | |||
self->m02 = x*z*(1-c)-y*s; | |||
self->m12 = y*z*(1-c)+x*s; | |||
self->m22 = z*z*(1-c)+c; | |||
} | |||
void | |||
mat4_set_translation( mat4 *self, | |||
float x, float y, float z) | |||
{ | |||
assert( self ); | |||
mat4_set_identity( self ); | |||
self-> m30 = x; | |||
self-> m31 = y; | |||
self-> m32 = z; | |||
} | |||
void | |||
mat4_set_scaling( mat4 *self, | |||
float x, float y, float z) | |||
{ | |||
assert( self ); | |||
mat4_set_identity( self ); | |||
self-> m00 = x; | |||
self-> m11 = y; | |||
self-> m22 = z; | |||
} | |||
void | |||
mat4_rotate( mat4 *self, | |||
float angle, | |||
float x, float y, float z) | |||
{ | |||
mat4 m; | |||
assert( self ); | |||
mat4_set_rotation( &m, angle, x, y, z); | |||
mat4_multiply( self, &m ); | |||
} | |||
void | |||
mat4_translate( mat4 *self, | |||
float x, float y, float z) | |||
{ | |||
mat4 m; | |||
assert( self ); | |||
mat4_set_translation( &m, x, y, z); | |||
mat4_multiply( self, &m ); | |||
} | |||
void | |||
mat4_scale( mat4 *self, | |||
float x, float y, float z) | |||
{ | |||
mat4 m; | |||
assert( self ); | |||
mat4_set_scaling( &m, x, y, z); | |||
mat4_multiply( self, &m ); | |||
} |
@@ -0,0 +1,117 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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 __MAT4_H__ | |||
#define __MAT4_H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/** | |||
* | |||
*/ | |||
typedef union | |||
{ | |||
float data[16]; /**< All compoments at once */ | |||
struct { | |||
float m00, m01, m02, m03; | |||
float m10, m11, m12, m13; | |||
float m20, m21, m22, m23; | |||
float m30, m31, m32, m33; | |||
}; | |||
} mat4; | |||
mat4 * | |||
mat4_new( void ); | |||
void | |||
mat4_set_identity( mat4 *self ); | |||
void | |||
mat4_set_zero( mat4 *self ); | |||
void | |||
mat4_multiply( mat4 *self, mat4 *other ); | |||
void | |||
mat4_set_orthographic( mat4 *self, | |||
float left, float right, | |||
float bottom, float top, | |||
float znear, float zfar ); | |||
void | |||
mat4_set_perspective( mat4 *self, | |||
float fovy, float aspect, | |||
float zNear, float zFar); | |||
void | |||
mat4_set_frustum( mat4 *self, | |||
float left, float right, | |||
float bottom, float top, | |||
float znear, float zfar ); | |||
void | |||
mat4_set_rotation( mat4 *self, | |||
float angle, | |||
float x, float y, float z); | |||
void | |||
mat4_set_translation( mat4 *self, | |||
float x, float y, float z); | |||
void | |||
mat4_set_scaling( mat4 *self, | |||
float x, float y, float z); | |||
void | |||
mat4_rotate( mat4 *self, | |||
float angle, | |||
float x, float y, float z); | |||
void | |||
mat4_translate( mat4 *self, | |||
float x, float y, float z); | |||
void | |||
mat4_scale( mat4 *self, | |||
float x, float y, float z); | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __MAT4_H__ */ |
@@ -0,0 +1,124 @@ | |||
// ---------------------------------------------------------------------------- | |||
// OpenGL Anti-Grain Geometry (GL-AGG) - Version 0.1 | |||
// A high quality OpenGL rendering engine for C | |||
// Copyright (C) 2012 Nicolas P. Rougier. All rights reserved. | |||
// Contact: Nicolas.Rougier@gmail.com | |||
// http://code.google.com/p/gl-agg/ | |||
// | |||
// 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. | |||
// ---------------------------------------------------------------------------- | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include "opengl.h" | |||
#include "shader.h" | |||
// ------------------------------------------------------------ shader_read --- | |||
char * | |||
shader_read( const char *filename ) | |||
{ | |||
FILE * file; | |||
char * buffer; | |||
size_t size; | |||
file = fopen( filename, "rb" ); | |||
if( !file ) | |||
{ | |||
fprintf( stderr, "Unable to open file \"%s\".\n", filename ); | |||
return 0; | |||
} | |||
fseek( file, 0, SEEK_END ); | |||
size = ftell( file ); | |||
fseek(file, 0, SEEK_SET ); | |||
buffer = (char *) malloc( (size+1) * sizeof( char *) ); | |||
fread( buffer, sizeof(char), size, file ); | |||
buffer[size] = 0; | |||
fclose( file ); | |||
return buffer; | |||
} | |||
// --------------------------------------------------------- shader_compile --- | |||
GLuint | |||
shader_compile( const char* source, | |||
const GLenum type ) | |||
{ | |||
GLint compile_status; | |||
GLuint handle = glCreateShader( type ); | |||
glShaderSource( handle, 1, &source, 0 ); | |||
glCompileShader( handle ); | |||
glGetShaderiv( handle, GL_COMPILE_STATUS, &compile_status ); | |||
if( compile_status == GL_FALSE ) | |||
{ | |||
GLchar messages[256]; | |||
glGetShaderInfoLog( handle, sizeof(messages), 0, &messages[0] ); | |||
fprintf( stderr, "%s\n", messages ); | |||
exit( EXIT_FAILURE ); | |||
} | |||
return handle; | |||
} | |||
// ------------------------------------------------------------ shader_load --- | |||
GLuint | |||
shader_load( const char * vert_filename, | |||
const char * frag_filename ) | |||
{ | |||
GLuint handle = glCreateProgram( ); | |||
GLint link_status; | |||
if( vert_filename && strlen( vert_filename ) ) | |||
{ | |||
char *vert_source = shader_read( vert_filename ); | |||
GLuint vert_shader = shader_compile( vert_source, GL_VERTEX_SHADER); | |||
glAttachShader( handle, vert_shader); | |||
glDeleteShader( vert_shader ); | |||
free( vert_source ); | |||
} | |||
if( frag_filename && strlen( frag_filename ) ) | |||
{ | |||
char *frag_source = shader_read( frag_filename ); | |||
GLuint frag_shader = shader_compile( frag_source, GL_FRAGMENT_SHADER); | |||
glAttachShader( handle, frag_shader); | |||
glDeleteShader( frag_shader ); | |||
free( frag_source ); | |||
} | |||
glLinkProgram( handle ); | |||
glGetProgramiv( handle, GL_LINK_STATUS, &link_status ); | |||
if (link_status == GL_FALSE) | |||
{ | |||
GLchar messages[256]; | |||
glGetProgramInfoLog( handle, sizeof(messages), 0, &messages[0] ); | |||
fprintf( stderr, "%s\n", messages ); | |||
exit(1); | |||
} | |||
return handle; | |||
} |
@@ -0,0 +1,119 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012,2013 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 __SHADER_H__ | |||
#define __SHADER_H__ | |||
#include "opengl.h" | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
/** | |||
* @file shader.h | |||
* @author Nicolas Rougier (Nicolas.Rougier@inria.fr) | |||
* | |||
* @defgroup shader Shader | |||
* | |||
* Simple functions for loading/building a shader from sources. | |||
* | |||
* <b>Example Usage</b>: | |||
* @code | |||
* #include "shader.h" | |||
* | |||
* int main( int arrgc, char *argv[] ) | |||
* { | |||
* GLuint shader = shader_load("shader.vert", "shader.frag"); | |||
* | |||
* return 0; | |||
* } | |||
* @endcode | |||
* | |||
* @{ | |||
*/ | |||
/** | |||
* Read a fragment or vertex shader from a file | |||
* | |||
* @param filename file to read shader from | |||
* @return a newly-allocated text buffer containing code. This buffer | |||
* must be freed after usage. | |||
* | |||
*/ | |||
char * | |||
shader_read( const char *filename ); | |||
/** | |||
* Compile a shader from a text buffer. | |||
* | |||
* @param source code of the shader | |||
* @param type type of the shader | |||
* | |||
* @return a handle on the compiled program | |||
* | |||
*/ | |||
GLuint | |||
shader_compile( const char* source, | |||
const GLenum type ); | |||
/** | |||
* Load a vertex and fragment shader sources and build program | |||
* | |||
* @param vert_filename vertex shader filename | |||
* @param frag_filename fragment shader filename | |||
* | |||
* @return a handle on the built program | |||
* | |||
*/ | |||
GLuint | |||
shader_load( const char * vert_filename, | |||
const char * frag_filename ); | |||
/** | |||
* | |||
*/ | |||
GLuint | |||
shader_get( GLuint self, | |||
const char * name ); | |||
/** @} */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* __SHADER_H__ */ |
@@ -0,0 +1,448 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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. | |||
* ============================================================================ | |||
*/ | |||
#include <wchar.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <stdarg.h> | |||
#include <assert.h> | |||
#include "opengl.h" | |||
#include "text-buffer.h" | |||
#define SET_GLYPH_VERTEX(value,x0,y0,z0,s0,t0,r,g,b,a,sh,gm) { \ | |||
glyph_vertex_t *gv=&value; \ | |||
gv->x=x0; gv->y=y0; gv->z=z0; \ | |||
gv->u=s0; gv->v=t0; \ | |||
gv->r=r; gv->g=g; gv->b=b; gv->a=a; \ | |||
gv->shift=sh; gv->gamma=gm;} | |||
// ---------------------------------------------------------------------------- | |||
text_buffer_t * | |||
text_buffer_new( size_t depth ) | |||
{ | |||
text_buffer_t *self = (text_buffer_t *) malloc (sizeof(text_buffer_t)); | |||
self->buffer = vertex_buffer_new( | |||
"vertex:3f,tex_coord:2f,color:4f,ashift:1f,agamma:1f" ); | |||
self->manager = font_manager_new( 512, 512, depth ); | |||
self->shader = shader_load("shaders/text.vert", | |||
"shaders/text.frag"); | |||
self->shader_texture = glGetUniformLocation(self->shader, "texture"); | |||
self->shader_pixel = glGetUniformLocation(self->shader, "pixel"); | |||
self->line_start = 0; | |||
self->line_ascender = 0; | |||
self->base_color.r = 0.0; | |||
self->base_color.g = 0.0; | |||
self->base_color.b = 0.0; | |||
self->base_color.a = 1.0; | |||
self->line_descender = 0; | |||
return self; | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_delete( text_buffer_t * self ) | |||
{ | |||
vertex_buffer_delete( self->buffer ); | |||
glDeleteProgram( self->shader ); | |||
free( self ); | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_clear( text_buffer_t * self ) | |||
{ | |||
assert( self ); | |||
vertex_buffer_clear( self->buffer ); | |||
self->line_start = 0; | |||
self->line_ascender = 0; | |||
self->line_descender = 0; | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_render( text_buffer_t * self ) | |||
{ | |||
glEnable( GL_BLEND ); | |||
glActiveTexture( GL_TEXTURE0 ); | |||
glBindTexture( GL_TEXTURE_2D, self->manager->atlas->id ); | |||
if( self->manager->atlas->depth == 1 ) | |||
{ | |||
//glDisable( GL_COLOR_MATERIAL ); | |||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | |||
glBlendColor( 1, 1, 1, 1 ); | |||
} | |||
else | |||
{ | |||
//glEnable( GL_COLOR_MATERIAL ); | |||
//glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |||
//glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ); | |||
//glBlendColor( 1.0, 1.0, 1.0, 1.0 ); | |||
//glBlendFunc( GL_CONSTANT_COLOR_EXT, GL_ONE_MINUS_SRC_COLOR ); | |||
//glBlendColor( self->base_color.r, | |||
//self->base_color.g, | |||
//self->base_color.b, | |||
//self->base_color.a ); | |||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); | |||
glBlendColor( 1, 1, 1, 1 ); | |||
} | |||
glUseProgram( self->shader ); | |||
glUniform1i( self->shader_texture, 0 ); | |||
glUniform3f( self->shader_pixel, | |||
1.0/self->manager->atlas->width, | |||
1.0/self->manager->atlas->height, | |||
self->manager->atlas->depth ); | |||
vertex_buffer_render( self->buffer, GL_TRIANGLES ); | |||
glUseProgram( 0 ); | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_printf( text_buffer_t * self, vec2 *pen, ... ) | |||
{ | |||
markup_t *markup; | |||
wchar_t *text; | |||
va_list args; | |||
if( vertex_buffer_size( self->buffer ) == 0 ) | |||
{ | |||
self->origin = *pen; | |||
} | |||
va_start ( args, pen ); | |||
do { | |||
markup = va_arg( args, markup_t * ); | |||
if( markup == NULL ) | |||
{ | |||
return; | |||
} | |||
text = va_arg( args, wchar_t * ); | |||
text_buffer_add_text( self, pen, markup, text, wcslen(text) ); | |||
} while( markup != 0 ); | |||
va_end ( args ); | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_move_last_line( text_buffer_t * self, float dy ) | |||
{ | |||
size_t i, j; | |||
for( i=self->line_start; i < vector_size( self->buffer->items ); ++i ) | |||
{ | |||
ivec4 *item = (ivec4 *) vector_get( self->buffer->items, i); | |||
for( j=item->vstart; j<item->vstart+item->vcount; ++j) | |||
{ | |||
glyph_vertex_t * vertex = | |||
(glyph_vertex_t *) vector_get( self->buffer->vertices, j ); | |||
vertex->y -= dy; | |||
} | |||
} | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_add_text( text_buffer_t * self, | |||
vec2 * pen, markup_t * markup, | |||
wchar_t * text, size_t length ) | |||
{ | |||
font_manager_t * manager = self->manager; | |||
size_t i; | |||
if( markup == NULL ) | |||
{ | |||
return; | |||
} | |||
if( !markup->font ) | |||
{ | |||
markup->font = font_manager_get_from_markup( manager, markup ); | |||
if( ! markup->font ) | |||
{ | |||
fprintf( stderr, "Houston, we've got a problem !\n" ); | |||
exit( EXIT_FAILURE ); | |||
} | |||
} | |||
if( length == 0 ) | |||
{ | |||
length = wcslen(text); | |||
} | |||
if( vertex_buffer_size( self->buffer ) == 0 ) | |||
{ | |||
self->origin = *pen; | |||
} | |||
text_buffer_add_wchar( self, pen, markup, text[0], 0 ); | |||
for( i=1; i<length; ++i ) | |||
{ | |||
text_buffer_add_wchar( self, pen, markup, text[i], text[i-1] ); | |||
} | |||
} | |||
// ---------------------------------------------------------------------------- | |||
void | |||
text_buffer_add_wchar( text_buffer_t * self, | |||
vec2 * pen, markup_t * markup, | |||
wchar_t current, wchar_t previous ) | |||
{ | |||
size_t vcount = 0; | |||
size_t icount = 0; | |||
vertex_buffer_t * buffer = self->buffer; | |||
texture_font_t * font = markup->font; | |||
float gamma = markup->gamma; | |||
// Maximum number of vertices is 20 (= 5x2 triangles) per glyph: | |||
// - 2 triangles for background | |||
// - 2 triangles for overline | |||
// - 2 triangles for underline | |||
// - 2 triangles for strikethrough | |||
// - 2 triangles for glyph | |||
glyph_vertex_t vertices[4*5]; | |||
GLuint indices[6*5]; | |||
texture_glyph_t *glyph; | |||
texture_glyph_t *black; | |||
float kerning = 0; | |||
if( current == L'\n' ) | |||
{ | |||
pen->x = self->origin.x; | |||
pen->y += self->line_descender; | |||
self->line_descender = 0; | |||
self->line_ascender = 0; | |||
self->line_start = vector_size( self->buffer->items ); | |||
return; | |||
} | |||
if( markup->font->ascender > self->line_ascender ) | |||
{ | |||
float y = pen->y; | |||
pen->y -= (markup->font->ascender - self->line_ascender); | |||
text_buffer_move_last_line( self, (int)(y-pen->y) ); | |||
self->line_ascender = markup->font->ascender; | |||
} | |||
if( markup->font->descender < self->line_descender ) | |||
{ | |||
self->line_descender = markup->font->descender; | |||
} | |||
glyph = texture_font_get_glyph( font, current ); | |||
black = texture_font_get_glyph( font, -1 ); | |||
if( glyph == NULL ) | |||
{ | |||
return; | |||
} | |||
if( previous && markup->font->kerning ) | |||
{ | |||
kerning = texture_glyph_get_kerning( glyph, previous ); | |||
} | |||
pen->x += kerning; | |||
// Background | |||
if( markup->background_color.alpha > 0 ) | |||
{ | |||
float r = markup->background_color.r; | |||
float g = markup->background_color.g; | |||
float b = markup->background_color.b; | |||
float a = markup->background_color.a; | |||
float x0 = ( pen->x -kerning ); | |||
float y0 = (int)( pen->y + font->descender ); | |||
float x1 = ( x0 + glyph->advance_x ); | |||
float y1 = (int)( y0 + font->height + font->linegap ); | |||
float s0 = black->s0; | |||
float t0 = black->t0; | |||
float s1 = black->s1; | |||
float t1 = black->t1; | |||
SET_GLYPH_VERTEX(vertices[vcount+0], | |||
(int)x0,y0,0, s0,t0, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+1], | |||
(int)x0,y1,0, s0,t1, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+2], | |||
(int)x1,y1,0, s1,t1, r,g,b,a, x1-((int)x1), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+3], | |||
(int)x1,y0,0, s1,t0, r,g,b,a, x1-((int)x1), gamma ); | |||
indices[icount + 0] = vcount+0; | |||
indices[icount + 1] = vcount+1; | |||
indices[icount + 2] = vcount+2; | |||
indices[icount + 3] = vcount+0; | |||
indices[icount + 4] = vcount+2; | |||
indices[icount + 5] = vcount+3; | |||
vcount += 4; | |||
icount += 6; | |||
} | |||
// Underline | |||
if( markup->underline ) | |||
{ | |||
float r = markup->underline_color.r; | |||
float g = markup->underline_color.g; | |||
float b = markup->underline_color.b; | |||
float a = markup->underline_color.a; | |||
float x0 = ( pen->x - kerning ); | |||
float y0 = (int)( pen->y + font->underline_position ); | |||
float x1 = ( x0 + glyph->advance_x ); | |||
float y1 = (int)( y0 + font->underline_thickness ); | |||
float s0 = black->s0; | |||
float t0 = black->t0; | |||
float s1 = black->s1; | |||
float t1 = black->t1; | |||
SET_GLYPH_VERTEX(vertices[vcount+0], | |||
(int)x0,y0,0, s0,t0, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+1], | |||
(int)x0,y1,0, s0,t1, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+2], | |||
(int)x1,y1,0, s1,t1, r,g,b,a, x1-((int)x1), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+3], | |||
(int)x1,y0,0, s1,t0, r,g,b,a, x1-((int)x1), gamma ); | |||
indices[icount + 0] = vcount+0; | |||
indices[icount + 1] = vcount+1; | |||
indices[icount + 2] = vcount+2; | |||
indices[icount + 3] = vcount+0; | |||
indices[icount + 4] = vcount+2; | |||
indices[icount + 5] = vcount+3; | |||
vcount += 4; | |||
icount += 6; | |||
} | |||
// Overline | |||
if( markup->overline ) | |||
{ | |||
float r = markup->overline_color.r; | |||
float g = markup->overline_color.g; | |||
float b = markup->overline_color.b; | |||
float a = markup->overline_color.a; | |||
float x0 = ( pen->x -kerning ); | |||
float y0 = (int)( pen->y + (int)font->ascender ); | |||
float x1 = ( x0 + glyph->advance_x ); | |||
float y1 = (int)( y0 + (int)font->underline_thickness ); | |||
float s0 = black->s0; | |||
float t0 = black->t0; | |||
float s1 = black->s1; | |||
float t1 = black->t1; | |||
SET_GLYPH_VERTEX(vertices[vcount+0], | |||
(int)x0,y0,0, s0,t0, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+1], | |||
(int)x0,y1,0, s0,t1, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+2], | |||
(int)x1,y1,0, s1,t1, r,g,b,a, x1-((int)x1), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+3], | |||
(int)x1,y0,0, s1,t0, r,g,b,a, x1-((int)x1), gamma ); | |||
indices[icount + 0] = vcount+0; | |||
indices[icount + 1] = vcount+1; | |||
indices[icount + 2] = vcount+2; | |||
indices[icount + 3] = vcount+0; | |||
indices[icount + 4] = vcount+2; | |||
indices[icount + 5] = vcount+3; | |||
vcount += 4; | |||
icount += 6; | |||
} | |||
/* Strikethrough */ | |||
if( markup->strikethrough ) | |||
{ | |||
float r = markup->strikethrough_color.r; | |||
float g = markup->strikethrough_color.g; | |||
float b = markup->strikethrough_color.b; | |||
float a = markup->strikethrough_color.a; | |||
float x0 = ( pen->x -kerning ); | |||
float y0 = (int)( pen->y + (int)font->ascender*.33); | |||
float x1 = ( x0 + glyph->advance_x ); | |||
float y1 = (int)( y0 + (int)font->underline_thickness ); | |||
float s0 = black->s0; | |||
float t0 = black->t0; | |||
float s1 = black->s1; | |||
float t1 = black->t1; | |||
SET_GLYPH_VERTEX(vertices[vcount+0], | |||
(int)x0,y0,0, s0,t0, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+1], | |||
(int)x0,y1,0, s0,t1, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+2], | |||
(int)x1,y1,0, s1,t1, r,g,b,a, x1-((int)x1), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+3], | |||
(int)x1,y0,0, s1,t0, r,g,b,a, x1-((int)x1), gamma ); | |||
indices[icount + 0] = vcount+0; | |||
indices[icount + 1] = vcount+1; | |||
indices[icount + 2] = vcount+2; | |||
indices[icount + 3] = vcount+0; | |||
indices[icount + 4] = vcount+2; | |||
indices[icount + 5] = vcount+3; | |||
vcount += 4; | |||
icount += 6; | |||
} | |||
{ | |||
// Actual glyph | |||
float r = markup->foreground_color.red; | |||
float g = markup->foreground_color.green; | |||
float b = markup->foreground_color.blue; | |||
float a = markup->foreground_color.alpha; | |||
float x0 = ( pen->x + glyph->offset_x ); | |||
float y0 = (int)( pen->y + glyph->offset_y ); | |||
float x1 = ( x0 + glyph->width ); | |||
float y1 = (int)( y0 - glyph->height ); | |||
float s0 = glyph->s0; | |||
float t0 = glyph->t0; | |||
float s1 = glyph->s1; | |||
float t1 = glyph->t1; | |||
SET_GLYPH_VERTEX(vertices[vcount+0], | |||
(int)x0,y0,0, s0,t0, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+1], | |||
(int)x0,y1,0, s0,t1, r,g,b,a, x0-((int)x0), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+2], | |||
(int)x1,y1,0, s1,t1, r,g,b,a, x1-((int)x1), gamma ); | |||
SET_GLYPH_VERTEX(vertices[vcount+3], | |||
(int)x1,y0,0, s1,t0, r,g,b,a, x1-((int)x1), gamma ); | |||
indices[icount + 0] = vcount+0; | |||
indices[icount + 1] = vcount+1; | |||
indices[icount + 2] = vcount+2; | |||
indices[icount + 3] = vcount+0; | |||
indices[icount + 4] = vcount+2; | |||
indices[icount + 5] = vcount+3; | |||
vcount += 4; | |||
icount += 6; | |||
vertex_buffer_push_back( buffer, vertices, vcount, indices, icount ); | |||
pen->x += glyph->advance_x * (1.0 + markup->spacing); | |||
} | |||
} |
@@ -0,0 +1,285 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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 __TEXT_BUFFER_H__ | |||
#define __TEXT_BUFFER_H__ | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
#include "vertex-buffer.h" | |||
#include "font-manager.h" | |||
#include "markup.h" | |||
#include "shader.h" | |||
/** | |||
* Use LCD filtering | |||
*/ | |||
#define LCD_FILTERING_ON 3 | |||
/** | |||
* Do not use LCD filtering | |||
*/ | |||
#define LCD_FILTERING_OFF 1 | |||
/** | |||
* @file text-buffer.h | |||
* @author Nicolas Rougier (Nicolas.Rougier@inria.fr) | |||
* | |||
* @defgroup text-buffer Text buffer | |||
* | |||
* | |||
* <b>Example Usage</b>: | |||
* @code | |||
* #include "shader.h" | |||
* | |||
* int main( int arrgc, char *argv[] ) | |||
* { | |||
* | |||
* return 0; | |||
* } | |||
* @endcode | |||
* | |||
* @{ | |||
*/ | |||
/** | |||
* Text buffer structure | |||
*/ | |||
typedef struct text_buffer_t { | |||
/** | |||
* Vertex buffer | |||
*/ | |||
vertex_buffer_t *buffer; | |||
/** | |||
* Font manager | |||
*/ | |||
font_manager_t *manager; | |||
/** | |||
* Base color for text | |||
*/ | |||
vec4 base_color; | |||
/** | |||
* Pen origin | |||
*/ | |||
vec2 origin; | |||
/** | |||
* Index (in the vertex buffer) of the line start | |||
*/ | |||
size_t line_start; | |||
/** | |||
* Current line ascender | |||
*/ | |||
float line_ascender; | |||
/** | |||
* Current line decender | |||
*/ | |||
float line_descender; | |||
/** | |||
* Shader handler | |||
*/ | |||
GLuint shader; | |||
/** | |||
* Shader "texture" location | |||
*/ | |||
GLuint shader_texture; | |||
/** | |||
* Shader "pixel" location | |||
*/ | |||
GLuint shader_pixel; | |||
} text_buffer_t; | |||
/** | |||
* Glyph vertex structure | |||
*/ | |||
typedef struct glyph_vertex_t { | |||
/** | |||
* Vertex x coordinates | |||
*/ | |||
float x; | |||
/** | |||
* Vertex y coordinates | |||
*/ | |||
float y; | |||
/** | |||
* Vertex z coordinates | |||
*/ | |||
float z; | |||
/** | |||
* Texture first coordinate | |||
*/ | |||
float u; | |||
/** | |||
* Texture second coordinate | |||
*/ | |||
float v; | |||
/** | |||
* Color red component | |||
*/ | |||
float r; | |||
/** | |||
* Color green component | |||
*/ | |||
float g; | |||
/** | |||
* Color blue component | |||
*/ | |||
float b; | |||
/** | |||
* Color alpha component | |||
*/ | |||
float a; | |||
/** | |||
* Shift along x | |||
*/ | |||
float shift; | |||
/** | |||
* Color gamma correction | |||
*/ | |||
float gamma; | |||
} glyph_vertex_t; | |||
/** | |||
* Creates a new empty text buffer. | |||
* | |||
* @param depth Underlying atlas bit depth (1 or 3) | |||
* | |||
* @return a new empty text buffer. | |||
* | |||
*/ | |||
text_buffer_t * | |||
text_buffer_new( size_t depth ); | |||
/** | |||
* Deletes texture buffer and its associated shader and vertex buffer. | |||
* | |||
* @param self texture buffer to delete | |||
* | |||
*/ | |||
void | |||
text_buffer_delete( text_buffer_t * self ); | |||
/** | |||
* Render a text buffer. | |||
* | |||
* @param self a text buffer | |||
* | |||
*/ | |||
void | |||
text_buffer_render( text_buffer_t * self ); | |||
/** | |||
* Print some text to the text buffer | |||
* | |||
* @param self a text buffer | |||
* @param pen position of text start | |||
* @param ... a series of markup_t *, wchar_t * ended by NULL | |||
* | |||
*/ | |||
void | |||
text_buffer_printf( text_buffer_t * self, vec2 * pen, ... ); | |||
/** | |||
* Add some text to the text buffer | |||
* | |||
* @param self a text buffer | |||
* @param pen position of text start | |||
* @param markup Markup to be used to add text | |||
* @param text Text to be added | |||
* @param length Length of text to be added | |||
*/ | |||
void | |||
text_buffer_add_text( text_buffer_t * self, | |||
vec2 * pen, markup_t * markup, | |||
wchar_t * text, size_t length ); | |||
/** | |||
* Add a char to the text buffer | |||
* | |||
* @param self a text buffer | |||
* @param pen position of text start | |||
* @param markup markup to be used to add text | |||
* @param current charactr to be added | |||
* @param previous previous character (if any) | |||
*/ | |||
void | |||
text_buffer_add_wchar( text_buffer_t * self, | |||
vec2 * pen, markup_t * markup, | |||
wchar_t current, wchar_t previous ); | |||
/** | |||
* Clear text buffer | |||
* | |||
* @param self a text buffer | |||
*/ | |||
void | |||
text_buffer_clear( text_buffer_t * self ); | |||
/** @} */ | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif /* #define __TEXT_BUFFER_H__ */ |
@@ -31,6 +31,7 @@ | |||
* policies, either expressed or implied, of Nicolas P. Rougier. | |||
* ============================================================================ | |||
*/ | |||
#include "../freetype/FreeTypeAmalgam.h" | |||
#include "../freetype/FreeTypeAmalgam.c" | |||
#include <stdint.h> | |||
#include <stdlib.h> | |||
@@ -478,7 +479,7 @@ texture_font_load_glyphs( texture_font_t * self, | |||
flags |= FT_LOAD_FORCE_AUTOHINT; | |||
} | |||
#if 0 | |||
if( depth == 3 ) | |||
{ | |||
FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT ); | |||
@@ -488,6 +489,7 @@ texture_font_load_glyphs( texture_font_t * self, | |||
FT_Library_SetLcdFilterWeights( library, self->lcd_weights ); | |||
} | |||
} | |||
#endif | |||
error = FT_Load_Glyph( face, glyph_index, flags ); | |||
if( error ) | |||
{ | |||
@@ -0,0 +1,168 @@ | |||
/* ============================================================================ | |||
* Freetype GL - A C OpenGL Freetype engine | |||
* Platform: Any | |||
* WWW: http://code.google.com/p/freetype-gl/ | |||
* ---------------------------------------------------------------------------- | |||
* Copyright 2011,2012 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. | |||
* ============================================================================ | |||
*/ | |||
#include <assert.h> | |||
#include <string.h> | |||
#include <stdlib.h> | |||
#include <stdio.h> | |||
#include "vec234.h" | |||
#include "platform.h" | |||
#include "vertex-attribute.h" | |||
// ---------------------------------------------------------------------------- | |||
vertex_attribute_t * | |||
vertex_attribute_new( GLchar * name, | |||
GLint size, | |||
GLenum type, | |||
GLboolean normalized, | |||
GLsizei stride, | |||
GLvoid *pointer ) | |||
{ | |||
vertex_attribute_t *attribute = | |||
(vertex_attribute_t *) malloc (sizeof(vertex_attribute_t)); | |||
assert( size > 0 ); | |||
attribute->name = (GLchar *) strdup( name ); | |||
attribute->index = -1; | |||
attribute->size = size; | |||
attribute->type = type; | |||
attribute->normalized = normalized; | |||
attribute->stride = stride; | |||
attribute->pointer = pointer; | |||
return attribute; | |||
} | |||