- got freetype-gl working under windows

This commit is contained in:
Mark Vejvoda 2011-11-17 23:21:08 +00:00
parent ca40f8d0ab
commit ab9243ea38
10 changed files with 171 additions and 51 deletions

View File

@ -163,7 +163,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="dsound.lib dxguid.lib ogg_static.lib vorbis_static.lib vorbisfile_static.lib opengl32.lib glu32.lib wsock32.lib libglest.lib mmc.lib lua5.1.lib xerces-c_3.lib Dbghelp.lib libpng.lib jpeg.lib zlib.lib sdl.lib sdlmain.lib winmm.lib openal32.lib iphlpapi.lib libstreflop.lib libcurl.lib ws2_32.lib libircclient.lib ftgl_static.lib freetype244MT.lib" AdditionalDependencies="dsound.lib dxguid.lib ogg_static.lib vorbis_static.lib vorbisfile_static.lib opengl32.lib glu32.lib wsock32.lib libglest.lib mmc.lib lua5.1.lib xerces-c_3.lib Dbghelp.lib libpng.lib jpeg.lib zlib.lib sdl.lib sdlmain.lib winmm.lib openal32.lib iphlpapi.lib libstreflop.lib libcurl.lib ws2_32.lib libircclient.lib ftgl_static.lib freetype244MT.lib glew32s.lib"
OutputFile="$(OutDir)\megaglest.exe" OutputFile="$(OutDir)\megaglest.exe"
LinkIncremental="1" LinkIncremental="1"
AdditionalLibraryDirectories="../../source/win32_deps/lib;&quot;../../build/$(ConfigurationName)/libglest&quot;;../../source/shared_lib/sources/streflop/libstreflop;../../source/win32_deps/libircclient/build/lib" AdditionalLibraryDirectories="../../source/win32_deps/lib;&quot;../../build/$(ConfigurationName)/libglest&quot;;../../source/shared_lib/sources/streflop/libstreflop;../../source/win32_deps/libircclient/build/lib"

View File

