Author Topic: SDL2 access inline?!  (Read 1064 times)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5111
  • O Rly?
    • View Profile
SDL2 access inline?!
« on: 2020-Apr-10 »
Hi coders!

i try to access SDL-Functions in GLB. Did anyone did it before?
Have no luck on that one...


[EDIT2]:

OK got it!
Had no luck with the GCC Version of SDL so i change it with the VC-Version.
Linking the Libs and using the Headerfiles are fine now! :)

 
« Last Edit: 2020-Apr-10 by Schranz0r »
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 400
    • View Profile
    • my personal website
Re: SDL2 access inline?!
« Reply #1 on: 2020-Apr-17 »
hm.. It would be nice to see some small example how to use such SDL inline :-)
From what I remember GLBasic doesn't feature haptics - vibration/rumble, at least I didn't found any code for it, so
so maybe using directly 'SDL haptics' could be a solution, if there would be easy way to get internal GLB joystick handle.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5111
  • O Rly?
    • View Profile
Re: SDL2 access inline?!
« Reply #2 on: 2020-Apr-18 »
Hi Dreamerman,

see Attachment!
Go to Project->Options in Ink change the path to the LIB-Folder to 

-L "C:\PATH_TO_THE_FOLDER\SDL_Calls\SDL2_VC\lib\x86"  -lSDL2

Then everything should work.
Maybe there is the old GLB-Bug with "RETURN" should be "return" in inline, IF->if ...

Code is a bit "Hacky" but you get the point ^^
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 400
    • View Profile
    • my personal website
Re: SDL2 access inline?!
« Reply #3 on: 2020-Apr-18 »
Thank You, nice and clean piece of code. Thats good to be able to use SDL functions directly like that.
Played with vibration/rumble but SDL tells me that my X360 controller doesn't support any haptic effects, yet it's marked as haptic device - SDL_JoystickIsHaptic return True, all gamecontroller/haptics initialization goes ok. Even when trying simplest code - some default haptic effect, my controller powers off, heh first time I see something like this, ofc. gamepad is fully working in any game... Will need to check this later..
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5111
  • O Rly?
    • View Profile
Re: SDL2 access inline?!
« Reply #4 on: 2020-Apr-18 »
Never used Haptic-things  :S
Therefor i can't help... Sry
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 400
    • View Profile
    • my personal website
Re: SDL2 access inline?!
« Reply #5 on: 2020-Apr-18 »
No problem, it looks that my problem got solved, after 'verifying' my code with C++ test project from SDL2 source.. and replacing batteries in gamepad to fully charged ones :D Still few times it had same problem, nevertheless, it's great to add some kind of force feedback/rumble effects to GLB projects. I will need to do some small project with examples.

Edit:

Proper project will come later, now what's need to be added to test haptics:
'global' variables in SDL2_Window type:
Code: (glbasic) [Select]
#include <stdio.h>      // for printf
SDL_Joystick *myJoystick = NULL;
SDL_Haptic *myHaptic = NULL;
Init subsystems:
Code: (glbasic) [Select]
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDL_InitSubSystem(SDL_INIT_HAPTIC);
after Init if window is created:
Code: (glbasic) [Select]
// Open the device
myJoystick = SDL_JoystickOpen(0);
printf("Haptic Init\n");
myHaptic = SDL_HapticOpenFromJoystick(myJoystick);
if(myHaptic == NULL)
{
printf("Error in opening Haptic Device (i.e. Rumble)\n");
printf(SDL_GetError());
}
else
{
printf("Haptic Device (i.e. Rumble) Opened\n");
}
printf("Number of Haptic Devices: %1d\n", SDL_NumHaptics());
printf("Controller is Haptic?: %1d\n", SDL_JoystickIsHaptic(myJoystick));
if (SDL_HapticRumbleInit( myHaptic ) != 0) printf("SDL_HapticRumbleInit error: %1d \n", SDL_GetError());
basic rumble effect:
Code: (glbasic) [Select]
FUNCTION RunRumble%:
INLINE
if (SDL_HapticRumblePlay( myHaptic, 0.25, 2000 ) != 0) printf("%10d \n", SDL_GetError());
ENDINLINE
ENDFUNCTION
change CloseWindow to clean after additional stuff:
Code: (glbasic) [Select]
FUNCTION CloseWindow:
INLINE
SDL_JoystickClose( myJoystick );
SDL_HapticClose( myHaptic );
ENDINLINE
self.running = FALSE
ENDFUNCTION
Test your gamepad from main loop with: Win.RunRumble()
Hopefully this can be used without all that window/rendered related stuff, thanks again :-)

Edit2:
It looks like only 'JOYSTICK' and 'HAPTIC' subsystems are needed so it's great, only small piece of coded needed for nice rumble effects :-)
« Last Edit: 2020-Apr-18 by dreamerman »
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline SnooPI

  • Dr. Type
  • ****
  • Posts: 415
    • View Profile
Re: SDL2 access inline?!
« Reply #6 on: 2020-Apr-19 »
It's a good idea.
In addition, the OOP version (although personally I don't like that).
Good work  :good:

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2747
    • View Profile
Re: SDL2 access inline?!
« Reply #7 on: 2020-Apr-20 »
Some useful stuff here, thank guys!  :booze:
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10814
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: SDL2 access inline?!
« Reply #8 on: 2020-Apr-20 »
You know about FORCEFEEDBACK command, do you?

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 400
    • View Profile
    • my personal website
Re: SDL2 access inline?!
« Reply #9 on: 2020-Apr-20 »
omg  :giveup: How could I missed that  :blink: really :lol:
But there is some problem, FORCEFEEDBACK isn't working with my x360 controller, if I'm getting it properly a 'FORCEFEEDBACK 0, 500, 1, 1' should do rumble effect but it does nothing. Ofc checked other possible parameters and same result, also tried example from help file and this also doesn't work, tried with GLB 14, 15 and newest 16, no luck.
Check my source code editor for GLBasic - link Update: 20.04.2020