- added GeoVah's initila Mac osX support (via cmake)

This commit is contained in:
Mark Vejvoda
2010-09-16 15:15:42 +00:00
parent 16f048c9e2
commit b115292ee5
16 changed files with 1033 additions and 243 deletions

View File

@@ -5,3 +5,7 @@ SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mk/cmake/Modules)
ADD_SUBDIRECTORY( source/shared_lib ) ADD_SUBDIRECTORY( source/shared_lib )
ADD_SUBDIRECTORY( source/glest_game ) ADD_SUBDIRECTORY( source/glest_game )
IF(APPLE)
include(mk/macosx/CMakeLists.txt)
ENDIF(APPLE)

View File

@@ -20,9 +20,11 @@ FIND_PATH(LUA_INCLUDE_DIR NAMES lua.hpp
PATHS /usr/include PATHS /usr/include
/usr/include/lua /usr/include/lua
/usr/include/lua5.1 /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) IF(LUA_INCLUDE_DIR AND LUA_LIBRARIES)
SET(LUA_FOUND TRUE) SET(LUA_FOUND TRUE)

View File

@@ -15,9 +15,13 @@ ENDIF(OGG_INCLUDE_DIR AND OGG_LIBRARY AND VORBIS_LIBRARY)
FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h) FIND_PATH(OGG_INCLUDE_DIR ogg/ogg.h)
FIND_LIBRARY(OGG_LIBRARY NAMES ogg) FIND_LIBRARY(OGG_LIBRARY NAMES ogg)
FIND_LIBRARY(VORBIS_LIBRARY NAMES vorbis) 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) SET(OGG_FOUND TRUE)
IF(NOT OGG_BE_QUIET) IF(NOT OGG_BE_QUIET)
MESSAGE(STATUS "OGG/Vorbis includes: ${OGG_INCLUDE_DIR}") 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 library : ${VORBIS_LIBRARY}")
MESSAGE(STATUS "Vorbis file library: ${VORBIS_FILE_LIBRARY}") MESSAGE(STATUS "Vorbis file library: ${VORBIS_FILE_LIBRARY}")
ENDIF(NOT OGG_BE_QUIET) 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) SET(OGG_FOUND FALSE)
MESSAGE("OGG/Vorbis was not found on this system!") 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( MARK_AS_ADVANCED(
OGG_INCLUDE_DIR OGG_INCLUDE_DIR

View File

@@ -11,9 +11,10 @@ IF (XERCESC_INCLUDE_DIR)
SET(XERCESC_FIND_QUIETLY TRUE) SET(XERCESC_FIND_QUIETLY TRUE)
ENDIF (XERCESC_INCLUDE_DIR) 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} ) FIND_LIBRARY(XERCESC_LIBRARY NAMES ${XERCESC_NAMES} )
# Handle the QUIETLY and REQUIRED arguments and set XERCESC_FOUND to # Handle the QUIETLY and REQUIRED arguments and set XERCESC_FOUND to

View File

@@ -51,6 +51,7 @@ LIB_DIRS =
platform/common platform/common
platform/sdl platform/sdl
platform/posix platform/posix
platform/unix
util util
graphics graphics
graphics/gl graphics/gl

168
mk/macosx/CMakeLists.txt Normal file
View File

@@ -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)

96
mk/macosx/Info.plist Normal file
View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>MegaGlest</string>
<key>CFBundleGetInfoString</key>
<string>3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved.</string>
<key>CFBundleIconFile</key>
<string>MegaGlest</string>
<key>CFBundleIdentifier</key>
<string>jp.ne.ivory.ciderhouse.MegaGlest</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>MegaGlest</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.2</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>MegaGlest</string>
<key>CFBundleGetInfoString</key>
<string>3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved.</string>
<key>CFBundleIconFile</key>
<string>MegaGlest</string>
<key>CFBundleIdentifier</key>
<string>jp.ne.ivory.ciderhouse.MegaGlest</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>MegaGlest</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.2</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>MegaGlest</string>
<key>CFBundleGetInfoString</key>
<string>3.2.2r1, © 2001-2009 The Glest Team All Rights Reserved.</string>
<key>CFBundleIconFile</key>
<string>MegaGlest</string>
<key>CFBundleIdentifier</key>
<string>jp.ne.ivory.ciderhouse.MegaGlest</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>MegaGlest</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.2.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.2</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>

BIN
mk/macosx/MegaGlest.icns Normal file

Binary file not shown.

View File

