fixed new font rendering on Linux and removed glew dependency

This commit is contained in:
Mark Vejvoda
2011-11-18 00:28:45 +00:00
parent ab9243ea38
commit 0e9b4851fd
9 changed files with 167 additions and 84 deletions

View File

@@ -191,8 +191,21 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
OPTION(USE_FREETYPEGL "Use Freetype-GL for on-screen fonts" ON) OPTION(USE_FREETYPEGL "Use Freetype-GL for on-screen fonts" ON)
if(USE_FREETYPEGL) if(USE_FREETYPEGL)
ADD_DEFINITIONS(-DUSE_FREETYPEGL) ADD_DEFINITIONS(-DUSE_FREETYPEGL)
FIND_PACKAGE(Freetype REQUIRED)
INCLUDE_DIRECTORIES(${FREETYPE_INCLUDE_PATH})
IF(UNIX)
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${FREETYPE_LIBRARY})
ENDIF()
endif(USE_FREETYPEGL) endif(USE_FREETYPEGL)
#FIND_PACKAGE(GLEW REQUIRED)
#INCLUDE_DIRECTORIES(${GLEW_INCLUDE_PATH})
#IF(UNIX)
# SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${GLEW_LIBRARY})
#ENDIF()
######################################################################################### #########################################################################################
# megaglest lib # megaglest lib

View File

@@ -33,21 +33,23 @@
#ifndef __VERTEX_BUFFER_H__ #ifndef __VERTEX_BUFFER_H__
#define __VERTEX_BUFFER_H__ #define __VERTEX_BUFFER_H__
#if defined(__APPLE__) #if defined(_WIN32)
//#include <Glut/glut.h>
#elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <GL/glew.h> #include <GL/glew.h>
#else #else
//#include <GL/glut.h> #include <GL/glu.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.
*/ */
@@ -471,4 +473,9 @@ vertex_attribute_new( GLenum target,
GL_TYPE_STRING( GLenum gtype ); GL_TYPE_STRING( GLenum gtype );
#ifdef __cplusplus
}
#endif
#endif /* __VERTEX_BUFFER_H__ */ #endif /* __VERTEX_BUFFER_H__ */

View File

