From b115292ee5dbe211107c1cf02f192b85341daa31 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 16 Sep 2010 15:15:42 +0000 Subject: [PATCH] - added GeoVah's initila Mac osX support (via cmake) --- CMakeLists.txt | 4 + mk/cmake/Modules/FindLUA.cmake | 4 +- mk/cmake/Modules/FindOGG.cmake | 12 +- mk/cmake/Modules/FindXercesC.cmake | 5 +- mk/linux/Jamfile | 1 + mk/macosx/CMakeLists.txt | 168 +++++++++++++ mk/macosx/Info.plist | 96 ++++++++ mk/macosx/MegaGlest.icns | Bin 0 -> 14404 bytes source/glest_game/CMakeLists.txt | 15 +- source/shared_lib/CMakeLists.txt | 48 +++- .../sources/platform/macosx/NSFont_OpenGL.h | 54 ++++ .../sources/platform/macosx/NSFont_OpenGL.m | 211 ++++++++++++++++ .../sources/platform/macosx/gl_wrap.mm | 206 ++++++++++++++++ .../sources/platform/sdl/gl_wrap.cpp | 233 +----------------- .../sources/platform/unix/gl_wrap.cpp | 74 ++++++ .../sources/platform/win32/gl_wrap.cpp | 145 +++++++++++ 16 files changed, 1033 insertions(+), 243 deletions(-) create mode 100644 mk/macosx/CMakeLists.txt create mode 100644 mk/macosx/Info.plist create mode 100644 mk/macosx/MegaGlest.icns create mode 100644 source/shared_lib/sources/platform/macosx/NSFont_OpenGL.h create mode 100644 source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m create mode 100644 source/shared_lib/sources/platform/macosx/gl_wrap.mm create mode 100644 source/shared_lib/sources/platform/unix/gl_wrap.cpp create mode 100644 source/shared_lib/sources/platform/win32/gl_wrap.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 46ae9a0c3..c050cc8c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,3 +5,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mk/cmake/Modules) ADD_SUBDIRECTORY( source/shared_lib ) ADD_SUBDIRECTORY( source/glest_game ) + +IF(APPLE) + include(mk/macosx/CMakeLists.txt) +ENDIF(APPLE) diff --git a/mk/cmake/Modules/FindLUA.cmake b/mk/cmake/Modules/FindLUA.cmake index a31921a68..245b12a9d 100644 --- a/mk/cmake/Modules/FindLUA.cmake +++ b/mk/cmake/Modules/FindLUA.cmake @@ -20,9 +20,11 @@ FIND_PATH(LUA_INCLUDE_DIR NAMES lua.hpp PATHS /usr/include /usr/include/lua /usr/include/lua5.1 + $ENV{LUA_HOME} ) -FIND_LIBRARY(LUA_LIBRARIES NAMES lua5.1 lua ) +FIND_LIBRARY(LUA_LIBRARIES NAMES lua5.1 lua + PATHS $ENV{LUA_HOME}) IF(LUA_INCLUDE_DIR AND LUA_LIBRARIES) SET(LUA_FOUND TRUE) diff --git a/mk/cmake/Modules/FindOGG.cmake b/mk/cmake/Modules/FindOGG.cmake index 837aff18c..00ae6ec89 100644 --- a/mk/cmake/Modules/FindOGG.cmake +++ b/mk/cmake/Modules/FindOGG.cmake @@ -15,9 +15,13 @@ ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY) FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h) FIND_LIBRARY(OGG_LIBRARY NAMES ogg) FIND_LIBRARY(VORBIS_LIBRARY NAMES vorbis) -FIND_LIBRARY(VORBIS_FILE_LIBRARY NAMES vorbisfile) -IF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND VORBIS_FILE_LIBRARY) +#on macosx the vorbisfile library is part of the vorbisone... +IF(NOT APPLE) + FIND_LIBRARY(VORBIS_FILE_LIBRARY NAMES vorbisfile) +ENDIF(NOT APPLE) + +IF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND (APPLE OR VORBIS_FILE_LIBRARY)) SET(OGG_FOUND TRUE) IF(NOT OGG_BE_QUIET) MESSAGE(STATUS "OGG/Vorbis includes: ${OGG_INCLUDE_DIR}") @@ -25,10 +29,10 @@ IF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND VORBIS_FILE_LIBRARY) MESSAGE(STATUS "Vorbis library : ${VORBIS_LIBRARY}") MESSAGE(STATUS "Vorbis file library: ${VORBIS_FILE_LIBRARY}") ENDIF(NOT OGG_BE_QUIET) -ELSE(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND VORBIS_FILE_LIBRARY) +ELSE(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND (APPLE OR VORBIS_FILE_LIBRARY)) SET(OGG_FOUND FALSE) MESSAGE("OGG/Vorbis was not found on this system!") -ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND VORBIS_FILE_LIBRARY) +ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY AND (APPLE OR VORBIS_FILE_LIBRARY)) MARK_AS_ADVANCED( OGG_INCLUDE_DIR diff --git a/mk/cmake/Modules/FindXercesC.cmake b/mk/cmake/Modules/FindXercesC.cmake index 631c5863c..93914a986 100644 --- a/mk/cmake/Modules/FindXercesC.cmake +++ b/mk/cmake/Modules/FindXercesC.cmake @@ -11,9 +11,10 @@ IF (XERCESC_INCLUDE_DIR) SET(XERCESC_FIND_QUIETLY TRUE) ENDIF (XERCESC_INCLUDE_DIR) -FIND_PATH(XERCESC_INCLUDE_DIR xercesc/dom/DOM.hpp) +FIND_PATH(XERCESC_INCLUDE_DIR xercesc + PATH_SUFFIXES DOM/dom.hpp) -SET(XERCESC_NAMES xerces-c xerces-c_3 xerces-c_2) +SET(XERCESC_NAMES xerces-c xerces-c_3 xerces-c_2 Xerces) FIND_LIBRARY(XERCESC_LIBRARY NAMES ${XERCESC_NAMES} ) # Handle the QUIETLY and REQUIRED arguments and set XERCESC_FOUND to diff --git a/mk/linux/Jamfile b/mk/linux/Jamfile index 089c47ab3..0bd1e8f24 100644 --- a/mk/linux/Jamfile +++ b/mk/linux/Jamfile @@ -51,6 +51,7 @@ LIB_DIRS = platform/common platform/sdl platform/posix + platform/unix util graphics graphics/gl diff --git a/mk/macosx/CMakeLists.txt b/mk/macosx/CMakeLists.txt new file mode 100644 index 000000000..57cceff62 --- /dev/null +++ b/mk/macosx/CMakeLists.txt @@ -0,0 +1,168 @@ +# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4 +# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support. +# These are just defaults/recommendations, but how we want to build +# out of the box. But the user needs to be able to change these options. +# So we must only set the values the first time CMake is run, or we +# will overwrite any changes the user sets. +# FORCE is used because the options are not reflected in the UI otherwise. +# Seems like a good place to add version specific compiler flags too. +IF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + IF(EXISTS /Developer/SDKs/MacOSX10.6.sdk) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.6 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + + ELSEIF(EXISTS /Developer/SDKs/MacOSX10.5.sdk) + # 64-bit compiles are not supported with Carbon. We should enable + # 64-bit compilation by default once osgviewer has been + # rewritten with Cocoa. + #SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSE() + # No Universal Binary support + # Should break down further to set the -mmacosx-version-min, + # but the SDK detection is too unreliable here. + ENDIF() +ENDIF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + + + +##install part + + + +include (InstallRequiredSystemLibraries) + +set (CPACK_RESOURCE_FILE_LICENSE + "${CMAKE_CURRENT_SOURCE_DIR}/docs/code_license.txt") +set (CPACK_GENERATOR Bundle) +set (CPACK_BUNDLE_NAME "MegaGlest") +set (CPACK_BUNDLE_STARTUP_COMMAND "${PROJECT_SOURCE_DIR}/data/glest_game/Debug/glest.bin") +set (CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/Info.plist") +INSTALL(FILES + ${LUA_LIBRARIES} + DESTINATION ../Frameworks + ) +INSTALL(DIRECTORY + ${OGG_LIBRARY} + ${XERCESC_LIBRARY} + ${VORBIS_LIBRARY} + ${SDL_LIBRARY} + DESTINATION ../Frameworks + ) + +include (CPack) +# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4 +# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support. +# These are just defaults/recommendations, but how we want to build +# out of the box. But the user needs to be able to change these options. +# So we must only set the values the first time CMake is run, or we +# will overwrite any changes the user sets. +# FORCE is used because the options are not reflected in the UI otherwise. +# Seems like a good place to add version specific compiler flags too. +IF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + IF(EXISTS /Developer/SDKs/MacOSX10.6.sdk) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.6 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + + ELSEIF(EXISTS /Developer/SDKs/MacOSX10.5.sdk) + # 64-bit compiles are not supported with Carbon. We should enable + # 64-bit compilation by default once osgviewer has been + # rewritten with Cocoa. + #SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSE() + # No Universal Binary support + # Should break down further to set the -mmacosx-version-min, + # but the SDK detection is too unreliable here. + ENDIF() +ENDIF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + + + +##install part + + + +include (InstallRequiredSystemLibraries) + +set (CPACK_RESOURCE_FILE_LICENSE + "${CMAKE_CURRENT_SOURCE_DIR}/docs/code_license.txt") +set (CPACK_GENERATOR Bundle) +set (CPACK_BUNDLE_NAME "MegaGlest") +set (CPACK_BUNDLE_STARTUP_COMMAND "${PROJECT_SOURCE_DIR}/data/glest_game/Debug/glest.bin") +set (CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/Info.plist") +INSTALL(FILES + ${LUA_LIBRARIES} + DESTINATION ../Frameworks + ) +INSTALL(DIRECTORY + ${OGG_LIBRARY} + ${XERCESC_LIBRARY} + ${VORBIS_LIBRARY} + ${SDL_LIBRARY} + DESTINATION ../Frameworks + ) + +include (CPack) +# Set defaults for Universal Binaries. We want 32-bit Intel/PPC on 10.4 +# and 32/64-bit Intel/PPC on >= 10.5. Anything <= 10.3 doesn't support. +# These are just defaults/recommendations, but how we want to build +# out of the box. But the user needs to be able to change these options. +# So we must only set the values the first time CMake is run, or we +# will overwrite any changes the user sets. +# FORCE is used because the options are not reflected in the UI otherwise. +# Seems like a good place to add version specific compiler flags too. +IF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + IF(EXISTS /Developer/SDKs/MacOSX10.6.sdk) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.6 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + + ELSEIF(EXISTS /Developer/SDKs/MacOSX10.5.sdk) + # 64-bit compiles are not supported with Carbon. We should enable + # 64-bit compilation by default once osgviewer has been + # rewritten with Cocoa. + #SET(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_OSX_ARCHITECTURES "i386" CACHE STRING "Build architectures for OSX" FORCE) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.5 -ftree-vectorize -fvisibility-inlines-hidden" CACHE STRING "Flags used by the compiler during all build types." FORCE) + ELSE() + # No Universal Binary support + # Should break down further to set the -mmacosx-version-min, + # but the SDK detection is too unreliable here. + ENDIF() +ENDIF(NOT CONFIG_HAS_BEEN_RUN_BEFORE) + + + +##install part + + + +include (InstallRequiredSystemLibraries) + +set (CPACK_RESOURCE_FILE_LICENSE + "${CMAKE_CURRENT_SOURCE_DIR}/docs/code_license.txt") +set (CPACK_GENERATOR Bundle) +set (CPACK_BUNDLE_NAME "MegaGlest") +set (CPACK_BUNDLE_STARTUP_COMMAND "${PROJECT_SOURCE_DIR}/data/glest_game/Debug/glest.bin") +set (CPACK_BUNDLE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/MegaGlest.icns") +set (CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/mk/macosx/Info.plist") +INSTALL(FILES + ${LUA_LIBRARIES} + DESTINATION ../Frameworks + ) +INSTALL(DIRECTORY + ${OGG_LIBRARY} + ${XERCESC_LIBRARY} + ${VORBIS_LIBRARY} + ${SDL_LIBRARY} + DESTINATION ../Frameworks + ) + +include (CPack) diff --git a/mk/macosx/Info.plist b/mk/macosx/Info.plist new file mode 100644 index 000000000..975f8feae --- /dev/null +++ b/mk/macosx/Info.plist @@ -0,0 +1,96 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + MegaGlest + CFBundleGetInfoString + 3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved. + CFBundleIconFile + MegaGlest + CFBundleIdentifier + jp.ne.ivory.ciderhouse.MegaGlest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MegaGlest + CFBundlePackageType + APPL + CFBundleShortVersionString + 3.2.2 + CFBundleSignature + ???? + CFBundleVersion + 3.2 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + MegaGlest + CFBundleGetInfoString + 3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved. + CFBundleIconFile + MegaGlest + CFBundleIdentifier + jp.ne.ivory.ciderhouse.MegaGlest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MegaGlest + CFBundlePackageType + APPL + CFBundleShortVersionString + 3.2.2 + CFBundleSignature + ???? + CFBundleVersion + 3.2 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + MegaGlest + CFBundleGetInfoString + 3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved. + CFBundleIconFile + MegaGlest + CFBundleIdentifier + jp.ne.ivory.ciderhouse.MegaGlest + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MegaGlest + CFBundlePackageType + APPL + CFBundleShortVersionString + 3.2.2 + CFBundleSignature + ???? + CFBundleVersion + 3.2 + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/mk/macosx/MegaGlest.icns b/mk/macosx/MegaGlest.icns new file mode 100644 index 0000000000000000000000000000000000000000..c95a57a7fb20d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M?P8J+MW%vOwO^Bfl$LY zo0Ap!)!Wtxl$?K?bR`vEKvg-}tGgSNneu=BXMuZ9f3z%D8UiaDc`ip$fOA%wHkX=z%m{@Jk(3Q2W zu5!Fy<8r%KRe9DpN_0)3Ep2TbUCrR$+OfH#&DUD8bzxtN47?s-&(B-AbXjxz4D-*M zqSDhdBpGR{?4q{!LucPD9>6Kt6;1Z{vv>BDVZ^N2a#yrRL?L)VL#O00NIY8G@{3 z{-sP_Oy47SnE4!2D3MwM73tjgpZ-%>S`&a$mEzLo!c0NT=Py3|kLgeaM=30B%@-vT zTRuLRhCbUAFIOxLKnUN=ld7ZAGQa zmRhV8#d>8!$Wh_6R#dE9xw>kl)3L&Ag}}oXZbVchnF$VF$byO(4krwlsQN +#import + +@interface NSFont (withay_OpenGL) + ++ (void) setOpenGLLogging:(BOOL)logEnabled; +- (BOOL) makeGLDisplayListFirst:(unichar)first count:(int)count base:(GLint)base; + +@end diff --git a/source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m b/source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m new file mode 100644 index 000000000..dd75a6e8c --- /dev/null +++ b/source/shared_lib/sources/platform/macosx/NSFont_OpenGL.m @@ -0,0 +1,211 @@ +/* + * This program is Copyright © 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 diff --git a/source/shared_lib/sources/platform/macosx/gl_wrap.mm b/source/shared_lib/sources/platform/macosx/gl_wrap.mm new file mode 100644 index 000000000..dd67672cb --- /dev/null +++ b/source/shared_lib/sources/platform/macosx/gl_wrap.mm @@ -0,0 +1,206 @@ +//This file is part of Glest Shared Library (www.glest.org) +//Copyright (C) 2005 Matthias Braun + +//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 +#include +#include +#include + +#import + +#include "opengl.h" +#include "sdl_private.h" +#include "noimpl.h" +#include "util.h" +#include "window.h" +#include +//#include +#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 diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index 83e38296b..30cfb9055 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -12,10 +12,6 @@ #include #include -#ifdef X11_AVAILABLE -#include -#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 *systemFontList = (std::vector *)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(fontInfo->ascent + fontInfo->descent) / 2); - if(height <= 0) { - height = static_cast(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 (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(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 (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(6)); - } - } - else { - float width = static_cast(fontInfo->per_char[p].width); //( fontInfo->per_char[p].rbearing - fontInfo->per_char[p].lbearing); - if(width <= 0) { - width = static_cast(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 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(glyphMetrics.gmBlackBoxY)); + + const char *getPlatformExtensions(const PlatformContextGl *pcgl) { + return ""; } - for(int i=0; i(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(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 diff --git a/source/shared_lib/sources/platform/unix/gl_wrap.cpp b/source/shared_lib/sources/platform/unix/gl_wrap.cpp new file mode 100644 index 000000000..1b6a9ef5b --- /dev/null +++ b/source/shared_lib/sources/platform/unix/gl_wrap.cpp @@ -0,0 +1,74 @@ +//This file is part of Glest Shared Library (www.glest.org) +//Copyright (C) 2005 Matthias Braun + +//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 +#include +#include +#include + + +#include + +#include "opengl.h" +#include "sdl_private.h" +#include "noimpl.h" +#include "util.h" +#include "window.h" +#include +//#include +#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 + (fontInfo->ascent + fontInfo->descent) / 2); + for(unsigned int i = 0; i < static_cast (charCount); ++i) { + if(i < fontInfo->min_char_or_byte2 || + i > fontInfo->max_char_or_byte2) { + metrics.setWidth(i, static_cast(6)); + } else { + int p = i - fontInfo->min_char_or_byte2; + metrics.setWidth(i, static_cast ( + 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 diff --git a/source/shared_lib/sources/platform/win32/gl_wrap.cpp b/source/shared_lib/sources/platform/win32/gl_wrap.cpp new file mode 100644 index 000000000..1623d40fa --- /dev/null +++ b/source/shared_lib/sources/platform/win32/gl_wrap.cpp @@ -0,0 +1,145 @@ +//This file is part of Glest Shared Library (www.glest.org) +//Copyright (C) 2005 Matthias Braun + +//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 +#include +#include +#include + +#include "opengl.h" +#include "sdl_private.h" +#include "noimpl.h" +#include "util.h" +#include "window.h" +#include +//#include +#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 *systemFontList = (std::vector *)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 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(glyphMetrics.gmBlackBoxY)); + } + for(int i=0; i(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(6)); + } + } + + DeleteObject(font); + + assert(err); + + } + + void createGlFontOutlines(uint32 &base, const string &type, int width, + float depth, int charCount, FontMetrics &metrics) { + NOIMPL; + } + +}}//end namespace