[Module] raylib-purebasic (Windows/Linux/macOS)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Danilo »

Some simple raygui controls are now available:
Label, Button, LabelButton, ImageButton, CheckBox, ProgressBar, Slider, SliderBar, Toggle, ToggleGroup, StatusBar, GroupBox, Panel

Image

Image

Image

Image
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Mijikai »

great stuff thanks :D
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Kuron »

Danilo wrote:Some simple raygui controls are now available:
Label, Button, LabelButton, ImageButton, CheckBox, ProgressBar, Slider, SliderBar, Toggle, ToggleGroup, StatusBar, GroupBox, Panel
Looks really nice Danilo. I am definitely keeping my eye on your work with this.
Best wishes to the PB community. Thank you for the memories. ♥️
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Saki »

Hi Danilo

This is a great work ! :D

Best regards Saki
地球上の平和
mgrundler
New User
New User
Posts: 2
Joined: Sun Jun 07, 2020 1:27 pm

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by mgrundler »

Hello,

i just downloaded your raylib-Purebasic-Extension and i would like to thank you very much, its exactly what i am looking for.
I am working / compiling under MacOS Catalina with PureBasic 5.72 (x86).
Because some examples from the raylib-website are missing, i decided to add my first contribution, its the "models-cubicmap"-Example converted to PureBasic:

Code: Select all


;*******************************************************************************************
;*
;*   raylib [models] example - Cubicmap loading and drawing
;*
;*   NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
;*
;*   This example has been created using raylib 1.8 (www.raylib.com)
;*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
;*
;*   Copyright (c) 2015 Ramon Santamaria (@raysan5)
;*
;*   Translated to PureBasic by Mathias Grundler, June 2020
;*
;********************************************************************************************
IncludePath "./../../"                  ; First we need to include
XIncludeFile "raylib.pbi"               ; the raylib-purebasic import

EnableExplicit                          ; All variables have to be defined before use

UseModule ray                           ; Import the module

; Initialization
;>-------------------------------------------------------------------------------------
#SCREEN_WIDTH = 800
#SCREEN_HEIGHT = 450

