raylib headers

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
MrSwiss
Posts: 3657
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: raylib headers

Postby MrSwiss » May 18, 2020 13:12

IchMagBier wrote:I may look into Raygui, but I would prefer a GUI that looks native to the operating system it is running on.
The only way to achieve that is, what I call a shim-library (programmer
syntax is the same for supported OS's, but using a OS specific backend).

IUP does exactly that: WinAPI on Windows, GTK2 or GTK3 on Linux.
(since it has a straight C interface, it integrates well in FB)
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 11, 2020 1:10

IchMagBier wrote:Hello there :)
I have ported the raylib headers and some examples to FreeBasic.

Wow, thank you! I'm pretty blown away, and need some time to dive into this.


paul doe wrote:This might serve as a drop-in replacement for those folks that wanted to replace EasyGL2D! I'll play around with it when I have a little more time and help you port some examples. Nice work!

Great stuff happens every time I take a break from this forum. And again I'm late to the scene! Raylib was something I looked at awhile back when contemplating a switch to C for my game engine; I was impressed at its simplicity and capability as far as my needs, and here it is for FB now.


paul doe wrote:
mrToad wrote:The real goal is to find any reasonable solution for my rendering.

Another user heard your pleas:
raylib headers

Thank you for this paul doe, or I would not have seen it! :) As it is, it took me forever to open the email notification that you replied to my thread with the raylib headers link. And you've been helping out with the examples, nice!

Now I need to get my hands dirty and see what I can do with this wonderful gift.
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 11, 2020 3:50

Issue:
I was able to run all the examples on Win 64, but only using raylib 2.6 dll. The 3.0 gives this error on program start: "The program can't start because libgcc_s_seh-1.dll is missing from your computer..."

I saw BasicCoder2's similar error (with a different dll missing), but the 64-bit version was said not to have outside dependencies. Are FB headers not yet compatible with 3.0? The site and ReadMe indicate they are compatible. I don't know what the trouble is, then.

New Example:
It would be nice to have a fb-translated example of scarfy as part of the examples collection, to show loading and animating sprites from a texture. I will try to do this and contribute it.

Important Addition:
Something I think very important for raylib to fit into the Basic spirit here, a function to get an FB.Image to GPU, like EasyGL2D had. The easiest solution I could think of was a conversion of FB.Image to raylib Image, but it seems beyond my capabilities. I did my best to look through raylib's use of stb_image.h for a struct, and found this:

Code: Select all

// stbi__context structure is our basic context used by all images, so it
// contains all the IO context, plus some basic image information
typedef struct
{
   stbi__uint32 img_x, img_y;
   int img_n, img_out_n;

   stbi_io_callbacks io;
   void *io_user_data;

   int read_from_callbacks;
   int buflen;
   stbi_uc buffer_start[128];
   int callback_already_read;

   stbi_uc *img_buffer, *img_buffer_end;
   stbi_uc *img_buffer_original, *img_buffer_original_end;
} stbi__context;

But I'm pretty lost in all that C code. The Image struct seems complex, perhaps because raylib supports several image formats. I don't know how to write the function to convert FB.Image.

I'm sure someone here would know how this might be done. :)

Edit: I may have been looking too deep. The struct is obviously defined here as:
struct Image; [20 bytes] // Image data pointer (RAM) and 4 data parameters

I assume it's a ULong any ptr (OS dependent) for the data pointer, now I need to know the 4 datas after that. I'll do more research. I wish it was fully described in that wiki. If I can get this to work I'll be pretty happy in my little (but challenging for me) endeavor. :)
Last edited by mrToad on Aug 13, 2020 23:41, edited 3 times in total.
srvaldez
Posts: 2576
Joined: Sep 25, 2005 21:54

Re: raylib headers

Postby srvaldez » Aug 11, 2020 16:33

hello mrToad
I downloaded raylib from https://github.com/raysan5/raylib/releases/tag/3.0.0 and the 64-bit dll has a dependency on libgcc_s_seh-1.dll
however there's a static lib also in the archive, would you try that?
there's no guarantee that the static lib is free of dependencies but it's worth a try
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 11, 2020 17:00

Here are my version of raylib 3.0 without any libgcc dependencies

Windows Linux 32/64 bit static and dynamic OpenGL 2.1 !

https://www.freebasic.net/forum/viewtopic.php?f=14&t=28796

Joshy
Last edited by D.J.Peters on Sep 06, 2020 0:18, edited 3 times in total.
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 11, 2020 17:19