@ -40,8 +40,8 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;&quot;../../source/win32_deps/xerces-c-3.0.1/src&quot;;&quot;../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude&quot;;../../source/win32_deps/lpng141;&quot;../../source/win32_deps/jpeg-8a&quot;;&quot;../../source/win32_deps/SDL-1.2.x/include&quot;;../../source/shared_lib/include/platform/sdl;&quot;../../source/win32_deps/openal-soft-1.12.854/include&quot;;../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;&quot;../../source/win32_deps/curl-7.21.3/include&quot;;../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;&quot;../../source/win32_deps/glew-1.7.0/include&quot;;../../source/shared_lib/include/graphics/md5" AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;&quot;../../source/win32_deps/xerces-c-3.0.1/src&quot;;&quot;../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude&quot;;../../source/win32_deps/lpng141;&quot;../../source/win32_deps/jpeg-8a&quot;;&quot;../../source/win32_deps/SDL-1.2.x/include&quot;;../../source/shared_lib/include/platform/sdl;&quot;../../source/win32_deps/openal-soft-1.12.854/include&quot;;../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;&quot;../../source/win32_deps/curl-7.21.3/include&quot;;../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;&quot;../../source/win32_deps/glew-1.7.0/include&quot;;../../source/shared_lib/include/graphics/md5;&quot;../../source/shared_lib/include/graphics/freetype-gl&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE;STATICLIB" PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE;STATICLIB;GLEW_STATIC"
StringPooling="true" StringPooling="true"
MinimalRebuild="true" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
@ -120,8 +120,8 @@
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1" FavorSizeOrSpeed="1"
WholeProgramOptimization="false" WholeProgramOptimization="false"
AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;&quot;../../source/win32_deps/xerces-c-3.0.1/src&quot;;&quot;../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude&quot;;../../source/win32_deps/lpng141;&quot;../../source/win32_deps/jpeg-8a&quot;;&quot;../../source/win32_deps/SDL-1.2.x/include&quot;;../../source/shared_lib/include/platform/sdl;&quot;../../source/win32_deps/openal-soft-1.12.854/include&quot;;../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;&quot;../../source/win32_deps/curl-7.21.3/include&quot;;../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;&quot;../../source/win32_deps/ftgl-2.1.3-rc5/src&quot;;&quot;../../source/win32_deps/freetype-2.4.4/include&quot;;&quot;../../source/win32_deps/glew-1.7.0/include&quot;;../../source/shared_lib/include/graphics/md5;$(NOINHERIT)" AdditionalIncludeDirectories="../../source/shared_lib/include;../../source/shared_lib/include/graphics;../../source/shared_lib/include/graphics/gl;../../source/shared_lib/include/platform;../../source/shared_lib/include/platform/win32;../../source/shared_lib/include/sound;../../source/shared_lib/include/sound/ds8;../../source/shared_lib/include/util;../../source/shared_lib/include/lua;../../source/shared_lib/include/xml;../../source/win32_deps/include;&quot;../../source/win32_deps/xerces-c-3.0.1/src&quot;;&quot;../../source/win32_deps/xerces-c-3.0.1/src/xercesc/xinclude&quot;;../../source/win32_deps/lpng141;&quot;../../source/win32_deps/jpeg-8a&quot;;&quot;../../source/win32_deps/SDL-1.2.x/include&quot;;../../source/shared_lib/include/platform/sdl;&quot;../../source/win32_deps/openal-soft-1.12.854/include&quot;;../../source/shared_lib/include/sound/openal;../../source/shared_lib/include/platform/posix;../../source/shared_lib/include/streflop;../../source/shared_lib/include/streflop/libm_flt32_source;../../source/shared_lib/include/platform/common;&quot;../../source/win32_deps/curl-7.21.3/include&quot;;../../source/shared_lib/include/map;../../source/shared_lib/include/platform/miniupnpc;../../source/shared_lib/include/libircclient/include;../../source/shared_lib/include/feathery_ftp;&quot;../../source/win32_deps/ftgl-2.1.3-rc5/src&quot;;&quot;../../source/win32_deps/freetype-2.4.4/include&quot;;&quot;../../source/win32_deps/glew-1.7.0/include&quot;;../../source/shared_lib/include/graphics/md5;&quot;../../source/shared_lib/include/graphics/freetype-gl&quot;;$(NOINHERIT)"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE;USE_FTGL;TA3D_PLATFORM_MSVC;TA3D_PLATFORM_WINDOWS;STATICLIB" PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;USE_PCH=1;USE_STREFLOP;STREFLOP_SSE;STREFLOP_RANDOM_GEN_SIZE=32;LIBM_COMPILING_FLT32;CURL_STATICLIB;UNICODE;USE_FTGL;TA3D_PLATFORM_MSVC;TA3D_PLATFORM_WINDOWS;STATICLIB;GLEW_STATIC"
StringPooling="true" StringPooling="true"
ExceptionHandling="2" ExceptionHandling="2"
RuntimeLibrary="0" RuntimeLibrary="0"
@ -248,10 +248,22 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
> >
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\edtaa3func.c"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\font-manager.c"
>
</File>
<File <File
RelativePath="..\..\source\shared_lib\sources\graphics\font_text.cpp" RelativePath="..\..\source\shared_lib\sources\graphics\font_text.cpp"
> >
</File> </File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\gl\font_text_freetypegl.cpp"
>
</File>
<File <File
RelativePath="..\..\source\shared_lib\sources\feathery_ftp\ftpAccount.c" RelativePath="..\..\source\shared_lib\sources\feathery_ftp\ftpAccount.c"
> >
@ -376,6 +388,10 @@
RelativePath="..\..\source\shared_lib\sources\map\map_preview.cpp" RelativePath="..\..\source\shared_lib\sources\map\map_preview.cpp"
> >
</File> </File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\markup.c"
>
</File>
<File <File
RelativePath="..\..\source\shared_lib\sources\streflop\Random.cpp" RelativePath="..\..\source\shared_lib\sources\streflop\Random.cpp"
> >
@ -396,6 +412,26 @@
RelativePath="..\..\source\shared_lib\sources\util\string_utils.cpp" RelativePath="..\..\source\shared_lib\sources\util\string_utils.cpp"
> >
</File> </File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\texture-atlas.c"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\texture-font.c"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\texture-glyph.c"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\vector.c"
>
</File>
<File
RelativePath="..\..\source\shared_lib\sources\graphics\freetype-gl\vertex-buffer.c"
>
</File>
<Filter <Filter
Name="graphics" Name="graphics"
> >
@ -500,11 +536,11 @@
> >
</File> </File>
<File <File
RelativePath="..\..\source\shared_lib\sources\graphics\texture.cpp" RelativePath="..\..\source\shared_lib\sources\graphics\md5\Texture.cpp"
> >
</File> </File>
<File <File
RelativePath="..\..\source\shared_lib\sources\graphics\md5\Texture.cpp" RelativePath="..\..\source\shared_lib\sources\graphics\texture.cpp"
> >
</File> </File>
<File <File

View File