@@ -30,11 +30,24 @@
* 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.
* ========================================================================= */ * ========================================================================= */
/*
#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
#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 <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <wchar.h> #include <wchar.h>
@@ -149,38 +162,38 @@ int main( int argc, char **argv )
// Header // Header
// ------------- // -------------
fwprintf( file, fwprintf( file,
L"/* =========================================================================\n" L"// =========================================================================\n"
L" * Freetype GL - A C OpenGL Freetype engine\n" L"// Freetype GL - A C OpenGL Freetype engine\n"
L" * Platform: Any\n" L"// Platform: Any\n"
L" * WWW: http://code.google.com/p/freetype-gl/\n" L"// WWW: http://code.google.com/p/freetype-gl/\n"
L" * -------------------------------------------------------------------------\n" L"// -------------------------------------------------------------------------\n"
L" * Copyright 2011 Nicolas P. Rougier. All rights reserved.\n" L"// Copyright 2011 Nicolas P. Rougier. All rights reserved.\n"
L" *\n" L"//\n"
L" * Redistribution and use in source and binary forms, with or without\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"// modification, are permitted provided that the following conditions are met:\n"
L" *\n" L"//\n"
L" * 1. Redistributions of source code must retain the above copyright notice,\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"// this list of conditions and the following disclaimer.\n"
L" *\n" L"//\n"
L" * 2. Redistributions in binary form must reproduce the above copyright\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"// notice, this list of conditions and the following disclaimer in the\n"
L" * documentation and/or other materials provided with the distribution.\n" L"// documentation and/or other materials provided with the distribution.\n"
L" *\n" L"//\n"
L" * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR\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"// 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"// 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"// EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n"
L" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" L"// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"
L" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\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"// 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"// 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"// (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"// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
L" *\n" L"//\n"
L" * The views and conclusions contained in the software and documentation are\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"// 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"// policies, either expressed or implied, of Nicolas P. Rougier.\n"
L" * ========================================================================= */\n" ); L"// ========================================================================= \n" );
@@ -269,38 +282,36 @@ int main( int argc, char **argv )
{ {
TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i ); TextureGlyph *glyph = (TextureGlyph *) vector_get( font->glyphs, i );
/* // // Debugging information
// Debugging information // wprintf( L"glyph : '%lc'\n",
wprintf( L"glyph : '%lc'\n", // glyph->charcode );
glyph->charcode ); // wprintf( L" size : %dx%d\n",
wprintf( L" size : %dx%d\n", // glyph->width, glyph->height );
glyph->width, glyph->height ); // wprintf( L" offset : %+d%+d\n",
wprintf( L" offset : %+d%+d\n", // glyph->offset_x, glyph->offset_y );
glyph->offset_x, glyph->offset_y ); // wprintf( L" advance : %f, %f\n",
wprintf( L" advance : %f, %f\n", // glyph->advance_x, glyph->advance_y );
glyph->advance_x, glyph->advance_y ); // wprintf( L" tex coords.: %f, %f, %f, %f\n",
wprintf( L" tex coords.: %f, %f, %f, %f\n", // glyph->u0, glyph->v0, glyph->u1, glyph->v1 );
glyph->u0, glyph->v0, glyph->u1, glyph->v1 ); //
// wprintf( L" kerning : " );
wprintf( L" kerning : " ); // if( glyph->kerning_count )
if( glyph->kerning_count ) // {
{ // for( j=0; j < glyph->kerning_count; ++j )
for( j=0; j < glyph->kerning_count; ++j ) // {
{ // wprintf( L"('%lc', %f)",
wprintf( L"('%lc', %f)", // glyph->kerning[j].charcode, glyph->kerning[j].kerning );
glyph->kerning[j].charcode, glyph->kerning[j].kerning ); // if( j < (glyph->kerning_count-1) )
if( j < (glyph->kerning_count-1) ) // {
{ // wprintf( L", " );
wprintf( L", " ); // }
} // }
} // }
} // else
else // {
{ // wprintf( L"None" );
wprintf( L"None" ); // }
} // wprintf( L"\n\n" );
wprintf( L"\n\n" );
*/
// TextureFont // TextureFont
if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) ) if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) )
@@ -347,3 +358,4 @@ int main( int argc, char **argv )
return 0; return 0;
} }
*/

View File

@@ -39,8 +39,9 @@
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
#endif #endif
#include <GL/gl.h>
//#include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
//#include <glprocs.h> //#include <glprocs.h>

View File

@@ -244,11 +244,12 @@ 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 ((FREETYPE_MAJOR <= 2) && ((FREETYPE_MINOR < 3)))
//#error "Need FreeType 2.3.0 or newer"
#else
if( self->lcd_filter ) if( self->lcd_filter )
{ {
FT_Library_SetLcdFilterWeights( library, self->lcd_weights ); FT_Library_SetLcdFilterWeights( library, self->lcd_weights );
@@ -360,10 +361,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); //free(buffer);
return (TextureGlyph *) vector_back( self->glyphs ); return (TextureGlyph *) vector_back( self->glyphs );
} }
free(buffer); //free(buffer);
return NULL; return NULL;
} }

View File

@@ -30,13 +30,14 @@
* 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.
* ========================================================================= */ * ========================================================================= */
#if defined(__APPLE__) #if defined(_WIN32)
//#include <Glut/glut.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <GL/glew.h>
#else #else
#include <GL/glu.h>
//#define WIN32_LEAN_AND_MEAN
//#include <windows.h>
#include <GL/glew.h>
#endif #endif
#include <assert.h> #include <assert.h>

