gen2brain / raylib-go Goto Github PK
View Code? Open in Web Editor NEWGo bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
License: zlib License
Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
License: zlib License
The function raylib.GetImageData returns an array of bytes instead of an array of raylib.Color. Hope you'll fix that soon.
The examples at the moment import raylib using it's full name, so all the calls using it need the full name.
eg from the snake example:
import (
"github.com/gen2brain/raylib-go/raylib"
)
type Snake struct {
Position raylib.Vector2
Size raylib.Vector2
Speed raylib.Vector2
Color raylib.Color
}
func main() {
game := Game{}
game.Init()
raylib.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
raylib.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
...
func (g *Game) Init() {
g.ScreenWidth = 800
g.ScreenHeight = 450
g.FramesCounter = 0
g.GameOver = false
...
Would it be better to shorten the import name to r
or even ray
, so the calls to raylib functions are each a few characters less to type? Other code pieces already use 1 letter names (eg g
above).
For example, importing it as r
instead:
import (
r "github.com/gen2brain/raylib-go/raylib"
)
type Snake struct {
Position r.Vector2
Size r.Vector2
Speed r.Vector2
Color r.Color
}
func main() {
game := Game{}
game.Init()
r.InitWindow(game.ScreenWidth, game.ScreenHeight, "sample game: snake")
r.SetTargetFPS(60)
for !r.WindowShouldClose() {
...
func (g *Game) Init() {
g.ScreenWidth = 800
g.ScreenHeight = 450
g.FramesCounter = 0
g.GameOver = false
...
Seems like a win?
Silly question but I've really only just seen raylib and it looks great I'm just wondering specifically for go, how would I get it compiling for the web?
Hi I'm on Arch Linux. All examples run fine with the exception of audio. When I run e.g. "module_playing" it opens the window but only shows a black screen. I hear nothing and Gnome asks me to close the hanging program.
I wonder if you have an idea what causes this? All of these examples run fine when I compile them for original raylib(C) 1.8.0.
It's hard to say with precision what's causing this because it's an intermittent problem, I don't seem to be able to find an exact pattern of behaviour.
All the examples that come with raylib-go work just fine, and I wrote a couple of my own that work just fine, loading textures and painting them on screen.
However once I started to create slightly more complex tests, I began to experience problems with some textures. I worked to narrow down the problem to the bare minimum, and I realised that the bare minimum code that comes with the examples also exhibits this problem if you leave the code unmodified, and you change the texture images you use.
For example, if I compile any of the raylib-go examples in the textures examples folder, and I run them unmodified they work just fine. Then I only change the image texture the example uses without changing anything of the code, and I start getting errors when I attempt to load the texture to GPU.
(the texture load function complains and doesn't return a texture handle).
So I tried different texture sizes. I created different PNG files of different sizes, and ran the code unmodified, only changing the texture files.
The texture samples appear to always work just fine for texture sizes of under 512 x 512 pixels in size.
Problems begin to appear after I increase the texture size beyond 512 x 512 pixels, the texture sometimes, apparently randomly, won't load to GPU.
This behaviour happens more frequently as you increase the texture size.
For example, if you attempt to load a 1024 x 1024 texture, that increases the frequency of failures, the programs fail more often. If you create textures of 2048 x 2048 and above, the frequency of failures is completely unpredictable, and programs fail to load textures of that size more than 50% of the time.
I'm using Ubuntu 16.04 with XGL extensions, and the Compiz manager, on an Intel Compute Stick that comes with a typical Intel GPU. This is the raylib output log when programs in the examples/textures folder are started.
INFO: Initializing raylib (v1.7.0)
INFO: Display device initialized successfully
INFO: Display size: 1920 x 1080
INFO: Render size: 800 x 450
INFO: Screen size: 800 x 450
INFO: Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: OpenGL 3.3 Core profile supported
INFO: GPU: Vendor: Intel Open Source Technology Center
INFO: GPU: Renderer: Mesa DRI Intel(R) Bay Trail
INFO: GPU: Version: 3.3 (Core Profile) Mesa 12.0.6
INFO: GPU: GLSL: 3.30
$ go get -v github.com/gen2brain/raylib-go/raylib
github.com/gen2brain/raylib-go/raylib
# github.com/gen2brain/raylib-go/raylib
In file included from C:\goworksp\src\github.com\gen2brain\raylib-go\raylib\audio.go:4:0:
./external/stb_vorbis.c:175:26: fatal error: alloca.h: No such file or directory
#include <alloca.h>
^
compilation terminated.
Hi, I'm a new go developer and I don't know much about this project so it might not be a mistake, but when I install the library it tells me the following:
In file included from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:18:0:
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c: In function 'updateCursorImage':
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:247:41: warning: passing argument 2 of 'LoadCursorW' from incompatible pointer type [-Wincompatible-pointer-types]
SetCursor(LoadCursorW(NULL, IDC_ARROW));
^~~~~~~~~
In file included from c:\mingw\include\windows.h:48:0,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_platform.h:65,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/internal.h:186,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/context.c:28,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:6:
c:\mingw\include\winuser.h:4003:27: note: expected 'LPCWSTR {aka const short unsigned int *}' but argument is of type 'CHAR * {aka char *}'
WINUSERAPI HCURSOR WINAPI LoadCursorW (HINSTANCE, LPCWSTR);
^~~~~~~~~~~
In file included from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:18:0:
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c: In function 'translateCursorShape':
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:406:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_ARROW;
^~~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:408:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_IBEAM;
^~~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:410:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_CROSS;
^~~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:412:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_HAND;
^~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:414:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_SIZEWE;
^~~~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:416:20: warning: return from incompatible pointer type [-Wincompatible-pointer-types]
return IDC_SIZENS;
^~~~~~~~~~
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c: In function '_glfwRegisterWindowClassWin32':
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:1198:42: warning: passing argument 2 of 'LoadCursorW' from incompatible pointer type [-Wincompatible-pointer-types]
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
^~~~~~~~~
In file included from c:\mingw\include\windows.h:48:0,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_platform.h:65,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/internal.h:186,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/context.c:28,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:6:
c:\mingw\include\winuser.h:4003:27: note: expected 'LPCWSTR {aka const short unsigned int *}' but argument is of type 'CHAR * {aka char *}'
WINUSERAPI HCURSOR WINAPI LoadCursorW (HINSTANCE, LPCWSTR);
^~~~~~~~~~~
In file included from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:18:0:
Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_window.c:1209:31: warning: passing argument 2 of 'LoadImageW' from incompatible pointer type [-Wincompatible-pointer-types]
IDI_APPLICATION, IMAGE_ICON,
^~~~~~~~~~~~~~~
In file included from c:\mingw\include\windows.h:48:0,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/win32_platform.h:65,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/internal.h:186,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib/external/glfw/src/context.c:28,
from Users\etian_ya1t1\go\src\github.com\gen2brain\raylib-go\raylib\cgo_windows.go:6:
c:\mingw\include\winuser.h:4015:26: note: expected 'LPCWSTR {aka const short unsigned int *}' but argument is of type 'CHAR * {aka char *}'
WINUSERAPI HANDLE WINAPI LoadImageW (HINSTANCE, LPCWSTR, UINT, int, int, UINT);`
Thanks.
Pd: I can use the library... I do not know if that is a error
Hi, I wanted to take a screenshot of the basic window example:
package main
import (
rl "github.com/gen2brain/raylib-go/raylib"
"time"
)
func main() {
rl.InitWindow(800, 450, "raylib [core] example - basic window")
rl.SetTargetFPS(60)
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
rl.EndDrawing()
time.Sleep(time.Second)
rl.TakeScreenshot("bar.png")
rl.CloseWindow()
}
Despite the window showing the correct background and text, the resulting image bar.png is just a black image (not transparent, confirmed with Photoshop). I added the pause just to be sure it wasn't some parallelism issue.
I ran this on W10.
Edit: I tried pausing also AFTER the screenshot call but got the same result.
Is there a way to retrieve a list of potential maximum window sizes?
Looking at an upstream issue related to window/monitor sizing, it points to the GLFW docs.
Reading through the info there, it seems like this is something GLFW can report back.
Is there presently a way to get that info with raylib/raylib-go? 😄
Hey, there!
The easing library is definitely useful, but the arguments being named single letters makes it hard to use, especially without any example. It might be good to rename the arguments to what they're expected to be (time / factor, min, max, etc). It might also be good to add an example, or something similar. I could do this myself, as well; I just have to get around to making a PR for it.
Thanks for the port, anyway! It's very useful.
Hi @gen2brain, is raylib-go aligned with latest raylib 1.8? do you follow the develop branch? what's the current state?
By the way, right now I'm working on raygui module, trying to improve it...
Hey,
coding a bit today let me saw that function is missing =/ Hope it will fixed soon, thanks in advance :D
Hey, there.
I'm trying to build my test project on Windows for assistance with fixing #13, and I'm having trouble getting Go and raylib-go up and running with MSYS2. I have MSYS2 downloaded and installed, but the instructions for raylib-go don't really mention too much more about how to install raylib-go. For example, I ran the line for Pacman, but go
wouldn't run in the MSYS2 terminal until I added GOROOT and GOPATH environment variables and tweaked the batch file to inherit the Windows PATH settings. Currently, after calling go get -v ...
for each dependency of my number, I call go build
in the directory of my project and get this:
$ go build
# _/C_/Users/SolarLuneUser/go/src/SingleScreen
github.com/gen2brain/raylib-go/raylib(.text): strdup: not defined
github.com/gen2brain/raylib-go/raylib(.text): strdup: not defined
github.com/gen2brain/raylib-go/raylib(.text): strdup: not defined
github.com/gen2brain/raylib-go/raylib(.text): strdup: not defined
github.com/gen2brain/raylib-go/raylib(.text): undefined: strdup
github.com/gen2brain/raylib-go/raylib(.text): undefined: strdup
github.com/gen2brain/raylib-go/raylib(.text): undefined: strdup
github.com/gen2brain/raylib-go/raylib(.text): undefined: strdup
as a result. It's also a bit surprising that the instructions state to install Go itself instead of just the prerequisites for an existing Go install. Am I supposed to run go
through the MSYS2 command prompt to build my project? My GOPATH
is C:\msys64\mingw64
and my GOROOT
is C:\msys64\mingw64\lib\go
. Is that correct?
Thanks for any help anyone can give. I'm running Windows 10 64-bit, by the way.
Hello,
I'm trying to use the audio functions, but I'm not able to link with OpenAL. If I try to run some audio example, I get the expected error:
audio.c:89:59: fatal error: AL/al.h: No such file or directory
I downloaded the OpenAL binaries (I am on Windows) from http://kcat.strangesoft.net/openal-binaries/openal-soft-1.18.2-bin.zip, but I don't know where to go from here. I probably should place the include and lib folders where the Cgo system can find them, but I cannot figure where...
Sorry if this is a trivial question, but I am not into C programming - that's why I am trying Go :)
Thank you!
I hope it's okay to ask here. Is there a way to define a seperate size for rendering and actual screen size?
Like let's say my game runs at 240x160. I increase the window size, so the graphics will adapt relative to that. But the game still thinks it's at 240x160.
Please add wayland support to the glfw dependency
At the moment, in the 3d picking example there is a warning about GetMouseRay()
not working correctly, but no pointer to further info:
// NOTE: This function is NOT WORKING properly!
ray = raylib.GetMouseRay(raylib.GetMousePosition(), camera)
Is that related to raysan5/raylib#35?
If so, the fix for that (raysan5/raylib@21229aa) looks to be in Raylib 1.4.0 and onwards, so the warning can probably be removed. (?) 😄
Found a weird bug earlier today, and took some time to confirm it on a 2nd system (just in case).
The bug is really easy to reproduce. It just needs a medium sized grid of Cubes to be created.
When the number of cubes passes some threshold, instead of rendering in the correct location the cubes start getting rendered directly in front of the camera as part of the camera.
Example code, with the threshold passed:
for i := -10; i < 10; i++ {
for j := -10; j < 11; j++ { // Change the 11 to 6 or lower, and the bug goes away
r.DrawCube(r.Vector3{X:float32(i), Z:float32(j)}, 0.2, 0.2, 0.2, r.Red)
}
}
Screenshots, showing the cubes incorrectly rendered directly in front of the camera:
When panning the camera around (eg using the mouse), the incorrectly placed cubes move with the camera. eg they're always fixed right in front, with the rest of the scene moving around.
This code is underneath the threshold, so things work:
for i := -10; i < 10; i++ {
for j := -10; j < 6; j++ { // Change the 6 to a higher number and a bug appears
r.DrawCube(r.Vector3{X:float32(i), Z:float32(j)}, 0.2, 0.2, 0.2, r.Red)
}
}
When things work correctly, this is how it's supposed to look:
For reference (as I tested this on two systems, with different OpenGL versions) the full code is here:
https://github.com/justinclift/raylib_bug1
It's super simple code. 😄
MINGW64 ~
$ go get -v github.com/gen2brain/raylib-go/raylib
github.com/gen2brain/raylib-go/raylib
# github.com/gen2brain/raylib-go/raylib
In file included from C:\goworksp\src\github.com\gen2brain\raylib-go\raylib\audio.c:89:0:
C:\goworksp\src\github.com\gen2brain\raylib-go\raylib\external/dr_flac.h:685:20: fatal error: endian.h: No such file or directory
#include <endian.h>
^
compilation terminated.
I have no endian.h file in MSYS2.
I'd love to build this and run it myself, especially on mobile. Could you include some basic steps for building the game so people can build it and add on to it?
Thanks!
I do the "go build MyProgramWithRaylibgo.go" with GOARCH=386 and get that error
"
github.com/gen2brain/raylib-go/raylib
..\github.com\gen2brain\raylib-go\raylib\raylib.go:1120:9: undefined: LoadImageEx
"
aslso after "go get -v -u github.com/gen2brain/raylib-go/raylib", same error.
I've found 2 problems with raygui.TextBox :
Hope you l'ill fix soon, I really need these bug fix for my game :D
I think that every time I updated GLFW, wayland build was broken, and new protocol files (.c/.h) generated with wayland-scanner
needed to be included. It would be good to test build in travis, but I am not sure if it can be just new matrix with some env in .travis.yml, something like that.
I tested in latest Ubuntu and there apt-get install libgl1-mesa-dev libwayland-dev libxkbcommon-dev
is enough, and I also added this symlink ln -sf /usr/lib/x86_64-linux-gnu/libwayland-egl.so.1.0.0 /usr/lib/x86_64-linux-gnu/libwayland-egl.so
For Ubuntu 14, that version is used in CI, libwayland-egl1-mesa-lts-xenial
must also be included, and again, I had to make a symlink, not sure why just so.1.0.0 is installed without any symlink.
Also, for latest GLFW I had to generate and include more .c files, see https://github.com/gen2brain/raylib-go/blob/master/raylib/cgo_linux.go#L19 (current raylib misses just wayland-idle-inhibit but after you update GLFW more are needed).
I updated GLFW because of this commit, it sounds bad glfw/glfw@8b9221d
When building with the wayland tag, following error occurs:
# github.com/gen2brain/raylib-go/raylib
In file included from ./external/glfw/src/internal.h:171:0,
from ./external/glfw/src/context.c:28,
from /.../go/src/github.com/gen2brain/raylib-go/raylib/cgo_linux.go:6:
./external/glfw/src/wl_platform.h:54:10: fatal error: wayland-relative-pointer-unstable-v1-client-protocol.h: No such file or directory
#include "wayland-relative-pointer-unstable-v1-client-protocol.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For more information please see:
Thanks!
Hi! Great job on the port, been having a blast using it over the past few days.
I noticed today that a number of Vector related Raymath functions in the go port are mutating the vector instead of returning a transformed copy, which seems to diverge in behaviour from Raymath C.
(Raylib C also initially had this behaviour but this was changed in this commit from last March.)
To illustrate my point, Vector2Scale
is one example of such difference:
Raymath C: https://github.com/raysan5/raylib/blob/master/src/raymath.h#L219-L223
Raymath go: https://github.com/gen2brain/raylib-go/blob/master/raymath/raymath.go#L57-L60
Would you consider updating Raymath-go to normalize with the behaviour of Raymath-C? (I am a novice Go developer but could help with this.)
Thanks!
Welp, wasted a day on this.
I tried to compile the RPI example and followed the guide. The installation went fine, but the compiler throws me this error.
# github.com/gen2brain/raylib-go/raylib
In file included from /usr/local/vc/include/interface/vcos/vcos.h:118:0,
from /usr/local/vc/include/interface/vmcs_host/vc_dispmanx.h:33,
from /usr/local/vc/include/bcm_host.h:50,
from core.c:185:
/usr/local/vc/include/interface/vcos/pthreads/vcos_platform.h: In function ‘vcos_semaphore_wait_timeout’:
/usr/local/vc/include/interface/vcos/pthreads/vcos_platform.h:307:7: warning: implicit declaration of function ‘sem_timedwait’ [-Wimplicit-function-declaration]
ret = sem_timedwait( sem, &ts );
^
# github.com/gen2brain/raylib-go/raylib
In file included from mini_al.c:4:0:
external/src/github.com/gen2brain/raylib-go/raylib/external/mini_al.h:5517:28: fatal error: alsa/asoundlib.h: No such file or directory
#include <alsa/asoundlib.h>
^
compilation terminated.
Surely a library must be missing, so I installed libasound2-dev and tried it again with no success. Adding -I/usr/include/alsa as CFLAG didn't work either.
With MSYS2 by following the instructions the result did not compile. I needed to change in cgo_windows_static.go
and cgo_windows.go
from -lOpenAL32
to -lopenal
. I did a clean MSYS2 setup to verify.
Not sure whether this was a typo, some differences in how MSYS2 was installed or some left-over dll-s that allowed it to work.
Error message:
# github.com/gen2brain/raylib-go/raylib
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenAL32
collect2.exe: error: ld returned 1 exit status
Hi, it doesn't seem that OpenBSD is supported. (Note that in core.c
, it notes that OpenBSD is supported by raylib)
Running
go get -v -u github.com/gen2brain/raylib-go/raylib
on OpenBSD -current (as of today) returns:
github.com/gen2brain/raylib-go (download)
github.com/gen2brain/raylib-go/raylib
# github.com/gen2brain/raylib-go/raylib
core.c:736:1: warning: control reaches end of non-void function [-Wreturn-type]
core.c:1360:1: warning: control reaches end of non-void function [-Wreturn-type]
core.c:1917:37: error: use of undeclared identifier 'gamepadReady'
core.c:1931:9: error: use of undeclared identifier 'gamepadReady'; did you mean 'gamepadName'?
core.c:1929:17: note: 'gamepadName' declared here
core.c:1970:37: error: use of undeclared identifier 'gamepadReady'
core.c:1970:97: error: use of undeclared identifier 'gamepadAxisState'
core.c:1982:37: error: use of undeclared identifier 'gamepadReady'
core.c:1983:10: error: use of undeclared identifier 'currentGamepadState'
core.c:1983:50: error: use of undeclared identifier 'previousGamepadState'
core.c:1984:10: error: use of undeclared identifier 'currentGamepadState'
core.c:1996:37: error: use of undeclared identifier 'gamepadReady'
core.c:1997:10: error: use of undeclared identifier 'currentGamepadState'
core.c:2009:37: error: use of undeclared identifier 'gamepadReady'
core.c:2010:10: error: use of undeclared identifier 'currentGamepadState'
core.c:2010:50: error: use of undeclared identifier 'previousGamepadState'
core.c:2011:10: error: use of undeclared identifier 'currentGamepadState'
core.c:2023:37: error: use of undeclared identifier 'gamepadReady'
core.c:2024:10: error: use of undeclared identifier 'currentGamepadState'
core.c:2045:10: error: use of undeclared identifier 'currentMouseState'; did you mean 'currentKeyState'?
core.c:320:13: note: 'currentKeyState' declared here
core.c:2045:39: error: use of undeclared identifier 'previousMouseState'; did you mean 'previousKeyState'?
core.c:319:13: note: 'previousKeyState' declared here
core.c:2045:71: error: use of undeclared identifier 'currentMouseState'; did you mean 'currentKeyState'?
core.c:320:13: note: 'currentKeyState' declared here
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Is there anything I'm missing? Most of the requirements (Xlib and such) are in the base system.
Thanks for looking into this.
I'm trying to use voya's chipmunk physics like in one of the physics examples. I'm having a hard time with it though because it's over 3 years old and a lot of the stuff that is in chipmunk doesn't seem to be in go version. I'm trying to use AddCollisionHandler . Is there a newer version of chipmunk-go or somewhere to get documentation on how to implement a collision handler ?
Raylib drawing commands aren't thread-safe - which isn't a huge deal, since OpenGL isn't to begin with - but since the examples don't lock an OS thread, drawing commands could potentially be issued on a different thread after garbage collection (as in this issue).
The quick and dirty way of fixing this would be to manually call runtime.LockOSThread
in the examples. However, this seems like a common enough gotcha with Go and graphics libraries that it might be a good idea to handle it in the binding somehow - possibly by providing a mainthread-style helper?
Support for web platform is partially implemented. There are still problems with _emscripten_set_main_loop().
go generate -tags js github.com/gen2brain/raylib-go/raylib
will generate raylib.js
file in github.com/gen2brain/raylib-go/raylib (emcc
from emscripten must be in PATH).
GopherJS bindings to raylib.js
are here https://github.com/gen2brain/raylib-go/blob/master/raylib/raylib_js.go .
gopherjs build
is then used to build project example or game to js. After that, https://github.com/gen2brain/raylib-go/blob/master/raylib/external/web/index.html should be edited to include that js file.
If I open that index.html in browser, I can see that InitWindow() works, OpenGL ES is active, etc. but per emscripten docs https://kripken.github.io/emscripten-site/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop, I need to set update()/mainloop() function there and use that in app, raylib also does that, but in C code (and includes emscripten.h).
https://github.com/gen2brain/raylib-go/blob/master/raylib/external/web/mainloop.js is added at the end of raylib.js (with --post-js option), and then SetMainLoop() https://github.com/gen2brain/raylib-go/blob/master/raylib/platform_web.go#L22 should be called in app.
Currently this gives error:
Invalid function pointer called with signature 'v'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this)
printErr @ index.html:179
nullFunc_v @ raylib.js:11789
b23 @ raylib.js:102220
dynCall_v @ raylib.js:101673
browserIterationFunc @ raylib.js:1960
runIter @ raylib.js:2077
Browser_mainLoop_runner @ raylib.js:2015
requestAnimationFrame (async)
requestAnimationFrame @ raylib.js:2398
Browser_mainLoop_scheduler_rAF @ raylib.js:1915
_emscripten_set_main_loop @ raylib.js:2035
_emscripten_set_main_loop_go @ raylib.js:105111
SetMainLoop @ platform_web.go:24
main @ main.go:10
$init @ basic_window.js:28354
$goroutine @ basic_window.js:1471
$runScheduled @ basic_window.js:1511
$schedule @ basic_window.js:1527
$go @ basic_window.js:1503
(anonymous) @ basic_window.js:28365
(anonymous) @ basic_window.js:28368
Edit: demo is here http://81.4.106.254/raylib-go/ , .js files are not optimized/compressed/obfuscated .
Good Evening.
Trying the GUI module I ran into the problem that keys are registered twice (i.e. I type 'e' I get 'ee') when typing into a raygui.Textbox.
This does not seem to be related to the framerate, and apparently it's only a problem with the textbox (keyboard works fine with the camera demos).
You can try the basic controls demo which reproduces the error in my PC (this happened every single time I've tried it so far).
I'm using Go 1.7.4 x86_64 running in Ubuntu 17.04.
I wonder if this is somehow related to #13 ? Not sure how this works internally but my problem happens when pressing the key quickly and not when holding the key down for a second.
Thanks.
I ask because raylib offers building for the web via emscripten and building natively for at least Android.
Are these features also available for raylib-go?
I've tried loading MP3 files instead of the OGG file included in the example, and the following info and error gets thrown. Note that the OGG file does play correctly, and I've tested this with a couple of different MP3 files that I know are not corrupt. Each MP3 fails with the same error.
INFO: Initializing raylib 2.0-dev
INFO: Display device initialized successfully
INFO: Display size: 3000 x 2000
INFO: Render size: 800 x 450
INFO: Screen size: 800 x 450
INFO: Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: OpenGL 3.3 Core profile supported
INFO: GPU: Vendor: NVIDIA Corporation
INFO: GPU: Renderer: GeForce GTX 1050/PCIe/SSE2
INFO: GPU: Version: 3.3.0 NVIDIA 391.40
INFO: GPU: GLSL: 3.30 NVIDIA via Cg compiler
INFO: Number of supported extensions: 374
INFO: [EXTENSION] DXT compressed textures supported
INFO: [EXTENSION] ETC2/EAC compressed textures supported
INFO: [EXTENSION] Anisotropic textures filtering supported (max: 16X)
INFO: [EXTENSION] Clamp mirror wrap texture mode supported
INFO: [TEX ID 1] Texture created successfully (1x1 - 1 mipmaps)
INFO: [TEX ID 1] Base white texture loaded successfully
INFO: [SHDR ID 1] Shader compiled successfully
INFO: [SHDR ID 2] Shader compiled successfully
INFO: [SHDR ID 3] Shader program loaded successfully
INFO: [SHDR ID 3] Default shader loaded successfully
INFO: [CPU] Default buffers initialized successfully (lines, triangles, quads)
INFO: [VAO ID 1] Default buffers VAO initialized successfully (lines)
INFO: [VAO ID 2] Default buffers VAO initialized successfully (triangles)
INFO: [VAO ID 3] Default buffers VAO initialized successfully (quads)
INFO: OpenGL default states initialized successfully
INFO: [TEX ID 2] Texture created successfully (128x128 - 1 mipmaps)
INFO: [TEX ID 2] Default font loaded successfully
INFO: Audio device initialized successfully: Default Playback Device
INFO: Audio backend: mini_al / WASAPI
INFO: Audio format: 32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
INFO: Audio channels: 2 -> 2
INFO: Audio sample rate: 44100 -> 48000
INFO: Audio buffer size: 1197
could not create context: module is not sane
WARNING: [test.mp3] XM file could not be opened
ERROR: PlayMusicStream() : No audio buffer
exit status 1
@gen2brain
I find it difficult to understand why is Vector2/3, Quaternions and Matrix structs separate from their respective math functions.
Instead of #raymath.Normalize(v *raylib.Vector2) { ... &v = normval}
Bundle all Vector2/3, Quaternions and Matrix into Raymath and pass the structs as recievers to the functions?
Example: func (v Vector2) Normalize() Vector2 { return normalizedVector }
That way whenever a vector2 needs to be normalized, they don't have to be called from two different packages and just do this:
normVec2 := raymath.NewVector2(1,1).Normalized()
normVec2 := raymath.NewVector2(1,1).Normalized()
versus
vec2 := raylib.NewVector2(1,1,1)
normVec2 := raymath.Normalize(vec2)
Hey, there! It seems like the angles returned by raymath.Vector2Angle isn't correct?
Here's a quick example:
left := raylib.NewVector2(-1, 0)
right := raylib.NewVector2(1, 0)
fmt.Println(raymath.Vector2Angle(left, right)) // Prints out "0", which is wrong
fmt.Println(raymath.Vector2Angle(right, left)) // Prints out "180", which is correct
down := raylib.NewVector2(0, 1)
fmt.Println(raymath.Vector2Angle(down, right)) // Prints out "315", which is wrong
fmt.Println(raymath.Vector2Angle(right, down)) // Prints out "135", which is also wrong
// Shouldn't it be 90 or 270?
EDIT: Huh, looks like for my purposes (telling which direction the player is heading in), just providing an empty Vector2 for the actual vector to check against works...?
left := raylib.NewVector2(-1, 0)
noDir := raylib.NewVector2(0, 0)
fmt.Println(raymath.Vector2Angle(noDir, left)) // Prints out "180", which is correct.
EDIT 2: But I notice that when I do it this way, it increases going clockwise, rather than counter-clockwise, as it "should" be when thinking of rotations with radians (though I know that this returns degrees, not radians).
The function TakeScreenshot
at line 2174 in core.c, captures screen shots of a fixed size, even if the window is partially off screen. The result is that the off screen part of the resulting screen shot is completely black. For examples, see these screen shots I made using the current code:
unsigned char *imgData = rlglReadScreenPixels(renderWidth, renderHeight)
This code can be fixed by clamping renderWidth
and renderHeight
to the size of the window actually visible on screen. This will result in smaller screen shot files for these cases.
Note: I am aware that this issue applies to the C code of raylib and should therefore probably be reported upstream. I am reporting it here as well, because the raylib C sources are included in this repo directly.
Hello!
So basically, IsKeyPressed() and IsKeyReleased() seem to be sending false values if you hold the key down for about a second or longer. Here's a quick example:
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
raylib.SetConfigFlags(raylib.FlagWindowResizable)
raylib.InitWindow(640, 480, "Test Game")
raylib.SetTargetFPS(30)
for !raylib.WindowShouldClose() {
// Update
if raylib.IsKeyPressed(raylib.KeyA) {
println("A pressed")
}
if raylib.IsKeyReleased(raylib.KeyB) {
println("B released")
}
// Draw
raylib.BeginDrawing()
raylib.ClearBackground(raylib.Black)
raylib.DrawFPS(10, 10)
raylib.EndDrawing()
}
}
If you tap the A key, "A pressed" will be printed to the console (which is fine). If you press and hold it, and then release the key after about a second, "A pressed" will be printed to the console twice. A similar thing for the B key - tapping "B" will print "B released" to the console, but pressing, holding for about a second, and releasing the B key will print "B released" twice.
I'm running Solus 3 (Linux) 64-bit.
When running go get -v -u github.com/gen2brain/raylib-go/raylib
I get the below stream of errors. Any ideas what could be causing this?
github.com/gen2brain/raylib-go/raylib
In file included from core.c:143:
In file included from go/src/github.com/gen2brain/raylib-go/raylib/external/glfw/include/GLFW/glfw3.h:195:
/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:5:2: warning: gl.h and gl3.h are both included. Compiler will not invoke errors if using removed OpenGL functionality. [-W#warnings]
core.c:667:6: error: conflicting types for 'IsWindowReady'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:803:12: note: previous declaration is here
core.c:673:6: error: conflicting types for 'WindowShouldClose'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:804:12: note: previous declaration is here
core.c:703:6: error: conflicting types for 'IsWindowMinimized'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:805:12: note: previous declaration is here
core.c:945:6: error: conflicting types for 'IsCursorHidden'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:826:12: note: previous declaration is here
core.c:1463:6: error: conflicting types for 'IsFileExtension'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:869:12: note: previous declaration is here
core.c:1602:6: error: conflicting types for 'ChangeDirectory'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:876:12: note: previous declaration is here
core.c:1608:6: error: conflicting types for 'IsFileDropped'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:877:12: note: previous declaration is here
core.c:1727:6: error: conflicting types for 'IsKeyPressed'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:890:12: note: previous declaration is here
core.c:1738:6: error: conflicting types for 'IsKeyDown'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:891:12: note: previous declaration is here
core.c:1745:6: error: conflicting types for 'IsKeyReleased'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:892:12: note: previous declaration is here
core.c:1756:6: error: conflicting types for 'IsKeyUp'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:893:12: note: previous declaration is here
core.c:1780:6: error: conflicting types for 'IsGamepadAvailable'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:898:12: note: previous declaration is here
core.c:1792:6: error: conflicting types for 'IsGamepadName'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:899:12: note: previous declaration is here
core.c:1845:6: error: conflicting types for 'IsGamepadButtonPressed'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:901:12: note: previous declaration is here
core.c:1859:6: error: conflicting types for 'IsGamepadButtonDown'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:902:12: note: previous declaration is here
core.c:1872:6: error: conflicting types for 'IsGamepadButtonReleased'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:903:12: note: previous declaration is here
core.c:1886:6: error: conflicting types for 'IsGamepadButtonUp'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:904:12: note: previous declaration is here
core.c:1905:6: error: conflicting types for 'IsMouseButtonPressed'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:910:12: note: previous declaration is here
core.c:1920:6: error: conflicting types for 'IsMouseButtonDown'
go/src/github.com/gen2brain/raylib-go/raylib/raylib.h:911:12: note: previous declaration is here
fatal error: too many errors emitted, stopping now [-ferror-limit=]
git version #1418583
raylib.GetKeyPressed() can not detect ENTER,TAB,BACKSPACE
and maybe other keys
but raygui depends on GetKeyPressed() ,especially TextBox
without BackSpace I can not even delete the chars I typed in the TextBox
After I add
2739 if (key == GLFW_KEY_BACKSPACE && action == GLFW_PRESS) {
2740 lastKeyPressed = key;
2741 }
2742 if (key == GLFW_KEY_TAB && action == GLFW_PRESS) {
2743 lastKeyPressed = key;
2744 }
2745 if (key == GLFW_KEY_ENTER && action == GLFW_PRESS) {
2746 lastKeyPressed = key;
2747 }
in
2691 static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
now it works
So is this a problem I misunderstanding or just a bug?
I am not very familiar with this cool lib
Hello, I recently tried several examples, when trying to change the FPS I realized that the speed of movement in objects changes, here I leave the codes changed:
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)func main() {
var screenHeight, screenWith int32
screenHeight = 480
screenWith = 720rl.InitWindow(screenWith, screenHeight, "60 FPS")
ballPosition := rl.NewVector2(float32(screenWith)/2, float32(screenHeight)/2)
rl.SetTargetFPS(60)for !rl.WindowShouldClose() {
if rl.IsKeyDown(rl.KeyLeft) {
ballPosition.X-- // ballPosition.X += 1
}
if rl.IsKeyDown(rl.KeyRight) {
ballPosition.X++
}
if rl.IsKeyDown(rl.KeyUp) {
ballPosition.Y--
}
if rl.IsKeyDown(rl.KeyDown) {
ballPosition.Y++
}
rl.BeginDrawing()
//***************************************************************
rl.DrawFPS(0, 0)
rl.ClearBackground(rl.Black)
rl.DrawCircleV(ballPosition, 100, rl.White)
//***************************************************************
rl.EndDrawing()
}
}
120 FPS:
package main
import (
"github.com/gen2brain/raylib-go/raylib"
)func main() {
var screenHeight, screenWith int32
screenHeight = 480
screenWith = 720rl.InitWindow(screenWith, screenHeight, "120 FPS")
ballPosition := rl.NewVector2(float32(screenWith)/2, float32(screenHeight)/2)
rl.SetTargetFPS(120)for !rl.WindowShouldClose() {
if rl.IsKeyDown(rl.KeyLeft) {
ballPosition.X-- // ballPosition.X += 1
}
if rl.IsKeyDown(rl.KeyRight) {
ballPosition.X++
}
if rl.IsKeyDown(rl.KeyUp) {
ballPosition.Y--
}
if rl.IsKeyDown(rl.KeyDown) {
ballPosition.Y++
}
rl.BeginDrawing()
//***************************************************************
rl.DrawFPS(0, 0)
rl.ClearBackground(rl.Black)
rl.DrawCircleV(ballPosition, 100, rl.White)
//***************************************************************
rl.EndDrawing()
}
}
Thanks.
Pd: That was translated with a page of automatic translation, so it can have errors.
Hello, I have never used bindings like this before. Considering that raylib can build to many targets, how does one do that with this library?
Everytime I try to build the raylib [core] example I get this issue.
go build github.com/gen2brain/raylib-go/raylib: invalid flag in #cgo CFLAGS: -fgnu89-inline
Using Go 1.10 with IntelliJ IDEA 2017.1.5 with CGO support enabled
Hey, there.
It's been awhile since the last update of the C sources in raylib - It'd be nice to get an update. I'm asking specifically because there is an issue with render textures clearing themselves in this version of raylib-go that isn't there in the latest version.
Thanks!
On go1.8.3 windows/amd64, using git bash, I attempted to build a raylib game with
GOOS=linux go build
and got
# github.com/gen2brain/raylib-go/raylib E:\go\src\github.com\gen2brain\raylib-go\raylib\rres.go:145: undefined: OpenAsset
I tried going to the raylib-go folder and cross-compiling it alone and got the same error
Trying any form of cross-compilation (changing only $GOOS, $GOARCH or both) gets me the same error
cat rres.go | grep
shows that there was a single call to OpenAsset on rres.go
It seems OpenAsset is defined on platform_*.go, in this case I suppose it should be using platform_desktop.go, which begins with the line // +build !android,!arm
I'm not sure how build constraints work, so I'm having trouble making sense of this, but it seems clear that the cross-compiling process is interfering with this somehow
Any help would be appreciated
Version 2.0 of raylib is released and the raylib GUI have a lot changed, an update is highly welcome ;)
The list of Ubuntu dependencies for 16.04 (at least on Ubuntu MATE, which is what I use) is incomplete.
I had to add the following packages to my apt-get install:
sudo apt-get install libgl1-mesa-dev libxrandr2 libxrandr-dev x11-xserver-utils
Everything worked just fine after that.
Hello,
I'm writing here because I don't understand why I can't post anything on your forum project page (Firefox 55.0.2).
I've made a simple test on (Ubuntu 16.04, golang 1.8, raylib 1.7).
package main
import (
"github.com/gen2brain/raylib-go/raylib"
"log"
)
func main() {
screenWidth := int32(800)
screenHeight := int32(450)
cpos := make([]raylib.Vector2, 0)
raylib.InitWindow(screenWidth, screenHeight, "RayMantha")
raylib.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
cursorPosition := raylib.GetMousePosition()
log.Println(cursorPosition)
raylib.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
if raylib.IsMouseButtonDown(raylib.MouseLeftButton) {
cpos = append(cpos, cursorPosition)
}
raylib.DrawText("Test", 30, 30, 30, raylib.DarkBlue)
raylib.DrawCircleV(cursorPosition, 1, raylib.DarkGray)
log.Println(cpos)
for _, elem := range cpos {
raylib.DrawCircleV(elem, 5, raylib.DarkGray)
}
log.Println(len(cpos))
raylib.EndDrawing()
}
raylib.CloseWindow()
}
I've got ERROR: MAX_QUADS_BATCH overflow error with 453 circles ? How to prevent this ?
thank you for your help.
Hi,
I wanted to try using raylib with qt. To do this I would need to get the window handle and use http://doc.qt.io/qt-5/qwindow.html#setParent to embed the window.
I think this may be the window handle:
GLFWWindow returns a *C.GLFWwindow reference (i.e. the GLFW window itself). This can be used for passing the GLFW window handle to external C libraries.
Could you make this available from your library? Thanks!
Hi, I get
package github.com/gen2brain/raylib-go: no buildable Go source files in ...
on macOS with glfw3
and openal-soft
installed with brew
and linked.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.