@ -32,20 +32,22 @@
* ========================================================================= */ * ========================================================================= */
#ifndef __VERTEX_BUFFER_H__ #ifndef __VERTEX_BUFFER_H__
#define __VERTEX_BUFFER_H__ #define __VERTEX_BUFFER_H__
#if defined(__APPLE__) #if defined(__APPLE__)
#include <Glut/glut.h> //#include <Glut/glut.h>
#elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <GL/glew.h>
#else #else
#include <GL/glut.h> //#include <GL/glut.h>
#endif #endif
#include "vector.h" #include "vector.h"
#define MAX_VERTEX_ATTRIBUTE 64 #define MAX_VERTEX_ATTRIBUTE 64
#ifdef __cplusplus
extern "C" {
#endif
/** /**
* Generic vertex attribute. * Generic vertex attribute.
*/ */
@ -133,8 +135,6 @@ typedef struct
VertexAttribute *attributes[MAX_VERTEX_ATTRIBUTE]; VertexAttribute *attributes[MAX_VERTEX_ATTRIBUTE];
} VertexBuffer; } VertexBuffer;
/** /**
* Creates an empty vertex buffer. * Creates an empty vertex buffer.
* *
@ -470,8 +470,5 @@ vertex_attribute_new( GLenum target,
char * char *
GL_TYPE_STRING( GLenum gtype ); GL_TYPE_STRING( GLenum gtype );
#ifdef __cplusplus
}
#endif
#endif /* __VERTEX_BUFFER_H__ */ #endif /* __VERTEX_BUFFER_H__ */

View File

@ -30,7 +30,10 @@
* those of the authors and should not be interpreted as representing official * those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of Nicolas P. Rougier. * policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */ * ========================================================================= */
#ifdef HAVE_FONTCONFIG
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#endif
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <wchar.h> #include <wchar.h>
@ -122,6 +125,7 @@ font_manager_get_from_description( FontManager *self,
{ {
assert( self ); assert( self );
{
TextureFont *font; TextureFont *font;
char *filename = font_manager_match_description( self, family, size, bold, italic ); char *filename = font_manager_match_description( self, family, size, bold, italic );
// fprintf(stderr, "Matched filename for %s: %s\n", family, filename); // fprintf(stderr, "Matched filename for %s: %s\n", family, filename);
@ -132,6 +136,7 @@ font_manager_get_from_description( FontManager *self,
font = font_manager_get_from_filename( self, filename, size ); font = font_manager_get_from_filename( self, filename, size );
free( filename ); free( filename );
return font; return font;
}
} }
TextureFont * TextureFont *
@ -140,10 +145,12 @@ font_manager_get_from_markup( FontManager *self,
{ {
assert( self ); assert( self );
assert( markup ); assert( markup );
{
TextureFont *font = TextureFont *font =
font_manager_get_from_description( self, markup->family, markup->size, font_manager_get_from_description( self, markup->family, markup->size,
markup->bold, markup->italic ); markup->bold, markup->italic );
return font; return font;
}
} }
@ -155,6 +162,8 @@ font_manager_match_description( FontManager *self,
const int italic ) const int italic )
{ {
char *filename = 0; char *filename = 0;
#ifdef HAVE_FONTCONFIG
int weight = FC_WEIGHT_REGULAR; int weight = FC_WEIGHT_REGULAR;
int slant = FC_SLANT_ROMAN; int slant = FC_SLANT_ROMAN;
if ( bold ) if ( bold )
@ -196,6 +205,8 @@ font_manager_match_description( FontManager *self,
} }
} }
FcPatternDestroy( match ); FcPatternDestroy( match );
#endif
return filename; return filename;
} }

View File

