Graphics drawing primitives and other support functions wrapped up in an add-on, C-based library for the Simple Direct Media (SDL) cross-platform API layer. SDL_gfx supports the original SDL1 library using software surfaces, and SDL2_gfx supports SDL2 using rendering functions.


SDL2_gfx Library

SDL2 graphics drawing primitives and other support functions

Latest Version (Ver 1.0.4 – 11 Feb 2018)

SDL2_gfx-1.0.4.tar.gz (.zip) (.asc)

Sources and archives also on https://sourceforge.net/projects/sdl2gfx/

Changes:
 - version rev to 1.0.4
 - fix int overflow in ellipseRGBA for large radii (thanks for reporting David)
 - fix aaline wrong direction hline bug (thanks Andre)
 - fix off-by-1 error in rotateSurface90Degrees (thanks Austin)
Older versions

SDL2_gfx-1.0.3.tar.gz (.zip)

SDL2_gfx-1.0.1.tar.gz (.zip)

SDL2_gfx-1.0.0.tar.gz

Documentation

Doxygen generated API documentation

(C) A. Schiffler, aschiffler [at] ferzkopp.net 2012-2018, licensed under the zlib license

Extensions / External Versions

The following external versions have been made of SDL2_gfx:

  • Richard Russell’s https://github.com/rtrussell/BBCSDL/blob/master/src/SDL2_gfxPrimitives.c adds the following routines:
    • thickEllipseRGBA() – Draw thick outline ellipse with blending.
    • thickArcRGBA() – Draw thick circular arc with blending.
    • thickCircleRGBA() – Draw thick outline circle with blending.
    • aaFilledEllipseRGBA() – Draw anti-aliased filled ellipse with blending.
    • aaFilledPolygonRGBA() – Draw anti-aliased filled polygon with blending.
    • aaFilledPieRGBA() – Draw anti-aliased filled pie or chord with blending.
    • aaArcRGBA() – Draw anti-aliased elliptical arc with blending.
    • aaBezierRGBA() – Draw anti-aliased Bézier curve with blending.
    • aaFilledPolyBezierRGBA() – Fill a region bounded by cubic Bézier curves.


SDL_gfx Library

SDL graphics drawing primitives and other support functions

The SDL_gfx library evolved out of the SDL_gfxPrimitives code which provided basic drawing routines such as lines, circles or polygons and SDL_rotozoom which implemented a interpolating rotozoomer for SDL surfaces.

The current components of the SDL_gfx library are:

  • Graphic Primitives (SDL_gfxPrimitves.h)
  • Rotozoomer (SDL_rotozoom.h)
  • Framerate control (SDL_framerate.h)
  • MMX image filters (SDL_imageFilter.h)
  • Custom Blit functions (SDL_gfxBlitFunc.h)

The library is backwards compatible to the above mentioned code. Its is written in plain C and can be used in C++ code.

(C) A. Schiffler, aschiffler [at] ferzkopp.net 1999-2018, licensed under the zlib license

Screenshots

SDL_gfxPrimitives

SDL_rotozoom
Documentation

Overview and doxygen generated API documentation

Downloads

Latest Version (Ver 2.0.27 – Sun Dec 10 2023)

SDL_gfx-2.0.27.tar.gz (or on SourceForge; see also ChangeLog)

Current Development Version via SVN

https://sourceforge.net/projects/sdlgfx/

Older Releases
SDL_gfx-2.0.26.tar.gz

SDL_gfx-2.0.25.tar.gz

SDL_gfx-2.0.24.tar.gz

Supported Platforms

The library compiles and is tested for a Linux target (gcc compiler) and a Win32 target (VisualC, xmingw32 cross-compiler) as well as BeOS and MacOS X PowerBuilder See README for VC and PowerBuilder compile information. When using the cross-compiler (available on the author’s homepage), the build process generates .DLLs. You can use the command line ‘LIB.EXE’ tool to generate VC6 compatible .LIB files for linking purposes.

Language Interfaces

SDL_gfx has been integrated with the following language interfaces:

  • Pascal: http://www.freepascal-meets-sdl.net
  • Perl: http://sdl.perl.org
  • Python: http://www.pygame.org
  • C#: http://cs-sdl.sourceforge.net
  • Lua: http://www.egsl.retrogamecoding.org
Notes on Graphics Primitives

Care has been taken so that all routines are fully alpha-aware and can blend any primitive onto the target surface if ALPHA<255. Surface depths supported are 1,2,3 and 4 bytes per pixel. Surface locking is implemented in each routine and the library should work well with hardware accelerated surfaces. Currently, The following Anti-Aliased drawing primitives are available:

  • AA-line
  • AA-circle
  • AA-ellipse
  • AA-polygon (not filled)
