WIITD / raylib-freebasic

FreeBasic bindings for raylib
MIT License
27 stars 8 forks source link

Shared object builds #7

Open Axle-Ozz-i-sofT opened 2 years ago

Axle-Ozz-i-sofT commented 2 years ago

Hi @WIITD

I was creating the FB bindings for V4.2 in the background but you beat me too it :) As such I am content to run with the work you have done. I have intentions of including raylib and raygui in some books I am writing on introduction to programming with examples in C, FreeBASIC and Python 3. I intend to use raylib/raygui for all 3 languages to exemplify basic graphics (graphics.h like) and GUIs.

Documentation for using raylib in FB is a little scant so I would like to confirm with you the C builds of the shared library you are creating for Windows and Linux (Ubuntu). I am currently building the shared library with "winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj.7z" on windows, but haven't got to the Linux side just yet.

As this is a 64 bit build I am first rebuilding the default 32bit "raylib.dll.rc.data" as 64 bit. @ECHO OFF REM Recompile the Resource data file for 64 bit. REM The library default is 32 bit. REM Pleas set the paths according to the compiler and source directory. SET PATH=%PATH%;SET PATH=%PATH%;C:\Dev-FreeBASIC\Winlibs\winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj\mingw64\bin SET PATH=%PATH%;C:\Dev-FreeBASIC\Winlibs\winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj\raylib\src windres raylib.dll.rc -o raylib.dll.rc.data --target=pe-x86-64 pause

I am then building the raylib4.2 and raygui3.2 into the dll/so with the following switches. The following also re-compiles the raylib.dll.rc.data after clean... REM Makefile laucher for 64-bit Compile. REM Please set the paths according to the compiler and source directory. SET PATH=%PATH%;SET PATH=%PATH%;C:\Dev-FreeBASIC\Winlibs\winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj\mingw64\bin SET PATH=%PATH%;C:\Dev-FreeBASIC\Winlibs\raylib-4.0.0\src REM Recompile the Resource file for Windows x86-64 windres raylib.dll.rc -o raylib.dll.rc.data --target=pe-x86-64 REM Clean up the build environment. mingw32-make clean REM Using OpenGL V2.1 for VirtualBox compatibility. REM mingw32-make V=1 -f Makefile PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_33 mingw32-make V=1 -f Makefile PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21 pause

The shell script for Ubuntu should be much the same.

Can you confirm that this build is what you are using with raylib.bi, raymath.bi and raymath.bi ?

Also, with your permission I would like to offer attribution for your work in the books. Is a link to the github project acceptable to you?

Sorry about dropping this in the issues sections as I am unaware of your username in the FB forums and I don't use twatter :)

Best regards Axle

WIITD commented 2 years ago

i'm not familiar with building raylib dll on windows, i use linux, while testing everything i used official precompiled so/dll, for testing it on windows i prebuild test binary on linux and then i used wine and windows wm to test it

Documentation for using raylib in FB is a little scant...

its just a binding so official raylib documentation should works just fine, but for working with fbc i wrote simple game using raylib and fb here is the build script i used, again it is written under linux so i would recommend using it as a example

Also, with your permission I would like to offer attribution for your work in the books. Is a link to the github project acceptable to you?

sure, link is fine and thanks

Sorry about dropping this in the issues sections as I am unaware of your username in the FB forums and I don't use twatter :)

no problem, i'm not present on fb forum anyway, and sorry for replying so late but github didn't show me this issue, no ping on app nor website

Axle-Ozz-i-sofT commented 2 years ago

Thanks for the reply I was mostly attempting to work out the raygui.bi integration. The pre built binaries from Raymon do not include rargui.h As it is best (or prob the only way is) to use the shared library for FB I see 2 ways suggested to build the dynamic libraries.

  1. building raygui as a stand alone shared object by changing raygui.h to raygui.c and raylib as a separate shared library. As per https://github.com/raysan5/raygui#building
    copy src/raygui.h src/raygui.c
    gcc -o src/raygui.dll src/raygui.c -shared -DRAYGUI_IMPLEMENTATION -DBUILD_LIBTYPE_SHARED -static-libgcc -lopengl32 -lgdi32 -lwinmm -Wl,--out-implib,src/librayguidll.a

    or

  2. Placing the raygui.h into the raylib source folders and building raylib with raygui integrated into the raylib.so/dll by adding the makefile switch "RAYLIB_MODULE_RAYGUI=TRUE"

~~So, did you target the 2 with each as a separate .so/.dll or 1 raylib with raygui combined as a single .so/.dll ? or do you think it wouldn't matter?~~ I think I answered my own question. Building raygui as a shared library attempts to include parts of raylib, so I think it will be better to just include raygui into raylib with "RAYLIB_MODULE_RAYGUI=TRUE" :)

