diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2011-06-12 19:58:19 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2011-06-12 19:58:19 +0800 |
commit | 551a4712dbf26ebeaea093cb454c7181db8f1f55 (patch) | |
tree | df2898a147d196156ab4ab8af0b281baa0aadc72 | |
parent | 2a31330d1c1309f28abff02e922d5e1877720411 (diff) |
Make sdl, fontconfig, opengl and opengles all *really* optional
-rw-r--r-- | configure.ac | 20 | ||||
-rw-r--r-- | src/Makefile.am | 18 | ||||
-rw-r--r-- | src/gles-test.c | 9 | ||||
-rw-r--r-- | src/sdl-freetype-opengl.c | 2 | ||||
-rw-r--r-- | src/sdl-freetype-opengles.c | 2 | ||||
-rw-r--r-- | src/wrap-test.cpp | 22 |
6 files changed, 61 insertions, 12 deletions
diff --git a/configure.ac b/configure.ac index 00df885..61c5f47 100644 --- a/configure.ac +++ b/configure.ac @@ -145,11 +145,11 @@ AC_CHECK_FUNCS(FT_GlyphSlot_Embolden FT_Library_SetLcdFilter) dnl Check for SDL SDL_VERSION=1.2.4 -enable_sdl=auto +#enable_sdl=auto AC_ARG_ENABLE(sdl, AS_HELP_STRING([--enable-sdl], [build sdl renderer (sdl must be installed)]), - [enable_sdl=$enableval], [enable_sdl=no]) + [], []) if test "x$enable_sdl" != "xno"; then AM_PATH_SDL($SDL_VERSION, @@ -162,11 +162,10 @@ AM_CONDITIONAL(HAVE_SDL, test "x$have_sdl" = "xyes") CFLAGS="$CFLAGS $SDL_CFLAGS" LIBS="$LIBS $SDL_LIBS" -enable_fontconfig=auto +#enable_fontconfig=auto AC_ARG_ENABLE(fontconfig, AS_HELP_STRING([--enable-fontconfig], - [build sdl-ft (fontconfig must be installed)]), - [enable_fontconfig=$enableval], [enable_fontconfig=no]) + [build sdl-ft (fontconfig must be installed)])) if test "x$enable_fontconfig" != "xno"; then PKG_CHECK_MODULES(FONTCONFIG, fontconfig, @@ -174,15 +173,18 @@ if test "x$enable_fontconfig" != "xno"; then [have_fontconfig=no]) fi +if test "x$have_fontconfig" == x"yes"; then + AC_DEFINE_UNQUOTED(HAVE_FONTCONFIG, 1, [defined if you have fontconfig headers and library]) +fi AM_CONDITIONAL(HAVE_FONTCONFIG, test "x$have_fontconfig" = "xyes") SDL_FT_REQUIRES="fontconfig $SDL_FT_REQUIRES" SDL_FREETYPE_OPENGL_REQUIRES="sdl-freetype" -enable_opengl=auto +#enable_opengl=auto AC_ARG_ENABLE(opengl, AS_HELP_STRING([--enable-opengl], [build sdl-freetype-opengl (openl must be available)]), - [enable_opengl=$enableval], [enable_opengl=no]) + [], []) if test "x$enable_opengl" != "xno"; then AX_CHECK_GL @@ -194,12 +196,12 @@ if test "x$no_x" != x"yes"; then fi SDL_FREETYPE_OPENGLES_REQUIRES="sdl-freetype" -enable_opengles=auto +#enable_opengles=auto have_opengles=no AC_ARG_ENABLE(opengles, AS_HELP_STRING([--enable-opengles], [build sdl-freetype-opengles (opengles must be available)]), - [enable_opengles=$enableval], [enable_opengles=no]) + [], []) if test "x$enable_opengles" != "xno"; then AC_CHECK_HEADERS([EGL/egl.h GLES/gl.h]) diff --git a/src/Makefile.am b/src/Makefile.am index 78fb735..9f0cdca 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -66,9 +66,13 @@ libsdl_freetype_opengles_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined libsdl_freetype_opengles_la_CFLAGS = $(GLES_CFLAGS) $(AM_CFLAGS) if HAVE_SDL +if HAVE_FONTCONFIG sdl_test = sdl-test +endif if HAVE_OPENGL +if HAVE_FONTCONFIG sdl_opengl_test = sdl-opengl-test +endif wrap_test = wrap-test endif endif @@ -94,10 +98,20 @@ sdl_opengl_test_SOURCES = sdl-opengl-test.c sdl_opengl_test_LDADD = libsdl-freetype-opengl.la libsdl-ft.la gles_test_SOURCES = gles-test.c -gles_test_LDADD = libsdl-freetype-opengles.la libsdl-ft.la $(EGL_LIBS) +gles_test_LDADD = libsdl-freetype-opengles.la $(EGL_LIBS) +if HAVE_FONTCONFIG +gles_test_LDADD += libsdl-ft.la +else +gles_test_LDADD += libsdl-freetype.la +endif wrap_test_SOURCES = wrap-test.cpp -wrap_test_LDADD = libsdl-freetype-opengl.la libsdl-ft.la +wrap_test_LDADD = libsdl-freetype-opengl.la +if HAVE_FONTCONFIG +wrap_test_LDADD += libsdl-ft.la +else +wrap_test_LDADD += libsdl-freetype.la +endif lib_LTLIBRARIES = \ libsdl-freetype.la \ diff --git a/src/gles-test.c b/src/gles-test.c index 1f1aae5..35fd5de 100644 --- a/src/gles-test.c +++ b/src/gles-test.c @@ -7,7 +7,10 @@ #include <sdl-freetype.h> #include <sdl-freetype-opengles.h> + +#ifdef HAVE_FONTCONFIG #include <sdl-ft.h> +#endif #include <stdio.h> @@ -178,8 +181,14 @@ main(int argc, char *argv[]) if (!InitOpenGL(WIDTH, HEIGHT)) return -1; +#ifdef HAVE_FONTCONFIG font = sdl_ft_create_font ("sans", 12, SDL_FT_WEIGHT_NORMAL, SDL_FT_SLANT_NORMAL, 96); +#else + if (argc < 2) + return -1; + font = sdl_freetype_font_create(argv[1], 12 * 96 / 72.0); +#endif if (!font) goto errquit0; diff --git a/src/sdl-freetype-opengl.c b/src/sdl-freetype-opengl.c index d7fefe6..39e96d2 100644 --- a/src/sdl-freetype-opengl.c +++ b/src/sdl-freetype-opengl.c @@ -465,6 +465,8 @@ sdl_freetype_opengl_glyphs_render (sdl_freetype_font_t * font, glDisable (GL_BLEND); glBindTexture (GL_TEXTURE_2D, 0); + + glMatrixMode (GL_MODELVIEW); } if (cached != stack_cached) diff --git a/src/sdl-freetype-opengles.c b/src/sdl-freetype-opengles.c index c20e463..e81dc4d 100644 --- a/src/sdl-freetype-opengles.c +++ b/src/sdl-freetype-opengles.c @@ -460,6 +460,8 @@ sdl_freetype_opengles_glyphs_render (sdl_freetype_font_t * font, glDisable (GL_BLEND); glBindTexture (GL_TEXTURE_2D, 0); + + glMatrixMode (GL_MODELVIEW); } if (cached != stack_cached) diff --git a/src/wrap-test.cpp b/src/wrap-test.cpp index 80fff06..03df1db 100644 --- a/src/wrap-test.cpp +++ b/src/wrap-test.cpp @@ -4,7 +4,10 @@ #include <sdl-freetype.h> #include <sdl-freetype-opengl.h> + +#ifdef HAVE_FONTCONFIG #include <sdl-ft.h> +#endif #include <stdio.h> @@ -149,7 +152,7 @@ DrawText(sdl_freetype_font_t * font, int yoffset; if (lines.size()) - yoffset = exts.ascent >> 16; + yoffset = (exts.height - exts.descent) >> 16; for (size_t i = 0; i < lines.size(); i++) { TextLine &line = lines[i]; @@ -225,14 +228,27 @@ main(int argc, char *argv[]) if (!screen) goto errquit0; + //use following code to create a font if fontconfig isn't + //available. + //font = sdl_freetype_font_create("/path/to/font.ttf", + // pixel_size); +#ifdef HAVE_FONTCONFIG font = sdl_ft_create_font ("sans", 18, SDL_FT_WEIGHT_NORMAL, SDL_FT_SLANT_NORMAL, 96); +#else + if (argc < 2) + goto errquit0; + font = sdl_freetype_font_create(argv[1], 18 * 96 / 72.0); +#endif if (!font) goto errquit0; + //create a opengl font renderer render = sdl_freetype_opengl_render_create (); if (!render) goto errquit1; + + //replace the default font renderer with opengl one sdl_freetype_font_set_render (font, render); glMatrixMode (GL_PROJECTION) ; @@ -282,10 +298,12 @@ main(int argc, char *argv[]) int h; + // draw a single line and left aligned text h = DrawText(font, text, -1, &rect, TextFormat(TF_SINGLELINE | TF_LEFT), color); DrawRect(400, 100, 200, 100); DrawLine(400, 100 + h, 400 + 200, 100 + h); + // draw a multiple lines and left aligned text rect.x = 100; rect.y = 100; rect.width = 100; @@ -294,6 +312,7 @@ main(int argc, char *argv[]) DrawRect(100, 100, 200, 100); DrawLine(100, 100 + h, 100 + 200, 100 + h); + // draw a multiple lines and right aligned text rect.x = 100; rect.y = 200; rect.width = 200; @@ -302,6 +321,7 @@ main(int argc, char *argv[]) DrawRect(100, 200, 200, 100); DrawLine(100, 200 + h, 100 + 200, 200 + h); + // draw a multiple lines and center aligned text rect.x = 100; rect.y = 300; rect.width = 200; |