InitWindow( #SCREEN_WIDTH, #SCREEN_HEIGHT, "raylib [models] example - cubesmap loading and drawing" )
If Not IsWindowReady()                  ; After creating the window, we check
    End                                 ; for errors at initialization.
EndIf                                   ; In case of error at init we end the program.

; Define the camera To look into our 3d world
;>-------------------------------------------------------------------------------------
Define camera.Camera3D
Define cam_position.Vector3
Define cam_target.Vector3
Define cam_up.Vector3
InitVector3( @cam_position, 16.0, 14.0, 16.0 )      ; Camera position
InitVector3( @cam_target  , 0.0, 0.0, 0.0 )      ; Camera looking at point
InitVector3( @cam_up      , 0.0, 1.0, 0.0 )      ; Camera up vector (rotation towards target)
camera\position = cam_position
camera\target = cam_target
camera\up = cam_up
camera\fovy = 45.0                                  ; Camera field-of-view Y
camera\type = #CAMERATYPE_PERSPECTIVE               ; Camera mode type

; NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Define mapimage.Image
LoadImageRaylib(@mapimage, "resources/cubicmap.png")   ; Loaded in CPU memory (RAM)

Define cubicmap.Texture2D
LoadTextureFromImage(@cubicmap, @mapimage)          ; Image converted to texture, GPU memory (VRAM)

Define meshvector.Vector3
InitVector3(@meshvector, 1.0, 1.0, 1.0 )
Define mesh.Mesh
GenMeshCubicmap(@mesh, @mapimage, @meshvector)
Define model.Model
LoadModelFromMesh(@model, @mesh)

Define texture.Texture2D
LoadTextureRayLib(@texture, "resources/cubicmap_atlas.png") 

model\materials\maps\texture = texture


Define mapposition.Vector3
InitVector3(@mapposition, -16.0, 0.0, -8.0 )           ; Map position

UnloadImage(@mapimage)                                 ; Once image has been converted to texture

SetCameraMode(@camera, #CAMERAMODE_ORBITAL)

SetTargetFPS(60)                        ; Set our game to run at 60 frames-per-second
;>-------------------------------------------------------------------------------------

; Main game loop
While Not WindowShouldClose()           ; Detect window close button or ESC key
    ; Update
    ;>---------------------------------------------------------------------------------
    UpdateCamera( @camera )             ; Update camera
    ;>---------------------------------------------------------------------------------

    ; Draw
    ;>---------------------------------------------------------------------------------
    BeginDrawing();

        ClearBackground(#COLOR_RAYWHITE)
        
        BeginMode3D(@camera)
        
          DrawModel(@model, @mapposition, 1.0, #COLOR_WHITE)
          
        EndMode3D()  
        
        Define drawpos.Vector2
        InitVector2(@drawpos, #SCREEN_WIDTH - (cubicmap\width * 4) - 20.0, 20.0)
        
        DrawTextureEx(@cubicmap, @drawpos, 0.0, 4.0, #COLOR_WHITE)
        DrawRectangleLines(#SCREEN_WIDTH - (cubicmap\width * 4) - 20, 20, cubicmap\width * 4, cubicmap\height * 4, #COLOR_GREEN);

        DrawTextRaylib("cubicmap image used to", 658, 90, 10, #COLOR_GRAY)
        DrawTextRaylib("generate map 3d model", 658, 104, 10, #COLOR_GRAY)
        
        DrawFPS(10, 10)

    EndDrawing()
    ;>---------------------------------------------------------------------------------
    
    If IsKeyPressed(#KEY_F1)
        TakeScreenshot("screenshots/textures_image_loading.png")
    EndIf
    
Wend
; De-Initialization
;>-------------------------------------------------------------------------------------
UnloadTexture(@cubicmap)                ; Texture unloading
UnloadTexture(@texture)                 ; Texture unloading
UnloadModel(@model)

CloseWindowRaylib()                     ; Close window and OpenGL context
;>-------------------------------------------------------------------------------------

I compiles and runs unter MacOS-Catalina.



Best regards,


Mathias
mgrundler
New User
New User
Posts: 2
Joined: Sun Jun 07, 2020 1:27 pm

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by mgrundler »

Here we go... another Example:

"texture_rectangle"

Code: Select all


;*******************************************************************************************
;*
;*   raylib [textures] rectangle - Texture loading and drawing a part defined by a rectangle
;*
;*   NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM)
;*
;*   This example has been created using raylib 1.4 (www.raylib.com)
;*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
;*
;*   Copyright (c) 2016 Ramon Santamaria (@raysan5)
;*
;*   Translated to PureBasic by Mathias Grundler, June 2020
;*
;********************************************************************************************
IncludePath "./../../"                  ; First we need to include
XIncludeFile "raylib.pbi"               ; the raylib-purebasic import

EnableExplicit                          ; All variables have to be defined before use

UseModule ray                           ; Import the module

; Initialization
;>-------------------------------------------------------------------------------------
#SCREEN_WIDTH = 800
#SCREEN_HEIGHT = 450
#MAX_FRAME_SPEED = 15
#MIN_FRAME_SPEED = 1


InitWindow( #SCREEN_WIDTH, #SCREEN_HEIGHT, "raylib [textures] example - image drawing" )
If Not IsWindowReady()                  ; After creating the window, we check
    End                                 ; for errors at initialization.
EndIf                                   ; In case of error at init we end the program.

; NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)

Define scarfy.Texture2D
LoadTextureRayLib(@scarfy, "resources/scarfy.png") 

Define position.Vector2
InitVector2(@position, 350.0, 280.0)

Define frameRec.Rectangle
InitRectangle(@frameRec, 0.0, 0.0, scarfy\width/6, scarfy\height)

Define currentFrame     = 0
Define framesCounter    = 0
Define framesSpeed      = 8

SetTargetFPS(60)                        ; Set our game to run at 60 frames-per-second
;>-------------------------------------------------------------------------------------

; Main game loop
While Not WindowShouldClose()           ; Detect window close button or ESC key
    ; Update
    ;>---------------------------------------------------------------------------------
    framesCounter + 1
    
    If (framesCounter >= (60 / framesSpeed))
      framesCounter = 0
      currentFrame  + 1
      If (currentFrame > 5)
        currentFrame = 0
      EndIf
      frameRec\x = currentFrame * (scarfy\width/6)
    EndIf
  
    If (IsKeyPressed(#KEY_RIGHT))
      framesSpeed +1
    ElseIf (IsKeyPressed(#KEY_LEFT))
      framesSpeed - 1
    EndIf
    
    If (framesSpeed > #MAX_FRAME_SPEED)
      framesSpeed = #MAX_FRAME_SPEED
    ElseIf (framesSpeed < #MIN_FRAME_SPEED)
      framesSpeed = #MIN_FRAME_SPEED
    EndIf
    
    ;>---------------------------------------------------------------------------------

    ; Draw
    ;>---------------------------------------------------------------------------------
    BeginDrawing()
    
        ClearBackground(#COLOR_RAYWHITE)

        DrawTexture(@scarfy, 15, 40, #COLOR_WHITE)
        DrawRectangleLines(15, 40, scarfy\width, scarfy\height, #COLOR_LIME)
        DrawRectangleLines(15 + frameRec\x, 40 + frameRec\y, frameRec\width, frameRec\height, #COLOR_RED)
        
        DrawTextRaylib("FRAME SPEED: ", 165, 210, 10, #COLOR_DARKGRAY)
        DrawTextRaylib(Str(framesSpeed), 575, 210, 10, #COLOR_DARKGRAY)
        DrawTextRaylib("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, #COLOR_DARKGRAY)
        
        Define i
        
        For i = 0 To #MAX_FRAME_SPEED-1
          If (i < framesSpeed)
            DrawRectangle(250 + (21 * i), 205, 20, 20, #COLOR_RED)
          EndIf
          DrawRectangleLines(250 + (21 * i), 205, 20, 20, #COLOR_MAROON)
        Next
        
        DrawTextureRec(@scarfy, @frameRec, @position, #COLOR_WHITE)
        
        DrawTextRaylib("(c) Scarfy sprite by Eiden Marsal", #SCREEN_WIDTH - 200, #SCREEN_HEIGHT - 20, 10, #COLOR_GRAY)

    EndDrawing()
    ;>---------------------------------------------------------------------------------
    
    If IsKeyPressed(#KEY_F1)
        TakeScreenshot("screenshots/textures_rectangle.png")
    EndIf
    
Wend

; De-Initialization
;>-------------------------------------------------------------------------------------
UnloadTexture(@scarfy)                  ; Texture unloading

CloseWindowRaylib()                     ; Close window and OpenGL context
;>-------------------------------------------------------------------------------------

Whooops... just saw that this example is already done :) Sorry for posting the "same thing"...


With regards,


Mathias
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Cyllceaux »

since the C-Backend... maybe this would be a nice replacement for ogre?
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Joubarbe »

Cyllceaux wrote: Mon Jan 10, 2022 4:59 pm since the C-Backend... maybe this would be a nice replacement for ogre?
+1
raylib just got to version 4 a few weeks ago.
User avatar
Caronte3D
Addict
Addict
Posts: 1025
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by Caronte3D »

+1
pfaber11
Enthusiast
Enthusiast
Posts: 145
Joined: Sat Apr 13, 2019 12:17 pm

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by pfaber11 »

Well I have just about had it with ogre , The reason, I've just spent 2 weeks trying to get it to animate an entity and I just keep failing . Anyway I'm going to try raylib for purebasic. Glad I looked at this thread . Bonjour
ccode_new
User
User
Posts: 21
Joined: Sat Jul 30, 2022 10:39 am

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by ccode_new »

Hi!

I like the RayLib.
Can you update your source code to the current RayLib version 4.2?
User avatar
idle
Always Here
Always Here
Posts: 5039
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by idle »

ccode_new wrote: Thu Jan 12, 2023 9:23 pm Hi!

I like the RayLib.
Can you update your source code to the current RayLib version 4.2?
you can also use it directly with c backend if your ok learning to use inline c
viewtopic.php?t=78826
ccode_new
User
User
Posts: 21
Joined: Sat Jul 30, 2022 10:39 am

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by ccode_new »

@idle:

But that's not particularly nice.
ccode_new
User
User
Posts: 21
Joined: Sat Jul 30, 2022 10:39 am

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by ccode_new »

Is there a way to use the "DrawTextPro" function without the detour:

ImageText -> LoadTextureFromImage -> DrawTextureEx

It is about the possibility of rotation of this function.

"DrawTextPro" doesn't work!

Enclosed:

I recompiled the "pbhelper" C files with this command:

"RLAPI void DrawTextPro(Font font, const char *text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint);"

Regardless of whether :
"DrawTextPro(*in_font.ray::Font, text.p-utf8,
*in_position.ray::Vector2, *origin.ray::Vector2, rotation.rl_float, fontSize.rl_float,
spacing.rl_float, tint.rl_ColorLong) __PBAS(DrawTextPro)"

with __PBAS or RLAS

There is no error message, but the function does not work.
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Module] raylib-purebasic (Windows/Linux/macOS)

Post by mk-soft »

I had to do a little trickery with PB v6.00 because the vector3 and vector4 structures already exist.

raylib.pbi

Code: Select all

;//----------------------------------------------------------------------------------
    ;// Structures Definition
    ;//----------------------------------------------------------------------------------
    
    ;// Vector2 type
    Structure Vector2 Align #PB_Structure_AlignC
        x.rl_float
        y.rl_float
    EndStructure
    
    ;// Vector3 type
    Structure Vector_3 Align #PB_Structure_AlignC
        x.rl_float
        y.rl_float
        z.rl_float
    EndStructure
    
    Macro Vector3
      Vector_3
    EndMacro
    
    ;// Vector4 type
    Structure Vector_4 Align #PB_Structure_AlignC
        x.rl_float
        y.rl_float
        z.rl_float
        w.rl_float
    EndStructure
    
    Macro Vector4
      Vector_4
    EndMacro
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply