PDA

View Full Version : SDL 2.0 for Pascal



End
30-07-2013, 10:39 AM
I'm writing Pascal-Headers for SDL 2.0, this is my repo:

https://github.com/ev1313/Pascal-SDL-2-Headers/

Actually I've translated:



"sdl.h",
"sdl_main.h",
"sdltype_s.h",
"sdl_stdinc.h",
"sdl_events.h",
"sdl_keyboard.h",
"sdl_keycode.h",
"sdl_scancode.h",
"sdl_mouse.h",
"sdl_video.h",
"sdl_pixels.h",
"sdl_surface.h",
"sdl_rwops.h",
"sdl_blendmode.h",
"sdl_rect.h",
"sdl_joystick.h",
"sdl_touch.h",
"sdl_gesture.h",
"sdl_error.h",
"sdl_version.h",
"sdl_render.h"


I'll not translate the headerfiles:



"sdl_opengl.h",
"sdl_opengles.h"
"sdl_opengles2.h"

Because you should use the dglopengl.pas from delphigl.com:

http://wiki.delphigl.com/index.php/Archiv:dglOpenGL

It supports all OpenGL Versions (1.0 to 4.4 30.07.2013) and is updated if there's a new Version.

Cybermonkey
30-07-2013, 02:10 PM
Will you implement statically linking in your headers? I think this is one of the most benefits of SDL2 over SDL1.2 ...

EDIT: Maybe I do something wrong but I got this errors on Linux:

fpc "sdl2.pas" -Sd (im Verzeichnis: /home/markus/Projekte/SDL2Pas/Pascal-SDL-2-Headers-master)Kompilierung fehlgeschlagen.
Free Pascal Compiler version 2.6.2 [2013/02/16] for i386
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling sdl2.pas
sdl2.pas(5555,26) Error: Identifier not found "TXEvent"
sdl2.pas(5555,26) Error: Error in type definition
sdl2.pas(5582,27) Error: Identifier not found "PDisplay"
sdl2.pas(5582,27) Error: Error in type definition
sdl2.pas(5583,25) Error: Identifier not found "TWindow"
sdl2.pas(5583,25) Error: Error in type definition
sdl2.pas(5593,27) Error: Identifier not found "TWindow"
sdl2.pas(5593,27) Error: Error in type definition
sdl2.pas(5594,27) Error: Identifier not found "TWindow"
sdl2.pas(5594,27) Error: Error in type definition
sdl2.pas(5927,1) Fatal: There were 10 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

Must I include X11? :(

EDIT2: Yes, that helps:

{$IFDEF LINUX}
uses X,xlib;
{$ENDIF}

End
31-07-2013, 03:34 PM
thanks for this hint with linux, i fixed this. But everything else is working? would be good to know (since my linux vm was destroyed by a virus ;( ).

Sorry, but i don't know how to implement statically linking. May you can help me?

Cybermonkey
30-10-2013, 12:44 PM
Hi, it's me again. I have one suggestion with SDL2_image:
I had to change line 56 from

IMG_LibName = 'libSDL_image-2.so';
to

IMG_LibName = 'libSDL_image.so';
that it works on Linux. I don't know if that's an issue with (K)Ubuntu only. I also comiled SDL2 and SDL2_image from source maybe that's the crux of the matter.
Anyway, thanks for your work with the Pascal SDL2 headers. I am now porting my Lua interpreter to SDL2 using your headers. When can we expect SDL2_net? ;)

Cybermonkey
01-11-2013, 09:11 PM
Another thing to mention is that it's rather difficult to use SDL_GetKeyboardState with Pascal (since it needs an array). I looked into the old JEDI headers and they had a helper TYPE for that. I used it the same way:

type PKeyStateArr = ^TKeyStateArr;
TKeyStateArr = array[0..65000] of UInt8;

My keyboard handling function now looks like that:

function keystate (key:integer):boolean;
var state:pkeystatearr;
begin
SDL_Pumpevents();
state:=pkeyStateArr(SDL_Getkeyboardstate(nil));
if state[key]<>0 then
begin
Result:=True;
end
else
Result:=False;
end;

If one checks a key one has to use the SDL scancodes.
For example

if keystate (SDL_SCANCODE_RIGHT) then begin
inc (x);
end;
Maybe that's also interesting for Jarrod ...

drezgames
02-11-2013, 12:12 PM
@Cybermonkey
Very cool. I will use your implementation, thanks.

Cybermonkey
05-11-2013, 09:30 PM
Sorry for annoying again, but I just noticed that SDL_hints.h is not ported, yet. Anyone still working on that headers?

Cybermonkey
06-11-2013, 08:39 PM
No one? So I did it myself ... Has anyone access to the github repository and can upload a file named "sdlhints.inc" ? This should be the content

type
TSDL_Char = PChar;


const
SDL_HINT_FRAMEBUFFER_ACCELERATION = 'SDL_FRAMEBUFFER_ACCELERATION';
SDL_HINT_RENDER_DRIVER = 'SDL_RENDER_DRIVER';
SDL_HINT_RENDER_OPENGL_SHADERS = 'SDL_RENDER_OPENGL_SHADERS';
SDL_HINT_RENDER_SCALE_QUALITY = 'SDL_RENDER_SCALE_QUALITY';
SDL_HINT_RENDER_VSYNC = 'SDL_RENDER_VSYNC';
SDL_HINT_VIDEO_X11_XVIDMODE = 'SDL_VIDEO_X11_XVIDMODE';
SDL_HINT_VIDEO_X11_XINERAMA = 'SDL_VIDEO_X11_XINERAMA';
SDL_HINT_VIDEO_X11_XRANDR = 'SDL_VIDEO_X11_XRANDR';
SDL_HINT_GRAB_KEYBOARD = 'SDL_GRAB_KEYBOARD';
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS = 'SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS';
SDL_HINT_IDLE_TIMER_DISABLED = 'SDL_IOS_IDLE_TIMER_DISABLED';
SDL_HINT_ORIENTATIONS = 'SDL_IOS_ORIENTATIONS';
SDL_HINT_XINPUT_ENABLED = 'SDL_XINPUT_ENABLED';
SDL_HINT_GAMECONTROLLERCONFIG = 'SDL_GAMECONTROLLERCONFIG';
SDL_HINT_ALLOW_TOPMOST = 'SDL_ALLOW_TOPMOST';


SDL_HINT_DEFAULT = 0;
SDL_HINT_NORMAL = SDL_HINT_DEFAULT + 1;
SDL_HINT_OVERRIDE = SDL_HINT_NORMAL + 1;


function SDL_SetHintWithPriority(name, value: TSDL_Char; priority: Uint32): TSDL_Bool; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetHintWithPriority' {$ENDIF} {$ENDIF};
function SDL_SetHint(name, value: TSDL_Char): TSDL_Bool; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SetHint' {$ENDIF} {$ENDIF};
function SDL_GetHint(name: TSDL_Char): TSDL_Char; cdecl; external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetHint' {$ENDIF} {$ENDIF};
procedure SDL_ClearHints; cdecl;external SDL_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_ClearHints' {$ENDIF} {$ENDIF};



You will have to include it in sdl2.pas.

End
08-11-2013, 11:33 AM
Hi,

sorry for not answering, i'm working on it ;)

I'll add your changes to my repository.

Thanks.

Cybermonkey
08-11-2013, 01:12 PM
Ah, thanks! I even registered at the DGL community and wanted to ask you there. Any chance of iOS/Android support soon?

End
08-11-2013, 03:40 PM
Ah, thanks! I even registered at the DGL community and wanted to ask you there. Any chance of iOS/Android support soon?

If i get the time. I even have a Android Handy now :)

But DGL is good, there i'm way more active ^^.

Cybermonkey
13-11-2013, 03:03 PM
That would be nice. I've got a tablet and want to play my own games on it ... ;)

Cybermonkey
13-11-2013, 08:48 PM
Another one from me trying to improve SDL2_Mixer this time. This is the original part with still C code in it (starting at line 115):

{* Good default values for a PC soundcard *}
const
MIX_DEFAULT_FREQUENCY = 22050; {
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
#else
MIX_DEFAULT_FORMAT = AUDIO_S16MSB
#endif }
MIX_DEFAULT_CHANNELS = 2;
MIX_MAX_VOLUME = 128; {* Volume of a chunk *}

I made this out of it:

{* Good default values for a PC soundcard *}
const
MIX_DEFAULT_FREQUENCY = 22050;
{$IFDEF ENDIAN_LITTLE}
MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
{$ELSE}
MIX_DEFAULT_FORMAT = AUDIO_S16MSB;
{$ENDIF}
MIX_DEFAULT_CHANNELS = 2;
MIX_MAX_VOLUME = 128; {* Volume of a chunk *}

I have to admit that I don't know if Delphi has that compiler switch (ENDIAN_LITTLE) but Free Pascal does.

piXelicidio
13-02-2014, 04:04 AM
Hi Junior! Hi Cybermonkey!

Seem this is a lonely road that of working with pascal and SDL2 :D
I've started working with your headers Junior, working great with Delphi XE3 and Lazarus for Win32.

Now I'm trying Lazarus + Linux + SDL2 ... but I'm a total newbie on Linux :(
I'm read from you Cybermonkey googling in another forum this:
"If someone has questions about SDL2 with FPC under Linux, don‘t hesitate to ask. "
Then i'm here :D

I "think" I've successfully installed SDL2 via PPA : https://launchpad.net/~zoogie/+archive/sdl2-snapshots (a friend help me )
Then successfully installed Lazarus 1.0.2.. can't remember how after many tries... but it works!

Now i'm trying a simply Hello World and Lazarus can't find the library lSDL2

------
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: cannot find -lSDL2
project1.lpr(66,1) Error:Error while linking
------

I have not experience with Linux or Freepascal, i'm Windows Delphi user :-/
I think can contribute with some "fancy" examples after I could manage to compile in these
three environments: FreePascal-Linux, FreePascal-Windows, Delphi XE3-(no-VCL, no-Firemonkey), Delphi XE3 + VCL

Any help very appreciated!

Super Vegeta
13-02-2014, 07:07 AM
My guess would be you don't have the appropriate developer packages installed. Try installing "SDL2-devel" and whatever other packages (_gfx, _net, et cetera) you may need.

Cybermonkey
13-02-2014, 09:10 AM
Hi, and yes, either the sdl2-devel is missing or the linker can't find the appr. libraries. What Linux do you use? I assume it's an Ubuntu distro, so I'd rather recommend to use the official libraries from your package manager.
1238

piXelicidio
13-02-2014, 10:54 PM
Hi.. I'll try it again. I tried with Ubuntu 12.?? first, now I've installed (ubuntu based) Linux Mint (seems more easy for a Windows guy like me).
Then do I have tell anything more to Lazarus to find the SDL libraries?
In windows I just copy the DLL the same folder with .EXE
Also it rise a new concern, about what a user of my game have to do to successful run my game on Linux, but I can let this for later..
Thanks

klausvdl
23-01-2016, 04:04 PM
I want to thank you (all contributors) for the SDL 2.0 headers!
Finally I was able to handle focus changing, keyboad input, game controllers etc.
A great relief! :)

Carver413
24-01-2016, 06:04 AM
there is also this which seems to be more complete although I have not tested it yet. http://forum.lazarus.freepascal.org/index.php/topic,30984.0.html