D.J.Peters wrote:here are my version of raylib 3.0 (Windows 32/64 bit static and dynamic are included)
Joshy
That works great, thank you! I'm curious what you did to it.
Last edited by mrToad on Sep 14, 2020 10:45, edited 1 time in total.
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 11, 2020 17:52

Regarding the struct of Image, I found only this in the code, but it provides everything about it:

Code: Select all

// Generate image: plain color
Image GenImageColor(int width, int height, Color color)
{
    Color *pixels = (Color *)RL_CALLOC(width*height, sizeof(Color));

    for (int i = 0; i < width*height; i++) pixels[i] = color;

    Image image = {
        .data = pixels,
        .width = width,
        .height = height,
        .format = UNCOMPRESSED_R8G8B8A8,
        .mipmaps = 1
    };

    return image;
}

So there is a data pointer, width, height, format, mipmaps. Each is 4 bytes, 20 bytes total. I believe now I can write a function to convert an FB.Image to raylib Image, upload to GPU, and make use of the 12 extra bytes in FB.Image to store textureID, u,v, etc, to maintain use of FB.Image rather than replace it with raylib code. I'll work on that later. :)
Last edited by mrToad on Aug 13, 2020 18:35, edited 3 times in total.
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 11, 2020 20:15

Many raylib "C" examples running as JavaScript in the web browser also !

example: https://www.raylib.com/examples/web/models/loader.html?name=models_box_collisions

Does anyone knows where I can download or see the WEBGL raylib stuf ?

Thank you

Joshy

EDIT: No way there isn't a JavaScript raylib you must compile and rebuild all raylib stuf with the emscripten SDK :-(

https://github.com/raysan5/raylib/wiki/ ... Web-(HTML5)
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 12, 2020 18:49

I found the most differences between raylib 2.6 and my version of fbraylib-3.0 the Vector2, Vector3, Quaternion and Matrix math are included !

Only the declares in "raylib.bi" must be added.

Joshy

Code: Select all

Vector2Add
Vector2Angle
Vector2Distance
Vector2Divide
Vector2DivideV
Vector2DotProduct
Vector2Length
Vector2Lerp
Vector2MultiplyV
Vector2Negate
Vector2Normalize
Vector2One
Vector2Rotate
Vector2Scale
Vector2Subtract
Vector2Zero

Vector3Add
Vector3Barycenter
Vector3CrossProduct
Vector3Distance
Vector3Divide
Vector3DivideV
Vector3DotProduct
Vector3Length
Vector3Lerp
Vector3Max
Vector3Min
Vector3Multiply
Vector3Negate
Vector3Normalize
Vector3One
Vector3OrthoNormalize
Vector3Perpendicular
Vector3Reflect
Vector3RotateByQuaternion
Vector3Scale
Vector3Subtract
Vector3ToFloatV
Vector3Transform
Vector3Zero

QuaternionFromAxisAngle
QuaternionFromEuler
QuaternionFromMatrix
QuaternionFromVector3ToVector3
QuaternionIdentity
QuaternionInvert
QuaternionLength
QuaternionLerp
QuaternionMultiply
QuaternionNlerp
QuaternionNormalize
QuaternionSlerp
QuaternionToAxisAngle
QuaternionToEuler
QuaternionToMatrix
QuaternionTransform

MatrixAdd
MatrixDeterminant
MatrixFrustum
MatrixIdentity
MatrixInvert
MatrixLookAt
MatrixMultiply
MatrixNormalize
MatrixOrtho
MatrixPerspective
MatrixRotate
MatrixRotateX
MatrixRotateXYZ
MatrixRotateY
MatrixRotateZ
MatrixScale
MatrixSubtract
MatrixToFloatV
MatrixTrace
MatrixTranslate
MatrixTranspose
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 12, 2020 18:55

The stb_perlin module is also included in fbraylib-3.0 !

Joshy

This declares must be added to file "raylib.bi"

Code: Select all

extern "C"

declare function stb_perlin_noise3             (x as single, y as single, z as single, x_wrap as long, y_wrap as long, z_wrap as long) as single
declare function stb_perlin_noise3_seed        (x as single, y as single, z as single, x_wrap as long, y_wrap as long, z_wrap as long, seed as long) as single
declare function stb_perlin_ridge_noise3       (x as single, y as single, z as single, lacunarity as single, gain as single, offsetas single, octaves as long) as single
declare function stb_perlin_fbm_noise3         (x as single, y as single, z as single, lacunarity as single, gain as single, int octaves) as single
declare function stb_perlin_turbulence_noise3  (x as single, y as single, z as single, lacunarity as single, gain as single, octaves as long) as single
declare function stb_perlin_noise3_wrap_nonpow2(x as single, y as single, z as single, x_wrap as long, y_wrap as long, z_wrap as long, seed as ubyte) as single

