mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 13:23:59 +02:00
- added GeoVah's initila Mac osX support (via cmake)
This commit is contained in:
54
source/shared_lib/sources/platform/macosx/NSFont_OpenGL.h
Normal file
54
source/shared_lib/sources/platform/macosx/NSFont_OpenGL.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Addition to NSFont to allow easy OpenGL display list creation of bitmaps
|
||||
* based on the receiver's font. Example usage:
|
||||
*
|
||||
* [ myFont makeGLDisplayListFirst:' ' count:95 base:displayListBase ];
|
||||
*
|
||||
* This creates a set of display lists, starting at displayListBase, with 95
|
||||
* characters starting with the space. Returns TRUE if all went well,
|
||||
* FALSE otherwise.
|
||||
*
|
||||
* By default, if any errors are encountered, NSLog() will be used to note
|
||||
* what happened; use
|
||||
*
|
||||
* [ NSFont setOpenGLLogging:NO ];
|
||||
*
|
||||
* to disable logging.
|
||||
*
|
||||
* This program is Copyright <20> 2002 Bryan L Blackburn. 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.
|
||||
* 3. Neither the names Bryan L Blackburn, Withay.com, nor the names of any
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BRYAN L BLACKBURN ``AS IS'' AND ANY EXPRESSED 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 THE AUTHOR 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.
|
||||
*/
|
||||
|
||||
/* NSFont_OpenGL.h */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <OpenGL/gl.h>
|
||||
|
||||
@interface NSFont (withay_OpenGL)
|
||||
|
||||
+ (void) setOpenGLLogging:(BOOL)logEnabled;
|
||||
- (BOOL) makeGLDisplayListFirst:(unichar)first count:(int)count base:(GLint)base;
|
||||
|
||||
@end
|
211
source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m
Normal file
211
source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m
Normal file
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* This program is Copyright <EFBFBD> 2002 Bryan L Blackburn. 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.
|
||||
* 3. Neither the names Bryan L Blackburn, Withay.com, nor the names of any
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BRYAN L BLACKBURN ``AS IS'' AND ANY EXPRESSED 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 THE AUTHOR 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.
|
||||
*
|
||||
* Initial version, 27 October, 2002
|
||||
*/
|
||||
|
||||
/* NSFont_OpenGL.m */
|
||||
|
||||
#import "NSFont_OpenGL.h"
|
||||
|
||||
@interface NSFont (withay_OpenGL_InternalMethods)
|
||||
- (BOOL) makeDisplayList:(GLint)listNum withImage:(NSImage *)theImage;
|
||||
+ (void) doOpenGLLog:(NSString *)format, ...;
|
||||
@end
|
||||
|
||||
@implementation NSFont (withay_OpenGL)
|
||||
|
||||
static BOOL openGLLoggingEnabled = YES;
|
||||
|
||||
/*
|
||||
* Enable/disable logging, class-wide, not object-wide
|
||||
*/
|
||||
+ (void) setOpenGLLogging:(BOOL)logEnabled
|
||||
{
|
||||
openGLLoggingEnabled = logEnabled;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create the set of display lists for the bitmaps
|
||||
*/
|
||||
- (BOOL) makeGLDisplayListFirst:(unichar)first count:(int)count base:(GLint)base
|
||||
{
|
||||
GLint curListIndex;
|
||||
NSColor *blackColor;
|
||||
NSDictionary *attribDict;
|
||||
GLint dListNum;
|
||||
NSString *currentChar;
|
||||
unichar currentUnichar;
|
||||
NSSize charSize;
|
||||
NSRect charRect;
|
||||
NSImage *theImage;
|
||||
BOOL retval;
|
||||
|
||||
// Make sure a list isn't already under construction
|
||||
glGetIntegerv( GL_LIST_INDEX, &curListIndex );
|
||||
if( curListIndex != 0 )
|
||||
{
|
||||
[ NSFont doOpenGLLog:@"Display list already under construction" ];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Save pixel unpacking state
|
||||
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
|
||||
|
||||
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
|
||||
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
|
||||
glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
||||
glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
||||
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
|
||||
blackColor = [ NSColor blackColor ];
|
||||
attribDict = [ NSDictionary dictionaryWithObjectsAndKeys:
|
||||
self, NSFontAttributeName,
|
||||
[ NSColor whiteColor ],
|
||||
NSForegroundColorAttributeName,
|
||||
blackColor, NSBackgroundColorAttributeName,
|
||||
nil ];
|
||||
charRect.origin.x = charRect.origin.y = 0;
|
||||
theImage = [ [ [ NSImage alloc ] initWithSize:NSMakeSize( 0, 0 ) ]
|
||||
autorelease ];
|
||||
retval = TRUE;
|
||||
for( dListNum = base, currentUnichar = first; currentUnichar < first + count;
|
||||
dListNum++, currentUnichar++ )
|
||||
{
|
||||
currentChar = [ NSString stringWithCharacters:¤tUnichar length:1 ];
|
||||
charSize = [ currentChar sizeWithAttributes:attribDict ];
|
||||
charRect.size = charSize;
|
||||
charRect = NSIntegralRect( charRect );
|
||||
if( charRect.size.width > 0 && charRect.size.height > 0 )
|
||||
{
|
||||
[ theImage setSize:charRect.size ];
|
||||
[ theImage lockFocus ];
|
||||
[ [ NSGraphicsContext currentContext ] setShouldAntialias:NO ];
|
||||
[ blackColor set ];
|
||||
[ NSBezierPath fillRect:charRect ];
|
||||
[ currentChar drawInRect:charRect withAttributes:attribDict ];
|
||||
[ theImage unlockFocus ];
|
||||
if( ![ self makeDisplayList:dListNum withImage:theImage ] )
|
||||
{
|
||||
retval = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glPopClientAttrib();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create one display list based on the given image. This assumes the image
|
||||
* uses 8-bit chunks to represent a sample
|
||||
*/
|
||||
- (BOOL) makeDisplayList:(GLint)listNum withImage:(NSImage *)theImage
|
||||
{
|
||||
NSBitmapImageRep *bitmap;
|
||||
int bytesPerRow, pixelsHigh, pixelsWide, samplesPerPixel;
|
||||
unsigned char *bitmapBytes;
|
||||
int currentBit, byteValue;
|
||||
unsigned char *newBuffer, *movingBuffer;
|
||||
int rowIndex, colIndex;
|
||||
|
||||
bitmap = [ NSBitmapImageRep imageRepWithData:[ theImage
|
||||
TIFFRepresentationUsingCompression:NSTIFFCompressionNone
|
||||
factor:0 ] ];
|
||||
pixelsHigh = [ bitmap pixelsHigh ];
|
||||
pixelsWide = [ bitmap pixelsWide ];
|
||||
bitmapBytes = [ bitmap bitmapData ];
|
||||
bytesPerRow = [ bitmap bytesPerRow ];
|
||||
samplesPerPixel = [ bitmap samplesPerPixel ];
|
||||
newBuffer = calloc( ceil( (float) bytesPerRow / 8.0 ), pixelsHigh );
|
||||
if( newBuffer == NULL )
|
||||
{
|
||||
[ NSFont doOpenGLLog:@"Failed to calloc() memory in "
|
||||
@"makeDisplayList:withImage:" ];
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
movingBuffer = newBuffer;
|
||||
/*
|
||||
* Convert the color bitmap into a true bitmap, ie, one bit per pixel. We
|
||||
* read at last row, write to first row as Cocoa and OpenGL have opposite
|
||||
* y origins
|
||||
*/
|
||||
for( rowIndex = pixelsHigh - 1; rowIndex >= 0; rowIndex-- )
|
||||
{
|
||||
currentBit = 0x80;
|
||||
byteValue = 0;
|
||||
for( colIndex = 0; colIndex < pixelsWide; colIndex++ )
|
||||
{
|
||||
if( bitmapBytes[ rowIndex * bytesPerRow + colIndex * samplesPerPixel ] )
|
||||
byteValue |= currentBit;
|
||||
currentBit >>= 1;
|
||||
if( currentBit == 0 )
|
||||
{
|
||||
*movingBuffer++ = byteValue;
|
||||
currentBit = 0x80;
|
||||
byteValue = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Fill out the last byte; extra is ignored by OpenGL, but each row
|
||||
* must start on a new byte
|
||||
*/
|
||||
if( currentBit != 0x80 )
|
||||
*movingBuffer++ = byteValue;
|
||||
}
|
||||
|
||||
glNewList( listNum, GL_COMPILE );
|
||||
glBitmap( pixelsWide, pixelsHigh, 0, 0, pixelsWide, 0, newBuffer );
|
||||
glEndList();
|
||||
free( newBuffer );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Log the warning/error, if logging is enabled
|
||||
*/
|
||||
+ (void) doOpenGLLog:(NSString *)format, ...
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if( openGLLoggingEnabled )
|
||||
{
|
||||
va_start( args, format );
|
||||
NSLogv( [ NSString stringWithFormat:@"NSFont_OpenGL: %@\n", format ],
|
||||
args );
|
||||
va_end( args );
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
206
source/shared_lib/sources/platform/macosx/gl_wrap.mm
Normal file
206
source/shared_lib/sources/platform/macosx/gl_wrap.mm
Normal file
@@ -0,0 +1,206 @@
|
||||
//This file is part of Glest Shared Library (www.glest.org)
|
||||
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
|
||||
//You can redistribute this code and/or modify it under
|
||||
//the terms of the GNU General Public License as published by the Free Software
|
||||
//Foundation; either version 2 of the License, or (at your option) any later
|
||||
//version.
|
||||
#include "gl_wrap.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "sdl_private.h"
|
||||
#include "noimpl.h"
|
||||
#include "util.h"
|
||||
#include "window.h"
|
||||
#include <vector>
|
||||
//#include <SDL_image.h>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Graphics::Gl;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
// ======================================
|
||||
// Global Fcs
|
||||
// ======================================
|
||||
|
||||
BOOL makeDisplayList(GLint listNum, NSImage *theImage)
|
||||
{
|
||||
NSBitmapImageRep *bitmap;
|
||||
int bytesPerRow, pixelsHigh, pixelsWide, samplesPerPixel;
|
||||
unsigned char *bitmapBytes;
|
||||
int currentBit, byteValue;
|
||||
unsigned char *newBuffer, *movingBuffer;
|
||||
int rowIndex, colIndex;
|
||||
|
||||
bitmap = [ NSBitmapImageRep imageRepWithData:[ theImage
|
||||
TIFFRepresentationUsingCompression:NSTIFFCompressionNone
|
||||
factor:0 ] ];
|
||||
pixelsHigh = [ bitmap pixelsHigh ];
|
||||
pixelsWide = [ bitmap pixelsWide ];
|
||||
bitmapBytes = [ bitmap bitmapData ];
|
||||
bytesPerRow = [ bitmap bytesPerRow ];
|
||||
samplesPerPixel = [ bitmap samplesPerPixel ];
|
||||
newBuffer = (unsigned char *)calloc( ceil( (float) bytesPerRow / 8.0 ), pixelsHigh );
|
||||
if( newBuffer == NULL )
|
||||
{
|
||||
NSLog(@"Failed to calloc() memory in makeDisplayList()");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
movingBuffer = newBuffer;
|
||||
/*
|
||||
* Convert the color bitmap into a true bitmap, ie, one bit per pixel. We
|
||||
* read at last row, write to first row as Cocoa and OpenGL have opposite
|
||||
* y origins
|
||||
*/
|
||||
for( rowIndex = pixelsHigh - 1; rowIndex >= 0; rowIndex-- )
|
||||
{
|
||||
currentBit = 0x80;
|
||||
byteValue = 0;
|
||||
for( colIndex = 0; colIndex < pixelsWide; colIndex++ )
|
||||
{
|
||||
if( bitmapBytes[ rowIndex * bytesPerRow + colIndex * samplesPerPixel ] )
|
||||
byteValue |= currentBit;
|
||||
currentBit >>= 1;
|
||||
if( currentBit == 0 )
|
||||
{
|
||||
*movingBuffer++ = byteValue;
|
||||
currentBit = 0x80;
|
||||
byteValue = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Fill out the last byte; extra is ignored by OpenGL, but each row
|
||||
* must start on a new byte
|
||||
*/
|
||||
if( currentBit != 0x80 )
|
||||
*movingBuffer++ = byteValue;
|
||||
}
|
||||
|
||||
glNewList( listNum, GL_COMPILE );
|
||||
glBitmap( pixelsWide, pixelsHigh, 0, 0, pixelsWide, 0, newBuffer );
|
||||
glEndList();
|
||||
free( newBuffer );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the set of display lists for the bitmaps
|
||||
*/
|
||||
BOOL makeGLDisplayListFirst(unichar first, int count, GLint base, NSFont *font, Shared::Graphics::FontMetrics &metrics)
|
||||
{
|
||||
GLint curListIndex;
|
||||
NSColor *blackColor = [NSColor blackColor];
|
||||
GLint dListNum;
|
||||
NSString *currentChar;
|
||||
unichar currentUnichar;
|
||||
NSSize charSize;
|
||||
NSRect charRect;
|
||||
NSImage *theImage;
|
||||
BOOL retval;
|
||||
|
||||
// float ascent = [font ascender];
|
||||
// float descent = [font descender];
|
||||
|
||||
NSDictionary *attribDict = [ NSDictionary dictionaryWithObjectsAndKeys:
|
||||
font, NSFontAttributeName,
|
||||
[NSColor whiteColor],
|
||||
NSForegroundColorAttributeName,
|
||||
[NSColor blackColor], NSBackgroundColorAttributeName,
|
||||
nil ];
|
||||
|
||||
// Make sure a list isn't already under construction
|
||||
glGetIntegerv( GL_LIST_INDEX, &curListIndex );
|
||||
if( curListIndex != 0 )
|
||||
{
|
||||
NSLog(@"Display list already under construction");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Save pixel unpacking state
|
||||
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
|
||||
|
||||
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
|
||||
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
|
||||
glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
|
||||
glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
|
||||
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
|
||||
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
|
||||
|
||||
charRect.origin.x = charRect.origin.y = 0;
|
||||
theImage = [ [ [ NSImage alloc ] initWithSize:NSMakeSize( 0, 0 ) ]
|
||||
autorelease ];
|
||||
retval = TRUE;
|
||||
float fontHeight = metrics.getHeight();
|
||||
float dy;
|
||||
|
||||
for( dListNum = base, currentUnichar = first; currentUnichar < first + count;
|
||||
dListNum++, currentUnichar++ )
|
||||
{
|
||||
currentChar = [ NSString stringWithCharacters:¤tUnichar length:1 ];
|
||||
|
||||
charSize = [ currentChar sizeWithAttributes:attribDict ];
|
||||
charRect.size = charSize;
|
||||
charRect = NSIntegralRect( charRect );
|
||||
dy = charRect.size.height - fontHeight;
|
||||
metrics.setWidth(dListNum-base, charRect.size.width);
|
||||
//metrics.setVirticalOffset(dListNum-base, fontHeight - charRect.size.height);
|
||||
|
||||
if( charRect.size.width > 0 && charRect.size.height > 0 )
|
||||
{
|
||||
charRect.size.height = fontHeight;
|
||||
[ theImage setSize:charRect.size ];
|
||||
[ theImage lockFocus ];
|
||||
[ [ NSGraphicsContext currentContext ] setShouldAntialias:NO ];
|
||||
[ blackColor set ];
|
||||
[ NSBezierPath fillRect:charRect ];
|
||||
//[ currentChar drawInRect:charRect withAttributes:attribDict ];
|
||||
[ currentChar drawAtPoint:NSMakePoint(0, 0) withAttributes:attribDict ];
|
||||
|
||||
[ theImage unlockFocus ];
|
||||
if( !makeDisplayList(dListNum, theImage) )
|
||||
{
|
||||
retval = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
glPopClientAttrib();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void createGlFontBitmaps(GLuint &base, const string &type, int size, int width,
|
||||
int charCount, Shared::Graphics::FontMetrics &metrics) {
|
||||
|
||||
|
||||
//@FF@ keep the reduction ratio ???
|
||||
size = (float)size * 0.80;
|
||||
NSFont *font = [NSFont fontWithName:[NSString stringWithCString:"Arial" encoding:NSUTF8StringEncoding] size:size];
|
||||
if( font == nil )
|
||||
NSLog( @"font is nil\n" );
|
||||
|
||||
float fontHeight = [font ascender] - [font descender];
|
||||
|
||||
metrics.setHeight(fontHeight);
|
||||
|
||||
if( !makeGLDisplayListFirst('\0', charCount, base, font, metrics) )
|
||||
NSLog( @"Didn't make display list\n" );
|
||||
|
||||
}
|
||||
|
||||
void createGlFontOutlines(GLuint &base, const string &type, int width,
|
||||
float depth, int charCount, Shared::Graphics::FontMetrics &metrics) {
|
||||
NOIMPL;
|
||||
}
|
||||
}}//end namespace
|
@@ -12,10 +12,6 @@
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#ifdef X11_AVAILABLE
|
||||
#include <GL/glx.h>
|
||||
#endif
|
||||
|
||||
#include "opengl.h"
|
||||
#include "sdl_private.h"
|
||||
#include "noimpl.h"
|
||||
@@ -143,227 +139,16 @@ void PlatformContextGl::makeCurrent() {
|
||||
void PlatformContextGl::swapBuffers() {
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
// ======================================
|
||||
// Global Fcs
|
||||
// ======================================
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe,
|
||||
NEWTEXTMETRICEX *lpntme,
|
||||
int FontType,
|
||||
LPARAM lParam) {
|
||||
std::vector<std::string> *systemFontList = (std::vector<std::string> *)lParam;
|
||||
systemFontList->push_back((char *)lpelfe->elfFullName);
|
||||
return 1; // I want to get all fonts
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
|
||||
int charCount, FontMetrics &metrics) {
|
||||
// -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 this is a Chinese font
|
||||
|
||||
#ifdef X11_AVAILABLE
|
||||
Display* display = glXGetCurrentDisplay();
|
||||
if(display == 0) {
|
||||
throw std::runtime_error("Couldn't create font: display is 0");
|
||||
}
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load font %s\n",__FILE__,__FUNCTION__,__LINE__,type.c_str());
|
||||
|
||||
XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str());
|
||||
if(!fontInfo) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] CANNOT load font %s, falling back to default\n",__FILE__,__FUNCTION__,__LINE__,type.c_str());
|
||||
fontInfo = XLoadQueryFont(display, "fixed");
|
||||
if(!fontInfo) {
|
||||
throw std::runtime_error("Font not found: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
// we need the height of 'a' which sould ~ be half ascent+descent
|
||||
float height = (static_cast<float>(fontInfo->ascent + fontInfo->descent) / 2);
|
||||
if(height <= 0) {
|
||||
height = static_cast<float>(6);
|
||||
}
|
||||
metrics.setHeight(height);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] height = %f\n",__FILE__,__FUNCTION__,__LINE__,height);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
for(unsigned int i = 0; i < static_cast<unsigned int> (charCount); ++i) {
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
if(i < fontInfo->min_char_or_byte2 || i > fontInfo->max_char_or_byte2) {
|
||||
|
||||
float width = static_cast<float>(6);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] setting size = %f\n",__FILE__,__FUNCTION__,__LINE__,width);
|
||||
|
||||
metrics.setWidth(i, width);
|
||||
} else {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
int p = i - fontInfo->min_char_or_byte2;
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,p,fontInfo->per_char);
|
||||
|
||||
if(fontInfo->per_char == NULL) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] p = %d fontInfo->per_char = %p\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),p,fontInfo->per_char);
|
||||
|
||||
XCharStruct *charinfo = &(fontInfo->min_bounds);
|
||||
//int charWidth = charinfo->rbearing - charinfo->lbearing;
|
||||
//int charHeight = charinfo->ascent + charinfo->descent;
|
||||
//int spanLength = (charWidth + 7) / 8;
|
||||
|
||||
if(charinfo != NULL) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] charinfo->width = %d\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),charinfo->width);
|
||||
metrics.setWidth(i, static_cast<float> (std::max((short)0,charinfo->width)));
|
||||
}
|
||||
else {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size 6\n",__FILE__,__FUNCTION__,__LINE__,type.c_str());
|
||||
|
||||
metrics.setWidth(i, static_cast<float>(6));
|
||||
}
|
||||
}
|
||||
else {
|
||||
float width = static_cast<float>(fontInfo->per_char[p].width); //( fontInfo->per_char[p].rbearing - fontInfo->per_char[p].lbearing);
|
||||
if(width <= 0) {
|
||||
width = static_cast<float>(6);
|
||||
}
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] type = [%s] using size = %f\n",__FILE__,__FUNCTION__,__LINE__,type.c_str(),width);
|
||||
metrics.setWidth(i, width);
|
||||
}
|
||||
}
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
glXUseXFont(fontInfo->fid, 0, charCount, base);
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
GLenum glerror = ::glGetError();
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] glerror = %d\n",__FILE__,__FUNCTION__,__LINE__,glerror);
|
||||
|
||||
XFreeFont(display, fontInfo);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
#else
|
||||
// we badly need a solution portable to more than just glx
|
||||
//NOIMPL;
|
||||
|
||||
std::string useRealFontName = type;
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load useRealFontName [%s], size = %d, width = %d\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),size,width);
|
||||
|
||||
static std::vector<std::string> systemFontList;
|
||||
if(systemFontList.size() == 0) {
|
||||
LOGFONT lf;
|
||||
//POSITION pos;
|
||||
//lf.lfCharSet = ANSI_CHARSET;
|
||||
lf.lfCharSet = (BYTE)charSet;
|
||||
lf.lfFaceName[0]='\0';
|
||||
|
||||
HDC hDC = wglGetCurrentDC();
|
||||
::EnumFontFamiliesEx(hDC,
|
||||
&lf,
|
||||
(FONTENUMPROC) EnumFontFamExProc,
|
||||
(LPARAM) &systemFontList, 0);
|
||||
|
||||
for(unsigned int idx = 0; idx < systemFontList.size(); ++idx) {
|
||||
string &fontName = systemFontList[idx];
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found system font [%s]\n",__FILE__,__FUNCTION__,__LINE__,fontName.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(unsigned int idx = 0; idx < systemFontList.size(); ++idx) {
|
||||
string &fontName = systemFontList[idx];
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] checking font [%s]\n",__FILE__,__FUNCTION__,__LINE__,fontName.c_str());
|
||||
|
||||
if(_stricmp(useRealFontName.c_str(),fontName.c_str()) != 0) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switch font name from [%s] to [%s]\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),fontName.c_str());
|
||||
|
||||
useRealFontName = fontName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HFONT font= CreateFont(
|
||||
size, 0, 0, 0, width, FALSE, FALSE, FALSE, charSet,
|
||||
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), useRealFontName.c_str());
|
||||
|
||||
assert(font!=NULL);
|
||||
|
||||
HDC dc= wglGetCurrentDC();
|
||||
SelectObject(dc, font);
|
||||
BOOL err= wglUseFontBitmaps(dc, 0, charCount, base);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] wglUseFontBitmaps returned = %d, charCount = %d, base = %d\n",__FILE__,__FUNCTION__,__LINE__,err,charCount,base);
|
||||
|
||||
FIXED one;
|
||||
one.value= 1;
|
||||
one.fract= 0;
|
||||
|
||||
FIXED zero;
|
||||
zero.value= 0;
|
||||
zero.fract= 0;
|
||||
|
||||
MAT2 mat2;
|
||||
mat2.eM11= one;
|
||||
mat2.eM12= zero;
|
||||
mat2.eM21= zero;
|
||||
mat2.eM22= one;
|
||||
|
||||
//MAT2 mat2 = {{0,1},{0,0},{0,0},{0,1}};
|
||||
|
||||
|
||||
//metrics
|
||||
GLYPHMETRICS glyphMetrics;
|
||||
int errorCode= GetGlyphOutline(dc, 'a', GGO_METRICS, &glyphMetrics, 0, NULL, &mat2);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] GetGlyphOutline returned = %d\n",__FILE__,__FUNCTION__,__LINE__,errorCode);
|
||||
|
||||
if(errorCode!=GDI_ERROR){
|
||||
metrics.setHeight(static_cast<float>(glyphMetrics.gmBlackBoxY));
|
||||
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl) {
|
||||
return "";
|
||||
}
|
||||
for(int i=0; i<charCount; ++i){
|
||||
int errorCode= GetGlyphOutline(dc, i, GGO_METRICS, &glyphMetrics, 0, NULL, &mat2);
|
||||
if(errorCode!=GDI_ERROR){
|
||||
metrics.setWidth(i, static_cast<float>(glyphMetrics.gmCellIncX));
|
||||
}
|
||||
else {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] GetGlyphOutline returned = %d for i = %d\n",__FILE__,__FUNCTION__,__LINE__,errorCode,i);
|
||||
metrics.setWidth(i, static_cast<float>(6));
|
||||
}
|
||||
|
||||
void *getGlProcAddress(const char *procName) {
|
||||
void* proc = SDL_GL_GetProcAddress(procName);
|
||||
assert(proc!=NULL);
|
||||
return proc;
|
||||
}
|
||||
|
||||
DeleteObject(font);
|
||||
|
||||
assert(err);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width,
|
||||
float depth, int charCount, FontMetrics &metrics) {
|
||||
NOIMPL;
|
||||
}
|
||||
|
||||
const char *getPlatformExtensions(const PlatformContextGl *pcgl) {
|
||||
return "";
|
||||
}
|
||||
|
||||
void *getGlProcAddress(const char *procName) {
|
||||
void* proc = SDL_GL_GetProcAddress(procName);
|
||||
assert(proc!=NULL);
|
||||
return proc;
|
||||
}
|
||||
|
||||
}}//end namespace
|
||||
}}//end namespace
|
||||
|
74
source/shared_lib/sources/platform/unix/gl_wrap.cpp
Normal file
74
source/shared_lib/sources/platform/unix/gl_wrap.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
//This file is part of Glest Shared Library (www.glest.org)
|
||||
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
|
||||
//You can redistribute this code and/or modify it under
|
||||
//the terms of the GNU General Public License as published by the Free Software
|
||||
//Foundation; either version 2 of the License, or (at your option) any later
|
||||
//version.
|
||||
#include "gl_wrap.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "sdl_private.h"
|
||||
#include "noimpl.h"
|
||||
#include "util.h"
|
||||
#include "window.h"
|
||||
#include <vector>
|
||||
//#include <SDL_image.h>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Graphics::Gl;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
|
||||
|
||||
// ======================================
|
||||
// Global Fcs
|
||||
// ======================================
|
||||
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
|
||||
int charCount, FontMetrics &metrics) {
|
||||
Display* display = glXGetCurrentDisplay();
|
||||
if(display == 0) {
|
||||
throw std::runtime_error("Couldn't create font: display is 0");
|
||||
}
|
||||
XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str());
|
||||
if(!fontInfo) {
|
||||
throw std::runtime_error("Font not found.");
|
||||
}
|
||||
|
||||
// we need the height of 'a' which sould ~ be half ascent+descent
|
||||
metrics.setHeight(static_cast<float>
|
||||
(fontInfo->ascent + fontInfo->descent) / 2);
|
||||
for(unsigned int i = 0; i < static_cast<unsigned int> (charCount); ++i) {
|
||||
if(i < fontInfo->min_char_or_byte2 ||
|
||||
i > fontInfo->max_char_or_byte2) {
|
||||
metrics.setWidth(i, static_cast<float>(6));
|
||||
} else {
|
||||
int p = i - fontInfo->min_char_or_byte2;
|
||||
metrics.setWidth(i, static_cast<float> (
|
||||
fontInfo->per_char[p].rbearing
|
||||
- fontInfo->per_char[p].lbearing));
|
||||
}
|
||||
}
|
||||
|
||||
glXUseXFont(fontInfo->fid, 0, charCount, base);
|
||||
XFreeFont(display, fontInfo);
|
||||
}
|
||||
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width,
|
||||
float depth, int charCount, FontMetrics &metrics) {
|
||||
NOIMPL;
|
||||
}
|
||||
|
||||
|
||||
}}//end namespace
|
145
source/shared_lib/sources/platform/win32/gl_wrap.cpp
Normal file
145
source/shared_lib/sources/platform/win32/gl_wrap.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
//This file is part of Glest Shared Library (www.glest.org)
|
||||
//Copyright (C) 2005 Matthias Braun <matze@braunis.de>
|
||||
|
||||
//You can redistribute this code and/or modify it under
|
||||
//the terms of the GNU General Public License as published by the Free Software
|
||||
//Foundation; either version 2 of the License, or (at your option) any later
|
||||
//version.
|
||||
#include "gl_wrap.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
|
||||
#include "opengl.h"
|
||||
#include "sdl_private.h"
|
||||
#include "noimpl.h"
|
||||
#include "util.h"
|
||||
#include "window.h"
|
||||
#include <vector>
|
||||
//#include <SDL_image.h>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace Shared::Graphics::Gl;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Platform{
|
||||
|
||||
|
||||
|
||||
// ======================================
|
||||
// Global Fcs
|
||||
// ======================================
|
||||
|
||||
int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe,
|
||||
NEWTEXTMETRICEX *lpntme,
|
||||
int FontType,
|
||||
LPARAM lParam) {
|
||||
std::vector<std::string> *systemFontList = (std::vector<std::string> *)lParam;
|
||||
systemFontList->push_back((char *)lpelfe->elfFullName);
|
||||
return 1; // I want to get all fonts
|
||||
}
|
||||
|
||||
void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
|
||||
int charCount, FontMetrics &metrics) {
|
||||
// -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 this is a Chinese font
|
||||
|
||||
std::string useRealFontName = type;
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] trying to load useRealFontName [%s], size = %d, width = %d\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),size,width);
|
||||
|
||||
static std::vector<std::string> systemFontList;
|
||||
if(systemFontList.size() == 0) {
|
||||
LOGFONT lf;
|
||||
//POSITION pos;
|
||||
//lf.lfCharSet = ANSI_CHARSET;
|
||||
lf.lfCharSet = (BYTE)charSet;
|
||||
lf.lfFaceName[0]='\0';
|
||||
|
||||
HDC hDC = wglGetCurrentDC();
|
||||
::EnumFontFamiliesEx(hDC,
|
||||
&lf,
|
||||
(FONTENUMPROC) EnumFontFamExProc,
|
||||
(LPARAM) &systemFontList, 0);
|
||||
|
||||
for(unsigned int idx = 0; idx < systemFontList.size(); ++idx) {
|
||||
string &fontName = systemFontList[idx];
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] found system font [%s]\n",__FILE__,__FUNCTION__,__LINE__,fontName.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(unsigned int idx = 0; idx < systemFontList.size(); ++idx) {
|
||||
string &fontName = systemFontList[idx];
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] checking font [%s]\n",__FILE__,__FUNCTION__,__LINE__,fontName.c_str());
|
||||
|
||||
if(_stricmp(useRealFontName.c_str(),fontName.c_str()) != 0) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] switch font name from [%s] to [%s]\n",__FILE__,__FUNCTION__,__LINE__,useRealFontName.c_str(),fontName.c_str());
|
||||
|
||||
useRealFontName = fontName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HFONT font= CreateFont(
|
||||
size, 0, 0, 0, width, FALSE, FALSE, FALSE, charSet,
|
||||
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
|
||||
DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), useRealFontName.c_str());
|
||||
|
||||
assert(font!=NULL);
|
||||
|
||||
HDC dc= wglGetCurrentDC();
|
||||
SelectObject(dc, font);
|
||||
BOOL err= wglUseFontBitmaps(dc, 0, charCount, base);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] wglUseFontBitmaps returned = %d, charCount = %d, base = %d\n",__FILE__,__FUNCTION__,__LINE__,err,charCount,base);
|
||||
|
||||
FIXED one;
|
||||
one.value= 1;
|
||||
one.fract= 0;
|
||||
|
||||
FIXED zero;
|
||||
zero.value= 0;
|
||||
zero.fract= 0;
|
||||
|
||||
MAT2 mat2;
|
||||
mat2.eM11= one;
|
||||
mat2.eM12= zero;
|
||||
mat2.eM21= zero;
|
||||
mat2.eM22= one;
|
||||
|
||||
//MAT2 mat2 = {{0,1},{0,0},{0,0},{0,1}};
|
||||
|
||||
|
||||
//metrics
|
||||
GLYPHMETRICS glyphMetrics;
|
||||
int errorCode= GetGlyphOutline(dc, 'a', GGO_METRICS, &glyphMetrics, 0, NULL, &mat2);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] GetGlyphOutline returned = %d\n",__FILE__,__FUNCTION__,__LINE__,errorCode);
|
||||
|
||||
if(errorCode!=GDI_ERROR){
|
||||
metrics.setHeight(static_cast<float>(glyphMetrics.gmBlackBoxY));
|
||||
}
|
||||
for(int i=0; i<charCount; ++i){
|
||||
int errorCode= GetGlyphOutline(dc, i, GGO_METRICS, &glyphMetrics, 0, NULL, &mat2);
|
||||
if(errorCode!=GDI_ERROR){
|
||||
metrics.setWidth(i, static_cast<float>(glyphMetrics.gmCellIncX));
|
||||
}
|
||||
else {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] GetGlyphOutline returned = %d for i = %d\n",__FILE__,__FUNCTION__,__LINE__,errorCode,i);
|
||||
metrics.setWidth(i, static_cast<float>(6));
|
||||
}
|
||||
}
|
||||
|
||||
DeleteObject(font);
|
||||
|
||||
assert(err);
|
||||
|
||||
}
|
||||
|
||||
void createGlFontOutlines(uint32 &base, const string &type, int width,
|
||||
float depth, int charCount, FontMetrics &metrics) {
|
||||
NOIMPL;
|
||||
}
|
||||
|
||||
}}//end namespace
|
Reference in New Issue
Block a user