... i wrote simple game ... <

I had a peek at that and will likely use it as a check for my own examples if I get stuck :)

I am using both Windows and Ubuntu and attempting to create both raylib and raygui examples in C, FB and Py3 on both platforms, so I have set myself a bit of a challenge X-)

I will let you know how it goes when I get to the FB examples and give some feedback for you :)

P.S. Don't stress about being in any hurry to reply, I'll be working on this for ages yet :)

WIITD commented 2 years ago

i did some testing and i couldn't get raygui.bi to work with raylib compiled with RAYLIB_MODULE_RAYGUI=TRUE but i it worked when i compiled raygui separately and added [ #inclib "raygui" ] to raygui.bi file, i will add some informations to README file on how to get raylib.bi and raygui.bi to work

Axle-Ozz-i-sofT commented 2 years ago

Hi WIITD

I just got through the basic Windows tests for FB_Raylib and raygui. raylib + raygui as shared library compiled in winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj Latest raygui-3.2 source. Move raygui.h to .\raylib-4.2.0\src\raygui.h Alter line 87 of the MakFile to find raygui.h in the src directory RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)

Build_raylib.cmd

REM Makefile laucher for 64-bit Compile.
REM Pleas set the paths accoring to the compiler and source directory.
SET PATH=%PATH%;SET PATH=%PATH%;C:\Dev-WinLibs_Raylib\winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj\mingw64\bin
SET PATH=%PATH%;C:\Dev-WinLibs_Raylib\winlibs-mingw-w64-x86_64-9.3.0-7.0.0-r3-sjlj\raylib-4.2.0\src
REM Recompile the Resource file for Windows x86-64
windres raylib.dll.rc -o raylib.dll.rc.data --target=pe-x86-64
REM Clean up the build environment.
mingw32-make clean
REM Using OpenGL V2.1 for VirtualBox compatability.
REM mingw32-make V=1 -f Makefile PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_33
mingw32-make V=1 -f Makefile PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21
pause

Move all compiled library files to the respective FBC directories. raylib.dll and libwinpthread-1.dll to the project source directory alongside of mytest.bas

I am using FBIde and the Settings FreeBASIC tab does not appear to correctly locate the raylib library files if I place them in FBC \bin, \inc or \lib

Changing the compiler command to "<$fbc>" "<$file>" -v -exx -p "C:\Dev-FreeBASIC\FreeBASIC-1.09.0-win64" appears to correct that. Alternative is to place the full paths to raylib\bin,lib,inc

The example from one of the github V3,5 binders "shapes_basic_shapes.bas" worked without issue.

#inclib "raylibdll"
#include once "raylib.bi"
...

The raygui_controls_test_suite.bas from the same git repository is for raylib V2.8 I think. There are quite a number of breaking API changes from 2.8 to 3.2

#inclib "raylibdll"
#include "raylib.bi"

#define RAYGUI_IMPLEMENTATION
#define RAYGUI_SUPPORT_ICONS
#include "raygui.bi"

#undef RAYGUI_IMPLEMENTATION

+

type bool as boolean

#ifndef NULL
  #define NULL cptr(any ptr, 0)
#endif

The rest is just correcting the API changes. I have "roughly" done most but 3 or 4 controls I am still working out. The example "shapes_basic_shapes.bas" compiles and the graphics window displays the controls as expected (Without the 3 missing controls) :) P.S. I have barely any experience with FB and haven't attempted to learn raylib other than testing the examples so I am thumbing my way through getting an example to work lol

Have a go with it if you want :) I am documenting everything I am doing to go into a guide/book so at some point I will be able to post them for others

2022-10-08 20 07 04 raygui_controls_test_suite.bas.txt

Axle-Ozz-i-sofT commented 2 years ago

P.S. I am just attempting to get the 3 development environments up with examples compiling in C, FB and Py3 atm. For C I am using raylib/gui as a combined -static library on windows 10 and Lubuntu 20.04LTS. I am using VirtualBox thus the OpenGL version 2.1 The only difference from the above is to remove RAYLIB_LIBTYPE=SHARED or safer change to RAYLIB_LIBTYPE=STATIC when calling the makefile to get the static C library. I'll do the shared libs for Lubuntu tomorrow and see how I go :) I did make the the shared libraries (including raygui) for Lubuntu previously but had some problems working out the raygui examples.bas from V2.8 plus the APIs where a bit broken between raylib and raygui at the time so I couldn't tell if I had a successful build of the shared library.