end extern

Code: Select all

// Documentation:
//
// float  stb_perlin_noise3( float x,
//                           float y,
//                           float z,
//                           int   x_wrap=0,
//                           int   y_wrap=0,
//                           int   z_wrap=0)
//
// This function computes a random value at the coordinate (x,y,z).
// Adjacent random values are continuous but the noise fluctuates
// its randomness with period 1, i.e. takes on wholly unrelated values
// at integer points. Specifically, this implements Ken Perlin's
// revised noise function from 2002.
//
// The "wrap" parameters can be used to create wraparound noise that
// wraps at powers of two. The numbers MUST be powers of two. Specify
// 0 to mean "don't care". (The noise always wraps every 256 due
// details of the implementation, even if you ask for larger or no
// wrapping.)
//
// float  stb_perlin_noise3_seed( float x,
//                                float y,
//                                float z,
//                                int   x_wrap=0,
//                                int   y_wrap=0,
//                                int   z_wrap=0,
//                                int   seed)
//
// As above, but 'seed' selects from multiple different variations of the
// noise function. The current implementation only uses the bottom 8 bits
// of 'seed', but possibly in the future more bits will be used.
//
//
// Fractal Noise:
//
// Three common fractal noise functions are included, which produce
// a wide variety of nice effects depending on the parameters
// provided. Note that each function will call stb_perlin_noise3
// 'octaves' times, so this parameter will affect runtime.
//
// float stb_perlin_ridge_noise3(float x, float y, float z,
//                               float lacunarity, float gain, float offset, int octaves)
//
// float stb_perlin_fbm_noise3(float x, float y, float z,
//                             float lacunarity, float gain, int octaves)
//
// float stb_perlin_turbulence_noise3(float x, float y, float z,
//                                    float lacunarity, float gain, int octaves)
//
// Typical values to start playing with:
//     octaves    =   6     -- number of "octaves" of noise3() to sum
//     lacunarity = ~ 2.0   -- spacing between successive octaves (use exactly 2.0 for wrapping output)
//     gain       =   0.5   -- relative weighting applied to each successive octave
//     offset     =   1.0?  -- used to invert the ridges, may need to be larger, not sure
//
//
// Contributors:
//    Jack Mott - additional noise functions
//    Jordan Peck - seeded noise
//
;
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 13, 2020 17:44

@D.J.Peters thanks for the explanation of your version of raylib.

Regarding 20 bytes for raylib Image struct (resolved)
Doing SizeOf(Image) returns 24 bytes, not 20. Many of the raylib structs return different bytes than described in the wiki. For example Mesh is 116 bytes although described as 60 bytes. Reason: 64-bit compiled pointers are 8 bytes, rather than 4 for 32-bit.

Also, I'm a bit silly for overlooking raylib.bi file. There is a Type definition for Image:

Code: Select all

Type Image
   data as any ptr
   width as long
   height as long
   mipmaps as long
   format as long
End Type
That's all I need. Been out of coding for awhile, too much art and music. ;)

Namespace for raylib?
I know standard C does not use namespaces like FB. So there appears to be no namespace for FB raylib. I wanted to separate FB.Image and raylib's Image in code. I've added Namespace RL to raylib.bi, just before extern "C". That seems to do the trick :) Hopefully I put it in the best place..

Code: Select all

#pragma once

#include once "crt/long.bi"
#include once "crt/stdarg.bi"

#inclib "raylib"
#ifdef __FB_LINUX__
   #inclib "X11"
#endif

Namespace RL

extern "C"
[...]
End Extern

End Namespace
Last edited by mrToad on Aug 14, 2020 20:43, edited 1 time in total.
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 14, 2020 13:28

I uploaded a fresh build of raylib 3.0 for FreeBASIC (Windows and Linux 32/64-bit static and dynamic)

(No need to put your fine older OpenGL 2.1 cards in the trash. The link to fbraylib-3.0.zip is the same as before)

I Tested the static build successful with FreeBASIC:
Windows XP 32-bit with OpenGL 2.1 (NVIDEA and ATI/AMD)
Windows 10 64-bit with OpenGL 2.1 and OpenGL 3.3 (NVIDEA)
Linux Slackware 32-bit OpenGL 2.1 (ATI/AMD)
Linux Ubuntu 32/64-bit OpenGL 2.1 and OpenGL 3.3 (NVIDEA)

Of course I tested all raylib 3.0 C examples with audio and shaders from github successful also !

That means you can use all this different shader versions :-)