@ -31,11 +31,19 @@
* policies, either expressed or implied, of Nicolas P. Rougier. * policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */ * ========================================================================= */
#if defined(__APPLE__) #if defined(__APPLE__)
#include <Glut/glut.h> //#include <Glut/glut.h>
#else #else
#include <GL/glut.h> //#include <GL/glut.h>
#endif #endif
#include <stdlib.h> //#include <stdlib.h>
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
//#include <glprocs.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <limits.h> #include <limits.h>
@ -55,6 +63,7 @@ texture_atlas_new( size_t width, size_t height, size_t depth )
{ {
assert( (depth == 1) || (depth == 3) ); assert( (depth == 1) || (depth == 3) );
{
TextureAtlas *self = (TextureAtlas *) malloc( sizeof(TextureAtlas) ); TextureAtlas *self = (TextureAtlas *) malloc( sizeof(TextureAtlas) );
if( !self ) if( !self )
{ {
@ -65,18 +74,22 @@ texture_atlas_new( size_t width, size_t height, size_t depth )
self->width = width; self->width = width;
self->height = height; self->height = height;
self->depth = depth; self->depth = depth;
{
Node node = {0,0,width}; Node node = {0,0,width};
vector_push_back( self->nodes, &node ); vector_push_back( self->nodes, &node );
self->texid = 0; self->texid = 0;
self->data = (unsigned char *) self->data = (unsigned char *)
calloc( width*height*depth, sizeof(unsigned char) ); calloc( width*height*depth, sizeof(unsigned char) );
{
// This is a special region that is used for background and underlined // This is a special region that is used for background and underlined
// decorations of glyphs // decorations of glyphs
int n = 4; int n = 4;
unsigned char buffer[n*n]; //unsigned char buffer[n*n];
unsigned char buffer[16];
memset(buffer, 255, n*n); memset(buffer, 255, n*n);
{
Region r = texture_atlas_get_region( self, 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); texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
self->black.x = r.x + 1; self->black.x = r.x + 1;
@ -85,6 +98,10 @@ texture_atlas_new( size_t width, size_t height, size_t depth )
self->black.height= r.height - 2; self->black.height= r.height - 2;
return self; return self;
}
}
}
}
} }
@ -149,6 +166,7 @@ texture_atlas_set_region( TextureAtlas *self,
assert( (x + width) <= self->width); assert( (x + width) <= self->width);
assert( y < self->height); assert( y < self->height);
assert( (y + height) <= self->height); assert( (y + height) <= self->height);
{
size_t i; size_t i;
size_t depth = self->depth; size_t depth = self->depth;
size_t charsize = sizeof(char); size_t charsize = sizeof(char);
@ -157,6 +175,7 @@ texture_atlas_set_region( TextureAtlas *self,
memcpy( self->data+((y+i)*self->width + x ) * charsize * depth, memcpy( self->data+((y+i)*self->width + x ) * charsize * depth,
data + (i*stride) * charsize, width * charsize * depth ); data + (i*stride) * charsize, width * charsize * depth );
} }
}
} }
@ -224,6 +243,7 @@ texture_atlas_get_region( TextureAtlas *self,
assert( width ); assert( width );
assert( height ); assert( height );
*/ */
{
int y, best_height, best_width, best_index; int y, best_height, best_width, best_index;
Node *node, *prev; Node *node, *prev;
Region region = {0,0,width,height}; Region region = {0,0,width,height};
@ -294,6 +314,7 @@ texture_atlas_get_region( TextureAtlas *self,
texture_atlas_merge( self ); texture_atlas_merge( self );
self->used += width * height; self->used += width * height;
return region; return region;
}
} }
@ -304,21 +325,28 @@ texture_atlas_clear( TextureAtlas *self )
vector_clear( self->nodes ); vector_clear( self->nodes );
self->used = 0; self->used = 0;
{
Node node = {0,0,self->width}; Node node = {0,0,self->width};
vector_push_back( self->nodes, &node ); vector_push_back( self->nodes, &node );
memset( self->data, 0, self->width*self->height*self->depth ); memset( self->data, 0, self->width*self->height*self->depth );
{
// This is a special region that is used for background and underlined // This is a special region that is used for background and underlined
// decorations of glyphs // decorations of glyphs
int n = 4; int n = 4;
unsigned char buffer[n*n]; //unsigned char buffer[n*n];
unsigned char buffer[16];
memset(buffer, 255, n*n); memset(buffer, 255, n*n);
{
Region r = texture_atlas_get_region( self, 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); texture_atlas_set_region( self, r.x, r.y, r.width, r.height, buffer, 1);
self->black.x = r.x + 1; self->black.x = r.x + 1;
self->black.y = r.y + 1; self->black.y = r.y + 1;
self->black.width = r.width - 2; self->black.width = r.width - 2;
self->black.height= r.height - 2; self->black.height= r.height - 2;
}
}
}
} }

View File

