From 974e6ae93be939977a32a2aff9e310ccfe5474b5 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 22 Jan 2012 21:52:00 -0500 Subject: [PATCH] Updated for SDL 2.0 --- IMG.c | 35 +++- IMG_gif.c | 2 +- IMG_jpg.c | 2 +- IMG_lbm.c | 2 +- IMG_pcx.c | 2 +- IMG_png.c | 2 +- IMG_pnm.c | 4 +- IMG_tif.c | 2 +- IMG_webp.c | 3 +- IMG_xcf.c | 6 +- IMG_xpm.c | 2 +- Makefile.in | 4 +- SDL_image.h | 8 +- acinclude/{sdl.m4 => sdl2.m4} | 37 ++--- aclocal.m4 | 2 +- configure | 52 +++--- configure.in | 2 +- showimage.c | 299 ++++++++++++++-------------------- 18 files changed, 219 insertions(+), 247 deletions(-) rename acinclude/{sdl.m4 => sdl2.m4} (84%) diff --git a/IMG.c b/IMG.c index d40e8650..b213a5f8 100644 --- a/IMG.c +++ b/IMG.c @@ -155,7 +155,7 @@ static int IMG_string_equals(const char *str1, const char *str2) } /* Load an image from an SDL datasource, optionally specifying the type */ -SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) +SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type) { int i; SDL_Surface *image; @@ -203,6 +203,39 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) return NULL; } +SDL_Texture *IMG_LoadTexture(SDL_Renderer *renderer, const char *file) +{ + SDL_Texture *texture = NULL; + SDL_Surface *surface = IMG_Load(file); + if (surface) { + texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + } + return texture; +} + +SDL_Texture *IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc) +{ + SDL_Texture *texture = NULL; + SDL_Surface *surface = IMG_Load_RW(src, freesrc); + if (surface) { + texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + } + return texture; +} + +SDL_Texture *IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type) +{ + SDL_Texture *texture = NULL; + SDL_Surface *surface = IMG_LoadTyped_RW(src, freesrc, type); + if (surface) { + texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_FreeSurface(surface); + } + return texture; +} + /* Invert the alpha of a surface for use with OpenGL This function is a no-op and only kept for backwards compatibility. */ diff --git a/IMG_gif.c b/IMG_gif.c index de93fa77..5b745889 100644 --- a/IMG_gif.c +++ b/IMG_gif.c @@ -81,7 +81,7 @@ int IMG_isGIF(SDL_RWops *src) #define Image SDL_Surface #define RWSetMsg IMG_SetError -#define ImageNewCmap(w, h, s) SDL_AllocSurface(SDL_SWSURFACE,w,h,8,0,0,0,0) +#define ImageNewCmap(w, h, s) SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,8,0,0,0,0) #define ImageSetCmap(s, i, R, G, B) do { \ s->format->palette->colors[i].r = R; \ s->format->palette->colors[i].g = G; \ diff --git a/IMG_jpg.c b/IMG_jpg.c index 7484ab1b..838b5e4b 100644 --- a/IMG_jpg.c +++ b/IMG_jpg.c @@ -416,7 +416,7 @@ SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src) lib.jpeg_calc_output_dimensions(&cinfo); /* Allocate an output surface to hold the image */ - surface = SDL_AllocSurface(SDL_SWSURFACE, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, cinfo.output_width, cinfo.output_height, 32, #if SDL_BYTEORDER == SDL_LIL_ENDIAN 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); diff --git a/IMG_lbm.c b/IMG_lbm.c index f475c60c..f50f92dc 100644 --- a/IMG_lbm.c +++ b/IMG_lbm.c @@ -253,7 +253,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src ) goto done; if ( bmhd.mask & 2 ) /* There is a transparent color */ - SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor ); + SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor ); /* Update palette informations */ diff --git a/IMG_pcx.c b/IMG_pcx.c index f62eac12..2243f439 100644 --- a/IMG_pcx.c +++ b/IMG_pcx.c @@ -140,7 +140,7 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src) error = "unsupported PCX format"; goto done; } - surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, bits, Rmask, Gmask, Bmask, Amask); if ( surface == NULL ) goto done; diff --git a/IMG_png.c b/IMG_png.c index 5f91f156..9925d4dd 100644 --- a/IMG_png.c +++ b/IMG_png.c @@ -467,7 +467,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src) Amask = 0x000000FF >> s; } } - surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, bit_depth*num_channels, Rmask,Gmask,Bmask,Amask); if ( surface == NULL ) { error = "Out of memory"; diff --git a/IMG_pnm.c b/IMG_pnm.c index 0787f52a..3eb8f143 100644 --- a/IMG_pnm.c +++ b/IMG_pnm.c @@ -149,7 +149,7 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src) if(kind == PPM) { /* 24-bit surface in R,G,B byte order */ - surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, #if SDL_BYTEORDER == SDL_LIL_ENDIAN 0x000000ff, 0x0000ff00, 0x00ff0000, #else @@ -158,7 +158,7 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src) 0); } else { /* load PBM/PGM as 8-bit indexed images */ - surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 8, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0, 0, 0, 0); } if ( surface == NULL ) diff --git a/IMG_tif.c b/IMG_tif.c index 25084ad7..e97485a0 100644 --- a/IMG_tif.c +++ b/IMG_tif.c @@ -235,7 +235,7 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src) Gmask = 0x0000FF00; Bmask = 0x00FF0000; Amask = 0xFF000000; - surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, img_width, img_height, 32, Rmask, Gmask, Bmask, Amask); if(!surface) goto error; diff --git a/IMG_webp.c b/IMG_webp.c index 94727ce1..26d1a1ad 100644 --- a/IMG_webp.c +++ b/IMG_webp.c @@ -228,7 +228,8 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src) Bmask = 0x00FF0000; Amask = features.has_alpha?0xFF000001:0; - surface = SDL_AllocSurface(SDL_SWSURFACE, features.width, features.height, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, + features.width, features.height, features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask); if ( surface == NULL ) { diff --git a/IMG_xcf.c b/IMG_xcf.c index 1dced65e..bc566b13 100644 --- a/IMG_xcf.c +++ b/IMG_xcf.c @@ -709,7 +709,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) } /* Create the surface of the appropriate type */ - surface = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32, 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000); if ( surface == NULL ) { @@ -727,7 +727,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) } fp = SDL_RWtell (src); - lays = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32, + lays = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32, 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000); if ( lays == NULL ) { @@ -774,7 +774,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) if (chnls) { SDL_Surface * chs; - chs = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32, + chs = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32, 0x00FF0000,0x0000FF00,0x000000FF,0xFF000000); if (chs == NULL) { diff --git a/IMG_xpm.c b/IMG_xpm.c index 486992f4..e577733d 100644 --- a/IMG_xpm.c +++ b/IMG_xpm.c @@ -431,7 +431,7 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src) add_colorhash(colors, nextkey, cpp, pixel); nextkey += cpp; if(rgb == 0xffffffff) - SDL_SetColorKey(image, SDL_SRCCOLORKEY, pixel); + SDL_SetColorKey(image, SDL_TRUE, pixel); break; } } diff --git a/Makefile.in b/Makefile.in index 18714dec..5f80696d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -52,7 +52,7 @@ am__aclocal_m4_deps = $(top_srcdir)/acinclude/libtool.m4 \ $(top_srcdir)/acinclude/ltsugar.m4 \ $(top_srcdir)/acinclude/ltversion.m4 \ $(top_srcdir)/acinclude/lt~obsolete.m4 \ - $(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl.m4 \ + $(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl2.m4 \ $(top_srcdir)/configure.in am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -293,8 +293,6 @@ EXTRA_DIST = \ VisualCE \ Xcode \ Xcode-iOS \ - MPWmake.sea.bin \ - Watcom-OS2.zip \ IMG_xxx.c \ IMG_UIImage.m \ SDL_image.spec \ diff --git a/SDL_image.h b/SDL_image.h index 23ce91f8..532b96b2 100644 --- a/SDL_image.h +++ b/SDL_image.h @@ -80,11 +80,17 @@ extern DECLSPEC void SDLCALL IMG_Quit(void); surface afterwards by calling: SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey); */ -extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type); +extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type); /* Convenience functions */ extern DECLSPEC SDL_Surface * SDLCALL IMG_Load(const char *file); extern DECLSPEC SDL_Surface * SDLCALL IMG_Load_RW(SDL_RWops *src, int freesrc); +/* Load an image directly into a render texture. + */ +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture(SDL_Renderer *renderer, const char *file); +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc); +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type); + /* Invert the alpha of a surface for use with OpenGL This function is now a no-op, and only provided for backwards compatibility. */ diff --git a/acinclude/sdl.m4 b/acinclude/sdl2.m4 similarity index 84% rename from acinclude/sdl.m4 rename to acinclude/sdl2.m4 index 6acf1b2f..c060ce81 100644 --- a/acinclude/sdl.m4 +++ b/acinclude/sdl2.m4 @@ -5,12 +5,14 @@ # stolen from Manish Singh # Shamelessly stolen from Owen Taylor +# serial 1 + dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS dnl AC_DEFUN([AM_PATH_SDL], [dnl -dnl Get the cflags and libraries from the sdl-config script +dnl Get the cflags and libraries from the sdl2-config script dnl AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)], sdl_prefix="$withval", sdl_prefix="") @@ -19,40 +21,37 @@ AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program], , enable_sdltest=yes) - min_sdl_version=ifelse([$1], ,1.2.0,$1) + min_sdl_version=ifelse([$1], ,0.9.0,$1) if test "x$sdl_prefix$sdl_exec_prefix" = x ; then - PKG_CHECK_MODULES(SDL, [sdl >= $min_sdl_version], + PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version], [sdl_pc=yes], - [dnl - AC_MSG_RESULT(no) - sdl_pc=no - ]) + [sdl_pc=no]) else sdl_pc=no if test x$sdl_exec_prefix != x ; then sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" if test x${SDL_CONFIG+set} != xset ; then - SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config + SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config fi fi if test x$sdl_prefix != x ; then sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" if test x${SDL_CONFIG+set} != xset ; then - SDL_CONFIG=$sdl_prefix/bin/sdl-config + SDL_CONFIG=$sdl_prefix/bin/sdl2-config fi fi fi if test "x$sdl_pc" = xyes ; then no_sdl="" - SDL_CONFIG="pkg-config sdl" + SDL_CONFIG="pkg-config sdl2" else as_save_PATH="$PATH" if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then PATH="$prefix/bin:$prefix/usr/bin:$PATH" fi - AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH]) + AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH]) PATH="$as_save_PATH" AC_MSG_CHECKING(for SDL - version >= $min_sdl_version) no_sdl="" @@ -78,7 +77,7 @@ AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run LIBS="$LIBS $SDL_LIBS" dnl dnl Now check if the installed SDL is sufficiently new. (Also sanity -dnl checks the results of sdl-config to some extent +dnl checks the results of sdl2-config to some extent dnl rm -f conf.sdltest AC_TRY_RUN([ @@ -128,11 +127,11 @@ int main (int argc, char *argv[]) } else { - printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); - printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); + printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); printf("*** best to upgrade to the required version.\n"); - printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); - printf("*** to point to the correct copy of sdl-config, and remove the file\n"); + printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n"); + printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); printf("*** config.cache before re-running configure\n"); return 1; } @@ -154,10 +153,10 @@ int main (int argc, char *argv[]) ifelse([$2], , :, [$2]) else if test "$SDL_CONFIG" = "no" ; then - echo "*** The sdl-config script installed by SDL could not be found" + echo "*** The sdl2-config script installed by SDL could not be found" echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" echo "*** your path, or set the SDL_CONFIG environment variable to the" - echo "*** full path to sdl-config." + echo "*** full path to sdl2-config." else if test -f conf.sdltest ; then : @@ -187,7 +186,7 @@ int main(int argc, char *argv[]) [ echo "*** The test program failed to compile or link. See the file config.log for the" echo "*** exact error that occured. This usually means SDL was incorrectly installed" echo "*** or that you have moved SDL since it was installed. In the latter case, you" - echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ]) + echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ]) CFLAGS="$ac_save_CFLAGS" CXXFLAGS="$ac_save_CXXFLAGS" LIBS="$ac_save_LIBS" diff --git a/aclocal.m4 b/aclocal.m4 index d90968bb..0137080d 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -965,4 +965,4 @@ m4_include([acinclude/ltsugar.m4]) m4_include([acinclude/ltversion.m4]) m4_include([acinclude/lt~obsolete.m4]) m4_include([acinclude/pkg.m4]) -m4_include([acinclude/sdl.m4]) +m4_include([acinclude/sdl2.m4]) diff --git a/configure b/configure index a2ad7709..bf05c065 100755 --- a/configure +++ b/configure @@ -12799,7 +12799,7 @@ find_lib() done } -SDL_VERSION=1.2.10 +SDL_VERSION=2.0.0 @@ -12958,12 +12958,12 @@ if test -n "$PKG_CONFIG"; then pkg_cv_SDL_CFLAGS="$SDL_CFLAGS" else if test -n "$PKG_CONFIG" && \ - { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl >= \$min_sdl_version\"") >&5 - ($PKG_CONFIG --exists --print-errors "sdl >= $min_sdl_version") 2>&5 + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\"") >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; then - pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl >= $min_sdl_version" 2>/dev/null` + pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl2 >= $min_sdl_version" 2>/dev/null` else pkg_failed=yes fi @@ -12976,12 +12976,12 @@ if test -n "$PKG_CONFIG"; then pkg_cv_SDL_LIBS="$SDL_LIBS" else if test -n "$PKG_CONFIG" && \ - { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl >= \$min_sdl_version\"") >&5 - ($PKG_CONFIG --exists --print-errors "sdl >= $min_sdl_version") 2>&5 + { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\"") >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; then - pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl >= $min_sdl_version" 2>/dev/null` + pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl2 >= $min_sdl_version" 2>/dev/null` else pkg_failed=yes fi @@ -13000,24 +13000,18 @@ else _pkg_short_errors_supported=no fi if test $_pkg_short_errors_supported = yes; then - SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "sdl >= $min_sdl_version"` + SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "sdl2 >= $min_sdl_version"` else - SDL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "sdl >= $min_sdl_version"` + SDL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "sdl2 >= $min_sdl_version"` fi # Put the nasty error message in config.log where it belongs echo "$SDL_PKG_ERRORS" >&5 { echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6; } - { echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6; } - sdl_pc=no - + sdl_pc=no elif test $pkg_failed = untried; then - { echo "$as_me:$LINENO: result: no" >&5 -echo "${ECHO_T}no" >&6; } - sdl_pc=no - + sdl_pc=no else SDL_CFLAGS=$pkg_cv_SDL_CFLAGS SDL_LIBS=$pkg_cv_SDL_LIBS @@ -13030,27 +13024,27 @@ fi if test x$sdl_exec_prefix != x ; then sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix" if test x${SDL_CONFIG+set} != xset ; then - SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config + SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config fi fi if test x$sdl_prefix != x ; then sdl_config_args="$sdl_config_args --prefix=$sdl_prefix" if test x${SDL_CONFIG+set} != xset ; then - SDL_CONFIG=$sdl_prefix/bin/sdl-config + SDL_CONFIG=$sdl_prefix/bin/sdl2-config fi fi fi if test "x$sdl_pc" = xyes ; then no_sdl="" - SDL_CONFIG="pkg-config sdl" + SDL_CONFIG="pkg-config sdl2" else as_save_PATH="$PATH" if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then PATH="$prefix/bin:$prefix/usr/bin:$PATH" fi - # Extract the first word of "sdl-config", so it can be a program name with args. -set dummy sdl-config; ac_word=$2 + # Extract the first word of "sdl2-config", so it can be a program name with args. +set dummy sdl2-config; ac_word=$2 { echo "$as_me:$LINENO: checking for $ac_word" >&5 echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } if test "${ac_cv_path_SDL_CONFIG+set}" = set; then @@ -13171,11 +13165,11 @@ int main (int argc, char *argv[]) } else { - printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); - printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); + printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro); printf("*** best to upgrade to the required version.\n"); - printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); - printf("*** to point to the correct copy of sdl-config, and remove the file\n"); + printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n"); + printf("*** to point to the correct copy of sdl2-config, and remove the file\n"); printf("*** config.cache before re-running configure\n"); return 1; } @@ -13233,10 +13227,10 @@ echo "${ECHO_T}no" >&6; } : else if test "$SDL_CONFIG" = "no" ; then - echo "*** The sdl-config script installed by SDL could not be found" + echo "*** The sdl2-config script installed by SDL could not be found" echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" echo "*** your path, or set the SDL_CONFIG environment variable to the" - echo "*** full path to sdl-config." + echo "*** full path to sdl2-config." else if test -f conf.sdltest ; then : @@ -13302,7 +13296,7 @@ sed 's/^/| /' conftest.$ac_ext >&5 echo "*** The test program failed to compile or link. See the file config.log for the" echo "*** exact error that occured. This usually means SDL was incorrectly installed" echo "*** or that you have moved SDL since it was installed. In the latter case, you" - echo "*** may want to edit the sdl-config script: $SDL_CONFIG" + echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" fi rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ diff --git a/configure.in b/configure.in index 3b53a50a..9bcfc1ab 100644 --- a/configure.in +++ b/configure.in @@ -113,7 +113,7 @@ find_lib() } dnl Check for SDL -SDL_VERSION=1.2.10 +SDL_VERSION=2.0.0 AC_SUBST(SDL_VERSION) AM_PATH_SDL($SDL_VERSION, :, diff --git a/showimage.c b/showimage.c index 6f29d7d5..678fbfc8 100644 --- a/showimage.c +++ b/showimage.c @@ -26,191 +26,132 @@ #include "SDL.h" #include "SDL_image.h" -/* #define XPM_INCLUDED and supply picture.xpm to test the XPM inclusion - feature */ - -#ifdef XPM_INCLUDED -#include "picture.xpm" -#endif /* Draw a Gimpish background pattern to show transparency in the image */ -static void draw_background(SDL_Surface *screen) +static void draw_background(SDL_Renderer *renderer, int w, int h) { - Uint8 *dst = screen->pixels; - int x, y; - int bpp = screen->format->BytesPerPixel; - Uint32 col[2]; - col[0] = SDL_MapRGB(screen->format, 0x66, 0x66, 0x66); - col[1] = SDL_MapRGB(screen->format, 0x99, 0x99, 0x99); - for(y = 0; y < screen->h; y++) { - for(x = 0; x < screen->w; x++) { - /* use an 8x8 checkerboard pattern */ - Uint32 c = col[((x ^ y) >> 3) & 1]; - switch(bpp) { - case 1: - dst[x] = (Uint8)c; - break; - case 2: - ((Uint16 *)dst)[x] = (Uint16)c; - break; - case 3: -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - dst[x * 3] = (Uint8)(c); - dst[x * 3 + 1] = (Uint8)(c >> 8); - dst[x * 3 + 2] = (Uint8)(c >> 16); -#else - dst[x * 3] = (Uint8)(c >> 16); - dst[x * 3 + 1] = (Uint8)(c >> 8); - dst[x * 3 + 2] = (Uint8)(c); -#endif - break; - case 4: - ((Uint32 *)dst)[x] = c; - break; - } - } - dst += screen->pitch; + SDL_Color col[2] = { + { 0x66, 0x66, 0x66, 0xff }, + { 0x99, 0x99, 0x99, 0xff }, + }; + int i, x, y; + SDL_Rect rect; + + rect.w = 8; + rect.h = 8; + for (y = 0; y < h; y += rect.h) { + for (x = 0; x < w; x += rect.w) { + /* use an 8x8 checkerboard pattern */ + i = (((x ^ y) >> 3) & 1); + SDL_SetRenderDrawColor(renderer, col[i].r, col[i].g, col[i].b, col[i].unused); + + rect.x = x; + rect.y = y; + SDL_RenderFillRect(renderer, &rect); + } } } int main(int argc, char *argv[]) { - Uint32 flags; - SDL_Surface *screen, *image; - int i, depth, done; - SDL_Event event; -#if 0 - SDL_RWops* rw_ops; -#endif - - /* Check command line usage */ - if ( ! argv[1] ) { - fprintf(stderr, "Usage: %s \n", argv[0]); - return(1); - } - - /* Initialize the SDL library */ - if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { - fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); - return(255); - } - - flags = SDL_SWSURFACE; - for ( i=1; argv[i]; ++i ) { - if ( strcmp(argv[i], "-fullscreen") == 0 ) { - SDL_ShowCursor(0); - flags |= SDL_FULLSCREEN; - continue; - } -#if 0 - rw_ops = SDL_RWFromFile(argv[1], "r"); - - fprintf(stderr, "BMP:\t%d\n", IMG_isBMP(rw_ops)); - fprintf(stderr, "GIF:\t%d\n", IMG_isGIF(rw_ops)); - fprintf(stderr, "JPG:\t%d\n", IMG_isJPG(rw_ops)); - fprintf(stderr, "PNG:\t%d\n", IMG_isPNG(rw_ops)); - fprintf(stderr, "TIF:\t%d\n", IMG_isTIF(rw_ops)); - /* fprintf(stderr, "TGA:\t%d\n", IMG_isTGA(rw_ops)); */ - fprintf(stderr, "PCX:\t%d\n", IMG_isPCX(rw_ops)); -#endif - - /* Open the image file */ -#ifdef XPM_INCLUDED - image = IMG_ReadXPMFromArray(picture_xpm); -#else - image = IMG_Load(argv[i]); -#endif - if ( image == NULL ) { - fprintf(stderr, "Couldn't load %s: %s\n", - argv[i], SDL_GetError()); - continue; - } - SDL_WM_SetCaption(argv[i], "showimage"); - - /* Create a display for the image */ - depth = SDL_VideoModeOK(image->w, image->h, 32, flags); - /* Use the deepest native mode, except that we emulate 32bpp - for viewing non-indexed images on 8bpp screens */ - if ( depth == 0 ) { - if ( image->format->BytesPerPixel > 1 ) { - depth = 32; - } else { - depth = 8; - } - } else - if ( (image->format->BytesPerPixel > 1) && (depth == 8) ) { - depth = 32; - } - if(depth == 8) - flags |= SDL_HWPALETTE; - screen = SDL_SetVideoMode(image->w, image->h, depth, flags); - if ( screen == NULL ) { - fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n", - image->w, image->h, depth, SDL_GetError()); - continue; - } - - /* Set the palette, if one exists */ - if ( image->format->palette ) { - SDL_SetColors(screen, image->format->palette->colors, - 0, image->format->palette->ncolors); - } - - /* Draw a background pattern if the surface has transparency */ - if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY)) - draw_background(screen); - - /* Display the image */ - SDL_BlitSurface(image, NULL, screen, NULL); - SDL_UpdateRect(screen, 0, 0, 0, 0); - - done = 0; - while ( ! done ) { - if ( SDL_PollEvent(&event) ) { - switch (event.type) { - case SDL_KEYUP: - switch (event.key.keysym.sym) { - case SDLK_LEFT: - if ( i > 1 ) { - i -= 2; - done = 1; - } - break; - case SDLK_RIGHT: - if ( argv[i+1] ) { - done = 1; - } - break; - case SDLK_ESCAPE: - case SDLK_q: - argv[i+1] = NULL; - /* Drop through to done */ - case SDLK_SPACE: - case SDLK_TAB: - done = 1; - break; - default: - break; - } - break; - case SDL_MOUSEBUTTONDOWN: - done = 1; - break; - case SDL_QUIT: - argv[i+1] = NULL; - done = 1; - break; - default: - break; - } - } else { - SDL_Delay(10); - } - } - SDL_FreeSurface(image); - } - - /* We're done! */ - SDL_Quit(); - return(0); + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *texture; + Uint32 flags; + int i, w, h, done; + SDL_Event event; + + /* Check command line usage */ + if ( ! argv[1] ) { + fprintf(stderr, "Usage: %s [-fullscreen] ...\n", argv[0]); + return(1); + } + + flags = SDL_WINDOW_HIDDEN; + for ( i=1; argv[i]; ++i ) { + if ( strcmp(argv[i], "-fullscreen") == 0 ) { + SDL_ShowCursor(0); + flags |= SDL_WINDOW_FULLSCREEN; + } + } + + if (SDL_CreateWindowAndRenderer(0, 0, flags, &window, &renderer) < 0) { + fprintf(stderr, "SDL_CreateWindowAndRenderer() failed: %s\n", SDL_GetError()); + return(2); + } + + for ( i=1; argv[i]; ++i ) { + if ( strcmp(argv[i], "-fullscreen") == 0 ) { + continue; + } + + /* Open the image file */ + texture = IMG_LoadTexture(renderer, argv[i]); + if (!texture) { + fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError()); + continue; + } + SDL_QueryTexture(texture, NULL, NULL, &w, &h); + + /* Show the window */ + SDL_SetWindowTitle(window, argv[i]); + SDL_SetWindowSize(window, w, h); + SDL_ShowWindow(window); + + /* Draw a background pattern in case the image has transparency */ + draw_background(renderer, w, h); + + /* Display the image */ + SDL_RenderCopy(renderer, texture, NULL, NULL); + SDL_RenderPresent(renderer); + + done = 0; + while ( ! done ) { + if ( SDL_PollEvent(&event) ) { + switch (event.type) { + case SDL_KEYUP: + switch (event.key.keysym.sym) { + case SDLK_LEFT: + if ( i > 1 ) { + i -= 2; + done = 1; + } + break; + case SDLK_RIGHT: + if ( argv[i+1] ) { + done = 1; + } + break; + case SDLK_ESCAPE: + case SDLK_q: + argv[i+1] = NULL; + /* Drop through to done */ + case SDLK_SPACE: + case SDLK_TAB: + done = 1; + break; + default: + break; + } + break; + case SDL_MOUSEBUTTONDOWN: + done = 1; + break; + case SDL_QUIT: + argv[i+1] = NULL; + done = 1; + break; + default: + break; + } + } else { + SDL_Delay(10); + } + } + SDL_DestroyTexture(texture); + } + + /* We're done! */ + SDL_Quit(); + return(0); }