@@ -54,6 +54,7 @@ SET(DIRS_WITH_SRC
type_instances type_instances
types types
world) world)
SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/") SET(GLEST_LIB_INCLUDE_ROOT "../shared_lib/include/")
SET(GLEST_LIB_INCLUDE_DIRS SET(GLEST_LIB_INCLUDE_DIRS
@@ -69,7 +70,8 @@ SET(GLEST_LIB_INCLUDE_DIRS
${GLEST_LIB_INCLUDE_ROOT}glew ${GLEST_LIB_INCLUDE_ROOT}glew
${GLEST_LIB_INCLUDE_ROOT}lua ${GLEST_LIB_INCLUDE_ROOT}lua
${GLEST_LIB_INCLUDE_ROOT}streflop ${GLEST_LIB_INCLUDE_ROOT}streflop
${GLEST_LIB_INCLUDE_ROOT}streflop/libm_flt32_source) ${GLEST_LIB_INCLUDE_ROOT}streflop/libm_flt32_source
${GLEST_LIB_INCLUDE_ROOT}map)
INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} ) INCLUDE_DIRECTORIES( ${GLEST_LIB_INCLUDE_DIRS} )
SET(MG_SOURCE_FILES "") SET(MG_SOURCE_FILES "")
@@ -80,10 +82,19 @@ FOREACH(DIR IN LISTS DIRS_WITH_SRC)
set(SRC_DIR_TO_GLOB ${DIR}) set(SRC_DIR_TO_GLOB ${DIR})
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.cpp) FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.cpp)
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR}) SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
IF(APPLE)
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.mm)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.m)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
ENDIF(APPLE)
ENDFOREACH(DIR) ENDFOREACH(DIR)
# [RCL] FIXME: make it compiler-agnostic # [RCL] FIXME: make it compiler-agnostic
SET(CMAKE_CXX_FLAGS "-O3 -msse -msse2 -mfpmath=sse -DSTREFLOP_SSE") SET(CMAKE_CXX_FLAGS "-O3 -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse -DSTREFLOP_SSE")
SET(TARGET_NAME "glest.bin") SET(TARGET_NAME "glest.bin")

View File