@ -34,7 +34,7 @@
#include FT_FREETYPE_H #include FT_FREETYPE_H
// #include FT_ADVANCES_H // #include FT_ADVANCES_H
#include FT_LCD_FILTER_H #include FT_LCD_FILTER_H
#include <stdint.h> //#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
@ -83,6 +83,7 @@ texture_font_new( TextureAtlas *atlas,
self->lcd_weights[3] = 0; self->lcd_weights[3] = 0;
self->lcd_weights[4] = 0; self->lcd_weights[4] = 0;
{
/* Get font metrics at high resolution */ /* Get font metrics at high resolution */
FT_Library library; FT_Library library;
FT_Face face; FT_Face face;
@ -91,6 +92,7 @@ texture_font_new( TextureAtlas *atlas,
return self; return self;
} }
{
FT_Size_Metrics metrics = face->size->metrics; FT_Size_Metrics metrics = face->size->metrics;
self->ascender = (metrics.ascender >> 6) / 100.0; self->ascender = (metrics.ascender >> 6) / 100.0;
self->descender = (metrics.descender >> 6) / 100.0; self->descender = (metrics.descender >> 6) / 100.0;
@ -98,6 +100,8 @@ texture_font_new( TextureAtlas *atlas,
self->linegap = self->height - self->ascender + self->descender; self->linegap = self->height - self->ascender + self->descender;
return self; return self;
}
}
} }
@ -224,6 +228,7 @@ texture_font_cache_glyphs( TextureFont *self,
{ {
glyph_index = FT_Get_Char_Index( face, charcodes[i] ); glyph_index = FT_Get_Char_Index( face, charcodes[i] );
{
// WARNING: We use texture-atlas depth to guess if user wants // WARNING: We use texture-atlas depth to guess if user wants
// LCD subpixel rendering // LCD subpixel rendering
FT_Int32 flags = FT_LOAD_RENDER; FT_Int32 flags = FT_LOAD_RENDER;
@ -239,12 +244,16 @@ texture_font_cache_glyphs( TextureFont *self,
if( depth == 3 ) if( depth == 3 )
{ {
#if ((FREETYPE_MAJOR <= 2) && ((FREETYPE_MINOR < 3)))
//#error "Need FreeType 2.3.0 or newer"
#else
FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT ); FT_Library_SetLcdFilter( library, FT_LCD_FILTER_LIGHT );
flags |= FT_LOAD_TARGET_LCD; flags |= FT_LOAD_TARGET_LCD;
if( self->lcd_filter ) if( self->lcd_filter )
{ {
FT_Library_SetLcdFilterWeights( library, self->lcd_weights ); FT_Library_SetLcdFilterWeights( library, self->lcd_weights );
} }
#endif
} }
error = FT_Load_Glyph( face, glyph_index, flags ); error = FT_Load_Glyph( face, glyph_index, flags );
@ -308,6 +317,7 @@ texture_font_cache_glyphs( TextureFont *self,
vector_push_back( self->glyphs, glyph ); vector_push_back( self->glyphs, glyph );
texture_glyph_delete( glyph ); texture_glyph_delete( glyph );
}
} }
FT_Done_Face( face ); FT_Done_Face( face );
FT_Done_FreeType( library ); FT_Done_FreeType( library );
@ -350,8 +360,10 @@ texture_font_get_glyph( TextureFont *self,
if( texture_font_cache_glyphs( self, buffer ) == 0 ) if( texture_font_cache_glyphs( self, buffer ) == 0 )
{ {
free(buffer);
return (TextureGlyph *) vector_back( self->glyphs ); return (TextureGlyph *) vector_back( self->glyphs );
} }
free(buffer);
return NULL; return NULL;
} }

View File

@ -31,10 +31,14 @@
* policies, either expressed or implied, of Nicolas P. Rougier. * policies, either expressed or implied, of Nicolas P. Rougier.
* ========================================================================= */ * ========================================================================= */
#if defined(__APPLE__) #if defined(__APPLE__)
#include <Glut/glut.h> //#include <Glut/glut.h>
#else #else
#include <GL/glut.h>
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h>
#include <GL/glew.h>
#endif #endif
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "texture-font.h" #include "texture-font.h"
@ -84,6 +88,7 @@ texture_glyph_render( TextureGlyph *self,
{ {
assert( self ); assert( self );
{
int x = pen->x + self->offset_x; int x = pen->x + self->offset_x;
int y = pen->y + self->offset_y + markup->rise; int y = pen->y + self->offset_y + markup->rise;
int w = self->width; int w = self->width;
@ -108,6 +113,7 @@ texture_glyph_render( TextureGlyph *self,
pen->x += self->advance_x + markup->spacing; pen->x += self->advance_x + markup->spacing;
pen->y += self->advance_y; pen->y += self->advance_y;
}
} }
@ -150,6 +156,8 @@ texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
g = markup->background_color.g; g = markup->background_color.g;
b = markup->background_color.b; b = markup->background_color.b;
a = markup->background_color.a; a = markup->background_color.a;
{
GLuint index = buffer->vertices->size; GLuint index = buffer->vertices->size;
GLuint indices[] = {index, index+1, index+2, GLuint indices[] = {index, index+1, index+2,
index, index+2, index+3}; index, index+2, index+3};
@ -159,6 +167,7 @@ texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
{ x1,y0,0, u1,v0, 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_indices( buffer, indices, 6 );
vertex_buffer_push_back_vertices( buffer, vertices, 4 ); vertex_buffer_push_back_vertices( buffer, vertices, 4 );
}
} }
// Underline // Underline
@ -177,6 +186,8 @@ texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
b = markup->foreground_color.b; b = markup->foreground_color.b;
a = markup->foreground_color.a; a = markup->foreground_color.a;
} }
{
int x0 = (int)( pen->x + self->offset_x ); int x0 = (int)( pen->x + self->offset_x );
int y0 = (int)( pen->y + self->offset_y + rise ); int y0 = (int)( pen->y + self->offset_y + rise );
int x1 = (int)( x0 + self->width ); int x1 = (int)( x0 + self->width );
@ -197,6 +208,7 @@ texture_glyph_add_to_vertex_buffer( const TextureGlyph *self,
pen->x += self->advance_x + spacing; pen->x += self->advance_x + spacing;
pen->y += self->advance_y; pen->y += self->advance_y;
}
} }