OpenGL 2.1 GLSL = #version 120
OpenGL 3.0 GLSL = #version 130
OpenGL 3.1 GLSL = #version 140
OpenGL 3.2 GLSL = #version 150
OpenGL 3.3 GLSL = #version 330

Joshy
mrToad
Posts: 409
Joined: Jun 07, 2005 23:03
Location: USA
Contact:

Re: raylib headers

Postby mrToad » Aug 15, 2020 22:44

D.J.Peters wrote:I uploaded a fresh build of raylib 3.0 for FreeBASIC (Windows and Linux 32/64-bit static and dynamic)

(No need to put your fine older OpenGL 2.1 cards in the trash. The link to fbraylib-3.0.zip is the same as before)
[...]
Joshy

Thanks Joshy. Although I have mainly a newer card, I always appreciate code that is friendly to older hardware, and I'm sure others will appreciate it too.
jepalza
Posts: 70
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: raylib headers

Postby jepalza » Aug 27, 2020 12:51

D.J.Peters wrote:Here are my version of raylib 3.0 without any libgcc dependencies
Windows 32/64 bit static and dynamic are included

new: Linux 32/64 bit static and dynamic are included

Joshy


Is "DrawCube" working? In this example is not working! With "DrawCube" only a plane is drawed.
("DrawCubeV" is good)

Code: Select all


#define RAYLIB_STATIC
#include "fbraylib.bi"
#include "fbraymath.bi"

Const screenWidth = 800
const screenHeight = 450
InitWindow(screenWidth, screenHeight, "3d cubes")

dim as Camera3D camara
camara.position = Type (10.0, 10.0, 10.0)
camara.target = Type(0.0, 0.0, 0.0)
camara.up = Type(0.0, 1.0, 0.0)
camara.fovy = 10.0           
camara.type = CAMERA_ORTHOGRAPHIC 
dim as Vector3 cubePosition1 = Type(0.0, 0.0, 0.0)
dim as Vector3 cubePosition2 = Type(3.0, 3.0, 0.0)

SetCameraMode(camara, camara.type)
SetTargetFPS(60)           

While WindowShouldClose() = 0 
    UpdateCamera(@camara)
   
    if IsKeyDown(asc("Z")) then camara.target = Type(0.0, 0.0, 0.0)

    BeginDrawing()
        ClearBackground(RAYWHITE)
        BeginMode3D(camara)
            DrawCube (cubePosition1, 2.0, 2.0, 2.0, BLUE)
            DrawCubeV(cubePosition2, type(2.0,2.0,2.0) , RED)
            DrawGrid(10, 1.0)
        EndMode3D()
    EndDrawing()

wend

CloseWindow()
D.J.Peters
Posts: 8203
Joined: May 28, 2005 3:28
Contact:

Re: raylib headers

Postby D.J.Peters » Aug 27, 2020 22:40

jepalza wrote:With "DrawCube" only a plane is drawed.
In file "fbraylib.bi" line 1619 DrawCube() must be:
declare sub DrawCube(byval position as Vector3, byval width_ as single, byval height as single, byval length as single, byval colour as Color)

May be there are more errors or mistakes !

My job was to get all libs (8 in total) compiled for Windows Linux 32/64-bit static and dynamic !

Your part are test it and find typos and have fun :-)

By the way you can use def...() to init any class ... and the key stuff use key codes not real ASCII
that means in your example on german keyboard I have press [Y] not [Z] as accepted !

Short NOTE update the camera or any other object only if something changed !
(it makes no sense update an object every frame if nothing changed)

here are how I use "var" and "defXYZ()"

Joshy

Code: Select all

#define RAYLIB_STATIC
#include "fbraymath.bi"

Const screenWidth = 800
const screenHeight = 450
InitWindow(screenWidth, screenHeight, "3d cubes")
SetTargetFPS(60)           

var cam = defCamera3D( _
  defVector3(10,10,10), _
  defVector3(0,0,0), _
  defVector3(0,1,0), _
  10, _
  CAMERA_ORTHOGRAPHIC)

var cubePosition1 = defVector3(0,0,0)
var cubePosition2 = defVector3(3,3,0)

While not WindowShouldClose()
  if IsKeyDown(KEY_Z) then
    cam.position.y-=.1
    UpdateCamera(@cam)
  end if 
  BeginDrawing()
    ClearBackground(RAYWHITE)
    BeginMode3D(cam)
      DrawCube (cubePosition1, 2.0, 2.0, 2.0, BLUE)
      DrawCubeV(cubePosition2, defVector3(2.0,2.0,2.0) , RED)
      DrawGrid(10, 1.0)
    EndMode3D()
  EndDrawing()
wend

CloseWindow()

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 3 guests