@@ -47,6 +47,7 @@ FIND_PACKAGE(CURL REQUIRED)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${CURL_LIBRARIES}) SET(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${CURL_LIBRARIES})
######################################################################################### #########################################################################################
# glest lib # glest lib
@@ -63,7 +64,14 @@ SET(DIRS_WITH_SRC
glew glew
lua lua
streflop streflop
streflop/libm_flt32_source) streflop/libm_flt32_source
map)
IF(APPLE)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} platform/macosx)
ELSE(APPLE)
SET(DIRS_WITH_SRC ${DIRS_WITH_SRC} platform/unix)
ENDIF(APPLE)
SET(MG_INCLUDES_ROOT "include/") SET(MG_INCLUDES_ROOT "include/")
SET(MG_SOURCES_ROOT "sources/") SET(MG_SOURCES_ROOT "sources/")
@@ -73,35 +81,55 @@ SET(MG_SOURCE_FILES "")
FOREACH(DIR IN LISTS DIRS_WITH_SRC) FOREACH(DIR IN LISTS DIRS_WITH_SRC)
set(INCLUDE_DIR_TO_GLOB ${MG_INCLUDES_ROOT}${DIR}) set(INCLUDE_DIR_TO_GLOB ${MG_INCLUDES_ROOT}${DIR})
INCLUDE_DIRECTORIES( ${INCLUDE_DIR_TO_GLOB} ) INCLUDE_DIRECTORIES( ${INCLUDE_DIR_TO_GLOB} )
#MESSAGE(STATUS "INCLUDE_DIR_TO_GLOB: ${INCLUDE_DIR_TO_GLOB}") IF(APPLE)
#FILE(GLOB INC_FILES_FROM_THIS_DIR ${INCLUDE_DIR_TO_GLOB}/*.h) #MESSAGE(STATUS "INCLUDE_DIR_TO_GLOB: ${INCLUDE_DIR_TO_GLOB}")
#MESSAGE(STATUS "INCLUDE FILES GLOBBED: ${INC_FILES_FROM_THIS_DIR}") FILE(GLOB INC_FILES_FROM_THIS_DIR ${INCLUDE_DIR_TO_GLOB}/*.h)
#SET(MG_INCLUDE_FILES ${MG_INCLUDE_FILES} ${INC_FILES_FROM_THIS_DIR}) #MESSAGE(STATUS "INCLUDE FILES GLOBBED: ${INC_FILES_FROM_THIS_DIR}")
SET(MG_INCLUDE_FILES ${MG_INCLUDE_FILES} ${INC_FILES_FROM_THIS_DIR})
ENDIF(APPLE)
set(SRC_DIR_TO_GLOB ${MG_SOURCES_ROOT}${DIR}) set(SRC_DIR_TO_GLOB ${MG_SOURCES_ROOT}${DIR})
#MESSAGE(STATUS "SRC_DIR_TO_GLOB: ${SRC_DIR_TO_GLOB}") #MESSAGE(STATUS "SRC_DIR_TO_GLOB: ${SRC_DIR_TO_GLOB}")
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.cpp) FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.cpp)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}") #MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR}) SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
IF(APPLE)
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.mm)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
FILE(GLOB SRC_FILES_FROM_THIS_DIR ${SRC_DIR_TO_GLOB}/*.m)
#MESSAGE(STATUS "SRC_FILES_FROM_THIS_DIR: ${SRC_FILES_FROM_THIS_DIR}")
SET(MG_SOURCE_FILES ${MG_SOURCE_FILES} ${SRC_FILES_FROM_THIS_DIR})
ENDIF(APPLE)
ENDFOREACH(DIR) ENDFOREACH(DIR)
#MESSAGE(STATUS "Source files: ${MG_INCLUDE_FILES}") #MESSAGE(STATUS "Source files: ${MG_INCLUDE_FILES}")
#MESSAGE(STATUS "Source files: ${MG_SOURCE_FILES}") #MESSAGE(STATUS "Source files: ${MG_SOURCE_FILES}")
#MESSAGE(STATUS "Include dirs: ${INCLUDE_DIRECTORIES}") #MESSAGE(STATUS "Include dirs: ${INCLUDE_DIRECTORIES}")
# FIXME: hackish, should be tested for # FIXME: hackish, should be tested for
SET(UNIX_SPECIFIC_DEFINES "-DX11_AVAILABLE -DHAVE_SYS_IOCTL_H") IF(APPLE)
SET(PLATFORM_SPECIFIC_DEFINES "-DHAVE_SYS_IOCTL_H")
ELSE(APPLE)
SET(PLATFORM_SPECIFIC_DEFINES "-DX11_AVAILABLE -DHAVE_SYS_IOCTL_H")
ENDIF(APPLE)
# FIXME: hackish... # FIXME: hackish...
SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32") SET(STREFLOP_PROPERTIES "-DSTREFLOP_SSE -DLIBM_COMPILING_FLT32")
# FIXME: should choose between platforms
SET_SOURCE_FILES_PROPERTIES(${MG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS SET_SOURCE_FILES_PROPERTIES(${MG_SOURCE_FILES} PROPERTIES COMPILE_FLAGS
"${UNIX_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}") "${PLATFORM_SPECIFIC_DEFINES} ${STREFLOP_PROPERTIES} ${CXXFLAGS}")
SET_SOURCE_FILES_PROPERTIES(${MG_INCLUDE_FILES} PROPERTIES HEADER_FILE_ONLY 1)
# [RCL] FIXME: make it compiler-agnostic # [RCL] FIXME: make it compiler-agnostic
SET(CMAKE_CXX_FLAGS "-O3 -msse -msse2 -mfpmath=sse") SET(CMAKE_CXX_FLAGS "-O3 -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse")
ADD_LIBRARY(glest_lib ${MG_SOURCE_FILES}) ADD_LIBRARY(glest_lib ${MG_SOURCE_FILES})
TARGET_LINK_LIBRARIES(glest_lib streflop) TARGET_LINK_LIBRARIES(glest_lib streflop)
TARGET_LINK_LIBRARIES(glest_lib ${EXTERNAL_LIBS}) TARGET_LINK_LIBRARIES(glest_lib ${EXTERNAL_LIBS})

View 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

View 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:&currentUnichar 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

View 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:&currentUnichar 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

View File

@@ -12,10 +12,6 @@
#include <stdexcept> #include <stdexcept>
#include <cassert> #include <cassert>
#ifdef X11_AVAILABLE
#include <GL/glx.h>
#endif
#include "opengl.h" #include "opengl.h"
#include "sdl_private.h" #include "sdl_private.h"
#include "noimpl.h" #include "noimpl.h"
@@ -143,227 +139,16 @@ void PlatformContextGl::makeCurrent() {
void PlatformContextGl::swapBuffers() { void PlatformContextGl::swapBuffers() {
SDL_GL_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}};
const char *getPlatformExtensions(const PlatformContextGl *pcgl) {
return "";
//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); void *getGlProcAddress(const char *procName) {
if(errorCode!=GDI_ERROR){ void* proc = SDL_GL_GetProcAddress(procName);
metrics.setWidth(i, static_cast<float>(glyphMetrics.gmCellIncX)); assert(proc!=NULL);
} return proc;
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); }}//end namespace
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

View 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

View 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