Index: /orxonox/trunk/config.h.in
===================================================================
--- /orxonox/trunk/config.h.in	(revision 3456)
+++ /orxonox/trunk/config.h.in	(revision 3457)
@@ -59,4 +59,7 @@
 #undef HAVE_SDL_SDL_IMAGE_H
 
+/* Define to 1 if you have the <SDL/SDL_ttf.h> header file. */
+#undef HAVE_SDL_SDL_TTF_H
+
 /* Define to 1 if you have the `sqrt' function. */
 #undef HAVE_SQRT
Index: /orxonox/trunk/configure
===================================================================
--- /orxonox/trunk/configure	(revision 3456)
+++ /orxonox/trunk/configure	(revision 3457)
@@ -6280,4 +6280,237 @@
         echo "SDL_image library not found."
 	echo "please install the SDL_image library, which can be found at http://www.libsdl.org/projects/SDL_image/"
+        echo "------------------"
+        exit -1
+     fi
+fi
+
+#---------#
+# SDL_ttf #
+#---------#
+def_sdl_ttf=yes
+# checking for SDL_ttf-headers
+
+for ac_header in SDL/SDL_ttf.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+else
+  # Is the header compilable?
+echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_header_compiler=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_header_compiler=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6
+
+# Is the header present?
+echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <$ac_header>
+_ACEOF
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } >/dev/null; then
+  if test -s conftest.err; then
+    ac_cpp_err=$ac_c_preproc_warn_flag
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
+  else
+    ac_cpp_err=
+  fi
+else
+  ac_cpp_err=yes
+fi
+if test -z "$ac_cpp_err"; then
+  ac_header_preproc=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+  ac_header_preproc=no
+fi
+rm -f conftest.err conftest.$ac_ext
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6
+
+# So?  What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+  yes:no: )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+    ac_header_preproc=yes
+    ;;
+  no:yes:* )
+    { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header:     check for missing prerequisite headers?" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header:     section \"Present But Cannot Be Compiled\"" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+    { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+    (
+      cat <<\_ASBOX
+## ---------------------------------------------- ##
+## Report this to orxonox-dev at mail.datacore.ch ##
+## ---------------------------------------------- ##
+_ASBOX
+    ) |
+      sed "s/^/$as_me: WARNING:     /" >&2
+    ;;
+esac
+echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6
+if eval "test \"\${$as_ac_Header+set}\" = set"; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  eval "$as_ac_Header=\$ac_header_preproc"
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+
+else
+  echo "sdl_ttf not found."; def_sdl_ttf=no
+fi
+
+done
+
+
+if test x$def_sdl_ttf = xyes; then
+# checking for SDL_ttf-lib
+  echo "$as_me:$LINENO: checking for main in -lSDL_ttf" >&5
+echo $ECHO_N "checking for main in -lSDL_ttf... $ECHO_C" >&6
+if test "${ac_cv_lib_SDL_ttf_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lSDL_ttf  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_SDL_ttf_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_SDL_ttf_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_SDL_ttf_main" >&5
+echo "${ECHO_T}$ac_cv_lib_SDL_ttf_main" >&6
+if test $ac_cv_lib_SDL_ttf_main = yes; then
+  FOUND_SDL_ttf=yes
+fi
+
+     if test x$FOUND_SDL_ttf = xyes ; then
+       LIBS="$LIBS -lSDL_ttf"
+     else
+        echo "------------------"
+        echo "SDL_ttf library not found."
+	echo "please install the SDL_ttf library, which can be found at http://www.libsdl.org/projects/SDL_ttf/"
         echo "------------------"
         exit -1
Index: /orxonox/trunk/configure.ac
===================================================================
--- /orxonox/trunk/configure.ac	(revision 3456)
+++ /orxonox/trunk/configure.ac	(revision 3457)
@@ -388,4 +388,26 @@
 fi
 
+#---------#
+# SDL_ttf #
+#---------#
+def_sdl_ttf=yes
+# checking for SDL_ttf-headers
+  AC_CHECK_HEADERS([SDL/SDL_ttf.h] ,,
+      [echo "sdl_ttf not found."; def_sdl_ttf=no ])
+
+if test x$def_sdl_ttf = xyes; then
+# checking for SDL_ttf-lib
+  AC_CHECK_LIB([SDL_ttf], [main], [FOUND_SDL_ttf=yes])
+     if test x$FOUND_SDL_ttf = xyes ; then
+       LIBS="$LIBS -lSDL_ttf"
+     else
+        echo "------------------"
+        echo "SDL_ttf library not found."
+	echo "please install the SDL_ttf library, which can be found at http://www.libsdl.org/projects/SDL_ttf/"
+        echo "------------------"
+        exit -1
+     fi   
+fi
+
 ## case no SDL-image:
 if test x$def_sdl_image = xno; then
Index: /orxonox/trunk/src/Makefile.am
===================================================================
--- /orxonox/trunk/src/Makefile.am	(revision 3456)
+++ /orxonox/trunk/src/Makefile.am	(revision 3457)
@@ -39,5 +39,6 @@
 		 skysphere.cc \
 		 light.cc \
-		 sfont/fontset.cc 
+		 sfont/fontset.cc \
+		 sfont/glfont.c
 
 noinst_HEADERS = ability.h \
Index: /orxonox/trunk/src/Makefile.in
===================================================================
--- /orxonox/trunk/src/Makefile.in	(revision 3456)
+++ /orxonox/trunk/src/Makefile.in	(revision 3457)
@@ -64,5 +64,6 @@
 	helper_parent.$(OBJEXT) track_manager.$(OBJEXT) \
 	matrix.$(OBJEXT) curve.$(OBJEXT) glmenu_imagescreen.$(OBJEXT) \
-	skysphere.$(OBJEXT) light.$(OBJEXT) fontset.$(OBJEXT)
+	skysphere.$(OBJEXT) light.$(OBJEXT) fontset.$(OBJEXT) \
+	glfont.$(OBJEXT)
 orxonox_OBJECTS = $(am_orxonox_OBJECTS)
 orxonox_LDADD = $(LDADD)
@@ -77,5 +78,5 @@
 @AMDEP_TRUE@	./$(DEPDIR)/data_tank.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/environment.Po ./$(DEPDIR)/fontset.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/game_loader.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/game_loader.Po ./$(DEPDIR)/glfont.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/glmenu_imagescreen.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/helper_parent.Po \
@@ -90,4 +91,8 @@
 @AMDEP_TRUE@	./$(DEPDIR)/track_manager.Po ./$(DEPDIR)/vector.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/world.Po ./$(DEPDIR)/world_entity.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
 CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
@@ -249,5 +254,6 @@
 		 skysphere.cc \
 		 light.cc \
-		 sfont/fontset.cc 
+		 sfont/fontset.cc \
+		 sfont/glfont.c
 
 noinst_HEADERS = ability.h \
@@ -311,5 +317,5 @@
 
 .SUFFIXES:
-.SUFFIXES: .cc .o .obj
+.SUFFIXES: .c .cc .o .obj
 $(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
 	@for dep in $?; do \
@@ -386,4 +392,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fontset.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game_loader.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glfont.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glmenu_imagescreen.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/helper_parent.Po@am__quote@
@@ -407,4 +414,36 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/world.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/world_entity.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+glfont.o: sfont/glfont.c
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT glfont.o -MD -MP -MF "$(DEPDIR)/glfont.Tpo" -c -o glfont.o `test -f 'sfont/glfont.c' || echo '$(srcdir)/'`sfont/glfont.c; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/glfont.Tpo" "$(DEPDIR)/glfont.Po"; else rm -f "$(DEPDIR)/glfont.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='sfont/glfont.c' object='glfont.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/glfont.Po' tmpdepfile='$(DEPDIR)/glfont.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o glfont.o `test -f 'sfont/glfont.c' || echo '$(srcdir)/'`sfont/glfont.c
+
+glfont.obj: sfont/glfont.c
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT glfont.obj -MD -MP -MF "$(DEPDIR)/glfont.Tpo" -c -o glfont.obj `if test -f 'sfont/glfont.c'; then $(CYGPATH_W) 'sfont/glfont.c'; else $(CYGPATH_W) '$(srcdir)/sfont/glfont.c'; fi`; \
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/glfont.Tpo" "$(DEPDIR)/glfont.Po"; else rm -f "$(DEPDIR)/glfont.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='sfont/glfont.c' object='glfont.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/glfont.Po' tmpdepfile='$(DEPDIR)/glfont.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o glfont.obj `if test -f 'sfont/glfont.c'; then $(CYGPATH_W) 'sfont/glfont.c'; else $(CYGPATH_W) '$(srcdir)/sfont/glfont.c'; fi`
 
 .cc.o:
Index: /orxonox/trunk/src/sfont/glfont.c
===================================================================
--- /orxonox/trunk/src/sfont/glfont.c	(revision 3457)
+++ /orxonox/trunk/src/sfont/glfont.c	(revision 3457)
@@ -0,0 +1,443 @@
+/* 
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+
+   ***
+   * This file is extended to the needs of the orxonox-project.         *
+   * the Copyright of the original file is below this copyright         *
+   *                                                                  ***
+
+*/
+
+/*
+    glfont:  An example of using the SDL_ttf library with OpenGL.
+    Copyright (C) 1997-2004 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The SDL_GL_* functions in this file are available in the public domain.
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+/* $Id: glfont.c,v 1.6 2004/01/04 17:41:55 slouken Exp $ */
+
+/* A simple program to test the text rendering feature of the TTF library */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+
+#include "../glincl.h"
+
+#define DEFAULT_PTSIZE	18
+#define DEFAULT_TEXT	"orxonox 1234567890"
+#define NUM_COLORS      256
+
+static char *Usage =
+"Usage: %s [-utf8|-unicode] [-b] [-i] [-u] [-fgcol r,g,b] [-bgcol r,g,b] \
+<font>.ttf [ptsize] [text]\n";
+
+void SDL_GL_Enter2DMode()
+{
+	SDL_Surface *screen = SDL_GetVideoSurface();
+
+	/* Note, there may be other things you need to change,
+	   depending on how you have your OpenGL state set up.
+	*/
+	glPushAttrib(GL_ENABLE_BIT);
+	glDisable(GL_DEPTH_TEST);
+	glDisable(GL_CULL_FACE);
+	glEnable(GL_TEXTURE_2D);
+
+	/* This allows alpha blending of 2D textures with the scene */
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+	glViewport(0, 0, screen->w, screen->h);
+
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadIdentity();
+
+	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+}
+
+void SDL_GL_Leave2DMode()
+{
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glMatrixMode(GL_PROJECTION);
+	glPopMatrix();
+
+	glPopAttrib();
+}
+
+/* Quick utility function for texture creation */
+static int power_of_two(int input)
+{
+	int value = 1;
+
+	while ( value < input ) {
+		value <<= 1;
+	}
+	return value;
+}
+
+GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
+{
+	GLuint texture;
+	int w, h;
+	SDL_Surface *image;
+	SDL_Rect area;
+	Uint32 saved_flags;
+	Uint8  saved_alpha;
+
+	/* Use the surface width and height expanded to powers of 2 */
+	w = power_of_two(surface->w);
+	h = power_of_two(surface->h);
+	texcoord[0] = 0.0f;			/* Min X */
+	texcoord[1] = 0.0f;			/* Min Y */
+	texcoord[2] = (GLfloat)surface->w / w;	/* Max X */
+	texcoord[3] = (GLfloat)surface->h / h;	/* Max Y */
+
+	image = SDL_CreateRGBSurface(
+			SDL_SWSURFACE,
+			w, h,
+			32,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
+			0x000000FF, 
+			0x0000FF00, 
+			0x00FF0000, 
+			0xFF000000
+#else
+			0xFF000000,
+			0x00FF0000, 
+			0x0000FF00, 
+			0x000000FF
+#endif
+		       );
+	if ( image == NULL ) {
+		return 0;
+	}
+
+	/* Save the alpha blending attributes */
+	saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
+	saved_alpha = surface->format->alpha;
+	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+		SDL_SetAlpha(surface, 0, 0);
+	}
+
+	/* Copy the surface into the GL texture image */
+	area.x = 0;
+	area.y = 0;
+	area.w = surface->w;
+	area.h = surface->h;
+	SDL_BlitSurface(surface, &area, image, &area);
+
+	/* Restore the alpha blending attributes */
+	if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
+		SDL_SetAlpha(surface, saved_flags, saved_alpha);
+	}
+
+	/* Create an OpenGL texture for the image */
+	glGenTextures(1, &texture);
+	glBindTexture(GL_TEXTURE_2D, texture);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexImage2D(GL_TEXTURE_2D,
+		     0,
+		     GL_RGBA,
+		     w, h,
+		     0,
+		     GL_RGBA,
+		     GL_UNSIGNED_BYTE,
+		     image->pixels);
+	SDL_FreeSurface(image); /* No longer needed */
+
+	return texture;
+}
+
+int setup(int argc, char *argv[])
+{
+	char *argv0 = argv[0];
+	SDL_Surface *screen;
+	TTF_Font *font;
+	SDL_Surface *text;
+	int ptsize;
+	int i, done;
+	SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
+	SDL_Color black = { 0x00, 0x00, 0x00, 0 };
+	SDL_Color *forecol;
+	SDL_Color *backcol;
+	GLenum gl_error;
+	GLuint texture;
+	int x, y, w, h;
+	GLfloat texcoord[4];
+	GLfloat texMinX, texMinY;
+	GLfloat texMaxX, texMaxY;
+
+	int renderstyle;
+	int dump;
+	enum {
+		RENDER_LATIN1,
+		RENDER_UTF8,
+		RENDER_UNICODE
+	} rendertype;
+	char *message;
+
+	/* Look for special execution mode */
+	dump = 0;
+	/* Look for special rendering types */
+	renderstyle = TTF_STYLE_NORMAL;
+	rendertype = RENDER_LATIN1;
+	/* Default is black and white */
+	forecol = &black;
+	backcol = &white;
+	for ( i=1; argv[i] && argv[i][0] == '-'; ++i ) {
+		if ( strcmp(argv[i], "-utf8") == 0 ) {
+			rendertype = RENDER_UTF8;
+		} else
+		if ( strcmp(argv[i], "-unicode") == 0 ) {
+			rendertype = RENDER_UNICODE;
+		} else
+		if ( strcmp(argv[i], "-b") == 0 ) {
+			renderstyle |= TTF_STYLE_BOLD;
+		} else
+		if ( strcmp(argv[i], "-i") == 0 ) {
+			renderstyle |= TTF_STYLE_ITALIC;
+		} else
+		if ( strcmp(argv[i], "-u") == 0 ) {
+			renderstyle |= TTF_STYLE_UNDERLINE;
+		} else
+		if ( strcmp(argv[i], "-dump") == 0 ) {
+			dump = 1;
+		} else
+		if ( strcmp(argv[i], "-fgcol") == 0 ) {
+			int r, g, b;
+			if ( sscanf (argv[++i], "%d,%d,%d", &r, &g, &b) != 3 ) {
+				fprintf(stderr, Usage, argv0);
+				return(1);
+			}
+			forecol->r = (Uint8)r;
+			forecol->g = (Uint8)g;
+			forecol->b = (Uint8)b;
+		} else
+		if ( strcmp(argv[i], "-bgcol") == 0 ) {
+			int r, g, b;
+			if ( sscanf (argv[++i], "%d,%d,%d", &r, &g, &b) != 3 ) {
+				fprintf(stderr, Usage, argv0);
+				return(1);
+			}
+			backcol->r = (Uint8)r;
+			backcol->g = (Uint8)g;
+			backcol->b = (Uint8)b;
+		} else {
+			fprintf(stderr, Usage, argv0);
+			return(1);
+		}
+	}
+	argv += i;
+	argc -= i;
+
+	/* Check usage */
+	if ( ! argv[0] ) {
+		fprintf(stderr, Usage, argv0);
+		return(1);
+	}
+
+	/* Initialize SDL */
+	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+		return(2);
+	}
+	atexit(SDL_Quit);
+
+	/* Initialize the TTF library */
+	if ( TTF_Init() < 0 ) {
+		fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
+		return(2);
+	}
+	atexit(TTF_Quit);
+
+	/* Open the font file with the requested point size */
+	ptsize = 0;
+	if ( argc > 1 ) {
+		ptsize = atoi(argv[1]);
+	}
+	if ( ptsize == 0 ) {
+		i = 2;
+		ptsize = DEFAULT_PTSIZE;
+	} else {
+		i = 3;
+	}
+	font = TTF_OpenFont(argv[0], ptsize);
+	if ( font == NULL ) {
+		fprintf(stderr, "Couldn't load %d pt font from %s: %s\n",
+					ptsize, argv[0], SDL_GetError());
+		return(2);
+	}
+	TTF_SetFontStyle(font, renderstyle);
+
+	if( dump ) {
+
+		for( i = 48; i < 123; i++ ) {
+			SDL_Surface* glyph = NULL;
+
+			glyph = TTF_RenderGlyph_Shaded( font, i, *forecol, *backcol );
+
+			if( glyph ) {
+				char outname[64];
+				sprintf( outname, "glyph-%d.bmp", i );
+				SDL_SaveBMP( glyph, outname );
+			}
+
+		}
+
+		return( 0 );
+	}
+
+	/* Set a 640x480 video mode */
+	screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
+	if ( screen == NULL ) {
+		fprintf(stderr, "Couldn't set 640x480 OpenGL mode: %s\n",
+							SDL_GetError());
+		return(2);
+	}
+
+	/* Render and center the message */
+	if ( argc > 2 ) {
+		message = argv[2];
+	} else {
+		message = DEFAULT_TEXT;
+	}
+	switch (rendertype) {
+	    case RENDER_LATIN1:
+		text = TTF_RenderText_Blended(font, message, *forecol);
+		break;
+
+	    case RENDER_UTF8:
+		text = TTF_RenderUTF8_Blended(font, message, *forecol);
+		break;
+
+	    case RENDER_UNICODE:
+		{
+			/* This doesn't actually work because you can't pass
+			   UNICODE text in via command line, AFAIK, but...
+			 */
+			Uint16 unicode_text[BUFSIZ];
+			int index;
+			for ( index = 0; (message[0] || message[1]); ++index ) {
+				unicode_text[index]  = ((Uint8 *)message)[0];
+				unicode_text[index] <<= 8;
+				unicode_text[index] |= ((Uint8 *)message)[1];
+				message += 2;
+			}
+			text = TTF_RenderUNICODE_Blended(font,
+					unicode_text, *forecol);
+		}
+		break;
+	    default:
+		text = NULL; /* This shouldn't happen */
+		break;
+	}
+	if ( text == NULL ) {
+		fprintf(stderr, "Couldn't render text: %s\n", SDL_GetError());
+		TTF_CloseFont(font);
+		return(2);
+	}
+	x = (screen->w - text->w)/2;
+	y = (screen->h - text->h)/2;
+	w = text->w;
+	h = text->h;
+	printf("Font is generally %d big, and string is %hd big\n",
+						TTF_FontHeight(font), text->h);
+
+	/* Convert the text into an OpenGL texture */
+	glGetError();
+	texture = SDL_GL_LoadTexture(text, texcoord);
+	if ( (gl_error = glGetError()) != GL_NO_ERROR ) {
+		/* If this failed, the text may exceed texture size limits */
+		printf("Warning: Couldn't create texture: 0x%x\n", gl_error);
+	}
+
+	/* Make texture coordinates easy to understand */
+	texMinX = texcoord[0];
+	texMinY = texcoord[1];
+	texMaxX = texcoord[2];
+	texMaxY = texcoord[3];
+
+	/* We don't need the original text surface anymore */
+	SDL_FreeSurface(text);
+
+	/* Initialize the GL state */
+	glViewport( 0, 0, screen->w, screen->h );
+	glMatrixMode( GL_PROJECTION );
+	glLoadIdentity( );
+
+	glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 );
+
+	glMatrixMode( GL_MODELVIEW );
+	glLoadIdentity( );
+
+	glEnable(GL_DEPTH_TEST);
+
+	glDepthFunc(GL_LESS);
+
+	glShadeModel(GL_SMOOTH);
+
+	/* Wait for a keystroke, and blit text on mouse press */
+	done = 0;
+	while ( ! done ) {
+
+	  /* Show the text on the screen */
+	  SDL_GL_Enter2DMode();
+	  glBindTexture(GL_TEXTURE_2D, texture);
+	  glBegin(GL_QUADS);
+	  glTexCoord2f(texMinX, texMinY); glVertex2i(x,   y  );
+	  glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y  );
+	  glTexCoord2f(texMinX, texMaxY); glVertex2i(x,   y+h);
+	  glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h);
+	  glEnd();
+	  SDL_GL_Leave2DMode();
+	  
+	  /* Swap the buffers so everything is visible */
+	  SDL_GL_SwapBuffers( );
+	}
+	TTF_CloseFont(font);
+	return(0);
+}
+
