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
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
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
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.
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
I am not familiar with that environment, but maybe check here: https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/
Unable to start program
SDL2_gfx-1.0.4\Win32\Debug\SDL2_gfx.dll is not a valid Win32 application
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.
Can you give a tutorial on how to compile gfx with windows?
Thanks
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.
Pingback:Download and use SDL2 gfx – Windows Questions
See comments below.
Pingback:How to add SDL2_gfxPrimitives to my visual studio 2019? – Windows Questions
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.
HI, the latest visual studio 2019 16.9.0 implemented the function
lrint, lrintf …
So I meet some compile error when compiling the gfx library.
So, some version check should be added to the macro at line 1742 in SDL2_gfxPrimitives.c
Here is some source of failed compile:
https://github.com/Taowyoo/rust-sdl2/runs/2239677331?check_suite_focus=true#step:5:145
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);
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.
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.
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);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Try to remove -DUSE_MMX.
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.
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.
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.
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!
Thanks – glad it worked for your needs!
Hello!
Sorry to bother you!
Have anyone build x64 dll on windows?
VS2017 donnot support _asm (x64)
How can i do it?
The DLL should be compilable to x64; what’s the error message you are getting?
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.
There is an off-by-1 issue with rectangleRGBA. It needs to be changed the same way boxRGBA was.
Thanks for the bug report. I’ll have a look – would you have the file/version/line#?
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.
This seems to be due to recent changes in the C Runtime Library (CRT) which are not handled by in SDL2Test.lib. See this thread for various solutions: https://stackoverflow.com/questions/30412951/unresolved-external-symbol-imp-fprintf-and-imp-iob-func-sdl2
Excelent!
I’ll take a look over there.
Thanks again!
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.
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.
Hello, Ferzkopp!
Could you please:
– Upload SDL2_gfx-1.0.4 to SourceForge, and
– GPG sign your tarballs?
Thanks
Done and done.
wget http://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-1.0.4.tar.gz.asc
gpg –keyserver pool.sks-keyservers.net –recv-key E1DDB871
gpg SDL2_gfx-1.0.4.tar.gz.asc
Could someone help me compiling and installing SDL2 gfx libary in mingw / codeblocks?
There is a tutorial somewhere?
Kind regards
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
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.
Great to hear that you got it working. I am not sure why your mingw64 compile failed. It is probably some sdl2-config setup issue (i.e. paths not set right to be able to check the version).
undefined reference to `WinMain@16′
https://stackoverflow.com/questions/32342285/undefined-reference-to-winmain16-c-sdl-2
The configure script needs to be updated
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
No idea – sorry.
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.
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.
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?
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.
Can not build on VC2015.
Error C1083 Cannot open include file: ‘SDL.h’: No such file or directory
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
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 ==========
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.Your link in SDL2_gfx section directs to SDL_gfx instead:
https://sourceforge.net/projects/sdlgfx/
Should be fixed now. Thanks for pointing this out.
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to http://www.ferzkopp.net:443
==> ERROR: Failure while downloading https://www.ferzkopp.net/Software/SDL2_gfx/SDL2_gfx-1.0.1.tar.gz
http://funkyimg.com/i/2viJb.png
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.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 🙂
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’
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.
Thanks for reporting. I’ll the fix into the next release.
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
Thanks for reporting.
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. 🙂
Thanks – link is fixed now.
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.
I don’t have the time to work on integrating this into SDL at this time – sorry.
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!
Yes, looks like a copy-n-paste bug. Thanks for letting me know.
Can you provide steps on to how build the SDL2_gfx dll for visual studio 2015?
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.
Hello,
Sorry to post here, but I’m getting desperate with your lib…
If you have time : http://stackoverflow.com/questions/39817226/sdl2-gfx-install-and-use-mac-os-x
I really don’t get how it works.