mirror of
https://github.com/glest/glest-source.git
synced 2025-08-27 01:44:23 +02:00
- added game statistics gathering and saving on masterserver.
see Table glestserver now has the field: gameUUID Table glestgamestats has game header stats Table glestgameplayerstats has game player stats
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,238 +1,238 @@
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#ifdef HAVE_FONTCONFIG
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include "font-manager.h"
|
||||
|
||||
|
||||
wchar_t *
|
||||
wcsdup( const wchar_t *string )
|
||||
{
|
||||
wchar_t * result;
|
||||
assert( string );
|
||||
result = (wchar_t *) malloc( (wcslen(string) + 1) * sizeof(wchar_t) );
|
||||
wcscpy( result, string );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FontManager *
|
||||
font_manager_new( size_t width, size_t height, size_t depth )
|
||||
{
|
||||
static FontManager *self = 0;
|
||||
if( !self )
|
||||
{
|
||||
TextureAtlas *atlas = texture_atlas_new( width, height, depth );
|
||||
self = (FontManager *) malloc( sizeof(FontManager) );
|
||||
if( !self )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
self->atlas = atlas;
|
||||
self->fonts = vector_new( sizeof(TextureFont) );
|
||||
self->cache = wcsdup( L" " );
|
||||
/*
|
||||
self->cache = wcsdup( L" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
L"`abcdefghijklmnopqrstuvwxyz{|}~" );
|
||||
*/
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
font_manager_delete( FontManager *self )
|
||||
{
|
||||
assert( self );
|
||||
vector_delete( self->fonts );
|
||||
texture_atlas_delete( self->atlas );
|
||||
if( self->cache )
|
||||
{
|
||||
free( self->cache );
|
||||
}
|
||||
free( self );
|
||||
}
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_filename( FontManager *self,
|
||||
const char * filename,
|
||||
const float size )
|
||||
{
|
||||
size_t i;
|
||||
TextureFont *font;
|
||||
|
||||
assert( self );
|
||||
|
||||
for( i=0; i<self->fonts->size;++i )
|
||||
{
|
||||
font = (TextureFont *) vector_get( self->fonts, i );
|
||||
if( (strcmp(font->filename, filename) == 0) && ( font->size == size) )
|
||||
{
|
||||
return font;
|
||||
}
|
||||
}
|
||||
font = texture_font_new( self->atlas, filename, size );
|
||||
texture_font_cache_glyphs( font, self->cache );
|
||||
if( font )
|
||||
{
|
||||
vector_push_back( self->fonts, font );
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_description( FontManager *self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
{
|
||||
TextureFont *font;
|
||||
char *filename = font_manager_match_description( self, family, size, bold, italic );
|
||||
// fprintf(stderr, "Matched filename for %s: %s\n", family, filename);
|
||||
if( !filename )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
font = font_manager_get_from_filename( self, filename, size );
|
||||
free( filename );
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_markup( FontManager *self,
|
||||
const Markup *markup )
|
||||
{
|
||||
assert( self );
|
||||
assert( markup );
|
||||
{
|
||||
TextureFont *font =
|
||||
font_manager_get_from_description( self, markup->family, markup->size,
|
||||
markup->bold, markup->italic );
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
font_manager_match_description( FontManager *self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic )
|
||||
{
|
||||
char *filename = 0;
|
||||
|
||||
#ifdef HAVE_FONTCONFIG
|
||||
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 );
|
||||
#endif
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *
|
||||
font_manager_get_cache( FontManager *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->cache;
|
||||
}
|
||||
|
||||
void
|
||||
font_manager_set_cache( FontManager *self,
|
||||
const wchar_t * cache )
|
||||
{
|
||||
assert( self );
|
||||
assert( cache );
|
||||
|
||||
if( self->cache )
|
||||
{
|
||||
free( self->cache );
|
||||
}
|
||||
self->cache = wcsdup( cache );
|
||||
}
|
||||
|
||||
#endif
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#ifdef HAVE_FONTCONFIG
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include "font-manager.h"
|
||||
|
||||
|
||||
wchar_t *
|
||||
wcsdup( const wchar_t *string )
|
||||
{
|
||||
wchar_t * result;
|
||||
assert( string );
|
||||
result = (wchar_t *) malloc( (wcslen(string) + 1) * sizeof(wchar_t) );
|
||||
wcscpy( result, string );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
FontManager *
|
||||
font_manager_new( size_t width, size_t height, size_t depth )
|
||||
{
|
||||
static FontManager *self = 0;
|
||||
if( !self )
|
||||
{
|
||||
TextureAtlas *atlas = texture_atlas_new( width, height, depth );
|
||||
self = (FontManager *) malloc( sizeof(FontManager) );
|
||||
if( !self )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
self->atlas = atlas;
|
||||
self->fonts = vector_new( sizeof(TextureFont) );
|
||||
self->cache = wcsdup( L" " );
|
||||
/*
|
||||
self->cache = wcsdup( L" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
L"`abcdefghijklmnopqrstuvwxyz{|}~" );
|
||||
*/
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
font_manager_delete( FontManager *self )
|
||||
{
|
||||
assert( self );
|
||||
vector_delete( self->fonts );
|
||||
texture_atlas_delete( self->atlas );
|
||||
if( self->cache )
|
||||
{
|
||||
free( self->cache );
|
||||
}
|
||||
free( self );
|
||||
}
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_filename( FontManager *self,
|
||||
const char * filename,
|
||||
const float size )
|
||||
{
|
||||
size_t i;
|
||||
TextureFont *font;
|
||||
|
||||
assert( self );
|
||||
|
||||
for( i=0; i<self->fonts->size;++i )
|
||||
{
|
||||
font = (TextureFont *) vector_get( self->fonts, i );
|
||||
if( (strcmp(font->filename, filename) == 0) && ( font->size == size) )
|
||||
{
|
||||
return font;
|
||||
}
|
||||
}
|
||||
font = texture_font_new( self->atlas, filename, size );
|
||||
texture_font_cache_glyphs( font, self->cache );
|
||||
if( font )
|
||||
{
|
||||
vector_push_back( self->fonts, font );
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_description( FontManager *self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
{
|
||||
TextureFont *font;
|
||||
char *filename = font_manager_match_description( self, family, size, bold, italic );
|
||||
// fprintf(stderr, "Matched filename for %s: %s\n", family, filename);
|
||||
if( !filename )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
font = font_manager_get_from_filename( self, filename, size );
|
||||
free( filename );
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
TextureFont *
|
||||
font_manager_get_from_markup( FontManager *self,
|
||||
const Markup *markup )
|
||||
{
|
||||
assert( self );
|
||||
assert( markup );
|
||||
{
|
||||
TextureFont *font =
|
||||
font_manager_get_from_description( self, markup->family, markup->size,
|
||||
markup->bold, markup->italic );
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
font_manager_match_description( FontManager *self,
|
||||
const char * family,
|
||||
const float size,
|
||||
const int bold,
|
||||
const int italic )
|
||||
{
|
||||
char *filename = 0;
|
||||
|
||||
#ifdef HAVE_FONTCONFIG
|
||||
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 );
|
||||
#endif
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t *
|
||||
font_manager_get_cache( FontManager *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->cache;
|
||||
}
|
||||
|
||||
void
|
||||
font_manager_set_cache( FontManager *self,
|
||||
const wchar_t * cache )
|
||||
{
|
||||
assert( self );
|
||||
assert( cache );
|
||||
|
||||
if( self->cache )
|
||||
{
|
||||
free( self->cache );
|
||||
}
|
||||
self->cache = wcsdup( cache );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,361 +1,361 @@
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
/*
|
||||
#if defined(__APPLE__)
|
||||
//#include <Glut/glut.h>
|
||||
#else
|
||||
//#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include "vector.h"
|
||||
#include "texture-font.h"
|
||||
#include "texture-glyph.h"
|
||||
#include "texture-atlas.h"
|
||||
#include "font-manager.h"
|
||||
|
||||
|
||||
void display( void )
|
||||
{
|
||||
int viewport[4];
|
||||
glGetIntegerv( GL_VIEWPORT, viewport );
|
||||
GLuint width = viewport[2];
|
||||
GLuint height = viewport[3];
|
||||
|
||||
glClearColor(1,1,1,1);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glColor4f(0,0,0,1);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f( 0, 1 ); glVertex2i( 0, 0 );
|
||||
glTexCoord2f( 0, 0 ); glVertex2i( 0, height );
|
||||
glTexCoord2f( 1, 0 ); glVertex2i( width, height );
|
||||
glTexCoord2f( 1, 1 ); glVertex2i( width, 0 );
|
||||
glEnd();
|
||||
glutSwapBuffers( );
|
||||
}
|
||||
|
||||
void reshape(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, width, 0, height, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void keyboard( unsigned char key, int x, int y )
|
||||
{
|
||||
if ( key == 27 )
|
||||
{
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
wchar_t * font_cache =
|
||||
L" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
L"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
char * font_family = "arial";
|
||||
float font_size = 16.0;
|
||||
char * font_filename = "arial.ttf";
|
||||
char * header_filename = "arial-16.h";
|
||||
|
||||
TextureAtlas * atlas = texture_atlas_new( 128, 128, 1 );
|
||||
TextureFont * font = texture_font_new( atlas, font_filename, font_size );
|
||||
|
||||
|
||||
glutInit( &argc, argv );
|
||||
glutInitWindowSize( atlas->width, atlas->height );
|
||||
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
|
||||
glutCreateWindow( "Freetype OpenGL" );
|
||||
glutReshapeFunc( reshape );
|
||||
glutDisplayFunc( display );
|
||||
glutKeyboardFunc( keyboard );
|
||||
glBindTexture( GL_TEXTURE_2D, atlas->texid );
|
||||
|
||||
size_t missed = texture_font_cache_glyphs( font, font_cache );
|
||||
|
||||
wprintf( L"Font filename : %s\n", font_filename );
|
||||
wprintf( L"Font size : %.1f\n", font_size );
|
||||
wprintf( L"Number of glyphs : %ld\n", wcslen(font_cache) );
|
||||
wprintf( L"Number of missed glyphs : %ld\n", missed );
|
||||
wprintf( L"Texture size : %ldx%ldx%ld\n", atlas->width, atlas->height, atlas->depth );
|
||||
wprintf( L"Texture occupancy : %.2f%%\n",
|
||||
100.0*atlas->used/(float)(atlas->width*atlas->height) );
|
||||
wprintf( L"\n" );
|
||||
wprintf( L"Header filename : %s\n", header_filename );
|
||||
|
||||
|
||||
|
||||
|
||||
// glutMainLoop();
|
||||
|
||||
|
||||
size_t texture_size = atlas->width * atlas->height *atlas->depth;
|
||||
size_t glyph_count = font->glyphs->size;
|
||||
size_t max_kerning_count = 1;
|
||||
for( i=0; i < glyph_count; ++i )
|
||||
{
|
||||
TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i );
|
||||
if( glyph->kerning_count > max_kerning_count )
|
||||
{
|
||||
max_kerning_count = glyph->kerning_count;
|
||||
}
|
||||
}
|
||||
|
||||
FILE *file = fopen( header_filename, "w" );
|
||||
|
||||
|
||||
// -------------
|
||||
// Header
|
||||
// -------------
|
||||
fwprintf( file,
|
||||
L"// =========================================================================\n"
|
||||
L"// Freetype GL - A C OpenGL Freetype engine\n"
|
||||
L"// Platform: Any\n"
|
||||
L"// WWW: http://code.google.com/p/freetype-gl/\n"
|
||||
L"// -------------------------------------------------------------------------\n"
|
||||
L"// Copyright 2011 Nicolas P. Rougier. All rights reserved.\n"
|
||||
L"//\n"
|
||||
L"// Redistribution and use in source and binary forms, with or without\n"
|
||||
L"// modification, are permitted provided that the following conditions are met:\n"
|
||||
L"//\n"
|
||||
L"// 1. Redistributions of source code must retain the above copyright notice,\n"
|
||||
L"// this list of conditions and the following disclaimer.\n"
|
||||
L"//\n"
|
||||
L"// 2. Redistributions in binary form must reproduce the above copyright\n"
|
||||
L"// notice, this list of conditions and the following disclaimer in the\n"
|
||||
L"// documentation and/or other materials provided with the distribution.\n"
|
||||
L"//\n"
|
||||
L"// THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR\n"
|
||||
L"// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
|
||||
L"// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n"
|
||||
L"// EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
|
||||
L"// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"
|
||||
L"// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n"
|
||||
L"// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n"
|
||||
L"// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
|
||||
L"// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n"
|
||||
L"// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
L"//\n"
|
||||
L"// The views and conclusions contained in the software and documentation are\n"
|
||||
L"// those of the authors and should not be interpreted as representing official\n"
|
||||
L"// policies, either expressed or implied, of Nicolas P. Rougier.\n"
|
||||
L"// ========================================================================= \n" );
|
||||
|
||||
|
||||
|
||||
// ----------------------
|
||||
// Structure declarations
|
||||
// ----------------------
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" wchar_t charcode;\n"
|
||||
L" float kerning;\n"
|
||||
L"} Kerning;\n\n" );
|
||||
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" wchar_t charcode;\n"
|
||||
L" int width, height;\n"
|
||||
L" int offset_x, offset_y;\n"
|
||||
L" float advance_x, advance_y;\n"
|
||||
L" float u0, v0, u1, v1;\n"
|
||||
L" size_t kerning_count;\n"
|
||||
L" Kerning kerning[%d];\n"
|
||||
L"} TextureGlyph;\n\n", max_kerning_count );
|
||||
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" size_t tex_width;\n"
|
||||
L" size_t tex_height;\n"
|
||||
L" size_t tex_depth;\n"
|
||||
L" char tex_data[%d];\n"
|
||||
L" float size;\n"
|
||||
L" float height;\n"
|
||||
L" float linegap;\n"
|
||||
L" float ascender;\n"
|
||||
L" float descender;\n"
|
||||
L" size_t glyphs_count;\n"
|
||||
L" TextureGlyph glyphs[%d];\n"
|
||||
L"} TextureFont;\n\n", texture_size, glyph_count );
|
||||
|
||||
|
||||
|
||||
fwprintf( file, L"TextureFont font = {\n" );
|
||||
|
||||
|
||||
// ------------
|
||||
// Texture data
|
||||
// ------------
|
||||
fwprintf( file, L" %d, %d, %d, \n", atlas->width, atlas->height, atlas->depth );
|
||||
fwprintf( file, L" {" );
|
||||
for( i=0; i < texture_size; i+= 32 )
|
||||
{
|
||||
for( j=0; j < 32 && (j+i) < texture_size ; ++ j)
|
||||
{
|
||||
if( (j+i) < (texture_size-1) )
|
||||
{
|
||||
fwprintf( file, L"%d,", atlas->data[i+j] );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"%d", atlas->data[i+j] );
|
||||
}
|
||||
}
|
||||
if( (j+i) < texture_size )
|
||||
{
|
||||
fwprintf( file, L"\n " );
|
||||
}
|
||||
}
|
||||
fwprintf( file, L"}, \n" );
|
||||
|
||||
|
||||
// -------------------
|
||||
// Texture information
|
||||
// -------------------
|
||||
fwprintf( file, L" %f, %f, %f, %f, %f, %d, \n",
|
||||
font->size, font->height,
|
||||
font->linegap,font->ascender, font->descender,
|
||||
glyph_count );
|
||||
|
||||
// --------------
|
||||
// Texture glyphs
|
||||
// --------------
|
||||
fwprintf( file, L" {\n" );
|
||||
for( i=0; i < glyph_count; ++i )
|
||||
{
|
||||
TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i );
|
||||
|
||||
// // Debugging information
|
||||
// wprintf( L"glyph : '%lc'\n",
|
||||
// glyph->charcode );
|
||||
// wprintf( L" size : %dx%d\n",
|
||||
// glyph->width, glyph->height );
|
||||
// wprintf( L" offset : %+d%+d\n",
|
||||
// glyph->offset_x, glyph->offset_y );
|
||||
// wprintf( L" advance : %f, %f\n",
|
||||
// glyph->advance_x, glyph->advance_y );
|
||||
// wprintf( L" tex coords.: %f, %f, %f, %f\n",
|
||||
// glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
|
||||
//
|
||||
// wprintf( L" kerning : " );
|
||||
// if( glyph->kerning_count )
|
||||
// {
|
||||
// for( j=0; j < glyph->kerning_count; ++j )
|
||||
// {
|
||||
// wprintf( L"('%lc', %f)",
|
||||
// glyph->kerning[j].charcode, glyph->kerning[j].kerning );
|
||||
// if( j < (glyph->kerning_count-1) )
|
||||
// {
|
||||
// wprintf( L", " );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wprintf( L"None" );
|
||||
// }
|
||||
// wprintf( L"\n\n" );
|
||||
|
||||
// TextureFont
|
||||
if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) )
|
||||
{
|
||||
fwprintf( file, L" {L'\\%lc', ", glyph->charcode );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L" {L'%lc', ", glyph->charcode );
|
||||
}
|
||||
fwprintf( file, L"%d, %d, ", glyph->width, glyph->height );
|
||||
fwprintf( file, L"%d, %d, ", glyph->offset_x, glyph->offset_y );
|
||||
fwprintf( file, L"%f, %f, ", glyph->advance_x, glyph->advance_y );
|
||||
fwprintf( file, L"%f, %f, %f, %f, ", glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
|
||||
fwprintf( file, L"%d, ", max_kerning_count );
|
||||
fwprintf( file, L"{ " );
|
||||
for( j=0; j < glyph->kerning_count; ++j )
|
||||
{
|
||||
wchar_t charcode = glyph->kerning[j].charcode;
|
||||
|
||||
if( (charcode == L'\'' ) || (charcode == L'\\') )
|
||||
{
|
||||
fwprintf( file, L"{L'\\%lc', %f}", charcode, glyph->kerning[j].kerning );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"{L'%lc', %f}", charcode, glyph->kerning[j].kerning );
|
||||
}
|
||||
if( j < (glyph->kerning_count-1) )
|
||||
{
|
||||
fwprintf( file, L", " );
|
||||
}
|
||||
}
|
||||
if( i < (glyph_count-1) )
|
||||
{
|
||||
fwprintf( file, L"} },\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"} }\n" );
|
||||
}
|
||||
}
|
||||
fwprintf( file, L" }\n};\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
/*
|
||||
#if defined(__APPLE__)
|
||||
//#include <Glut/glut.h>
|
||||
#else
|
||||
//#include <GL/glut.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
#else
|
||||
#include <GL/glew.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#include "vector.h"
|
||||
#include "texture-font.h"
|
||||
#include "texture-glyph.h"
|
||||
#include "texture-atlas.h"
|
||||
#include "font-manager.h"
|
||||
|
||||
|
||||
void display( void )
|
||||
{
|
||||
int viewport[4];
|
||||
glGetIntegerv( GL_VIEWPORT, viewport );
|
||||
GLuint width = viewport[2];
|
||||
GLuint height = viewport[3];
|
||||
|
||||
glClearColor(1,1,1,1);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
glEnable( GL_BLEND );
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glColor4f(0,0,0,1);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f( 0, 1 ); glVertex2i( 0, 0 );
|
||||
glTexCoord2f( 0, 0 ); glVertex2i( 0, height );
|
||||
glTexCoord2f( 1, 0 ); glVertex2i( width, height );
|
||||
glTexCoord2f( 1, 1 ); glVertex2i( width, 0 );
|
||||
glEnd();
|
||||
glutSwapBuffers( );
|
||||
}
|
||||
|
||||
void reshape(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(0, width, 0, height, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void keyboard( unsigned char key, int x, int y )
|
||||
{
|
||||
if ( key == 27 )
|
||||
{
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
wchar_t * font_cache =
|
||||
L" !\"#$%&'()*+,-./0123456789:;<=>?"
|
||||
L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
|
||||
L"`abcdefghijklmnopqrstuvwxyz{|}~";
|
||||
|
||||
char * font_family = "arial";
|
||||
float font_size = 16.0;
|
||||
char * font_filename = "arial.ttf";
|
||||
char * header_filename = "arial-16.h";
|
||||
|
||||
TextureAtlas * atlas = texture_atlas_new( 128, 128, 1 );
|
||||
TextureFont * font = texture_font_new( atlas, font_filename, font_size );
|
||||
|
||||
|
||||
glutInit( &argc, argv );
|
||||
glutInitWindowSize( atlas->width, atlas->height );
|
||||
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
|
||||
glutCreateWindow( "Freetype OpenGL" );
|
||||
glutReshapeFunc( reshape );
|
||||
glutDisplayFunc( display );
|
||||
glutKeyboardFunc( keyboard );
|
||||
glBindTexture( GL_TEXTURE_2D, atlas->texid );
|
||||
|
||||
size_t missed = texture_font_cache_glyphs( font, font_cache );
|
||||
|
||||
wprintf( L"Font filename : %s\n", font_filename );
|
||||
wprintf( L"Font size : %.1f\n", font_size );
|
||||
wprintf( L"Number of glyphs : %ld\n", wcslen(font_cache) );
|
||||
wprintf( L"Number of missed glyphs : %ld\n", missed );
|
||||
wprintf( L"Texture size : %ldx%ldx%ld\n", atlas->width, atlas->height, atlas->depth );
|
||||
wprintf( L"Texture occupancy : %.2f%%\n",
|
||||
100.0*atlas->used/(float)(atlas->width*atlas->height) );
|
||||
wprintf( L"\n" );
|
||||
wprintf( L"Header filename : %s\n", header_filename );
|
||||
|
||||
|
||||
|
||||
|
||||
// glutMainLoop();
|
||||
|
||||
|
||||
size_t texture_size = atlas->width * atlas->height *atlas->depth;
|
||||
size_t glyph_count = font->glyphs->size;
|
||||
size_t max_kerning_count = 1;
|
||||
for( i=0; i < glyph_count; ++i )
|
||||
{
|
||||
TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i );
|
||||
if( glyph->kerning_count > max_kerning_count )
|
||||
{
|
||||
max_kerning_count = glyph->kerning_count;
|
||||
}
|
||||
}
|
||||
|
||||
FILE *file = fopen( header_filename, "w" );
|
||||
|
||||
|
||||
// -------------
|
||||
// Header
|
||||
// -------------
|
||||
fwprintf( file,
|
||||
L"// =========================================================================\n"
|
||||
L"// Freetype GL - A C OpenGL Freetype engine\n"
|
||||
L"// Platform: Any\n"
|
||||
L"// WWW: http://code.google.com/p/freetype-gl/\n"
|
||||
L"// -------------------------------------------------------------------------\n"
|
||||
L"// Copyright 2011 Nicolas P. Rougier. All rights reserved.\n"
|
||||
L"//\n"
|
||||
L"// Redistribution and use in source and binary forms, with or without\n"
|
||||
L"// modification, are permitted provided that the following conditions are met:\n"
|
||||
L"//\n"
|
||||
L"// 1. Redistributions of source code must retain the above copyright notice,\n"
|
||||
L"// this list of conditions and the following disclaimer.\n"
|
||||
L"//\n"
|
||||
L"// 2. Redistributions in binary form must reproduce the above copyright\n"
|
||||
L"// notice, this list of conditions and the following disclaimer in the\n"
|
||||
L"// documentation and/or other materials provided with the distribution.\n"
|
||||
L"//\n"
|
||||
L"// THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR\n"
|
||||
L"// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
|
||||
L"// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n"
|
||||
L"// EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
|
||||
L"// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"
|
||||
L"// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n"
|
||||
L"// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n"
|
||||
L"// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
|
||||
L"// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n"
|
||||
L"// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
|
||||
L"//\n"
|
||||
L"// The views and conclusions contained in the software and documentation are\n"
|
||||
L"// those of the authors and should not be interpreted as representing official\n"
|
||||
L"// policies, either expressed or implied, of Nicolas P. Rougier.\n"
|
||||
L"// ========================================================================= \n" );
|
||||
|
||||
|
||||
|
||||
// ----------------------
|
||||
// Structure declarations
|
||||
// ----------------------
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" wchar_t charcode;\n"
|
||||
L" float kerning;\n"
|
||||
L"} Kerning;\n\n" );
|
||||
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" wchar_t charcode;\n"
|
||||
L" int width, height;\n"
|
||||
L" int offset_x, offset_y;\n"
|
||||
L" float advance_x, advance_y;\n"
|
||||
L" float u0, v0, u1, v1;\n"
|
||||
L" size_t kerning_count;\n"
|
||||
L" Kerning kerning[%d];\n"
|
||||
L"} TextureGlyph;\n\n", max_kerning_count );
|
||||
|
||||
fwprintf( file,
|
||||
L"typedef struct\n"
|
||||
L"{\n"
|
||||
L" size_t tex_width;\n"
|
||||
L" size_t tex_height;\n"
|
||||
L" size_t tex_depth;\n"
|
||||
L" char tex_data[%d];\n"
|
||||
L" float size;\n"
|
||||
L" float height;\n"
|
||||
L" float linegap;\n"
|
||||
L" float ascender;\n"
|
||||
L" float descender;\n"
|
||||
L" size_t glyphs_count;\n"
|
||||
L" TextureGlyph glyphs[%d];\n"
|
||||
L"} TextureFont;\n\n", texture_size, glyph_count );
|
||||
|
||||
|
||||
|
||||
fwprintf( file, L"TextureFont font = {\n" );
|
||||
|
||||
|
||||
// ------------
|
||||
// Texture data
|
||||
// ------------
|
||||
fwprintf( file, L" %d, %d, %d, \n", atlas->width, atlas->height, atlas->depth );
|
||||
fwprintf( file, L" {" );
|
||||
for( i=0; i < texture_size; i+= 32 )
|
||||
{
|
||||
for( j=0; j < 32 && (j+i) < texture_size ; ++ j)
|
||||
{
|
||||
if( (j+i) < (texture_size-1) )
|
||||
{
|
||||
fwprintf( file, L"%d,", atlas->data[i+j] );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"%d", atlas->data[i+j] );
|
||||
}
|
||||
}
|
||||
if( (j+i) < texture_size )
|
||||
{
|
||||
fwprintf( file, L"\n " );
|
||||
}
|
||||
}
|
||||
fwprintf( file, L"}, \n" );
|
||||
|
||||
|
||||
// -------------------
|
||||
// Texture information
|
||||
// -------------------
|
||||
fwprintf( file, L" %f, %f, %f, %f, %f, %d, \n",
|
||||
font->size, font->height,
|
||||
font->linegap,font->ascender, font->descender,
|
||||
glyph_count );
|
||||
|
||||
// --------------
|
||||
// Texture glyphs
|
||||
// --------------
|
||||
fwprintf( file, L" {\n" );
|
||||
for( i=0; i < glyph_count; ++i )
|
||||
{
|
||||
TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i );
|
||||
|
||||
// // Debugging information
|
||||
// wprintf( L"glyph : '%lc'\n",
|
||||
// glyph->charcode );
|
||||
// wprintf( L" size : %dx%d\n",
|
||||
// glyph->width, glyph->height );
|
||||
// wprintf( L" offset : %+d%+d\n",
|
||||
// glyph->offset_x, glyph->offset_y );
|
||||
// wprintf( L" advance : %f, %f\n",
|
||||
// glyph->advance_x, glyph->advance_y );
|
||||
// wprintf( L" tex coords.: %f, %f, %f, %f\n",
|
||||
// glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
|
||||
//
|
||||
// wprintf( L" kerning : " );
|
||||
// if( glyph->kerning_count )
|
||||
// {
|
||||
// for( j=0; j < glyph->kerning_count; ++j )
|
||||
// {
|
||||
// wprintf( L"('%lc', %f)",
|
||||
// glyph->kerning[j].charcode, glyph->kerning[j].kerning );
|
||||
// if( j < (glyph->kerning_count-1) )
|
||||
// {
|
||||
// wprintf( L", " );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// wprintf( L"None" );
|
||||
// }
|
||||
// wprintf( L"\n\n" );
|
||||
|
||||
// TextureFont
|
||||
if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) )
|
||||
{
|
||||
fwprintf( file, L" {L'\\%lc', ", glyph->charcode );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L" {L'%lc', ", glyph->charcode );
|
||||
}
|
||||
fwprintf( file, L"%d, %d, ", glyph->width, glyph->height );
|
||||
fwprintf( file, L"%d, %d, ", glyph->offset_x, glyph->offset_y );
|
||||
fwprintf( file, L"%f, %f, ", glyph->advance_x, glyph->advance_y );
|
||||
fwprintf( file, L"%f, %f, %f, %f, ", glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
|
||||
fwprintf( file, L"%d, ", max_kerning_count );
|
||||
fwprintf( file, L"{ " );
|
||||
for( j=0; j < glyph->kerning_count; ++j )
|
||||
{
|
||||
wchar_t charcode = glyph->kerning[j].charcode;
|
||||
|
||||
if( (charcode == L'\'' ) || (charcode == L'\\') )
|
||||
{
|
||||
fwprintf( file, L"{L'\\%lc', %f}", charcode, glyph->kerning[j].kerning );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"{L'%lc', %f}", charcode, glyph->kerning[j].kerning );
|
||||
}
|
||||
if( j < (glyph->kerning_count-1) )
|
||||
{
|
||||
fwprintf( file, L", " );
|
||||
}
|
||||
}
|
||||
if( i < (glyph_count-1) )
|
||||
{
|
||||
fwprintf( file, L"} },\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
fwprintf( file, L"} }\n" );
|
||||
}
|
||||
}
|
||||
fwprintf( file, L" }\n};\n" );
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
@@ -1,299 +1,299 @@
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "font-manager.h"
|
||||
#include "markup.h"
|
||||
|
||||
Markup *
|
||||
markup_new( void )
|
||||
{
|
||||
Color black = {0,0,0,1};
|
||||
Color white = {1,1,1,1};
|
||||
|
||||
Markup *self = (Markup *) malloc( sizeof(Markup) );
|
||||
if( !self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->family = strdup("monotype");
|
||||
self->italic = 0;
|
||||
self->bold = 0;
|
||||
self->size = 16;
|
||||
self->rise = 0;
|
||||
self->spacing= 0;
|
||||
|
||||
self->foreground_color = black;
|
||||
self->background_color = white;
|
||||
self->underline = 0;
|
||||
self->underline_color = black;
|
||||
self->overline = 0;
|
||||
self->overline_color = black;
|
||||
self->strikethrough = 0;
|
||||
self->strikethrough_color = black;
|
||||
|
||||
self->font = 0;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
markup_delete( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
free( self->family );
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
markup_cmp( const Markup *self,
|
||||
const Markup *other )
|
||||
{
|
||||
size_t n = sizeof( Markup ) - sizeof( TextureFont * );
|
||||
return memcmp( self, other, n );
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
markup_get_family( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->family;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_family( Markup *self,
|
||||
const char *family )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_italic( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->italic;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_italic( Markup *self,
|
||||
const int italic )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_bold( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->bold;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_bold( Markup *self,
|
||||
const int bold )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_size( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
return self->size;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_size( Markup *self,
|
||||
const float size )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_rise( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->rise;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_rise( Markup *self, const float rise )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_spacing( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->spacing;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_spacing( Markup *self, const float spacing )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_foreground_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->foreground_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_foreground_color( Markup *self, const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_background_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->background_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_background_color( Markup *self, const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_outline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->outline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_outline( Markup *self,
|
||||
const int outline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_outline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->outline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_outline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_underline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->underline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_underline( Markup *self,
|
||||
const int underline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_underline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->underline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_underline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_overline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->overline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_overline( Markup *self,
|
||||
const int overline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_overline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->overline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_overline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_strikethrough( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->strikethrough;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_strikethrough( Markup *self,
|
||||
const int strikethrough )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_strikethrough_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->strikethrough_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_strikethrough_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "font-manager.h"
|
||||
#include "markup.h"
|
||||
|
||||
Markup *
|
||||
markup_new( void )
|
||||
{
|
||||
Color black = {0,0,0,1};
|
||||
Color white = {1,1,1,1};
|
||||
|
||||
Markup *self = (Markup *) malloc( sizeof(Markup) );
|
||||
if( !self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->family = strdup("monotype");
|
||||
self->italic = 0;
|
||||
self->bold = 0;
|
||||
self->size = 16;
|
||||
self->rise = 0;
|
||||
self->spacing= 0;
|
||||
|
||||
self->foreground_color = black;
|
||||
self->background_color = white;
|
||||
self->underline = 0;
|
||||
self->underline_color = black;
|
||||
self->overline = 0;
|
||||
self->overline_color = black;
|
||||
self->strikethrough = 0;
|
||||
self->strikethrough_color = black;
|
||||
|
||||
self->font = 0;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
void
|
||||
markup_delete( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
free( self->family );
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
markup_cmp( const Markup *self,
|
||||
const Markup *other )
|
||||
{
|
||||
size_t n = sizeof( Markup ) - sizeof( TextureFont * );
|
||||
return memcmp( self, other, n );
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
markup_get_family( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->family;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_family( Markup *self,
|
||||
const char *family )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_italic( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->italic;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_italic( Markup *self,
|
||||
const int italic )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_bold( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->bold;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_bold( Markup *self,
|
||||
const int bold )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_size( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
return self->size;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_size( Markup *self,
|
||||
const float size )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_rise( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->rise;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_rise( Markup *self, const float rise )
|
||||
{
|
||||
}
|
||||
|
||||
float
|
||||
markup_get_spacing( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->spacing;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_spacing( Markup *self, const float spacing )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_foreground_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->foreground_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_foreground_color( Markup *self, const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_background_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->background_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_background_color( Markup *self, const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_outline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->outline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_outline( Markup *self,
|
||||
const int outline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_outline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->outline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_outline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_underline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->underline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_underline( Markup *self,
|
||||
const int underline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_underline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->underline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_underline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_overline( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->overline;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_overline( Markup *self,
|
||||
const int overline )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_overline_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->overline_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_overline_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
markup_get_strikethrough( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->strikethrough;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_strikethrough( Markup *self,
|
||||
const int strikethrough )
|
||||
{
|
||||
}
|
||||
|
||||
Color
|
||||
markup_get_strikethrough_color( Markup *self )
|
||||
{
|
||||
assert( self );
|
||||
return self->strikethrough_color;
|
||||
}
|
||||
|
||||
void
|
||||
markup_set_strikethrough_color( Markup *self,
|
||||
const Color * color )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,350 +1,350 @@
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include "texture-atlas.h"
|
||||
|
||||
#define max(a,b) (a)>(b)?(a):(b)
|
||||
#define min(a,b) (a)<(b)?(a):(b)
|
||||
|
||||
typedef struct { int x, y, width; } Node;
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
TextureAtlas *
|
||||
texture_atlas_new( size_t width, size_t height, size_t depth )
|
||||
{
|
||||
assert( (depth == 1) || (depth == 3) );
|
||||
|
||||
{
|
||||
TextureAtlas *self = (TextureAtlas *) malloc( sizeof(TextureAtlas) );
|
||||
if( !self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
self->nodes = vector_new( sizeof(Node) );
|
||||
self->used = 0;
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->depth = depth;
|
||||
|
||||
{
|
||||
Node node = {0,0,width};
|
||||
vector_push_back( self->nodes, &node );
|
||||
self->texid = 0;
|
||||
self->data = (unsigned char *)
|
||||
calloc( width*height*depth, sizeof(unsigned char) );
|
||||
|
||||
{
|
||||
// This is a special region that is used for background and underlined
|
||||
// decorations of glyphs
|
||||
int n = 4;
|
||||
//unsigned char buffer[n*n];
|
||||
unsigned char buffer[16];
|
||||
memset(buffer, 255, n*n);
|
||||
{
|
||||
Region r = texture_atlas_get_region( self, n, n );
|
||||
texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
|
||||
self->black.x = r.x + 1;
|
||||
self->black.y = r.y + 1;
|
||||
self->black.width = r.width - 2;
|
||||
self->black.height= r.height - 2;
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_delete( TextureAtlas *self )
|
||||
{
|
||||
assert( self );
|
||||
vector_delete( self->nodes );
|
||||
if( self->data )
|
||||
{
|
||||
free( self->data );
|
||||
}
|
||||
if( self->texid )
|
||||
{
|
||||
glDeleteTextures( 1, &self->texid );
|
||||
}
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_upload( TextureAtlas *self )
|
||||
{
|
||||
assert( self );
|
||||
assert( self->data );
|
||||
if( !self->texid )
|
||||
{
|
||||
glGenTextures( 1, &self->texid );
|
||||
}
|
||||
glBindTexture( GL_TEXTURE_2D, self->texid );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
if( self->depth == 3 )
|
||||
{
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, self->width, self->height,
|
||||
0, GL_RGB, GL_UNSIGNED_BYTE, self->data );
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, self->width, self->height,
|
||||
0, GL_ALPHA, GL_UNSIGNED_BYTE, self->data );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
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 )
|
||||
{
|
||||
assert( self );
|
||||
assert( x < self->width);
|
||||
assert( (x + width) <= self->width);
|
||||
assert( y < self->height);
|
||||
assert( (y + height) <= self->height);
|
||||
{
|
||||
size_t i;
|
||||
size_t depth = self->depth;
|
||||
size_t charsize = sizeof(char);
|
||||
for( i=0; i<height; ++i )
|
||||
{
|
||||
memcpy( self->data+((y+i)*self->width + x ) * charsize * depth,
|
||||
data + (i*stride) * charsize, width * charsize * depth );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
int
|
||||
texture_atlas_fit( TextureAtlas *self,
|
||||
size_t index, size_t width, size_t height )
|
||||
{
|
||||
Node *node = (Node *) (vector_get( self->nodes, index ));
|
||||
int x = node->x, y, width_left = width;
|
||||
size_t i = index;
|
||||
|
||||
if ( (x + width) > self->width )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
y = node->y;
|
||||
while( width_left > 0 )
|
||||
{
|
||||
node = (Node *) (vector_get( self->nodes, i ));
|
||||
y = max( y, node->y );
|
||||
if( (y + height) > self->height )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
width_left -= node->width;
|
||||
++i;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_merge( TextureAtlas *self )
|
||||
{
|
||||
Node *node, *next;
|
||||
size_t i;
|
||||
|
||||
for( i=0; i< self->nodes->size-1; ++i )
|
||||
{
|
||||
node = (Node *) (vector_get( self->nodes, i ));
|
||||
next = (Node *) (vector_get( self->nodes, i+1 ));
|
||||
|
||||
if( node->y == next->y )
|
||||
{
|
||||
node->width += next->width;
|
||||
vector_erase( self->nodes, i+1 );
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
Region
|
||||
texture_atlas_get_region( TextureAtlas *self,
|
||||
size_t width, size_t height )
|
||||
{
|
||||
assert( self );
|
||||
/*
|
||||
assert( width );
|
||||
assert( height );
|
||||
*/
|
||||
{
|
||||
int y, best_height, best_width, best_index;
|
||||
Node *node, *prev;
|
||||
Region region = {0,0,width,height};
|
||||
size_t i;
|
||||
|
||||
best_height = INT_MAX;
|
||||
best_index = -1;
|
||||
best_width = INT_MAX;
|
||||
for( i=0; i<self->nodes->size; ++i )
|
||||
{
|
||||
y = texture_atlas_fit( self, i, width, height );
|
||||
if( y >= 0 )
|
||||
{
|
||||
node = (Node *) vector_get( self->nodes, i );
|
||||
if( ( y + height < best_height ) ||
|
||||
( y + height == best_height && node->width < best_width) )
|
||||
{
|
||||
best_height = y + height;
|
||||
best_index = i;
|
||||
best_width = node->width;
|
||||
region.x = node->x;
|
||||
region.y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( best_index == -1 )
|
||||
{
|
||||
region.x = -1;
|
||||
region.y = -1;
|
||||
region.width = 0;
|
||||
region.height = 0;
|
||||
return region;
|
||||
}
|
||||
|
||||
node = (Node *) malloc( sizeof(Node) );
|
||||
node->x = region.x;
|
||||
node->y = region.y + height;
|
||||
node->width = width;
|
||||
vector_insert( self->nodes, best_index, node );
|
||||
free( node );
|
||||
|
||||
for(i = best_index+1; i < self->nodes->size; ++i)
|
||||
{
|
||||
node = (Node *) vector_get( self->nodes, i );
|
||||
prev = (Node *) vector_get( self->nodes, i-1 );
|
||||
|
||||
if (node->x < (prev->x + prev->width) )
|
||||
{
|
||||
int shrink = prev->x + prev->width - node->x;
|
||||
node->x += shrink;
|
||||
node->width -= shrink;
|
||||
if (node->width <= 0)
|
||||
{
|
||||
vector_erase( self->nodes, i );
|
||||
--i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
texture_atlas_merge( self );
|
||||
self->used += width * height;
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_clear( TextureAtlas *self )
|
||||
{
|
||||
|
||||
vector_clear( self->nodes );
|
||||
self->used = 0;
|
||||
{
|
||||
Node node = {0,0,self->width};
|
||||
vector_push_back( self->nodes, &node );
|
||||
|
||||
memset( self->data, 0, self->width*self->height*self->depth );
|
||||
|
||||
|
||||
{
|
||||
// This is a special region that is used for background and underlined
|
||||
// decorations of glyphs
|
||||
int n = 4;
|
||||
//unsigned char buffer[n*n];
|
||||
unsigned char buffer[16];
|
||||
memset(buffer, 255, n*n);
|
||||
{
|
||||
Region r = texture_atlas_get_region( self, n, n );
|
||||
texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
|
||||
self->black.x = r.x + 1;
|
||||
self->black.y = r.y + 1;
|
||||
self->black.width = r.width - 2;
|
||||
self->black.height= r.height - 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include "texture-atlas.h"
|
||||
|
||||
#define max(a,b) (a)>(b)?(a):(b)
|
||||
#define min(a,b) (a)<(b)?(a):(b)
|
||||
|
||||
typedef struct { int x, y, width; } Node;
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
TextureAtlas *
|
||||
texture_atlas_new( size_t width, size_t height, size_t depth )
|
||||
{
|
||||
assert( (depth == 1) || (depth == 3) );
|
||||
|
||||
{
|
||||
TextureAtlas *self = (TextureAtlas *) malloc( sizeof(TextureAtlas) );
|
||||
if( !self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
self->nodes = vector_new( sizeof(Node) );
|
||||
self->used = 0;
|
||||
self->width = width;
|
||||
self->height = height;
|
||||
self->depth = depth;
|
||||
|
||||
{
|
||||
Node node = {0,0,width};
|
||||
vector_push_back( self->nodes, &node );
|
||||
self->texid = 0;
|
||||
self->data = (unsigned char *)
|
||||
calloc( width*height*depth, sizeof(unsigned char) );
|
||||
|
||||
{
|
||||
// This is a special region that is used for background and underlined
|
||||
// decorations of glyphs
|
||||
int n = 4;
|
||||
//unsigned char buffer[n*n];
|
||||
unsigned char buffer[16];
|
||||
memset(buffer, 255, n*n);
|
||||
{
|
||||
Region r = texture_atlas_get_region( self, n, n );
|
||||
texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
|
||||
self->black.x = r.x + 1;
|
||||
self->black.y = r.y + 1;
|
||||
self->black.width = r.width - 2;
|
||||
self->black.height= r.height - 2;
|
||||
|
||||
return self;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_delete( TextureAtlas *self )
|
||||
{
|
||||
assert( self );
|
||||
vector_delete( self->nodes );
|
||||
if( self->data )
|
||||
{
|
||||
free( self->data );
|
||||
}
|
||||
if( self->texid )
|
||||
{
|
||||
glDeleteTextures( 1, &self->texid );
|
||||
}
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_upload( TextureAtlas *self )
|
||||
{
|
||||
assert( self );
|
||||
assert( self->data );
|
||||
if( !self->texid )
|
||||
{
|
||||
glGenTextures( 1, &self->texid );
|
||||
}
|
||||
glBindTexture( GL_TEXTURE_2D, self->texid );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
|
||||
if( self->depth == 3 )
|
||||
{
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, self->width, self->height,
|
||||
0, GL_RGB, GL_UNSIGNED_BYTE, self->data );
|
||||
}
|
||||
else
|
||||
{
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, self->width, self->height,
|
||||
0, GL_ALPHA, GL_UNSIGNED_BYTE, self->data );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
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 )
|
||||
{
|
||||
assert( self );
|
||||
assert( x < self->width);
|
||||
assert( (x + width) <= self->width);
|
||||
assert( y < self->height);
|
||||
assert( (y + height) <= self->height);
|
||||
{
|
||||
size_t i;
|
||||
size_t depth = self->depth;
|
||||
size_t charsize = sizeof(char);
|
||||
for( i=0; i<height; ++i )
|
||||
{
|
||||
memcpy( self->data+((y+i)*self->width + x ) * charsize * depth,
|
||||
data + (i*stride) * charsize, width * charsize * depth );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
int
|
||||
texture_atlas_fit( TextureAtlas *self,
|
||||
size_t index, size_t width, size_t height )
|
||||
{
|
||||
Node *node = (Node *) (vector_get( self->nodes, index ));
|
||||
int x = node->x, y, width_left = width;
|
||||
size_t i = index;
|
||||
|
||||
if ( (x + width) > self->width )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
y = node->y;
|
||||
while( width_left > 0 )
|
||||
{
|
||||
node = (Node *) (vector_get( self->nodes, i ));
|
||||
y = max( y, node->y );
|
||||
if( (y + height) > self->height )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
width_left -= node->width;
|
||||
++i;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_merge( TextureAtlas *self )
|
||||
{
|
||||
Node *node, *next;
|
||||
size_t i;
|
||||
|
||||
for( i=0; i< self->nodes->size-1; ++i )
|
||||
{
|
||||
node = (Node *) (vector_get( self->nodes, i ));
|
||||
next = (Node *) (vector_get( self->nodes, i+1 ));
|
||||
|
||||
if( node->y == next->y )
|
||||
{
|
||||
node->width += next->width;
|
||||
vector_erase( self->nodes, i+1 );
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
Region
|
||||
texture_atlas_get_region( TextureAtlas *self,
|
||||
size_t width, size_t height )
|
||||
{
|
||||
assert( self );
|
||||
/*
|
||||
assert( width );
|
||||
assert( height );
|
||||
*/
|
||||
{
|
||||
int y, best_height, best_width, best_index;
|
||||
Node *node, *prev;
|
||||
Region region = {0,0,width,height};
|
||||
size_t i;
|
||||
|
||||
best_height = INT_MAX;
|
||||
best_index = -1;
|
||||
best_width = INT_MAX;
|
||||
for( i=0; i<self->nodes->size; ++i )
|
||||
{
|
||||
y = texture_atlas_fit( self, i, width, height );
|
||||
if( y >= 0 )
|
||||
{
|
||||
node = (Node *) vector_get( self->nodes, i );
|
||||
if( ( y + height < best_height ) ||
|
||||
( y + height == best_height && node->width < best_width) )
|
||||
{
|
||||
best_height = y + height;
|
||||
best_index = i;
|
||||
best_width = node->width;
|
||||
region.x = node->x;
|
||||
region.y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( best_index == -1 )
|
||||
{
|
||||
region.x = -1;
|
||||
region.y = -1;
|
||||
region.width = 0;
|
||||
region.height = 0;
|
||||
return region;
|
||||
}
|
||||
|
||||
node = (Node *) malloc( sizeof(Node) );
|
||||
node->x = region.x;
|
||||
node->y = region.y + height;
|
||||
node->width = width;
|
||||
vector_insert( self->nodes, best_index, node );
|
||||
free( node );
|
||||
|
||||
for(i = best_index+1; i < self->nodes->size; ++i)
|
||||
{
|
||||
node = (Node *) vector_get( self->nodes, i );
|
||||
prev = (Node *) vector_get( self->nodes, i-1 );
|
||||
|
||||
if (node->x < (prev->x + prev->width) )
|
||||
{
|
||||
int shrink = prev->x + prev->width - node->x;
|
||||
node->x += shrink;
|
||||
node->width -= shrink;
|
||||
if (node->width <= 0)
|
||||
{
|
||||
vector_erase( self->nodes, i );
|
||||
--i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
texture_atlas_merge( self );
|
||||
self->used += width * height;
|
||||
return region;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_atlas_clear( TextureAtlas *self )
|
||||
{
|
||||
|
||||
vector_clear( self->nodes );
|
||||
self->used = 0;
|
||||
{
|
||||
Node node = {0,0,self->width};
|
||||
vector_push_back( self->nodes, &node );
|
||||
|
||||
memset( self->data, 0, self->width*self->height*self->depth );
|
||||
|
||||
|
||||
{
|
||||
// This is a special region that is used for background and underlined
|
||||
// decorations of glyphs
|
||||
int n = 4;
|
||||
//unsigned char buffer[n*n];
|
||||
unsigned char buffer[16];
|
||||
memset(buffer, 255, n*n);
|
||||
{
|
||||
Region r = texture_atlas_get_region( self, n, n );
|
||||
texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
|
||||
self->black.x = r.x + 1;
|
||||
self->black.y = r.y + 1;
|
||||
self->black.width = r.width - 2;
|
||||
self->black.height= r.height - 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,240 +1,240 @@
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "texture-font.h"
|
||||
#include "texture-glyph.h"
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
TextureGlyph *
|
||||
texture_glyph_new( void )
|
||||
{
|
||||
TextureGlyph *self = (TextureGlyph *) malloc( sizeof(TextureGlyph) );
|
||||
if(! self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
self->width = 0;
|
||||
self->height = 0;
|
||||
self->offset_x = 0;
|
||||
self->offset_y = 0;
|
||||
self->advance_x = 0.0;
|
||||
self->advance_y = 0.0;
|
||||
self->u0 = 0.0;
|
||||
self->v0 = 0.0;
|
||||
self->u1 = 0.0;
|
||||
self->v1 = 0.0;
|
||||
self->kerning_count = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_delete( TextureGlyph *self )
|
||||
{
|
||||
assert( self );
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_render( TextureGlyph *self,
|
||||
Markup *markup,
|
||||
Pen *pen )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
{
|
||||
int x = pen->x + self->offset_x;
|
||||
int y = pen->y + self->offset_y + markup->rise;
|
||||
int w = self->width;
|
||||
int h = self->height;
|
||||
|
||||
float u0 = self->u0;
|
||||
float v0 = self->v0;
|
||||
float u1 = self->u1;
|
||||
float v1 = self->v1;
|
||||
|
||||
glBegin( GL_TRIANGLES );
|
||||
{
|
||||
glTexCoord2f( u0, v0 ); glVertex2i( x, y );
|
||||
glTexCoord2f( u0, v1 ); glVertex2i( x, y-h );
|
||||
glTexCoord2f( u1, v1 ); glVertex2i( x+w, y-h );
|
||||
|
||||
glTexCoord2f( u0, v0 ); glVertex2i( x, y );
|
||||
glTexCoord2f( u1, v1 ); glVertex2i( x+w, y-h );
|
||||
glTexCoord2f( u1, v0 ); glVertex2i( x+w, y );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
pen->x += self->advance_x + markup->spacing;
|
||||
pen->y += self->advance_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
|
||||
VertexBuffer *buffer,
|
||||
const Markup *markup,
|
||||
Pen *pen, int kerning )
|
||||
{
|
||||
TextureFont *font = self->font;
|
||||
float r = 1;
|
||||
float g = 1;
|
||||
float b = 1;
|
||||
float a = 1;
|
||||
int rise = 0;
|
||||
int spacing = 0;
|
||||
|
||||
if( markup )
|
||||
{
|
||||
rise = markup->rise;
|
||||
spacing = markup->spacing;
|
||||
}
|
||||
|
||||
pen->x += kerning;
|
||||
|
||||
// Background
|
||||
if( markup && markup->background_color.a > 0 )
|
||||
{
|
||||
float u0 = font->atlas->black.x / (float) font->atlas->width;
|
||||
float v0 = font->atlas->black.y / (float) font->atlas->height;
|
||||
float u1 = u0 + font->atlas->black.width / (float) font->atlas->width;
|
||||
float v1 = v0 + font->atlas->black.height / (float) font->atlas->height;
|
||||
int x0 = pen->x - kerning;
|
||||
int y0 = pen->y + font->descender;
|
||||
int x1 = x0 + self->advance_x + markup->spacing + kerning;
|
||||
int y1 = y0 + font->height - font->linegap;
|
||||
r = markup->background_color.r;
|
||||
g = markup->background_color.g;
|
||||
b = markup->background_color.b;
|
||||
a = markup->background_color.a;
|
||||
|
||||
{
|
||||
GLuint index = buffer->vertices->size;
|
||||
GLuint indices[] = {index, index+1, index+2,
|
||||
index, index+2, index+3};
|
||||
TextureGlyphVertex vertices[] = { { x0,y0,0, u0,v0, r,g,b,a },
|
||||
{ x0,y1,0, u0,v1, r,g,b,a },
|
||||
{ x1,y1,0, u1,v1, r,g,b,a },
|
||||
{ x1,y0,0, u1,v0, r,g,b,a } };
|
||||
vertex_buffer_push_back_indices( buffer, indices, 6 );
|
||||
vertex_buffer_push_back_vertices( buffer, vertices, 4 );
|
||||
}
|
||||
}
|
||||
|
||||
// Underline
|
||||
|
||||
// Overline
|
||||
|
||||
// Outline
|
||||
|
||||
// Strikethrough
|
||||
|
||||
// Actual glyph
|
||||
if( markup )
|
||||
{
|
||||
r = markup->foreground_color.r;
|
||||
g = markup->foreground_color.g;
|
||||
b = markup->foreground_color.b;
|
||||
a = markup->foreground_color.a;
|
||||
}
|
||||
|
||||
{
|
||||
int x0 = (int)( pen->x + self->offset_x );
|
||||
int y0 = (int)( pen->y + self->offset_y + rise );
|
||||
int x1 = (int)( x0 + self->width );
|
||||
int y1 = (int)( y0 - self->height );
|
||||
float u0 = self->u0;
|
||||
float v0 = self->v0;
|
||||
float u1 = self->u1;
|
||||
float v1 = self->v1;
|
||||
GLuint index = buffer->vertices->size;
|
||||
GLuint indices[] = {index, index+1, index+2,
|
||||
index, index+2, index+3};
|
||||
TextureGlyphVertex vertices[] = { { x0,y0,0, u0,v0, r,g,b,a },
|
||||
{ x0,y1,0, u0,v1, r,g,b,a },
|
||||
{ x1,y1,0, u1,v1, r,g,b,a },
|
||||
{ x1,y0,0, u1,v0, r,g,b,a } };
|
||||
vertex_buffer_push_back_indices( buffer, indices, 6 );
|
||||
vertex_buffer_push_back_vertices( buffer, vertices, 4 );
|
||||
|
||||
pen->x += self->advance_x + spacing;
|
||||
pen->y += self->advance_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
float
|
||||
texture_glyph_get_kerning( TextureGlyph *self,
|
||||
wchar_t charcode )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
assert( self );
|
||||
if( !self->kerning )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( i=0; i<self->kerning_count; ++i )
|
||||
{
|
||||
if( self->kerning[i].charcode == charcode )
|
||||
{
|
||||
return self->kerning[i].kerning;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* =========================================================================
|
||||
* 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.
|
||||
* ========================================================================= */
|
||||
|
||||
#ifdef USE_FREETYPEGL
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "texture-font.h"
|
||||
#include "texture-glyph.h"
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
TextureGlyph *
|
||||
texture_glyph_new( void )
|
||||
{
|
||||
TextureGlyph *self = (TextureGlyph *) malloc( sizeof(TextureGlyph) );
|
||||
if(! self )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
self->width = 0;
|
||||
self->height = 0;
|
||||
self->offset_x = 0;
|
||||
self->offset_y = 0;
|
||||
self->advance_x = 0.0;
|
||||
self->advance_y = 0.0;
|
||||
self->u0 = 0.0;
|
||||
self->v0 = 0.0;
|
||||
self->u1 = 0.0;
|
||||
self->v1 = 0.0;
|
||||
self->kerning_count = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_delete( TextureGlyph *self )
|
||||
{
|
||||
assert( self );
|
||||
free( self );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_render( TextureGlyph *self,
|
||||
Markup *markup,
|
||||
Pen *pen )
|
||||
{
|
||||
assert( self );
|
||||
|
||||
{
|
||||
int x = pen->x + self->offset_x;
|
||||
int y = pen->y + self->offset_y + markup->rise;
|
||||
int w = self->width;
|
||||
int h = self->height;
|
||||
|
||||
float u0 = self->u0;
|
||||
float v0 = self->v0;
|
||||
float u1 = self->u1;
|
||||
float v1 = self->v1;
|
||||
|
||||
glBegin( GL_TRIANGLES );
|
||||
{
|
||||
glTexCoord2f( u0, v0 ); glVertex2i( x, y );
|
||||
glTexCoord2f( u0, v1 ); glVertex2i( x, y-h );
|
||||
glTexCoord2f( u1, v1 ); glVertex2i( x+w, y-h );
|
||||
|
||||
glTexCoord2f( u0, v0 ); glVertex2i( x, y );
|
||||
glTexCoord2f( u1, v1 ); glVertex2i( x+w, y-h );
|
||||
glTexCoord2f( u1, v0 ); glVertex2i( x+w, y );
|
||||
}
|
||||
glEnd();
|
||||
|
||||
pen->x += self->advance_x + markup->spacing;
|
||||
pen->y += self->advance_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
void
|
||||
texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
|
||||
VertexBuffer *buffer,
|
||||
const Markup *markup,
|
||||
Pen *pen, int kerning )
|
||||
{
|
||||
TextureFont *font = self->font;
|
||||
float r = 1;
|
||||
float g = 1;
|
||||
float b = 1;
|
||||
float a = 1;
|
||||
int rise = 0;
|
||||
int spacing = 0;
|
||||
|
||||
if( markup )
|
||||
{
|
||||
rise = markup->rise;
|
||||
spacing = markup->spacing;
|
||||
}
|
||||
|
||||
pen->x += kerning;
|
||||
|
||||
// Background
|
||||
if( markup && markup->background_color.a > 0 )
|
||||
{
|
||||
float u0 = font->atlas->black.x / (float) font->atlas->width;
|
||||
float v0 = font->atlas->black.y / (float) font->atlas->height;
|
||||
float u1 = u0 + font->atlas->black.width / (float) font->atlas->width;
|
||||
float v1 = v0 + font->atlas->black.height / (float) font->atlas->height;
|
||||
int x0 = pen->x - kerning;
|
||||
int y0 = pen->y + font->descender;
|
||||
int x1 = x0 + self->advance_x + markup->spacing + kerning;
|
||||
int y1 = y0 + font->height - font->linegap;
|
||||
r = markup->background_color.r;
|
||||
g = markup->background_color.g;
|
||||
b = markup->background_color.b;
|
||||
a = markup->background_color.a;
|
||||
|
||||
{
|
||||
GLuint index = buffer->vertices->size;
|
||||
GLuint indices[] = {index, index+1, index+2,
|
||||
index, index+2, index+3};
|
||||
TextureGlyphVertex vertices[] = { { x0,y0,0, u0,v0, r,g,b,a },
|
||||
{ x0,y1,0, u0,v1, r,g,b,a },
|
||||
{ x1,y1,0, u1,v1, r,g,b,a },
|
||||
{ x1,y0,0, u1,v0, r,g,b,a } };
|
||||
vertex_buffer_push_back_indices( buffer, indices, 6 );
|
||||
vertex_buffer_push_back_vertices( buffer, vertices, 4 );
|
||||
}
|
||||
}
|
||||
|
||||
// Underline
|
||||
|
||||
// Overline
|
||||
|
||||
// Outline
|
||||
|
||||
// Strikethrough
|
||||
|
||||
// Actual glyph
|
||||
if( markup )
|
||||
{
|
||||
r = markup->foreground_color.r;
|
||||
g = markup->foreground_color.g;
|
||||
b = markup->foreground_color.b;
|
||||
a = markup->foreground_color.a;
|
||||
}
|
||||
|
||||
{
|
||||
int x0 = (int)( pen->x + self->offset_x );
|
||||
int y0 = (int)( pen->y + self->offset_y + rise );
|
||||
int x1 = (int)( x0 + self->width );
|
||||
int y1 = (int)( y0 - self->height );
|
||||
float u0 = self->u0;
|
||||
float v0 = self->v0;
|
||||
float u1 = self->u1;
|
||||
float v1 = self->v1;
|
||||
GLuint index = buffer->vertices->size;
|
||||
GLuint indices[] = {index, index+1, index+2,
|
||||
index, index+2, index+3};
|
||||
TextureGlyphVertex vertices[] = { { x0,y0,0, u0,v0, r,g,b,a },
|
||||
{ x0,y1,0, u0,v1, r,g,b,a },
|
||||
{ x1,y1,0, u1,v1, r,g,b,a },
|
||||
{ x1,y0,0, u1,v0, r,g,b,a } };
|
||||
vertex_buffer_push_back_indices( buffer, indices, 6 );
|
||||
vertex_buffer_push_back_vertices( buffer, vertices, 4 );
|
||||
|
||||
pen->x += self->advance_x + spacing;
|
||||
pen->y += self->advance_y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
float
|
||||
texture_glyph_get_kerning( TextureGlyph *self,
|
||||
wchar_t charcode )
|
||||
{
|
||||
size_t i;
|
||||
|
||||
assert( self );
|
||||
if( !self->kerning )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for( i=0; i<self->kerning_count; ++i )
|
||||
{
|
||||
if( self->kerning[i].charcode == charcode )
|
||||
{
|
||||
return self->kerning[i].kerning;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -41,16 +41,16 @@
|
||||
|
||||
#if defined(_WIN32) || defined(___APPLE__)
|
||||
|
||||
char * strndup(const char *old, size_t sz)
|
||||
{
|
||||
size_t len = strnlen (old, sz);
|
||||
char *t = malloc(len + 1);
|
||||
|
||||
if (t != NULL) {
|
||||
memcpy (t, old, len);
|
||||
t[len] = '\0';
|
||||
}
|
||||
return t;
|
||||
char * strndup(const char *old, size_t sz)
|
||||
{
|
||||
size_t len = strnlen (old, sz);
|
||||
char *t = malloc(len + 1);
|
||||
|
||||
if (t != NULL) {
|
||||
memcpy (t, old, len);
|
||||
t[len] = '\0';
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -779,7 +779,7 @@ void fromEndianMapFileHeader(MapFileHeader &header) {
|
||||
|
||||
void MapPreview::loadFromFile(const string &path) {
|
||||
|
||||
// "Could not open file, result: 3 - 2 No such file or directory [C:\Documents and Settings\人間五\Application Data\megaglest\maps\clearings_in_the_woods.gbm]
|
||||
// "Could not open file, result: 3 - 2 No such file or directory [C:\Documents and Settings\人間五\Application Data\megaglest\maps\clearings_in_the_woods.gbm]
|
||||
|
||||
#ifdef WIN32
|
||||
wstring wstr = utf8_decode(path);
|
||||
|
@@ -234,12 +234,12 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d] AFTER glewInit call err = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,err);
|
||||
|
||||
if (GLEW_OK != err) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
|
||||
//return 1;
|
||||
throw std::runtime_error((char *)glewGetErrorString(err));
|
||||
if (GLEW_OK != err) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
|
||||
//return 1;
|
||||
throw std::runtime_error((char *)glewGetErrorString(err));
|
||||
}
|
||||
//fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
|
||||
|
||||
@@ -262,7 +262,7 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,
|
||||
}
|
||||
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -34,94 +34,94 @@ string PlatformExceptionHandler::application_binary="";
|
||||
bool PlatformExceptionHandler::disableBacktrace = false;
|
||||
PlatformExceptionHandler *PlatformExceptionHandler::thisPointer= NULL;
|
||||
|
||||
// Constructs object and convert lpaszString to Unicode
|
||||
LPWSTR Ansi2WideString(LPCSTR lpaszString) {
|
||||
LPWSTR lpwszString(NULL);
|
||||
|
||||
if(lpaszString != NULL) {
|
||||
int nLen = ::lstrlenA(lpaszString) + 1;
|
||||
lpwszString = new WCHAR[nLen];
|
||||
if (lpwszString == NULL) {
|
||||
return lpwszString;
|
||||
}
|
||||
|
||||
memset(lpwszString, 0, nLen * sizeof(WCHAR));
|
||||
|
||||
if (::MultiByteToWideChar(CP_ACP, 0, lpaszString, nLen, lpwszString, nLen) == 0) {
|
||||
// Conversation failed
|
||||
return lpwszString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int nLen = 1;
|
||||
lpwszString = new WCHAR[nLen];
|
||||
if (lpwszString == NULL) {
|
||||
return lpwszString;
|
||||
}
|
||||
|
||||
memset(lpwszString, 0, nLen * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
return lpwszString;
|
||||
// Constructs object and convert lpaszString to Unicode
|
||||
LPWSTR Ansi2WideString(LPCSTR lpaszString) {
|
||||
LPWSTR lpwszString(NULL);
|
||||
|
||||
if(lpaszString != NULL) {
|
||||
int nLen = ::lstrlenA(lpaszString) + 1;
|
||||
lpwszString = new WCHAR[nLen];
|
||||
if (lpwszString == NULL) {
|
||||
return lpwszString;
|
||||
}
|
||||
|
||||
memset(lpwszString, 0, nLen * sizeof(WCHAR));
|
||||
|
||||
if (::MultiByteToWideChar(CP_ACP, 0, lpaszString, nLen, lpwszString, nLen) == 0) {
|
||||
// Conversation failed
|
||||
return lpwszString;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int nLen = 1;
|
||||
lpwszString = new WCHAR[nLen];
|
||||
if (lpwszString == NULL) {
|
||||
return lpwszString;
|
||||
}
|
||||
|
||||
memset(lpwszString, 0, nLen * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
return lpwszString;
|
||||
}
|
||||
|
||||
// Convert a wide Unicode string to an UTF8 string
|
||||
std::string utf8_encode(const std::wstring &wstr) {
|
||||
if(wstr.length() == 0) {
|
||||
std::string wstrTo;
|
||||
return wstrTo;
|
||||
}
|
||||
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
||||
std::string strTo( size_needed, 0 );
|
||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
||||
replaceAll(strTo, "/", "\\");
|
||||
replaceAll(strTo, "\\\\", "\\");
|
||||
updatePathClimbingParts(strTo);
|
||||
return strTo;
|
||||
}
|
||||
|
||||
// Convert an UTF8 string to a wide Unicode String
|
||||
std::wstring utf8_decode(const std::string &str) {
|
||||
if(str.length() == 0) {
|
||||
std::wstring wstrTo;
|
||||
return wstrTo;
|
||||
}
|
||||
string friendly_path = str;
|
||||
replaceAll(friendly_path, "/", "\\");
|
||||
replaceAll(friendly_path, "\\\\", "\\");
|
||||
updatePathClimbingParts(friendly_path);
|
||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), NULL, 0);
|
||||
std::wstring wstrTo( size_needed, 0 );
|
||||
MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), &wstrTo[0], size_needed);
|
||||
return wstrTo;
|
||||
}
|
||||
// Convert a wide Unicode string to an UTF8 string
|
||||
std::string utf8_encode(const std::wstring &wstr) {
|
||||
if(wstr.length() == 0) {
|
||||
std::string wstrTo;
|
||||
return wstrTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param location The location of the registry key. For example "Software\\Bethesda Softworks\\Morrowind"
|
||||
* @param name the name of the registry key, for example "Installed Path"
|
||||
* @return the value of the key or an empty string if an error occured.
|
||||
*/
|
||||
std::string getRegKey(const std::string& location, const std::string& name){
|
||||
HKEY key;
|
||||
CHAR value[1024];
|
||||
DWORD bufLen = 1024*sizeof(CHAR);
|
||||
long ret;
|
||||
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, location.c_str(), 0, KEY_QUERY_VALUE, &key);
|
||||
if( ret != ERROR_SUCCESS ){
|
||||
return std::string();
|
||||
}
|
||||
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
|
||||
RegCloseKey(key);
|
||||
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
|
||||
return std::string();
|
||||
}
|
||||
string stringValue = value;
|
||||
size_t i = stringValue.length();
|
||||
while( i > 0 && stringValue[i-1] == '\0' ){
|
||||
--i;
|
||||
}
|
||||
return stringValue.substr(0,i);
|
||||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
|
||||
std::string strTo( size_needed, 0 );
|
||||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
|
||||
replaceAll(strTo, "/", "\\");
|
||||
replaceAll(strTo, "\\\\", "\\");
|
||||
updatePathClimbingParts(strTo);
|
||||
return strTo;
|
||||
}
|
||||
|
||||
// Convert an UTF8 string to a wide Unicode String
|
||||
std::wstring utf8_decode(const std::string &str) {
|
||||
if(str.length() == 0) {
|
||||
std::wstring wstrTo;
|
||||
return wstrTo;
|
||||
}
|
||||
string friendly_path = str;
|
||||
replaceAll(friendly_path, "/", "\\");
|
||||
replaceAll(friendly_path, "\\\\", "\\");
|
||||
updatePathClimbingParts(friendly_path);
|
||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), NULL, 0);
|
||||
std::wstring wstrTo( size_needed, 0 );
|
||||
MultiByteToWideChar(CP_UTF8, 0, &friendly_path[0], (int)friendly_path.size(), &wstrTo[0], size_needed);
|
||||
return wstrTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param location The location of the registry key. For example "Software\\Bethesda Softworks\\Morrowind"
|
||||
* @param name the name of the registry key, for example "Installed Path"
|
||||
* @return the value of the key or an empty string if an error occured.
|
||||
*/
|
||||
std::string getRegKey(const std::string& location, const std::string& name){
|
||||
HKEY key;
|
||||
CHAR value[1024];
|
||||
DWORD bufLen = 1024*sizeof(CHAR);
|
||||
long ret;
|
||||
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, location.c_str(), 0, KEY_QUERY_VALUE, &key);
|
||||
if( ret != ERROR_SUCCESS ){
|
||||
return std::string();
|
||||
}
|
||||
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
|
||||
RegCloseKey(key);
|
||||
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
|
||||
return std::string();
|
||||
}
|
||||
string stringValue = value;
|
||||
size_t i = stringValue.length();
|
||||
while( i > 0 && stringValue[i-1] == '\0' ){
|
||||
--i;
|
||||
}
|
||||
return stringValue.substr(0,i);
|
||||
}
|
||||
|
||||
LONG WINAPI PlatformExceptionHandler::handler(LPEXCEPTION_POINTERS pointers){
|
||||
@@ -175,76 +175,76 @@ void PlatformExceptionHandler::install(string dumpFileName){
|
||||
}
|
||||
|
||||
string PlatformExceptionHandler::getStackTrace() {
|
||||
string result = "\nStack Trace:\n";
|
||||
string result = "\nStack Trace:\n";
|
||||
if(PlatformExceptionHandler::disableBacktrace == true) {
|
||||
result += "disabled...";
|
||||
return result;
|
||||
}
|
||||
#ifndef __MINGW32__
|
||||
|
||||
CONTEXT context = { 0 };
|
||||
context.ContextFlags = CONTEXT_FULL;
|
||||
|
||||
IMAGEHLP_SYMBOL *pSym = (IMAGEHLP_SYMBOL*)new BYTE[sizeof(IMAGEHLP_SYMBOL) + 256];
|
||||
pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
|
||||
pSym->MaxNameLength = 256;
|
||||
|
||||
IMAGEHLP_LINE line = { 0 };
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE);
|
||||
|
||||
IMAGEHLP_MODULE module = { 0 };
|
||||
module.SizeOfStruct = sizeof(IMAGEHLP_MODULE);
|
||||
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
if (GetThreadContext(hThread, &context)) {
|
||||
STACKFRAME stackframe = { 0 };
|
||||
stackframe.AddrPC.Offset = context.Eip;
|
||||
stackframe.AddrPC.Mode = AddrModeFlat;
|
||||
stackframe.AddrFrame.Offset = context.Ebp;
|
||||
stackframe.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
SymInitialize(hProcess, NULL, TRUE);
|
||||
BOOL fSuccess = TRUE;
|
||||
|
||||
do
|
||||
{
|
||||
fSuccess = StackWalk(IMAGE_FILE_MACHINE_I386,
|
||||
GetCurrentProcess(),
|
||||
GetCurrentThread(),
|
||||
&stackframe,
|
||||
&context,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
DWORD dwDisplacement = 0;
|
||||
SymGetSymFromAddr(hProcess, stackframe.AddrPC.Offset, &dwDisplacement, pSym);
|
||||
SymGetLineFromAddr(hProcess, stackframe.AddrPC.Offset, &dwDisplacement, &line);
|
||||
SymGetModuleInfo(hProcess, stackframe.AddrPC.Offset, &module);
|
||||
|
||||
// RetAddr Arg1 Arg2 Arg3 module!funtion FileName(line)+offset
|
||||
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"%08lx %08lx %08lx %08lx %s!%s %s(%lu) %+ld\n",
|
||||
stackframe.AddrReturn.Offset,
|
||||
stackframe.Params[0],
|
||||
stackframe.Params[1],
|
||||
stackframe.Params[2],
|
||||
pSym->Name,
|
||||
module.ModuleName,
|
||||
line.FileName,
|
||||
line.LineNumber,
|
||||
dwDisplacement);
|
||||
result += szBuf;
|
||||
|
||||
} while (fSuccess);
|
||||
|
||||
SymCleanup(hProcess);
|
||||
}
|
||||
#ifndef __MINGW32__
|
||||
|
||||
CONTEXT context = { 0 };
|
||||
context.ContextFlags = CONTEXT_FULL;
|
||||
|
||||
IMAGEHLP_SYMBOL *pSym = (IMAGEHLP_SYMBOL*)new BYTE[sizeof(IMAGEHLP_SYMBOL) + 256];
|
||||
pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
|
||||
pSym->MaxNameLength = 256;
|
||||
|
||||
IMAGEHLP_LINE line = { 0 };
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE);
|
||||
|
||||
IMAGEHLP_MODULE module = { 0 };
|
||||
module.SizeOfStruct = sizeof(IMAGEHLP_MODULE);
|
||||
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
HANDLE hThread = GetCurrentThread();
|
||||
if (GetThreadContext(hThread, &context)) {
|
||||
STACKFRAME stackframe = { 0 };
|
||||
stackframe.AddrPC.Offset = context.Eip;
|
||||
stackframe.AddrPC.Mode = AddrModeFlat;
|
||||
stackframe.AddrFrame.Offset = context.Ebp;
|
||||
stackframe.AddrFrame.Mode = AddrModeFlat;
|
||||
|
||||
SymInitialize(hProcess, NULL, TRUE);
|
||||
BOOL fSuccess = TRUE;
|
||||
|
||||
do
|
||||
{
|
||||
fSuccess = StackWalk(IMAGE_FILE_MACHINE_I386,
|
||||
GetCurrentProcess(),
|
||||
GetCurrentThread(),
|
||||
&stackframe,
|
||||
&context,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
DWORD dwDisplacement = 0;
|
||||
SymGetSymFromAddr(hProcess, stackframe.AddrPC.Offset, &dwDisplacement, pSym);
|
||||
SymGetLineFromAddr(hProcess, stackframe.AddrPC.Offset, &dwDisplacement, &line);
|
||||
SymGetModuleInfo(hProcess, stackframe.AddrPC.Offset, &module);
|
||||
|
||||
// RetAddr Arg1 Arg2 Arg3 module!funtion FileName(line)+offset
|
||||
|
||||
char szBuf[8096]="";
|
||||
snprintf(szBuf,8096,"%08lx %08lx %08lx %08lx %s!%s %s(%lu) %+ld\n",
|
||||
stackframe.AddrReturn.Offset,
|
||||
stackframe.Params[0],
|
||||
stackframe.Params[1],
|
||||
stackframe.Params[2],
|
||||
pSym->Name,
|
||||
module.ModuleName,
|
||||
line.FileName,
|
||||
line.LineNumber,
|
||||
dwDisplacement);
|
||||
result += szBuf;
|
||||
|
||||
} while (fSuccess);
|
||||
|
||||
SymCleanup(hProcess);
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
megaglest_runtime_error::megaglest_runtime_error(const string& __arg,bool noStackTrace)
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -223,11 +223,11 @@ std::map<string,string> Properties::getTagReplacementValues(std::map<string,stri
|
||||
|
||||
//const wchar_t *wBuf = &szPath[0];
|
||||
//size_t size = MAX_PATH + 1;
|
||||
//char pMBBuffer[MAX_PATH + 1]="";
|
||||
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
|
||||
//string appPath="";
|
||||
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
|
||||
std::string appPath = utf8_encode(szPath);
|
||||
//char pMBBuffer[MAX_PATH + 1]="";
|
||||
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
|
||||
//string appPath="";
|
||||
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
|
||||
std::string appPath = utf8_encode(szPath);
|
||||
|
||||
//string appPath = szPath;
|
||||
mapTagReplacementValues["$APPDATA"] = appPath;
|
||||
@@ -318,17 +318,17 @@ bool Properties::applyTagsToValue(string &value, const std::map<string,string> *
|
||||
// For win32 we allow use of the appdata variable since that is the recommended
|
||||
// place for application data in windows platform
|
||||
#ifdef WIN32
|
||||
TCHAR szPath[MAX_PATH];
|
||||
// Get path for each computer, non-user specific and non-roaming data.
|
||||
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
|
||||
TCHAR szPath[MAX_PATH];
|
||||
// Get path for each computer, non-user specific and non-roaming data.
|
||||
if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA,
|
||||
NULL, 0, szPath))) {
|
||||
//const wchar_t *wBuf = &szPath[0];
|
||||
//size_t size = MAX_PATH + 1;
|
||||
//char pMBBuffer[MAX_PATH + 1]="";
|
||||
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
|
||||
//string appPath="";
|
||||
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
|
||||
std::string appPath = utf8_encode(szPath);
|
||||
//char pMBBuffer[MAX_PATH + 1]="";
|
||||
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
|
||||
//string appPath="";
|
||||
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
|
||||
std::string appPath = utf8_encode(szPath);
|
||||
|
||||
//string appPath = szPath;
|
||||
replaceAll(value, "$APPDATA", appPath);
|
||||
|
Reference in New Issue
Block a user