View File

@ -44,6 +44,7 @@ vector_new( size_t item_size )
{ {
assert( item_size ); assert( item_size );
{
Vector *self = (Vector *) malloc( sizeof(Vector) ); Vector *self = (Vector *) malloc( sizeof(Vector) );
if( !self ) if( !self )
{ {
@ -54,6 +55,7 @@ vector_new( size_t item_size )
self->capacity = 1; self->capacity = 1;
self->items = malloc( self->item_size * self->capacity ); self->items = malloc( self->item_size * self->capacity );
return self; return self;
}
} }
@ -77,7 +79,8 @@ vector_get( const Vector *self,
assert( self ); assert( self );
assert( self->size ); assert( self->size );
assert( index < self->size ); assert( index < self->size );
return self->items + index * self->item_size;
return (char *)self->items + index * self->item_size;
} }
@ -202,7 +205,7 @@ vector_set( Vector *self,
assert( self ); assert( self );
assert( self->size ); assert( self->size );
assert( index < self->size ); assert( index < self->size );
memcpy( self->items + index * self->item_size, memcpy( (char *)self->items + index * self->item_size,
item, self->item_size ); item, self->item_size );
} }
@ -223,8 +226,8 @@ vector_insert( Vector *self,
} }
if( index < self->size ) if( index < self->size )
{ {
memmove( self->items + (index + 1) * self->item_size, memmove( (char *)self->items + (index + 1) * self->item_size,
self->items + (index + 0) * self->item_size, (char *)self->items + (index + 0) * self->item_size,
(self->size - index) * self->item_size); (self->size - index) * self->item_size);
} }
self->size++; self->size++;
@ -243,8 +246,8 @@ vector_erase_range( Vector *self,
assert( first < self->size ); assert( first < self->size );
assert( last < self->size+1 ); assert( last < self->size+1 );
assert( first < last ); assert( first < last );
memmove( self->items + first * self->item_size, memmove( (char *)self->items + first * self->item_size,
self->items + last * self->item_size, (char *)self->items + last * self->item_size,
(self->size - last) * self->item_size); (self->size - last) * self->item_size);
self->size -= (last-first); self->size -= (last-first);
} }
@ -318,7 +321,7 @@ vector_push_back_data( Vector *self,
{ {
vector_reserve(self, self->size+count); vector_reserve(self, self->size+count);
} }
memmove( self->items + self->size * self->item_size, data, memmove( (char *)self->items + self->size * self->item_size, data,
count*self->item_size ); count*self->item_size );
self->size += count; self->size += count;
} }
@ -341,10 +344,10 @@ vector_insert_data( Vector *self,
{ {
vector_reserve(self, self->size+count); vector_reserve(self, self->size+count);
} }
memmove( self->items + (index + count ) * self->item_size, memmove( (char *)self->items + (index + count ) * self->item_size,
self->items + (index ) * self->item_size, (char *)self->items + (index ) * self->item_size,
count*self->item_size ); count*self->item_size );
memmove( self->items + index * self->item_size, data, memmove( (char *)self->items + index * self->item_size, data,
count*self->item_size ); count*self->item_size );
self->size += count; self->size += count;
} }

View File