Seeing that I have the dev environment and a 2 basic example working, I will do the same on Lubuntu and see if the partial gui controls example compiles.

Axle-Ozz-i-sofT commented 2 years ago

You can ignore this if you wish. I left it here in case you encountered the directory naming issue I describe at the end. Hi WIITD The previous steps a stated above worked for raylib V4.0.0 with raygui V3.2 I am now attempting the same steps + many alternative steps with fail to build using raylib V4.2.0 MakeFile.

I placed a DEBUG print of the variable "RAYLIB_MODULE_RAYGUI_PATH" at Line 682:

...
Line 87: RAYLIB_MODULE_RAYGUI_PATH ?= $(RAYLIB_SRC_PATH)
...
# Compile raygui module
# NOTE: raygui header should be distributed with raylib.h
raygui.o : raygui.c
    $(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS)
    $(info VAR is $(RAYLIB_MODULE_RAYGUI_PATH))
raygui.c:
ifeq ($(PLATFORM_SHELL), cmd)
    @echo #define RAYGUI_IMPLEMENTATION > raygui.c
    @echo #include "$(RAYLIB_MODULE_RAYGUI_PATH)/raygui.h" >> raygui.c
else
    @echo "#define RAYGUI_IMPLEMENTATION" > raygui.c
    @echo "#include \"$(RAYLIB_MODULE_RAYGUI_PATH)/raygui.h\"" >> raygui.c
endif

terminal output

$ make PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21
VAR is ../src
gcc -c raygui.c -Wall -D_DEFAULT_SOURCE -DPLATFORM_DESKTOP -DGRAPHICS_API_OPENGL_21 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing  -std=c99 -fPIC -O1 -Werror=implicit-function-declaration -fPIC -DBUILD_LIBTYPE_SHARED -I. -Iexternal/glfw/include -Iexternal/glfw/deps/mingw
raygui.c:2:10: fatal error: ../src/../../raygui/src/raygui.h: No such file or directory
    2 | #include "../src/../../raygui/src/raygui.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:681: raygui.o] Error 1

I am completely lost as to where this variable (../src/../../raygui/src/raygui.h) is coming from when it should be ../src/raygui.h There is no "../src/../../raygui/src/" anywhere in the MakeFile that I can find ¯\_(ツ)_/¯

I am not sure if this is the same that you encountered when attempting RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED?

I am going to go back and compare this with the V4.0.0 MakeFile which worked previously and may even use the previous V4.0.0 MakeFile as a test. Axle

OK, Linux is weird. I was compiling from the downloaded source (raylib-4.2.0.tar.gz + raygui-3.2.tar.gz) in a sub directory /home/User/Documents/ And the build failed. I just downloaded both raylib and raygui via git clone https://github.com/raysan5/raylib.git raylib in the /home/user and the everything worked as expected without any changes to the source or MakeFile.

make PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=STATIC GRAPHICS=GRAPHICS_API_OPENGL_21 Success make clean make PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21 Success

I had some confusion and issues building raylib previously with differences between the git clone and the source release, so maybe the git repository is OK and the raylib-4.2.0.tar.gz is damaged... or some other weird file permission or path issue that I haven't discovered yet.

Sorry for crowding you Issues thread. I thought I had this nailed :(

I had to rename raygui-3.2 to raylib and raylib-4.2.0 to raygui and everything compiled fine without change. Likely the same issue I have had on Windows. Even raysan had said to move the raygui.h to raylib\src etc

Axle-Ozz-i-sofT commented 2 years ago

Confirmation of shapes_basic_shapes.bas and modified raygui_controls_test_suite.bas Lubuntu 20.04LTS

/home/Username/raylib /home/Username/raygui cd /raylib/src

make PLATFORM=PLATFORM_DESKTOP RAYLIB_MODULE_RAYGUI=TRUE RAYLIB_LIBTYPE=SHARED GRAPHICS=GRAPHICS_API_OPENGL_21

sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.

Check file permissions for raylib.bi etc RW R R Move FB headers to /usr/local/include/freebasic sudo cp --update --verbose raylib.bi /usr/local/include/freebasic ... ... Using Geany 1.36 (default FB compiler settings fbc -w all "%f" make... "./%e" )

Includes as for attached examples.

Compile: fbc -w all "raygui_controls_test_suite.bas" (in directory: /home/Axle1/Documents/Raylibs_test/FB) Compilation finished successfully.

All good :) When I get the raylib build and example build docs cleaned up I will organize a download for you.

2022-10-09 22 49 29 shapes_basic_shapes.bas.txt raygui_controls_test_suite.bas.txt