View File

@@ -80,7 +80,11 @@ vector_get( const Vector *self,
assert( self->size ); assert( self->size );
assert( index < self->size ); assert( index < self->size );
#ifdef _WIN32
return (char *)self->items + index * self->item_size; return (char *)self->items + index * self->item_size;
#else
return self->items + index * self->item_size;
#endif
} }
@@ -205,8 +209,15 @@ vector_set( Vector *self,
assert( self ); assert( self );
assert( self->size ); assert( self->size );
assert( index < self->size ); assert( index < self->size );
#ifdef _WIN32
memcpy( (char *)self->items + index * self->item_size, memcpy( (char *)self->items + index * self->item_size,
item, self->item_size ); item, self->item_size );
#else
memcpy( self->items + index * self->item_size,
item, self->item_size );
#endif
} }
@@ -226,9 +237,16 @@ vector_insert( Vector *self,
} }
if( index < self->size ) if( index < self->size )
{ {
#ifdef _WIN32
memmove( (char *)self->items + (index + 1) * self->item_size, memmove( (char *)self->items + (index + 1) * self->item_size,
(char *)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);
#else
memmove( self->items + (index + 1) * self->item_size,
self->items + (index + 0) * self->item_size,
(self->size - index) * self->item_size);
#endif
} }
self->size++; self->size++;
vector_set( self, index, item ); vector_set( self, index, item );
@@ -246,9 +264,16 @@ 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 );
#ifdef _WIN32
memmove( (char *)self->items + first * self->item_size, memmove( (char *)self->items + first * self->item_size,
(char *)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);
#else
memmove( self->items + first * self->item_size,
self->items + last * self->item_size,
(self->size - last) * self->item_size);
#endif
self->size -= (last-first); self->size -= (last-first);
} }
@@ -321,8 +346,15 @@ vector_push_back_data( Vector *self,
{ {
vector_reserve(self, self->size+count); vector_reserve(self, self->size+count);
} }
#ifdef _WIN32
memmove( (char *)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 );
#else
memmove( self->items + self->size * self->item_size, data,
count*self->item_size );
#endif
self->size += count; self->size += count;
} }
@@ -344,11 +376,22 @@ vector_insert_data( Vector *self,
{ {
vector_reserve(self, self->size+count); vector_reserve(self, self->size+count);
} }
#ifdef _WIN32
memmove( (char *)self->items + (index + count ) * self->item_size, memmove( (char *)self->items + (index + count ) * self->item_size,
(char *)self->items + (index ) * self->item_size, (char *)self->items + (index ) * self->item_size,
count*self->item_size ); count*self->item_size );
memmove( (char *)self->items + index * self->item_size, data, memmove( (char *)self->items + index * self->item_size, data,
count*self->item_size ); count*self->item_size );
#else
memmove( self->items + (index + count ) * self->item_size,
self->items + (index ) * self->item_size,
count*self->item_size );
memmove( self->items + index * self->item_size, data,
count*self->item_size );
#endif
self->size += count; self->size += count;
} }

View File

@@ -80,7 +80,12 @@ vertex_buffer_new( const char *format )
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 );
#ifdef _WIN32
pointer = (char *)pointer + attribute->size*GL_TYPE_SIZE( attribute->type ); pointer = (char *)pointer + attribute->size*GL_TYPE_SIZE( attribute->type );
#else
pointer += attribute->size*GL_TYPE_SIZE( attribute->type );
#endif
self->attributes[index] = attribute; self->attributes[index] = attribute;
index++; index++;
} }

View File

@@ -12,7 +12,7 @@
#ifdef USE_FREETYPEGL #ifdef USE_FREETYPEGL
#include "font_text_freetypegl.h" #include "font_text_freetypegl.h"
#include "vectort.h" #include "vector.h"
//#include "opengl.h" //#include "opengl.h"
#include <stdexcept> #include <stdexcept>