Skip to content

Commit

Permalink
Good GLEW/GLUT search. Sample to show the fonts
Browse files Browse the repository at this point in the history
I created a simple sample. And I created the cmake stuff to correctly
find and compile with GLUT & GLEW.
I tried to anticipate many situations where GLEW/GLUT install might lead
to a PITA. GLEW_LOCATION and GLUT_LOCATION are welcome to help this
sample to run.
  • Loading branch information
tlorach committed Dec 17, 2012
1 parent 0641e91 commit 76f8328
Show file tree
Hide file tree
Showing 17 changed files with 3,344 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ pip-log.txt

# Mac crap
.DS_Store

#specific to the project
cmake_built
65 changes: 65 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 2.8)

PROJECT( OpenGLText )

# Specify the list of directories to search for cmake modules.
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
)

set( CMAKE_PROGRAM_PATH "$ENV{PATH}")

if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set (ARCH "x64" CACHE STRING "CPU Architecture")
else ()
set (ARCH "x86" CACHE STRING "CPU Architecture")
endif()

set(EXECUTABLE_OUTPUT_PATH
${PROJECT_BINARY_DIR}/bin
CACHE PATH
"Directory where executables will be stored"
)

if(UNIX)
set(OS "linux")
add_definitions(-DLINUX)
else(UNIX)
if(APPLE)
else(APPLE)
if(WIN32)
set(OS "win")
add_definitions(-DNOMINMAX)
endif(WIN32)
endif(APPLE)
endif(UNIX)

# Macro for adding files close to the executable
macro(_copy_files_to_target target thefiles)
if(WIN32)
foreach (FFF ${thefiles} )
add_custom_command(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/${FFF}"
$<TARGET_FILE_DIR:${target}>
VERBATIM
)
endforeach()
endif()

endmacro()


find_package(OpenGL)
# ===============> GLUT
find_package(GLUT)
if(NOT GLUT_FOUND)
message(WARNING "Try to set GLUT_LOCATION")
endif()
# ===============> GLEW
if (NOT APPLE)
find_package(GLEW REQUIRED)
endif()

add_subdirectory(example)
2 changes: 1 addition & 1 deletion OpenGLText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# include "gl\glew.h"
//# include "logging.h"

#include "oglText.h"
#include "OpenGLText.h"
#include "tga.h"

#ifndef M_PI
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ __Few comments:__
* we must link against Freetype library to have it working. This is flexible, of course (becaude we can directly read any .ttf file...), but this is not appropriate for my goal : one might not want to link against freetype library if he targeted Android or iOS...
* The rendering loop... is not the efficient way to do. Each font is rendered separately. Our approach is to render almost everything in one single drawcall.

The basic idea behing this patch is to allow me to save a tga file made of the character I need with the right size. a binary file will be created, in which structures of Glyphs are stored.
The basic idea behind this patch is to allow me to save a tga file made of the character I need with the right size. a binary file will be created, in which structures of Glyphs are stored.
134 changes: 134 additions & 0 deletions cmake/FindGLEW.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#

# Try to find GLEW library and include path.
# Once done this will define
#
# GLEW_FOUND
# GLEW_INCLUDE_DIR
# GLEW_LIBRARY
# GLEW_SOURCE
#

include(FindPackageHandleStandardArgs)

if (WIN32)
find_path( GLEW_INCLUDE_DIR
NAMES
GL/glew.h
PATHS
${GLEW_LOCATION}/include
$ENV{GLEW_LOCATION}/include
$ENV{PROGRAMFILES}/GLEW/include
${PROJECT_SOURCE_DIR}/extern/glew/include
DOC "The directory where GL/glew.h resides" )
find_file( GLEW_SOURCE
NAMES
glew.c
PATHS
${GLEW_LOCATION}/src
$ENV{GLEW_LOCATION}/src
$ENV{PROGRAMFILES}/GLEW/src
${PROJECT_SOURCE_DIR}/extern/glew/src
DOC "The directory where GL/glew.c resides" )
if(ARCH STREQUAL "x86")
find_library( GLEW_LIBRARY
NAMES
glew GLEW glew32s glew32
PATHS
${GLEW_LOCATION}/lib
${GLEW_LOCATION}/lib/x86
${GLEW_LOCATION}/lib/win32
$ENV{GLEW_LOCATION}/lib
$ENV{GLEW_LOCATION}/lib/x86
$ENV{GLEW_LOCATION}/lib/win32
$ENV{PROGRAMFILES}/GLEW/lib
$ENV{PROGRAMFILES}/GLEW/lib/x86
$ENV{PROGRAMFILES}/GLEW/lib/win32
${PROJECT_SOURCE_DIR}/extern/glew/bin
${PROJECT_SOURCE_DIR}/extern/glew/lib
${PROJECT_SOURCE_DIR}/extern/glew/lib/x86
${PROJECT_SOURCE_DIR}/extern/glew/lib/win32
DOC "The GLEW library")
else()
find_library( GLEW_LIBRARY
NAMES
glew GLEW glew32s glew32
PATHS
${GLEW_LOCATION}/lib/x64
$ENV{GLEW_LOCATION}/lib/x64
$ENV{PROGRAMFILES}/GLEW/lib/x64
${PROJECT_SOURCE_DIR}/extern/glew/bin
${PROJECT_SOURCE_DIR}/extern/glew/lib/x64
${GLEW_LOCATION}/lib
$ENV{GLEW_LOCATION}/lib
$ENV{PROGRAMFILES}/GLEW/lib
${PROJECT_SOURCE_DIR}/extern/glew/lib
DOC "The GLEW library")
endif()
endif ()

if (${CMAKE_HOST_UNIX})
find_path( GLEW_INCLUDE_DIR
NAMES
GL/glew.h
PATHS
${GLEW_LOCATION}/include
$ENV{GLEW_LOCATION}/include
/usr/include
/usr/local/include
/sw/include
/opt/local/include
NO_DEFAULT_PATH
DOC "The directory where GL/glew.h resides"
)
find_library( GLEW_LIBRARY
NAMES
GLEW glew
PATHS
${GLEW_LOCATION}/lib
$ENV{GLEW_LOCATION}/lib
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
NO_DEFAULT_PATH
DOC "The GLEW library")
endif ()

if (GLEW_INCLUDE_DIR AND EXISTS "${GLEW_INCLUDE_DIR}/GL/glew.h")

file(STRINGS "${GLEW_INCLUDE_DIR}/GL/glew.h" GLEW_4_2 REGEX "^#define GL_VERSION_4_2.*$")
if (GLEW_4_2)
SET(OPENGL_4_2_FOUND TRUE)
else ()
message(WARNING
"glew-1.7.0 or newer needed for supporting OpenGL 4.2 dependent features"
)
endif ()

file(STRINGS "${GLEW_INCLUDE_DIR}/GL/glew.h" GLEW_4_3 REGEX "^#define GL_VERSION_4_3.*$")
if (GLEW_4_3)
SET(OPENGL_4_3_FOUND TRUE)
else ()
message(WARNING
"glew-1.9.0 or newer needed for supporting OpenGL 4.3 dependent features"
)
endif ()

endif ()

if(GLEW_SOURCE)
find_package_handle_standard_args(GLEW DEFAULT_MSG
GLEW_INCLUDE_DIR
GLEW_SOURCE
)
else()
find_package_handle_standard_args(GLEW DEFAULT_MSG
GLEW_INCLUDE_DIR
GLEW_LIBRARY
)
endif()

mark_as_advanced( GLEW_FOUND )
Loading

0 comments on commit 76f8328

Please sign in to comment.