veandco / go-sdl2

SDL2 binding for Go
https://godoc.org/github.com/veandco/go-sdl2
BSD 3-Clause "New" or "Revised" License
2.21k stars 221 forks source link

How to install SDL_gfx on windows #444

Closed Suceru closed 4 years ago

Suceru commented 4 years ago

Mingw is currently installed, its directory is in D:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64 , the SDL_image and ttf are installed to copy the entire SDL2_image-devel-2.0.5-mingw.tar.gz\SDL2_image-devel-2.0.5-mingw.tar\SDL2_image-2.0.5\x86_64-w64-mingw32 folder to D:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\x86_64-w64-mingw32

But SDL_gfx is different from SDL_ttf, it does not have the x86_64-w64-mingw32 folder, I do not understand how to install SDL_gfx-2.0.26.tar.gz to Windows 10 .

veeableful commented 4 years ago

Hi @Suceru! Sorry for the late reply. Could you try this method and see if it works for you? I will add it to the README if it's simple enough to follow.

Suceru commented 4 years ago

Hi @Suceru! Sorry for the late reply. Could you try this method and see if it works for you? I will add it to the README if it's simple enough to follow. @veeableful I'm not familiar with mingw, i downloadedSDL2_gfx.dll and put it in the \bin directory like SDL_image. Then copy all the .h files to the x86_64-w64-mingw32\include\SDL2 folder, and change the file name and header file to 2 (eg:like SDL2_gfxPrimitives.h). When using go run C:\Users\fidax\go\src\github.com\veandco\go-sdl2\.go-sdl2-examples\examples\gfx command, it prompts ld.exe: cannot find -lSDL2_gfx

SDL2_gfx

copy to

folder

change the file names

header name

In CMD run go run gfx.go

cmd go run
veeableful commented 4 years ago

Hi @Suceru, have you tried to put it inside lib as well?

Suceru commented 4 years ago

@veeableful Sorry, when I did this, I didn't know what I should do next. I have put SDL2_gfx.dll in \lib, Run ... .

copy cmd go run
# github.com/veandco/go-sdl2/gfx
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:91:90: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_pixelColor
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:103:86: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_pixelRGBA
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:113:81: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_hlineColor
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:126:92: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_hlineRGBA
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:136:81: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_vlineColor
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:149:92: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_vlineRGBA
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:160:91: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_rectangleColor
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:174:102: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_rectangleRGBA
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:186:104: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_roundedRectangleColor
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:201:115: cannot use _cgo0 (type *_Ctype_struct_SDL_Renderer) as type *_Ctype_struct_SDL_Surface in argument to _Cfunc_roundedRectangleRGBA
go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:201:115: too many errors
veeableful commented 4 years ago

Hmm that's strange.. are you using sdl.Surface instead of sdl.Renderer with gfx functions?

Suceru commented 4 years ago

@veeableful I am directly running the code for the example.

go\src\github.com\veandco\go-sdl2.go-sdl2-examples\examples\gfx\gfx.go

That's what he originally wrote. So, I don't known

veeableful commented 4 years ago

Hi @Suceru, I see that you are using sdl.Surface (at least from what I can tell in the screenshot above) and the example doesn't have sdl.Surface. Are you using the latest go-sdl2?

Suceru commented 4 years ago

Yes, go-sdl2 is the latest version. There is no SDL_surface code in the examples, only SDL_renderer. The location of this error message comes from the file SDL_gfx.go

. # github.com/veandco/go-sdl2/gfx go\src\github.com\veandco\go-sdl2\gfx\sdl_gfx.go:91:90: cannot use _cgo0 (type _Ctype_struct_SDL_Renderer) as type _Ctype_struct_SDL_Surface in argument to _Cfunc_pixelColor

My other SDL2 configurations can be used normally, but sdl_gfx does not know how to install. I put the sdl_gfx.dll in the link you posted earlier into the \ binand \ lib folders (I don't know if it is correct). In addition, copy the .h file in the downloaded sdl_gfx archive to the\included\sdl2 folder and then#include <SDL/SDL.h> inside changed to #include <SDL2/SDL.h> When the#include <SDL2 / SDL.h> error is not prompted, show the SDL_surface cannot be used. My intuition is that only go-sdl_gfx is correct, there should be problems in the setting part ofmingw

veeableful commented 4 years ago

Hmm that's weird... Could you post the definition of pixelColor in the SDL2_gfxPrimitives.h file? It should be in the include directory. The one I have looks like this:

SDL2_GFXPRIMITIVES_SCOPE int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color);
Suceru commented 4 years ago

@veeableful Oh, thank you guys, I have configured. First of all, I mistakenly regarded the gfx of SDLas the gfx of SDL2 (I saw two versions 1.0.4 and 2.0.25 on the website, I didn't pay much attention to 2.0.25 as the latest version of SDL2). Then I copied the .h and .c files of SDL2-gfx to the \include\SDL2 of mingw folder and it worked fine. The correct is:

need SDL2-gfx

The err is:

err sdl-gfx

put .h and .c to \SDL2

put to sdl

put SDL_gfx.dll to \bin and \lib(If this are missing , will be errs:1. exit status 3221225781 and 2. ``` /x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2_gfx collect2.exe: error: ld returned 1 exit status



<img width="582" alt="SDL2_gfx-dll" src="https://user-images.githubusercontent.com/20983345/72696786-81527300-3b78-11ea-9dd4-a72021db1537.PNG">
Suceru commented 4 years ago

@veeableful It turns out that the method you proposed earlier is correct, as long as you download the .dll file and .h and .c files, you can use it. oh, thank you!!!

run
veeableful commented 4 years ago

No problem @Suceru! Glad I could help 😃