@ -63,6 +63,7 @@ vertex_buffer_new( const char *format )
do do
{ {
end = (char *) (strchr(start+1, ':')); end = (char *) (strchr(start+1, ':'));
{
char *desc = 0; char *desc = 0;
if (end == NULL) if (end == NULL)
{ {
@ -72,14 +73,18 @@ vertex_buffer_new( const char *format )
{ {
desc = strndup(start, end-start); desc = strndup(start, end-start);
} }
{
VertexAttribute *attribute = vertex_attribute_parse( desc ); VertexAttribute *attribute = vertex_attribute_parse( desc );
start = end+1; start = end+1;
free(desc); free(desc);
attribute->pointer = pointer; attribute->pointer = pointer;
stride += attribute->size*GL_TYPE_SIZE( attribute->type ); stride += attribute->size*GL_TYPE_SIZE( attribute->type );
pointer+= attribute->size*GL_TYPE_SIZE( attribute->type ); pointer = (char *)pointer + attribute->size*GL_TYPE_SIZE( attribute->type );
self->attributes[index] = attribute; self->attributes[index] = attribute;
index++; index++;
}
}
} while ( end && (index < MAX_VERTEX_ATTRIBUTE) ); } while ( end && (index < MAX_VERTEX_ATTRIBUTE) );
for( i=0; i<index; ++i ) for( i=0; i<index; ++i )
@ -156,6 +161,7 @@ vertex_buffer_print( VertexBuffer * self )
{ {
assert(self); assert(self);
{
int i = 0; int i = 0;
fprintf( stderr, "%ld vertices, %ld indices\n", fprintf( stderr, "%ld vertices, %ld indices\n",
@ -205,6 +211,7 @@ vertex_buffer_print( VertexBuffer * self )
i += 1; i += 1;
} }
}
} }
@ -269,6 +276,7 @@ vertex_buffer_render ( VertexBuffer *self,
glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT ); glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
glBindBuffer( GL_ARRAY_BUFFER, self->vertices_id ); glBindBuffer( GL_ARRAY_BUFFER, self->vertices_id );
{
size_t i; size_t i;
for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i ) for( i=0; i<MAX_VERTEX_ATTRIBUTE; ++i )
{ {
@ -303,6 +311,7 @@ vertex_buffer_render ( VertexBuffer *self,
glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
glPopClientAttrib( ); glPopClientAttrib( );
}
} }
@ -499,16 +508,22 @@ vertex_attribute_parse( char *format )
int size, index; int size, index;
char ctype; char ctype;
sscanf( format, "%dgn%d%c", &index, &size, &ctype ); sscanf( format, "%dgn%d%c", &index, &size, &ctype );
{
GLenum type = GL_TYPE( ctype ); GLenum type = GL_TYPE( ctype );
return vertex_attribute_new( 0, index, size, type, GL_TRUE, 0, 0 ); return vertex_attribute_new( 0, index, size, type, GL_TRUE, 0, 0 );
}
} }
else else
{ {
int size, index; int size, index;
char ctype; char ctype;
sscanf( format, "%dg%d%c", &index, &size, &ctype ); sscanf( format, "%dg%d%c", &index, &size, &ctype );
{
GLenum type = GL_TYPE( ctype ); GLenum type = GL_TYPE( ctype );
return vertex_attribute_new( 0, index, size, type, GL_FALSE, 0, 0 ); return vertex_attribute_new( 0, index, size, type, GL_FALSE, 0, 0 );
}
} }
} }
@ -519,9 +534,12 @@ vertex_attribute_parse( char *format )
int size; int size;
char ctarget, ctype; char ctarget, ctype;
sscanf( format, "%c%d%c", &ctarget, &size, &ctype ); sscanf( format, "%c%d%c", &ctarget, &size, &ctype );
{
GLenum type = GL_TYPE( ctype ); GLenum type = GL_TYPE( ctype );
GLenum target = GL_VERTEX_ATTRIBUTE_TARGET( ctarget ); GLenum target = GL_VERTEX_ATTRIBUTE_TARGET( ctarget );
return vertex_attribute_new( target, 0, size, type, GL_FALSE, 0, 0 ); return vertex_attribute_new( target, 0, size, type, GL_FALSE, 0, 0 );
}
} }
fprintf(stderr, "Vertex attribute format not understood\n"); fprintf(stderr, "Vertex attribute format not understood\n");

View File

