- Timestamp:
- Mar 30, 2005, 9:14:35 PM (20 years ago)
- Location:
- orxonox/branches/textEngine
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/configure
r3681 r3682 6106 6106 ## CHECKING FOR HEADERS AND LIBS ## 6107 6107 ################################### 6108 6109 #-----------# 6110 # SDL_Image # 6111 #-----------# 6112 #if test x$def_sdl_image = xyes; then 6113 # checking for SDL_image-headers 6114 6115 for ac_header in SDL/SDL_ttf.h 6116 do 6117 as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` 6118 if eval "test \"\${$as_ac_Header+set}\" = set"; then 6119 echo "$as_me:$LINENO: checking for $ac_header" >&5 6120 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 6121 if eval "test \"\${$as_ac_Header+set}\" = set"; then 6122 echo $ECHO_N "(cached) $ECHO_C" >&6 6123 fi 6124 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 6125 echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 6126 else 6127 # Is the header compilable? 6128 echo "$as_me:$LINENO: checking $ac_header usability" >&5 6129 echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6 6130 cat >conftest.$ac_ext <<_ACEOF 6131 /* confdefs.h. */ 6132 _ACEOF 6133 cat confdefs.h >>conftest.$ac_ext 6134 cat >>conftest.$ac_ext <<_ACEOF 6135 /* end confdefs.h. */ 6136 $ac_includes_default 6137 #include <$ac_header> 6138 _ACEOF 6139 rm -f conftest.$ac_objext 6140 if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 6141 (eval $ac_compile) 2>conftest.er1 6142 ac_status=$? 6143 grep -v '^ *+' conftest.er1 >conftest.err 6144 rm -f conftest.er1 6145 cat conftest.err >&5 6146 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6147 (exit $ac_status); } && 6148 { ac_try='test -z "$ac_c_werror_flag" 6149 || test ! -s conftest.err' 6150 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6151 (eval $ac_try) 2>&5 6152 ac_status=$? 6153 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6154 (exit $ac_status); }; } && 6155 { ac_try='test -s conftest.$ac_objext' 6156 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6157 (eval $ac_try) 2>&5 6158 ac_status=$? 6159 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6160 (exit $ac_status); }; }; then 6161 ac_header_compiler=yes 6162 else 6163 echo "$as_me: failed program was:" >&5 6164 sed 's/^/| /' conftest.$ac_ext >&5 6165 6166 ac_header_compiler=no 6167 fi 6168 rm -f conftest.err conftest.$ac_objext conftest.$ac_ext 6169 echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 6170 echo "${ECHO_T}$ac_header_compiler" >&6 6171 6172 # Is the header present? 6173 echo "$as_me:$LINENO: checking $ac_header presence" >&5 6174 echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6 6175 cat >conftest.$ac_ext <<_ACEOF 6176 /* confdefs.h. */ 6177 _ACEOF 6178 cat confdefs.h >>conftest.$ac_ext 6179 cat >>conftest.$ac_ext <<_ACEOF 6180 /* end confdefs.h. */ 6181 #include <$ac_header> 6182 _ACEOF 6183 if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 6184 (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 6185 ac_status=$? 6186 grep -v '^ *+' conftest.er1 >conftest.err 6187 rm -f conftest.er1 6188 cat conftest.err >&5 6189 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6190 (exit $ac_status); } >/dev/null; then 6191 if test -s conftest.err; then 6192 ac_cpp_err=$ac_c_preproc_warn_flag 6193 ac_cpp_err=$ac_cpp_err$ac_c_werror_flag 6194 else 6195 ac_cpp_err= 6196 fi 6197 else 6198 ac_cpp_err=yes 6199 fi 6200 if test -z "$ac_cpp_err"; then 6201 ac_header_preproc=yes 6202 else 6203 echo "$as_me: failed program was:" >&5 6204 sed 's/^/| /' conftest.$ac_ext >&5 6205 6206 ac_header_preproc=no 6207 fi 6208 rm -f conftest.err conftest.$ac_ext 6209 echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 6210 echo "${ECHO_T}$ac_header_preproc" >&6 6211 6212 # So? What about this header? 6213 case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in 6214 yes:no: ) 6215 { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 6216 echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} 6217 { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 6218 echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} 6219 ac_header_preproc=yes 6220 ;; 6221 no:yes:* ) 6222 { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 6223 echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} 6224 { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 6225 echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} 6226 { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 6227 echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} 6228 { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 6229 echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} 6230 { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 6231 echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} 6232 { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 6233 echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} 6234 ( 6235 cat <<\_ASBOX 6236 ## ---------------------------------------------- ## 6237 ## Report this to orxonox-dev at mail.datacore.ch ## 6238 ## ---------------------------------------------- ## 6239 _ASBOX 6240 ) | 6241 sed "s/^/$as_me: WARNING: /" >&2 6242 ;; 6243 esac 6244 echo "$as_me:$LINENO: checking for $ac_header" >&5 6245 echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6 6246 if eval "test \"\${$as_ac_Header+set}\" = set"; then 6247 echo $ECHO_N "(cached) $ECHO_C" >&6 6248 else 6249 eval "$as_ac_Header=\$ac_header_preproc" 6250 fi 6251 echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_Header'}'`" >&5 6252 echo "${ECHO_T}`eval echo '${'$as_ac_Header'}'`" >&6 6253 6254 fi 6255 if test `eval echo '${'$as_ac_Header'}'` = yes; then 6256 cat >>confdefs.h <<_ACEOF 6257 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 6258 _ACEOF 6259 6260 else 6261 echo "sdl_ttf not found. falling back to other options"; def_sdl_ttf=no 6262 fi 6263 6264 done 6265 6266 #fi 6267 #if test x$def_sdl_ttf = xyes; then 6268 # checking for SDL_ttf-lib 6269 echo "$as_me:$LINENO: checking for main in -lSDL_ttf" >&5 6270 echo $ECHO_N "checking for main in -lSDL_ttf... $ECHO_C" >&6 6271 if test "${ac_cv_lib_SDL_ttf_main+set}" = set; then 6272 echo $ECHO_N "(cached) $ECHO_C" >&6 6273 else 6274 ac_check_lib_save_LIBS=$LIBS 6275 LIBS="-lSDL_ttf $LIBS" 6276 cat >conftest.$ac_ext <<_ACEOF 6277 /* confdefs.h. */ 6278 _ACEOF 6279 cat confdefs.h >>conftest.$ac_ext 6280 cat >>conftest.$ac_ext <<_ACEOF 6281 /* end confdefs.h. */ 6282 6283 6284 int 6285 main () 6286 { 6287 main (); 6288 ; 6289 return 0; 6290 } 6291 _ACEOF 6292 rm -f conftest.$ac_objext conftest$ac_exeext 6293 if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 6294 (eval $ac_link) 2>conftest.er1 6295 ac_status=$? 6296 grep -v '^ *+' conftest.er1 >conftest.err 6297 rm -f conftest.er1 6298 cat conftest.err >&5 6299 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6300 (exit $ac_status); } && 6301 { ac_try='test -z "$ac_c_werror_flag" 6302 || test ! -s conftest.err' 6303 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6304 (eval $ac_try) 2>&5 6305 ac_status=$? 6306 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6307 (exit $ac_status); }; } && 6308 { ac_try='test -s conftest$ac_exeext' 6309 { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 6310 (eval $ac_try) 2>&5 6311 ac_status=$? 6312 echo "$as_me:$LINENO: \$? = $ac_status" >&5 6313 (exit $ac_status); }; }; then 6314 ac_cv_lib_SDL_ttf_main=yes 6315 else 6316 echo "$as_me: failed program was:" >&5 6317 sed 's/^/| /' conftest.$ac_ext >&5 6318 6319 ac_cv_lib_SDL_ttf_main=no 6320 fi 6321 rm -f conftest.err conftest.$ac_objext \ 6322 conftest$ac_exeext conftest.$ac_ext 6323 LIBS=$ac_check_lib_save_LIBS 6324 fi 6325 echo "$as_me:$LINENO: result: $ac_cv_lib_SDL_ttf_main" >&5 6326 echo "${ECHO_T}$ac_cv_lib_SDL_ttf_main" >&6 6327 if test $ac_cv_lib_SDL_ttf_main = yes; then 6328 FOUND_SDL_ttf=yes 6329 fi 6330 6331 if test x$FOUND_SDL_ttf = xyes ; then 6332 LIBS="$LIBS -lSDL_ttf" 6333 else 6334 echo "------------------" 6335 echo "SDL_ttf library not found." 6336 echo "please install the SDL_ttf library, which can be found at http://www.libsdl.org/projects/SDL_ttf/" 6337 echo "------------------" 6338 exit -1 6339 fi 6340 #fi 6341 6108 6342 6109 6343 #-----------# -
orxonox/branches/textEngine/configure.ac
r3681 r3682 401 401 # SDL_Image # 402 402 #-----------# 403 #if test x$def_sdl_ttf = xyes; then 404 # checking for SDL_ttf-headers 405 AC_CHECK_HEADERS([SDL/SDL_ttf.h] ,, 406 [echo "sdl_ttf not found. falling back to other options"; def_sdl_ttf=no ]) 407 #fi 408 #if test x$def_sdl_ttf = xyes; then 409 # checking for SDL_ttf-lib 410 AC_CHECK_LIB([SDL_ttf], [main], [FOUND_SDL_ttf=yes]) 411 if test x$FOUND_SDL_ttf = xyes ; then 412 LIBS="$LIBS -lSDL_ttf" 413 else 414 echo "------------------" 415 echo "SDL_ttf library not found." 416 echo "please install the SDL_ttf library, which can be found at http://www.libsdl.org/projects/SDL_ttf/" 417 echo "------------------" 418 exit -1 419 fi 420 #fi 421 422 423 #-----------# 424 # SDL_Image # 425 #-----------# 403 426 if test x$def_sdl_image = xyes; then 404 427 # checking for SDL_image-headers -
orxonox/branches/textEngine/src/Makefile.am
r3681 r3682 56 56 lib/graphics/light.cc \ 57 57 lib/graphics/font/fontset.cc \ 58 lib/graphics/font/glfont.cc \ 58 59 lib/graphics/importer/array.cc \ 59 60 lib/graphics/importer/objModel.cc \ … … 110 111 lib/graphics/graphics_engine.h \ 111 112 lib/graphics/light.h \ 113 lib/graphics/font/glfont.h \ 112 114 lib/graphics/font/fontset.h \ 113 115 lib/data/data_tank.h \ -
orxonox/branches/textEngine/src/Makefile.in
r3681 r3682 64 64 null_parent.$(OBJEXT) helper_parent.$(OBJEXT) \ 65 65 data_tank.$(OBJEXT) graphics_engine.$(OBJEXT) light.$(OBJEXT) \ 66 fontset.$(OBJEXT) array.$(OBJEXT) objModel.$(OBJEXT) \ 67 primitive_model.$(OBJEXT) model.$(OBJEXT) material.$(OBJEXT) \ 68 texture.$(OBJEXT) base_entity.$(OBJEXT) base_object.$(OBJEXT) \ 69 ini_parser.$(OBJEXT) list.$(OBJEXT) resource_manager.$(OBJEXT) \ 70 vector.$(OBJEXT) curve.$(OBJEXT) glmenu_imagescreen.$(OBJEXT) 66 fontset.$(OBJEXT) glfont.$(OBJEXT) array.$(OBJEXT) \ 67 objModel.$(OBJEXT) primitive_model.$(OBJEXT) model.$(OBJEXT) \ 68 material.$(OBJEXT) texture.$(OBJEXT) base_entity.$(OBJEXT) \ 69 base_object.$(OBJEXT) ini_parser.$(OBJEXT) list.$(OBJEXT) \ 70 resource_manager.$(OBJEXT) vector.$(OBJEXT) curve.$(OBJEXT) \ 71 glmenu_imagescreen.$(OBJEXT) 71 72 orxonox_OBJECTS = $(am_orxonox_OBJECTS) 72 73 orxonox_LDADD = $(LDADD) … … 84 85 @AMDEP_TRUE@ ./$(DEPDIR)/game_loader.Po \ 85 86 @AMDEP_TRUE@ ./$(DEPDIR)/garbage_collector.Po \ 87 @AMDEP_TRUE@ ./$(DEPDIR)/glfont.Po \ 86 88 @AMDEP_TRUE@ ./$(DEPDIR)/glmenu_imagescreen.Po \ 87 89 @AMDEP_TRUE@ ./$(DEPDIR)/graphics_engine.Po \ … … 262 264 lib/graphics/light.cc \ 263 265 lib/graphics/font/fontset.cc \ 266 lib/graphics/font/glfont.cc \ 264 267 lib/graphics/importer/array.cc \ 265 268 lib/graphics/importer/objModel.cc \ … … 316 319 lib/graphics/graphics_engine.h \ 317 320 lib/graphics/light.h \ 321 lib/graphics/font/glfont.h \ 318 322 lib/graphics/font/fontset.h \ 319 323 lib/data/data_tank.h \ … … 419 423 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/game_loader.Po@am__quote@ 420 424 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/garbage_collector.Po@am__quote@ 425 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glfont.Po@am__quote@ 421 426 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glmenu_imagescreen.Po@am__quote@ 422 427 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/graphics_engine.Po@am__quote@ … … 784 789 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 785 790 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o fontset.obj `if test -f 'lib/graphics/font/fontset.cc'; then $(CYGPATH_W) 'lib/graphics/font/fontset.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/font/fontset.cc'; fi` 791 792 glfont.o: lib/graphics/font/glfont.cc 793 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT glfont.o -MD -MP -MF "$(DEPDIR)/glfont.Tpo" -c -o glfont.o `test -f 'lib/graphics/font/glfont.cc' || echo '$(srcdir)/'`lib/graphics/font/glfont.cc; \ 794 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/glfont.Tpo" "$(DEPDIR)/glfont.Po"; else rm -f "$(DEPDIR)/glfont.Tpo"; exit 1; fi 795 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='lib/graphics/font/glfont.cc' object='glfont.o' libtool=no @AMDEPBACKSLASH@ 796 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/glfont.Po' tmpdepfile='$(DEPDIR)/glfont.TPo' @AMDEPBACKSLASH@ 797 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 798 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o glfont.o `test -f 'lib/graphics/font/glfont.cc' || echo '$(srcdir)/'`lib/graphics/font/glfont.cc 799 800 glfont.obj: lib/graphics/font/glfont.cc 801 @am__fastdepCXX_TRUE@ if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT glfont.obj -MD -MP -MF "$(DEPDIR)/glfont.Tpo" -c -o glfont.obj `if test -f 'lib/graphics/font/glfont.cc'; then $(CYGPATH_W) 'lib/graphics/font/glfont.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/font/glfont.cc'; fi`; \ 802 @am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/glfont.Tpo" "$(DEPDIR)/glfont.Po"; else rm -f "$(DEPDIR)/glfont.Tpo"; exit 1; fi 803 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='lib/graphics/font/glfont.cc' object='glfont.obj' libtool=no @AMDEPBACKSLASH@ 804 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ depfile='$(DEPDIR)/glfont.Po' tmpdepfile='$(DEPDIR)/glfont.TPo' @AMDEPBACKSLASH@ 805 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 806 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o glfont.obj `if test -f 'lib/graphics/font/glfont.cc'; then $(CYGPATH_W) 'lib/graphics/font/glfont.cc'; else $(CYGPATH_W) '$(srcdir)/lib/graphics/font/glfont.cc'; fi` 786 807 787 808 array.o: lib/graphics/importer/array.cc -
orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc
r3681 r3682 55 55 #include <SDL/SDL_ttf.h> 56 56 57 #include " ../glincl.h"58 #include " ../debug.h"57 #include "glincl.h" 58 #include "debug.h" 59 59 60 60 … … 276 276 277 277 char Usage[100] = "orxonox test" ; 278 void SDL_GL_Enter2DMode() 279 { 280 } 281 282 void SDL_GL_Leave2DMode() 283 { 284 } 278 void GLFont::enter2DMode() 279 { 280 SDL_Surface *screen = SDL_GetVideoSurface(); 281 282 /* Note, there may be other things you need to change, 283 depending on how you have your OpenGL state set up. 284 */ 285 glPushAttrib(GL_ENABLE_BIT); 286 glDisable(GL_DEPTH_TEST); 287 glDisable(GL_CULL_FACE); 288 glEnable(GL_TEXTURE_2D); 289 290 /* This allows alpha blending of 2D textures with the scene */ 291 glEnable(GL_BLEND); 292 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 293 294 glViewport(0, 0, screen->w, screen->h); 295 296 glMatrixMode(GL_PROJECTION); 297 glPushMatrix(); 298 glLoadIdentity(); 299 300 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0); 301 302 glMatrixMode(GL_MODELVIEW); 303 glPushMatrix(); 304 glLoadIdentity(); 305 306 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 307 } 308 309 310 void GLFont::leave2DMode() 311 { 312 glMatrixMode(GL_MODELVIEW); 313 glPopMatrix(); 314 315 glMatrixMode(GL_PROJECTION); 316 glPopMatrix(); 317 318 glPopAttrib(); 319 } 320 321 322 GLuint GLFont::loadTexture(SDL_Surface *surface, GLfloat *texcoord) 323 { 324 GLuint texture; 325 int w, h; 326 SDL_Surface *image; 327 SDL_Rect area; 328 Uint32 saved_flags; 329 Uint8 saved_alpha; 330 331 /* Use the surface width and height expanded to powers of 2 */ 332 w = power_of_two(surface->w); 333 h = power_of_two(surface->h); 334 texcoord[0] = 0.0f; /* Min X */ 335 texcoord[1] = 0.0f; /* Min Y */ 336 texcoord[2] = (GLfloat)surface->w / w; /* Max X */ 337 texcoord[3] = (GLfloat)surface->h / h; /* Max Y */ 338 339 image = SDL_CreateRGBSurface( 340 SDL_SWSURFACE, 341 w, h, 342 32, 343 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 344 0x000000FF, 345 0x0000FF00, 346 0x00FF0000, 347 0xFF000000 348 #else 349 0xFF000000, 350 0x00FF0000, 351 0x0000FF00, 352 0x000000FF 353 #endif 354 ); 355 if ( image == NULL ) { 356 return 0; 357 } 358 359 /* Save the alpha blending attributes */ 360 saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK); 361 saved_alpha = surface->format->alpha; 362 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 363 SDL_SetAlpha(surface, 0, 0); 364 } 365 366 /* Copy the surface into the GL texture image */ 367 area.x = 0; 368 area.y = 0; 369 area.w = surface->w; 370 area.h = surface->h; 371 SDL_BlitSurface(surface, &area, image, &area); 372 373 /* Restore the alpha blending attributes */ 374 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 375 SDL_SetAlpha(surface, saved_flags, saved_alpha); 376 } 377 378 /* Create an OpenGL texture for the image */ 379 glGenTextures(1, &texture); 380 glBindTexture(GL_TEXTURE_2D, texture); 381 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 382 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 383 glTexImage2D(GL_TEXTURE_2D, 384 0, 385 GL_RGBA, 386 w, h, 387 0, 388 GL_RGBA, 389 GL_UNSIGNED_BYTE, 390 image->pixels); 391 SDL_FreeSurface(image); /* No longer needed */ 392 393 return texture; 394 } 395 285 396 286 397 /* Quick utility function for texture creation */ 287 static int power_of_two(int input) 288 { 289 } 290 291 292 293 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) 294 { 295 296 } 297 298 int setup(int argc, char *argv[]) 299 { 300 char *argv0 = argv[0]; 301 SDL_Surface *screen; 302 TTF_Font *font; 303 SDL_Surface *text; 304 int ptsize; 305 int i, done; 306 SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 }; 307 SDL_Color black = { 0x00, 0x00, 0x00, 0 }; 308 SDL_Color *forecol; 309 SDL_Color *backcol; 310 GLenum gl_error; 311 GLuint texture; 312 int x, y, w, h; 313 GLfloat texcoord[4]; 314 GLfloat texMinX, texMinY; 315 GLfloat texMaxX, texMaxY; 316 317 int renderstyle; 318 int dump; 319 enum { 320 RENDER_LATIN1, 321 RENDER_UTF8, 322 RENDER_UNICODE 323 } rendertype; 324 char *message; 325 326 /* Look for special execution mode */ 327 dump = 0; 328 /* Look for special rendering types */ 329 rendertype = RENDER_LATIN1; 330 /* Default is black and white */ 331 forecol = &black; 332 backcol = &white; 333 for ( i=1; argv[i] && argv[i][0] == '-'; ++i ) { 334 if ( strcmp(argv[i], "-utf8") == 0 ) { 335 rendertype = RENDER_UTF8; 336 } else 337 if ( strcmp(argv[i], "-unicode") == 0 ) { 338 rendertype = RENDER_UNICODE; 339 } else 340 if ( strcmp(argv[i], "-b") == 0 ) { 341 renderstyle |= TTF_STYLE_BOLD; 342 } else 343 if ( strcmp(argv[i], "-i") == 0 ) { 344 renderstyle |= TTF_STYLE_ITALIC; 345 } else 346 if ( strcmp(argv[i], "-u") == 0 ) { 347 renderstyle |= TTF_STYLE_UNDERLINE; 348 } else 349 if ( strcmp(argv[i], "-dump") == 0 ) { 350 dump = 1; 351 } else 352 if ( strcmp(argv[i], "-fgcol") == 0 ) { 353 int r, g, b; 354 if ( sscanf (argv[++i], "%d,%d,%d", &r, &g, &b) != 3 ) { 355 fprintf(stderr, Usage, argv0); 356 return(1); 357 } 358 forecol->r = (Uint8)r; 359 forecol->g = (Uint8)g; 360 forecol->b = (Uint8)b; 361 } else 362 if ( strcmp(argv[i], "-bgcol") == 0 ) { 363 int r, g, b; 364 if ( sscanf (argv[++i], "%d,%d,%d", &r, &g, &b) != 3 ) { 365 fprintf(stderr, Usage, argv0); 366 return(1); 367 } 368 backcol->r = (Uint8)r; 369 backcol->g = (Uint8)g; 370 backcol->b = (Uint8)b; 371 } else { 372 fprintf(stderr, Usage, argv0); 373 return(1); 374 } 375 } 376 argv += i; 377 argc -= i; 378 379 /* Check usage */ 380 if ( ! argv[0] ) { 381 fprintf(stderr, Usage, argv0); 382 return(1); 383 } 384 385 /* Initialize SDL */ 386 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 387 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 388 return(2); 389 } 390 atexit(SDL_Quit); 391 392 /* Initialize the TTF library */ 393 if ( TTF_Init() < 0 ) { 394 fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError()); 395 return(2); 396 } 397 atexit(TTF_Quit); 398 399 /* Open the font file with the requested point size */ 400 ptsize = 0; 401 if ( argc > 1 ) { 402 ptsize = atoi(argv[1]); 403 } 404 if ( ptsize == 0 ) { 405 i = 2; 406 ptsize = DEFAULT_PTSIZE; 407 } else { 408 i = 3; 409 } 410 font = TTF_OpenFont(argv[0], ptsize); 411 if ( font == NULL ) { 412 fprintf(stderr, "Couldn't load %d pt font from %s: %s\n", 413 ptsize, argv[0], SDL_GetError()); 414 return(2); 415 } 416 417 if( dump ) { 418 419 for( i = 48; i < 123; i++ ) { 420 SDL_Surface* glyph = NULL; 421 422 glyph = TTF_RenderGlyph_Shaded( font, i, *forecol, *backcol ); 423 424 if( glyph ) { 425 char outname[64]; 426 sprintf( outname, "glyph-%d.bmp", i ); 427 SDL_SaveBMP( glyph, outname ); 428 } 429 430 } 431 432 return( 0 ); 433 } 434 435 /* Set a 640x480 video mode */ 436 screen = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); 437 if ( screen == NULL ) { 438 fprintf(stderr, "Couldn't set 640x480 OpenGL mode: %s\n", 439 SDL_GetError()); 440 return(2); 441 } 442 443 /* Render and center the message */ 444 if ( argc > 2 ) { 445 message = argv[2]; 446 } else { 447 message = DEFAULT_TEXT; 448 } 449 switch (rendertype) { 450 case RENDER_LATIN1: 451 text = TTF_RenderText_Blended(font, message, *forecol); 452 break; 453 454 case RENDER_UTF8: 455 text = TTF_RenderUTF8_Blended(font, message, *forecol); 456 break; 457 458 case RENDER_UNICODE: 459 { 460 /* This doesn't actually work because you can't pass 461 UNICODE text in via command line, AFAIK, but... 462 */ 463 Uint16 unicode_text[BUFSIZ]; 464 int index; 465 for ( index = 0; (message[0] || message[1]); ++index ) { 466 unicode_text[index] = ((Uint8 *)message)[0]; 467 unicode_text[index] <<= 8; 468 unicode_text[index] |= ((Uint8 *)message)[1]; 469 message += 2; 470 } 471 text = TTF_RenderUNICODE_Blended(font, 472 unicode_text, *forecol); 473 } 474 break; 475 default: 476 text = NULL; /* This shouldn't happen */ 477 break; 478 } 479 if ( text == NULL ) { 480 fprintf(stderr, "Couldn't render text: %s\n", SDL_GetError()); 481 TTF_CloseFont(font); 482 return(2); 483 } 484 x = (screen->w - text->w)/2; 485 y = (screen->h - text->h)/2; 486 w = text->w; 487 h = text->h; 488 printf("Font is generally %d big, and string is %hd big\n", 489 TTF_FontHeight(font), text->h); 490 491 /* Convert the text into an OpenGL texture */ 492 glGetError(); 493 texture = SDL_GL_LoadTexture(text, texcoord); 494 if ( (gl_error = glGetError()) != GL_NO_ERROR ) { 495 /* If this failed, the text may exceed texture size limits */ 496 printf("Warning: Couldn't create texture: 0x%x\n", gl_error); 497 } 498 499 /* Make texture coordinates easy to understand */ 500 texMinX = texcoord[0]; 501 texMinY = texcoord[1]; 502 texMaxX = texcoord[2]; 503 texMaxY = texcoord[3]; 504 505 /* We don't need the original text surface anymore */ 506 SDL_FreeSurface(text); 507 508 /* Initialize the GL state */ 509 glViewport( 0, 0, screen->w, screen->h ); 510 glMatrixMode( GL_PROJECTION ); 511 glLoadIdentity( ); 512 513 glOrtho( -2.0, 2.0, -2.0, 2.0, -20.0, 20.0 ); 514 515 glMatrixMode( GL_MODELVIEW ); 516 glLoadIdentity( ); 517 518 glEnable(GL_DEPTH_TEST); 519 520 glDepthFunc(GL_LESS); 521 522 glShadeModel(GL_SMOOTH); 523 524 /* Wait for a keystroke, and blit text on mouse press */ 525 done = 0; 526 while ( ! done ) { 527 528 /* Show the text on the screen */ 529 SDL_GL_Enter2DMode(); 530 glBindTexture(GL_TEXTURE_2D, texture); 531 glBegin(GL_QUADS); 532 glTexCoord2f(texMinX, texMinY); glVertex2i(x, y ); 533 glTexCoord2f(texMaxX, texMinY); glVertex2i(x+w, y ); 534 glTexCoord2f(texMinX, texMaxY); glVertex2i(x, y+h); 535 glTexCoord2f(texMaxX, texMaxY); glVertex2i(x+w, y+h); 536 glEnd(); 537 SDL_GL_Leave2DMode(); 538 539 /* Swap the buffers so everything is visible */ 540 SDL_GL_SwapBuffers( ); 541 } 542 TTF_CloseFont(font); 543 return(0); 544 } 545 398 int GLFont::power_of_two(int input) 399 { 400 int value = 1; 401 402 while ( value < input ) { 403 value <<= 1; 404 } 405 return value; 406 } -
orxonox/branches/textEngine/src/lib/graphics/font/glfont.h
r3681 r3682 7 7 #define _GLFONT_H 8 8 9 #include " ../glincl.h"9 #include "glincl.h" 10 10 11 11 class GLFont … … 44 44 static bool ttfInitialized; 45 45 46 void enter2DMode(void); 47 void leave2DMode(void); 48 49 GLuint loadTexture(SDL_Surface* surface, GLfloat* texcoord); 50 51 static int power_of_two(int input); 52 46 53 }; 47 54
Note: See TracChangeset
for help on using the changeset viewer.