Interface
Please check README in archive and .h files for up-to-date interface information.
SDL_gfx / SDL2_gfx
Tagged on:             

67 thoughts on “SDL_gfx / SDL2_gfx

  • February 22, 2024 at 12:32 pm
    Permalink

    Hello,

    need help for compiling and using sdl2_gfx for mingw 64. I use codeblock. At the moment, when i try to compile the project, i receive this error: ld.ece can0t find -lsdl2_gfx

    Thank you in advance

    Reply
  • December 30, 2021 at 5:03 pm
    Permalink

    Unable to start program

    SDL2_gfx-1.0.4\Win32\Debug\SDL2_gfx.dll is not a valid Win32 application

    Reply
    • February 22, 2024 at 4:30 pm
      Permalink

      DLLs are used by applications, they are not applications by themselves. On Windows, files with the extension .exe (such as the SDL2_gfx test programs) can be started.

      Reply
  • November 21, 2021 at 7:49 am
    Permalink

    Can you give a tutorial on how to compile gfx with windows?

    Thanks

    Reply
    • November 21, 2021 at 11:54 am
      Permalink

      Please see information in the comments on how to setup SDL2 alongside SDL2_gfx and manually edit the project files to point to the .h and .dll files. I’ll also try to update the solution to VS2022 and provide some info for VSCode over the holidays.

      Reply
  • Pingback:Download and use SDL2 gfx – Windows Questions

    • November 19, 2021 at 7:15 pm
      Permalink

      See comments below.

      Reply
  • Pingback:How to add SDL2_gfxPrimitives to my visual studio 2019? – Windows Questions

    • June 4, 2021 at 9:23 am
      Permalink

      Prerequisites: both SDL2 and SDL2_gfx downloaded and compiled in a folder alongside your project. That will provide .h files to compile and .lib files for linking and .pdb files for debugging and .dll files for running.

      Have a look at the sdlgfx2-code/test/TestGfx.vcxproj file (i.e. in Notepad) how the locations to these files are then referenced for a project:


      <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
      <ClCompile>
      <AdditionalIncludeDirectories<..;..\..\sdl2gfx;..\..\SDL2_gfx;..\..\SDL2-2.0.5\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      ...
      <Link>
      <AdditionalDependencies<SDL2.lib;SDL2main.lib;SDL2test.lib;SDL2_gfx.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories<..\$(Platform)\$(Configuration);..\..\sdl2gfx\$(Platform)\$(Configuration);..\..\SDL2_gfx\$(Platform)\$(Configuration);..\..\SDL2-2.0.5\VisualC\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      ...

      One can edit these settings in VS by right-clicking on the project and selecting Properties. The dialog that is shown will have many options for compiling, linking, etc. including these ones.

      It is also helpful automate the placement of the .dll files that are needed to run the new application during a compile using:


      <PostBuildEvent>
      <Command>
      copy /y "..\..\SDL2-2.0.5\VisualC\$(Platform)\$(Configuration)\SDL2.dll" "$(TargetName)\$(Platform)\$(Configuration)\SDL2.dll"
      copy /y "..\$(Platform)\$(Configuration)\SDL2_gfx.dll" "$(TargetName)\$(Platform)\$(Configuration)\SDL2_gfx.dll"
      </Command>
      <Message>Copy SDL2 and SDL2_gfx DLLs</Message<
      </PostBuildEvent>

      Note also, that there are duplicate definitions for Debug and Release compiles.

      Reply
    • March 31, 2021 at 8:15 pm
      Permalink

      I can’t repro this with the latest version of the code pulled with “svn checkout svn+ssh://ferzkopp@svn.code.sf.net/p/sdl2gfx/code/trunk sdl2gfx-code” for some reasons. Opening the .sln file with Microsoft Visual Studio Community 2019 Version 16.9.3 needed two attempts to launch an a “Retarget” to the latest build tools. After that everything builds and the TestGfx runs fine.

      I did see a Warning C28251 Inconsistent annotation for ‘lrint’: this instance has no annotations. See c:\program files (x86)\windows kits\10\include\10.0.19041.0\ucrt\corecrt_math.h(518). file: \sdl2gfx-code\SDL2_gfxPrimitives.c line: 1771 which goes away when skipping the unnecessary intrinsic declaration using the following patch (as suggested).

      Index: SDL2_gfxPrimitives.c
      ===================================================================
      — SDL2_gfxPrimitives.c (revision 33)
      +++ SDL2_gfxPrimitives.c (working copy)
      @@ -1758,8 +1758,10 @@

      /* Windows targets do not have lrint, so provide a local inline version */
      #if defined(_MSC_VER)
      +#if _MSC_FULL_VER < 192829913 +/* VS2019 16.9.0+ implemented the function */ +#elif defined(_M_X64) /* Detect 64bit and use intrinsic version */ -#ifdef _M_X64 #include
      static __inline long
      lrint(float f)
      @@ -1792,7 +1794,7 @@
      }
      #pragma warning(pop)
      #else
      -#error lrint needed for MSVC on non X86/AMD64/ARM targets.
      +#error lrint needed for MSVC pre VS2019 16.9.0 on non-X86/AMD64/ARM targets.
      #endif
      #endif

      _Check_return_ _ACRTIMP long __cdecl lrint(_In_ double _X);

      Reply
  • March 31, 2021 at 12:21 pm
    Permalink

    Recently, I am trying to build sdl2_gfx with the latest Visual Studio.
    And meet problems:
    SDL2_gfxPrimitives.c(1766): error C2169: ‘lrint’: intrinsic function, cannot be defined

    According to:
    https://forum.audacityteam.org/viewtopic.php?f=19&p=419828
    https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/lrint-lrintf-lrintl-llrint-llrintf-llrintl?view=msvc-160
    It seems The lrint is implemented begin from Visual Studio 2019 version 16.9.0.
    So this needs to update the code to check the MSVC version.

    Reply
    • March 31, 2021 at 7:13 pm
      Permalink

      Thanks for the report. I’ll put it on the list of TODOs for the next version, and post a patch here once I have the final working code.

      Reply
  • February 26, 2021 at 12:21 pm
    Permalink

    Hello,
    Im trying to build your library on the new Mac M1, I have the following errors, any idea how to solve it ?
    it was working fine with Intel Mac

    /bin/sh ./libtool –tag=CC –mode=compile gcc -DPACKAGE_NAME=\”\” -DPACKAGE_TARNAME=\”\” -DPACKAGE_VERSION=\”\” -DPACKAGE_STRING=\”\” -DPACKAGE_BUGREPORT=\”\” -DPACKAGE_URL=\”\” -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\”.libs/\” -DPACKAGE=\”SDL2_gfx\” -DVERSION=\”1.0.2\” -DSIZEOF_LONG=8 -I. -I.. -g -O2 -O -DUSE_MMX -I/opt/homebrew/include/SDL2 -D_THREAD_SAFE -MT SDL2_imageFilter.lo -MD -MP -MF .deps/SDL2_imageFilter.Tpo -c -o SDL2_imageFilter.lo ../SDL2_imageFilter.c
    libtool: compile: gcc -DPACKAGE_NAME=\”\” -DPACKAGE_TARNAME=\”\” -DPACKAGE_VERSION=\”\” -DPACKAGE_STRING=\”\” -DPACKAGE_BUGREPORT=\”\” -DPACKAGE_URL=\”\” -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\”.libs/\” -DPACKAGE=\”SDL2_gfx\” -DVERSION=\”1.0.2\” -DSIZEOF_LONG=8 -I. -I.. -g -O2 -O -DUSE_MMX -I/opt/homebrew/include/SDL2 -D_THREAD_SAFE -MT SDL2_imageFilter.lo -MD -MP -MF .deps/SDL2_imageFilter.Tpo -c ../SDL2_imageFilter.c -fno-common -DPIC -o .libs/SDL2_imageFilter.o
    In file included from ../SDL2_imageFilter.c:51:
    /Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include/mmintrin.h:50:12: error: invalid conversion between vector type ‘__m64’ (vector of 1 ‘long long’ value) and integer type ‘int’ of different size
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include/mmintrin.h:129:12: error: invalid conversion between vector type ‘__m64’ (vector of 1 ‘long long’ value) and integer type ‘int’ of different size
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include/mmintrin.h:159:12: error: invalid conversion between vector type ‘__m64’ (vector of 1 ‘long long’ value) and integer type ‘int’ of different size
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Reply
    • March 31, 2021 at 7:10 pm
      Permalink

      Try to remove -DUSE_MMX.

      Reply
  • July 10, 2020 at 3:45 pm
    Permalink

    Hello, thanks for the great library, it’s very helpful! I believe I found an issue with the method SDL2_rotozoom.c:_rotozoomSurfaceSizeTrig(…)

    I believe there are two issues. 1) The input argument zoomy isn’t used. Trying to zoom a surface in the y plane does nothing. 2) I believe you want to remove lines 968 and 969 and replace lines 970 and 971 with:

    970: x = (double)(width / 2) * zoomx;
    971: y = (double)(height / 2) * zoomy;

    When I made the above change and use the input arguments zoomx=1, zoomy=10, width=10, height=10, angle=90 it should take a 10×10 square zoom by 10x in the y-plane, resulting in a 10×100 rectangle, then rotate it 90 degrees. This should generate a 100×10 output. After the changes to lines 968-971 the output arguments are dstwidth=100, dstheight=12, canglezoom=0.9948, sanglezoom=0.1736, which is (about) what I would expect.

    Reply
  • June 29, 2020 at 11:02 am
    Permalink

    Hi. By default it does not build on ARM (Raspberry Pi). I think I’ve managed to fix this on the run though.
    Errors I’ve got:
    gcc: error: unrecognized command line option ‘-mmmx’
    So I remove the -mmmx (two occurences) option from generated Makefile. Still errors:
    /usr/lib/gcc/arm-linux-gnueabihf/8/include/mmintrin.h:28:2: error: #error mmintrin.h included without enabling WMMX/WMMX2 instructions (e.g. -march=iwmmxt or -march=iwmmxt2)
    #error mmintrin.h included without enabling WMMX/WMMX2 instructions (e.g. -march=iwmmxt or -march=iwmmxt2)
    ^~~~~

    So I removed -DUSE_MMX from Makefile (occured two times) and it seems to be working fine, I need to build my project to check.

    BTW. Why do I need to change the headers:
    #include “SDL.h”
    to:
    #include “SDL2/SDL.h”

    Happens on Ubuntu/Raspbian.

    Reply
  • February 11, 2020 at 6:03 am
    Permalink

    Hey!

    I tried out SDL2_gfx recently but I think it doesn’t work with the current version of SDL2.
    An assertion failure happens whenever I use anything with the gfx primitives. The error happens within SDL_render.c:2213 ‘renderer && renderer->magic == &renderer_magic’

    Any advice how this could be fixed?

    Thanks in advance.

    Reply
  • March 6, 2019 at 9:03 pm
    Permalink

    Hey thanks for making this awesome library! I managed to install it under msys2 with the pacman package manager and at least I was able to compile and link my programs to it and draw filled polygons and circles which was the entire reason I needed it!

    Reply
    • March 6, 2019 at 9:22 pm
      Permalink

      Thanks – glad it worked for your needs!

      Reply
  • December 14, 2018 at 1:31 am
    Permalink

    Hello!
    Sorry to bother you!
    Have anyone build x64 dll on windows?
    VS2017 donnot support _asm (x64)
    How can i do it?

    Reply
    • December 16, 2018 at 9:50 am
      Permalink

      The DLL should be compilable to x64; what’s the error message you are getting?

      Reply
      • December 16, 2018 at 10:32 pm
        Permalink

        I have solved the compile problem. It because of “_ASM” whitch dones’t support by visual studio.
        So i disable MMX.

        Another private request, how can i draw rect or circle or others with a specified width. not 1 pixel width? The only function support it is “thickLine”.
        I think it is very useful to draw “thick” rects or circles. Can you add these functions ( if it is easy for you)?
        Thank you for your prompt reply.

        Reply
  • November 19, 2018 at 12:39 pm
    Permalink

    There is an off-by-1 issue with rectangleRGBA. It needs to be changed the same way boxRGBA was.

    Reply
    • December 16, 2018 at 10:00 am
      Permalink

      Thanks for the bug report. I’ll have a look – would you have the file/version/line#?

      Reply
  • June 7, 2018 at 6:49 pm
    Permalink

    Hi!
    I have these errors rebuilding the solution in MVS Community 2017:

    1>—— Rebuild All started: Project: SDL2_gfx, Configuration: Debug Win32 ——
    1>SDL2_imageFilter.c
    1>SDL2_rotozoom.c
    1>SDL2_gfxPrimitives.c
    1>SDL2_framerate.c
    1>Generating Code…
    1>SDL2_framerate.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
    1> Creating library Win32\Debug\SDL2_gfx.lib and object Win32\Debug\SDL2_gfx.exp
    1>SDL2_gfx.vcxproj -> C:\SDL2_gfx\Win32\Debug\SDL2_gfx.dll
    1>Done building project “SDL2_gfx.vcxproj”.
    2>—— Rebuild All started: Project: TestGfx, Configuration: Debug Win32 ——
    3>—— Rebuild All started: Project: TestImageFilter, Configuration: Debug Win32 ——
    4>—— Rebuild All started: Project: TestRotozoom, Configuration: Debug Win32 ——
    5>—— Rebuild All started: Project: TestFramerate, Configuration: Debug Win32 ——
    2>TestGfx.c
    5>TestFramerate.c
    4>TestRotozoom.c
    3>testimagefilter.c
    5>c:\sdl2_gfx\test\testframerate.c(104): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
    2>TestGfx.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
    4>TestRotozoom.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
    5>TestFramerate.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
    2>SDL2test.lib(SDL_test_common.obj) : warning LNK4217: locally defined symbol _printf imported in function _SDLTest_CommonInit
    4>SDL2test.lib(SDL_test_common.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _SDLTest_CommonInit
    5>SDL2test.lib(SDL_test_common.obj) : error LNK2019: unresolved external symbol __imp__printf referenced in function _SDLTest_CommonInit
    5>TestFramerate\Win32\Debug\TestFramerate.exe : fatal error LNK1120: 1 unresolved externals
    4>TestRotozoom\Win32\Debug\TestRotozoom.exe : fatal error LNK1120: 1 unresolved externals
    3>testimagefilter.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
    4>Done building project “TestRotozoom.vcxproj” — FAILED.
    5>Done building project “TestFramerate.vcxproj” — FAILED.
    2>TestGfx.vcxproj -> C:\SDL2_gfx\test\TestGfx\Win32\Debug\TestGfx.exe
    2>Copy SDL2 and SDL2_gfx DLLs
    2>El sistema no puede encontrar la ruta especificada.
    2> 1 archivo(s) copiado(s).
    2>sample16x16.bmp
    2>sample24-box.bmp
    2>sample24.bmp
    2>sample2x2.bmp
    2>sample3x3.bmp
    2>sample8-box.bmp
    2>sample8.bmp
    2> 7 archivo(s) copiado(s).
    2>Done building project “TestGfx.vcxproj”.
    3>TestImageFilter.vcxproj -> C:\SDL2_gfx\test\TestImageFilter\Win32\Debug\TestImageFilter.exe
    3>Copy SDL2 and SDL2_gfx DLLs
    3>El sistema no puede encontrar la ruta especificada.
    3> 1 archivo(s) copiado(s).
    3>Done building project “TestImageFilter.vcxproj”.
    ========== Rebuild All: 3 succeeded, 2 failed, 0 skipped ==========

    Help, please!
    Thank you.

    Reply
  • April 28, 2018 at 8:46 am
    Permalink

    JFYI, changing #include “SDL.h” to #include has broken a lot of projects which refer to SDL includes as SDL/SDL.h and don’t include SDL/ into include paths.

    Reply
  • March 16, 2018 at 6:19 pm
    Permalink

    Could anyone please tell me how to compile this library for Windows 10? I have gone to lots of sites, and read the ‘Readme’ file, but I still cannot understand how to extract the dlls. I am not the most tech savvy person, so if anyone can tell me how to extract the library, I would be very thankful.

    Reply
  • March 15, 2018 at 11:48 pm
    Permalink

    Hello, Ferzkopp!

    Could you please:
    – Upload SDL2_gfx-1.0.4 to SourceForge, and
    – GPG sign your tarballs?

    Thanks

    Reply
  • March 12, 2018 at 8:05 am
    Permalink

    Could someone help me compiling and installing SDL2 gfx libary in mingw / codeblocks?
    There is a tutorial somewhere?

    Kind regards

    Reply
  • February 6, 2018 at 7:03 am
    Permalink

    I keep getting this error when I try to compile under mingw64. The truth is, I DO HAVE SDL2 2.0.7 installed correctly and I can compile just fine. The following compiles for me just fine:

    g++ sdl_test.cpp `sdl2-config –cflags –libs` -o sdl_test -std=c++0x

    But in configure for SDL2_gfx I get this.

    checking for SDL… checking for sdl2-config… okok /c/Windows/system32/sdl2-config
    /c/Windows/system32/sdl2-config
    checking for SDL – version >= 2.0.0… no
    *** Could not run SDL test program, checking why…
    *** The test program compiled, but did not run. This usually means
    *** that the run-time linker is not finding SDL or finding the wrong
    *** version of SDL. If it is not finding SDL, you’ll need to set your
    *** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
    *** to the installed location Also, make sure you have run ldconfig if that
    *** is required on your system

    Reply
    • February 9, 2018 at 4:56 am
      Permalink

      UPDATE 2 ***

      I ended up installing MS Visual Studio and after many Gb of downloading dependencies it compiled well enough to get the DLL and libs.

      Reply
  • November 25, 2017 at 8:35 am
    Permalink

    Can anyone please tell me how to build this library on android using c4droid!I would be really thankful if you could.Sorry if this comment sounds dumb

    Reply
    • November 26, 2017 at 1:20 am
      Permalink

      No idea – sorry.

      Reply
  • August 29, 2017 at 8:15 pm
    Permalink

    when I use texturedPolygon, my FPS plummets and other sprites in my game begin to flash!
    any idea what could cause this?
    The polygon has a low number of points (<16), and the texture, a PNG 320×320, isn't anything fancy either.

    Reply
    • August 29, 2017 at 9:12 pm
      Permalink

      SDL_gfx/SDL2_gfx is a software renderer to create various geometric objects with the API SDL1 or SDL2 provides. The texturedPolygon routine was added during the SDL1 release when this still made some sense for certain usage scenarios, and worked reasonably well with the SDL_Surface in-memory blitting interface. In SDL2, the core drawing interface changed to a small set of accelerated point and line drawing commands. In particular this routine does not work/perform well under SDL2 as it pretty much copies the texture pixel-by-pixel using SDL_RenderCopy(renderer, texture, &source_rect, &dst_rect) calls. So in SDL2 the API is provided as backwards compatibility layer, but it really shouldn’t be used for anything but small areas or simple stuff. It is also not multi-thread capable due to its use of a shared line-buffer object. If you want to draw textured polygons efficiently, you really need to use OpenGL or some other hardware accelerated API. SDL should help you initialize the API, but otherwise does not provide any other interfaces.

      Reply
      • August 29, 2017 at 10:20 pm
        Permalink

        that makes things clear, thanks a lot.
        then I’ll go ahead and setup OpenGL, though will I be able to continue to use the SDL_Renderer simultaneously then? I guess not when it uses DirectX… could it work when I force it to use OpenGL?

        Reply
        • August 29, 2017 at 11:59 pm
          Permalink

          You would probably need to render into a texture (SDL_RENDERER_TARGETTEXTURE = the renderer supports rendering to texture) and then draw the texture using a quad.

          Reply
  • July 15, 2017 at 5:30 am
    Permalink

    Can not build on VC2015.
    Error C1083 Cannot open include file: ‘SDL.h’: No such file or directory

    Reply
    • July 15, 2017 at 5:52 am
      Permalink

      When linked , gives another errors :
      Severity Code Description Project File Line Suppression State
      Warning LNK4217 locally defined symbol _printf imported in function _SDLTest_CommonInit TestGfx d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Warning LNK4075 ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification SDL2_gfx d:\Nowy folder\SDL2_gfx-1.0.1\SDL2_framerate.obj 1
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 186
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 188
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 190
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 192
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 194
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 217
      Warning C4267 ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data TestGfx d:\nowy folder\sdl2_gfx-1.0.1\test\testgfx.c 234
      Warning LNK4075 ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification TestGfx d:\Nowy folder\SDL2_gfx-1.0.1\test\TestGfx.obj 1
      Warning LNK4075 ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification TestRotozoom d:\Nowy folder\SDL2_gfx-1.0.1\test\TestRotozoom.obj 1
      Warning LNK4217 locally defined symbol _fprintf imported in function _SDLTest_CommonInit TestGfx d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Error LNK2019 unresolved external symbol __imp____iob_func referenced in function _SDLTest_CommonInit TestGfx d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Error LNK1120 1 unresolved externals TestGfx d:\Nowy folder\SDL2_gfx-1.0.1\test\TestGfx\Win32\Debug\TestGfx.exe 1
      Error LNK2019 unresolved external symbol __imp__printf referenced in function _SDLTest_CommonInit TestRotozoom d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Error LNK2019 unresolved external symbol __imp__fprintf referenced in function _SDLTest_CommonInit TestRotozoom d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Error LNK2019 unresolved external symbol __imp____iob_func referenced in function _SDLTest_CommonInit TestRotozoom d:\Nowy folder\SDL2_gfx-1.0.1\test\SDL2test.lib(SDL_test_common.obj) 1
      Error LNK1120 3 unresolved externals TestRotozoom d:\Nowy folder\SDL2_gfx-1.0.1\test\TestRotozoom\Win32\Debug\TestRotozoom.exe 1
      Warning LNK4075 ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification TestImageFilter d:\Nowy folder\SDL2_gfx-1.0.1\test\testimagefilter.obj 1

      Reply
      • July 15, 2017 at 2:04 pm
        Permalink

        Not sure what’s happening. My VisualStudio build shows the same warning, but otherwise works:

        1>—— Build started: Project: SDL2_gfx, Configuration: Debug Win32 ——
        1>SDL2_imageFilter.c
        1>SDL2_rotozoom.c
        1>SDL2_gfxPrimitives.c
        1>SDL2_framerate.c
        1>Generating Code…
        1>SDL2_framerate.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
        1> Creating library Win32\Debug\SDL2_gfx.lib and object Win32\Debug\SDL2_gfx.exp
        1>SDL2_gfx.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\Win32\Debug\SDL2_gfx.dll
        1>SDL2_gfx.vcxproj -> Win32\Debug\SDL2_gfx.pdb (Full PDB)
        1>Done building project “SDL2_gfx.vcxproj”.
        2>—— Build started: Project: TestGfx, Configuration: Debug Win32 ——
        3>—— Build started: Project: TestImageFilter, Configuration: Debug Win32 ——
        4>—— Build started: Project: TestRotozoom, Configuration: Debug Win32 ——
        5>—— Build started: Project: TestFramerate, Configuration: Debug Win32 ——
        2>TestGfx.c
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(186): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(188): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(190): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(192): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(194): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(217): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>d:\projects\sdl2_gfx-1.0.3\test\testgfx.c(234): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        3>testimagefilter.c
        2>TestGfx.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
        4>TestRotozoom.c
        5>TestFramerate.c
        5>d:\projects\sdl2_gfx-1.0.3\test\testframerate.c(104): warning C4267: ‘function’: conversion from ‘size_t’ to ‘Sint16’, possible loss of data
        2>TestGfx.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestGfx\Win32\Debug\TestGfx.exe
        2>TestGfx.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestGfx\Win32\Debug\TestGfx.pdb (Full PDB)
        4>TestRotozoom.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
        2> 1 file(s) copied.
        2> 1 file(s) copied.
        2>sample16x16.bmp
        5>TestFramerate.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
        2>sample24-box.bmp
        2>sample24.bmp
        2>sample2x2.bmp
        2>sample3x3.bmp
        2>sample8-box.bmp
        2>sample8.bmp
        2> 7 file(s) copied.
        2>Done building project “TestGfx.vcxproj”.
        4>TestRotozoom.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestRotozoom\Win32\Debug\TestRotozoom.exe
        3>testimagefilter.obj : warning LNK4075: ignoring ‘/EDITANDCONTINUE’ due to ‘/SAFESEH’ specification
        5>TestFramerate.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestFramerate\Win32\Debug\TestFramerate.exe
        4>TestRotozoom.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestRotozoom\Win32\Debug\TestRotozoom.pdb (Full PDB)
        4> 1 file(s) copied.
        4> 1 file(s) copied.
        4>.\sample16x16.bmp
        4>.\sample24-box.bmp
        4>.\sample24.bmp
        4>.\sample2x2.bmp
        4>.\sample3x3.bmp
        4>.\sample8-box.bmp
        4>.\sample8.bmp
        4> 7 file(s) copied.
        4>Done building project “TestRotozoom.vcxproj”.
        5>TestFramerate.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestFramerate\Win32\Debug\TestFramerate.pdb (Full PDB)
        5> 1 file(s) copied.
        5> 1 file(s) copied.
        5>Done building project “TestFramerate.vcxproj”.
        3>TestImageFilter.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestImageFilter\Win32\Debug\TestImageFilter.exe
        3>TestImageFilter.vcxproj -> D:\Projects\SDL2_gfx-1.0.3\test\TestImageFilter\Win32\Debug\TestImageFilter.pdb (Full PDB)
        3> 1 file(s) copied.
        3> 1 file(s) copied.
        3>Done building project “TestImageFilter.vcxproj”.
        ========== Build: 5 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

        Reply
    • July 15, 2017 at 1:58 pm
      Permalink

      Run notepad SDL2_gfx.vcxproj and edit the AdditionalIncludeDirectories element from the default ..\SDL2-2.0.5\include;%(AdditionalIncludeDirectories) to match the local install location of SDL2.

      Reply
    • July 15, 2017 at 2:02 pm
      Permalink

      Should be fixed now. Thanks for pointing this out.

      Reply
    • July 15, 2017 at 1:53 pm
      Permalink

      I don’t think SSL is enabled on the site; wget http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-1.0.1.tar.gz works.

      Reply
  • July 7, 2017 at 3:59 pm
    Permalink

    For anyone struggling with the (seemingly) lack of an SDL_gfx.framework for xcode:

    – Download the latest version of SDL_gfx and unzip it.
    – Open the folder that was made by unzipping the download and unzip xocde.zip that’s in there .
    – Open the xcode folder that was made when you unzipped the second time and click the xcode project file to open it with xcode.
    – Build the project.
    – Go to wherever your output path is and copy the resulting SDL2_gfx.framework ‘file’ to wherever you keep your extra frameworks which for me is /Library/frameworks.

    Don’t forget to add this as a linked library under the ‘build phases’ tab of your project!

    Big thanks to the author by the way 🙂

    Reply
  • July 4, 2017 at 9:50 am
    Permalink

    In case anyone was having trouble compiling this in MSYS with MinGW, or a similar unix on Windows environment, and getting an error:

    *** Warning: linker path does not have real file for library -lmingw32.
    *** Warning: linker path does not have real file for library -lSDL2main.
    *** Warning: linker path does not have real file for library -luuid.

    Exporting the following variable did the trick:
    export lt_cv_deplibs_check_method=’pass_all’

    Reply
  • June 4, 2017 at 2:09 pm
    Permalink

    You have an off-by-one error in your rotateSurface90Degrees method. It is in the 270 degree rotation part of the switch statement.

    case 3: /* rotated 270 degrees clockwise */
    {
    for (row = 0; row h; ++row) {
    srcBuf = (Uint8*)(src->pixels) + (row * src->pitch);
    dstBuf = (Uint8*)(dst->pixels) + (row * bpp) + (dst->h * dst->pitch);
    for (col = 0; col w; ++col) {
    memcpy (dstBuf, srcBuf, bpp);
    srcBuf += bpp;
    dstBuf -= dst->pitch;
    }
    }
    }
    break;
    }

    the initial dstBuf value goes too far in memory by a pitch line.
    dstBuf = (Uint8*)(dst->pixels) + (row * bpp) + (dst->h * dst->pitch);
    should be
    dstBuf = (Uint8*)(dst->pixels) + (row * bpp) + ((dst->h – 1) * dst->pitch);

    imagine if the image were just a line of 10 vertical pixels being rotated 270 degrees causing them to become horizontal.
    dstBuf’s pitch would be 40 if the bytes per pixel were 4.
    say dstBuf’s pixel memory location were 0.
    dst’s pixel data would be from byte 0 to 39.
    dstBuf would first evaluate to 0 + (0 * 4) + (1 * 40) = 40 which is beyond the allocated memory for dst surface.

    hopefully you see the problem.
    I figure you could have figured it out yourself just by looking at the difference in code I presented, but the explanation for the change is to save you some thinking.

    Reply
    • June 4, 2017 at 9:52 pm
      Permalink

      Thanks for reporting. I’ll the fix into the next release.

      Reply
  • April 21, 2017 at 5:26 pm
    Permalink

    There’s a bug with drawing horizontal AA lines. If xx0 > xx1, the line gets drawn in the wrong direction: (line 952 in SDL2_gfxPrimitives.c)

    return (hlineRGBA(renderer, xx0, xx0+dx, y1, r, g, b, a));

    Changing the above to:

    return (hlineRGBA(renderer, xx0, xx0+(xdir*dx), y1, r, g, b, a));

    fixed the problem as xdir was set to -1 when xx0 > xx1

    Reply
    • May 2, 2017 at 8:07 am
      Permalink

      Thanks for reporting.

      Reply
  • March 16, 2017 at 5:39 am
    Permalink

    SDL_gfx-2.0.26 link is pointing to the SDL_gfx.2.0.25.tar.gz? The repository seems to be on 2,0.26, but there is no tarball. 🙂

    Reply
    • March 27, 2017 at 8:31 am
      Permalink

      Thanks – link is fixed now.

      Reply
  • February 4, 2017 at 6:12 am
    Permalink

    Hi!

    Have you considered enriching the SDL_BlitScaled()
    with the smooth zooming like your zoomSurface() has?
    The problem I have with zoomSurface() is that it creates
    the new surface from which I have to blit. Extra copy
    operation. Having the smoothing functionality in SDL_BlitScaled()
    and SDL_SoftStretch() would save me from extra copy.

    Reply
    • February 20, 2017 at 9:35 pm
      Permalink

      I don’t have the time to work on integrating this into SDL at this time – sorry.

      Reply
  • December 25, 2016 at 2:23 pm
    Permalink

    Thanks for your work on SDL2_gfx ferzkopp!

    Its helping me a lot on a current project.

    I’ve noticed something in the source code of SDL2_gfxPrimitives.c:
    ——-
    int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
    Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    {
    (…)
    /*
    * Special case – no rounding
    */
    if (rad <= 1) {
    return rectangleRGBA(renderer, x1, y1, x2, y2, r, g, b, a);
    }

    maybe it shoud be:
    /*
    * Special case – no rounding
    */
    if (rad <= 1) {
    return boxColor(renderer, x1, y1, x2, y2, r, g, b, a);
    }
    —-
    If a roundedBoxRGBA is being asked with no radius, a boxColor probably should be delivered instead of rectangleColor.

    I've patched and rebuilt that way but figured you could use this feedback

    Thanks!

    Reply
    • December 25, 2016 at 6:49 pm
      Permalink

      Yes, looks like a copy-n-paste bug. Thanks for letting me know.

      Reply
  • October 15, 2016 at 4:03 pm
    Permalink

    Can you provide steps on to how build the SDL2_gfx dll for visual studio 2015?

    Reply
    • December 25, 2016 at 2:11 pm
      Permalink

      In you’re still looking for an answer: the SDL2_gfx downloads are available in .tar.gz and .zip: the .zip comes with vs2015 solution, (almost) ready to build. If you have the SDL2-devel-2.0.5-VC (or other version) development Libraries already the only thing you’ll need to do is set its include and library paths on the vs project and build it.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.