@ -12,7 +12,7 @@
#ifdef USE_FREETYPEGL #ifdef USE_FREETYPEGL
#include "font_text_freetypegl.h" #include "font_text_freetypegl.h"
#include "vector.h" #include "vectort.h"
//#include "opengl.h" //#include "opengl.h"
#include <stdexcept> #include <stdexcept>
@ -22,10 +22,12 @@
#include <fontconfig/fontconfig.h> #include <fontconfig/fontconfig.h>
#endif #endif
#include "platform_common.h"
#include "util.h" #include "util.h"
using namespace std; using namespace std;
using namespace Shared::Util; using namespace Shared::Util;
using namespace Shared::PlatformCommon;
namespace Shared { namespace Graphics { namespace Gl { namespace Shared { namespace Graphics { namespace Gl {
@ -67,7 +69,7 @@ void TextFreetypeGL::init(string fontName, int fontSize) {
this->buffer = vertex_buffer_new( "v3f:t2f:c4f" ); this->buffer = vertex_buffer_new( "v3f:t2f:c4f" );
//font = texture_font_new( atlas, "Verdana", minsize ); //font = texture_font_new( atlas, "Verdana", minsize );
this->font = texture_font_new( atlas, fontFile, fontFaceSize ); this->font = texture_font_new( atlas, fontFile, (float)fontFaceSize );
//font = texture_font_new( atlas, font_manager_match_description( 0, "Verdana", minsize, bold, italic ), minsize ); //font = texture_font_new( atlas, font_manager_match_description( 0, "Verdana", minsize, bold, italic ), minsize );
int missed = texture_font_cache_glyphs( font, cache ); int missed = texture_font_cache_glyphs( font, cache );
@ -95,10 +97,10 @@ void TextFreetypeGL::Render(const char* str, const int len) {
vertex_buffer_clear( this->buffer ); vertex_buffer_clear( this->buffer );
float currentColor[4]; float currentColor[4] = { 0,0,0,1 };
glGetFloatv(GL_CURRENT_COLOR,currentColor); glGetFloatv(GL_CURRENT_COLOR,currentColor);
Markup markup = { 0, this->fontFaceSize, 0, 0, 0.0, 0.0, Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0,
{currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {0,0,0,0}, {currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {0,0,0,0},
0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1},
0, {0,0,0,1}, 0, {0,0,0,1}, 0 }; 0, {0,0,0,1}, 0, {0,0,0,1}, 0 };
@ -118,10 +120,10 @@ void TextFreetypeGL::Render(const char* str, const int len) {
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar ); TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
// Take kerning into account if necessary // Take kerning into account if necessary
int kx = texture_glyph_get_kerning( glyph, prevChar ); float kx = texture_glyph_get_kerning( glyph, prevChar );
// Add glyph to the vertex buffer // Add glyph to the vertex buffer
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, kx ); texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx );
} }
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid ); //glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
@ -130,6 +132,7 @@ void TextFreetypeGL::Render(const char* str, const int len) {
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable( GL_TEXTURE_2D ); glEnable( GL_TEXTURE_2D );
vertex_buffer_render( this->buffer, GL_TRIANGLES, "vtc" ); vertex_buffer_render( this->buffer, GL_TRIANGLES, "vtc" );
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );
@ -149,10 +152,10 @@ void TextFreetypeGL::Render(const wchar_t* str, const int len) {
vertex_buffer_clear( this->buffer ); vertex_buffer_clear( this->buffer );
float currentColor[4]; GLfloat currentColor[4] = { 0,0,0,1 };
glGetFloatv(GL_CURRENT_COLOR,currentColor); glGetFloatv(GL_CURRENT_COLOR,currentColor);
Markup markup = { 0, this->fontFaceSize, 0, 0, 0.0, 0.0, Markup markup = { 0, (float)this->fontFaceSize, 0, 0, 0.0, 0.0,
{currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {0,0,0,0}, {currentColor[0],currentColor[1],currentColor[2],currentColor[3]}, {0,0,0,0},
0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1}, 0, {0,0,0,1},
0, {0,0,0,1}, 0, {0,0,0,1}, 0 }; 0, {0,0,0,1}, 0, {0,0,0,1}, 0 };
@ -163,10 +166,10 @@ void TextFreetypeGL::Render(const wchar_t* str, const int len) {
TextureGlyph *glyph = texture_font_get_glyph( this->font, text[i] ); TextureGlyph *glyph = texture_font_get_glyph( this->font, text[i] );
// Take kerning into account if necessary // Take kerning into account if necessary
int kx = texture_glyph_get_kerning( glyph, text[i-1] ); float kx = texture_glyph_get_kerning( glyph, text[i-1] );
// Add glyph to the vertex buffer // Add glyph to the vertex buffer
texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, kx ); texture_glyph_add_to_vertex_buffer( glyph, this->buffer, &markup, &pen, (int)kx );
} }
//glBindTexture( GL_TEXTURE_2D, manager->atlas->texid ); //glBindTexture( GL_TEXTURE_2D, manager->atlas->texid );
@ -202,7 +205,7 @@ float TextFreetypeGL::LineHeight(const char* str, const int len) {
float result = 0; float result = 0;
if(strlen(str) > 0) { if(strlen(str) > 0) {
TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
result = glyph->height; result = (float)glyph->height;
} }
return result; return result;
} }
@ -211,7 +214,7 @@ float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) {
float result = 0; float result = 0;
if(wcslen(str) > 0) { if(wcslen(str) > 0) {
TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
result = glyph->height; result = (float)glyph->height;
} }
return result; return result;
} }