Giter Club home page Giter Club logo

pascal-sdl-2-headers's Introduction

Pascal-SDL-2-Headers

These are the Pascal SDL 2 Headers.

Installation

Just add the headers to your include path. Include sdl2.pas for the main SDL2 library (should be always needed). Furthermore headers for the other SDL2 libraries are provided:

  • sdl2_image.pas
  • sdl2_mixer.pas
  • sdl2_net.pas
  • sdl2_ttf.pas

Bugs / Contributions

If you have any contributions, feel free to drop a pull request or send in a patch.

Same goes for bugs, please use the github issue tracker.

License

You may license the Pascal SDL 2 Headers either with the MPL license or with the zlib license, both included.

pascal-sdl-2-headers's People

Contributors

anyeos avatar basisbit avatar cpicanco avatar dpethes avatar ev1313 avatar free-pascal-meets-sdl-website avatar frostney avatar graemeg avatar kibook avatar nfsmonstr avatar olafkryus avatar pixelicidio avatar rumly111 avatar suve avatar tednilsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pascal-sdl-2-headers's Issues

SDL_clipboard.h?

I cant find it anywhere, are you planing on adding it? I tried to do it myself and failed miserably, 2 out of 3 functions work, but pasting text into the app returns garbage...

Bugs in sdlsyswm.inc

There seem to be some differences between sdlsyswm.inc and SDL_syswm.h that cause problems.

  1. The record __WMINFO_WINDOWS should be:

    __WMINFO_WINDOWS = record
    window: HWND; {< The window handle *}
    hdc: HDC; (
    < The window device context *)
    end;

Instead, currently, it lacks the hdc field.

  1. The record TSDL_SysWMinfo should start out like this:

    TSDL_SysWMinfo = record
    version: TSDL_version;
    subsystem: TSDL_SYSWM_TYPE;
    Case TSDL_SYSWM_TYPE of
    ...

Instead, currently, no allocation is made for the subsystem field (which may or may not work out depending on field alignment)

SDL_GetEventFilter defined incorectly

Original c code is
SDL_bool SDL_GetEventFilter(SDL_EventFilter* filter, void** userdata)

Delphi definition is in sdlevents.inc is:

function SDL_GetEventFilter(filter: PSDL_EventFilter; userdata: Pointer): TSDL_Bool; cdecl;

right definition should be:
SDL_GetEventFilter = function(out filter: PSDL_EventFilter; out userdata: PPointer): TSDL_Bool cdecl;

** means that it is not a pointer but pointer to pointer and function is returning values so it should have at least out parameters.

I am not 100% sure about out parameters but I tested and it worked only if I used out parameters.

Missing SDL_Free()

Sorry if this is not the case, but I downloaded your headers tonight and I was not able to find SDL_Free() used to free the UTF8 clipboard data. Is it missing or am I just missing it? Thanks!

Why LGPL license?

First off, I want to thank you again for your efforts in providing SDL2 bindings for Pascal. But I can't get my head around why you chose LGPL as its license. SDL 2.0 itself use the zlib license, only SDL 1.2 used LGPL. The SDL 1.2 Pascal headers itself used MPL. Lazarus and FreePascal use LGPL, but with a static linking exception.

Where I'm a bit concerned is what it means when I want to make something that's based on these headers, like say a game engine, it seems to me that the game engine will need to be licensed under LGPL respectively.

I'm also not sure what it means in terms of usage in an application. LGPL says that an LGPL-ed program can be distributed if it's not derivate work which means it needs to link dynamically. But the headers itself don't provide the library (SDL itself does) and are therefore part of the application.

I would be grateful if you could clear up these concerns for me.

TSDL_Window Icon missing

Regarding to this http://fossies.org/dox/SDL2-2.0.3/structSDL__Window.html the TSDL_Window record should look like this (See below). Otherwise the following values are in the wrong place, which is true for me.

Im on arch linux 64 bit and the used sdl version is:
sdl2-2.0.3-1

<sdlvideo.inc>

TSDL_Window = record
magic: Pointer;
id: UInt32;
title: PAnsiChar;
icon: PSDL_Surface; {CHANGED}
x,y: SInt32;
...

Unit names not recognized correctly in Linux?

A reader reported this (ref):

Had some weird results on Linux with the SDL2 units, had to rename them to use lowercase prefixes (i.e sdl2_image instead of SDL2_image). The project using the units would build fine in Lazarus, but code completion (ctrl+space) triggered errors (unit not found), and compiling from command line also reported errors about missing units. Might be the same case on OSX, haven’t tried it yet.

I guess it has to do with the case sensitivity of file names in Linux. At the moment I can't try it out myself.

  • Can anyone confirm? In Lazarus and/or command line?
  • Would re-naming the files, fix this issue (as suggested by the reporter)?

SDLK_COMMA in sdlscancode.inc

Hello,
I believe SDLK_COMMA is incorrect in sdlscancode.inc (its mapped to a semi-colon)

Thanks for your efforts!

Typos 2

file: sdl.pas | line: 457
... var ThreadId: TThreadID ...
You probably meant to write 'TSDL_ThreadID' instead of 'TThreadID'...
though not sure, since I think that delphi had a type named that.
But even if it did, its unit isn't declared in uses. So its throws an
'unnamed type' compiler exception.

file: sdl.pas | line: 1806
... r: UInt8; g: UInt8; b: UInt8 ...
since this is a getter, it needs a pointer (PUInt8)

file: sdl.pas | line: 1790
... r: PUInt8; g: PUInt8; b: PUInt8 ...
since this is a setter, it needs a non-pointer (UInt8)

Invalid TSDL_RendererFlip declaration

TSDL_RendererFlip type is declared as enumeration in pascal.
Which is not a good way to do, since in fact it should be used as set.
Members of SDL_RendererFlip type are expected to be used as bitwise operations: https://wiki.libsdl.org/SDL_RendererFlip
(It's possible to do SDL_FLIP_HORIZONTAL or SDL_FLIP_VERTICAL)

There're multiple ways to do that.

  1. The safest way, is to declare TSDL_RenderFlipType as integer. Declare its members as constants
    Patch attached: sdlrenderer.zip

WARN: enums in C are integers, and should 32-bits. Enums are 32 bits in FPC, by default. They're packed in Delphi by default. Thus if an enumeration is part of a record, care must be taken when declaring alignment, since the final structure might end up be different, depending on the compiler used!
(In this, the type is passed as a parameter, and it's not a big ise)

  1. Add additional enumeration type, which would match the mask of SDL_FLIP_HORIZONTAL or SDL_FLIP_VERTICAL.
Index: sdlrenderer.inc
===================================================================
--- sdlrenderer.inc     (revision 159)
+++ sdlrenderer.inc     (working copy)
@@ -60,6 +60,7 @@
   TSDL_RendererFlip = (SDL_FLIP_NONE,       {**< Do not flip *}
                        SDL_FLIP_HORIZONTAL, {**< flip horizontally *}
                        SDL_FLIP_VERTICAL,    {**< flip vertically *}
+                       SDL_FLIP_DIAGONAL   {**< flip diagonally *}
                        );

   {**

However, that introduces a conflict with SDL headers and documentations (since they don't have SDL_FLIP_DIAGONAL constant)

  1. Declare TSDL_RenderFlip as a set, which also introduces a difference between pascal and C headers.

Argument type mistaken

In sdlrenderer.inc at line 657 (SDL_RenderCopyEx function prototype) the last argument type is PSDL_RendererFlip. It should probably be TSDL_RendererFlip.

A small bug in sdl2_ttf.pas

in sdl2_ttf.pas:

function TTF_RenderUNICODE_Blended(font: PTTF_Font; text: UInt16; fg: TSDL_Color): PSDL_Surface cdecl; external TTF_LibName {$IFDEF DELPHI} {$IFDEF MACOS} name '_TTF_RenderUNICODE_Blended' {$ENDIF} {$ENDIF};

the type of "text" should be PUint16

missing some core units

all im seeing is the C but core primitives do exist. They should be here. I shouldnt have to rewrite them. Shipped with SDL, not separately although some have.

Another Typo in sdlscancodes.inc

I believe SDLK_BACKSLASH = '' should be SDLD_BACKSLASH = '' as Pascal does not require that to be escaped in the natural text. The way it is now causes issues in Case statements because it cannot be typecasted to a number.

Linux jedi.inc compile problems

Haven't used this before and thought I'd try it out but it won't compile. Linux, Lazarus 1.6 FPC 3.0. Following error messages:

Compile Project, Target: chapter3: Exit code 256, Errors: 2, Warnings: 1
jedi.inc(55,4) Warning: Misplaced global compiler switch, ignored
jedi.inc(397,5) Error: Incompatible types: got "AnsiString" expected "Int64"
jedi.inc(397,5) Error: Compile time expression: Wanted Boolean but got at IF or ELSEIF

Thanks.

Support static linking

Hello I'm currently looking into making this work with static linking.
I managed to get static linking with sdl2 to work after some changes (net/mixer/image are wip atm).

Is there an interest for supporting static builds?

Missing field "last_fullscreen_flags" in TSDL_Window

Hi, first off... Thanks for the headers.

After getting some weird results (using SDL 2.0.4) in a TSDL_Window I was getting from SDL_CreateWindow, I discovered the TSDL_Window record was missing the "last_fullscreen_flags" field. Please see: https://fossies.org/dox/SDL2-2.0.4/structSDL__Window.html

So in sdlvideo.inc after the flags: UInt32; field, at line 60 please insert:
last_fullscreen_flags: UInt32;

The correct structure should now be:
{* Define the SDL window structure, corresponding to toplevel windows *}
TSDL_Window = record
magic: Pointer;
id: UInt32;
title: PAnsiChar;
icon: PSDL_Surface;
x,y: SInt32;
w,h: SInt32;
min_w, min_h: SInt32;
max_w, max_h: SInt32;
flags: UInt32;
last_fullscreen_flags: UInt32;
{* Stored position and size for windowed mode * }
windowed: TSDL_Rect;
fullscreen_mode: TSDL_DisplayMode;
brightness: Float;
gamma: PUInt16;
saved_gamma: PUInt16; {* (just offset into gamma) *}
surface: PSDL_Surface;
surface_valid: TSDL_Bool;
shaper: PSDL_WindowShaper;
data: PSDL_WindowUserData;
driverdata: Pointer;
prev: PSDL_Window;
next: PSDL_Window;
end;

Typos

Line: 2437 | File: sdl.pas
SDL_GetWindowSurface seems to return another window
(I think it should return a PSDL_Surface)

Line: 1435 | File: sdl.pas
SDL_GetSurfaceColorMod args: R,G,B are UInt8 (no Pointers)
(I think it should be PUInt8; a Pointer)

TSDL_Palette.colors type issue

SDL2 wiki defines SDL_Palette.colors as "an array of SDL_Color structures representing the palette" while in the header it is just a pointer. I was doing some translations from C to pascal and I wasnt able to replicate the access to an array member as in colors[col]. I am not sure if this is my bad and if i should be first convering TSDL_Palette into a usable array first (or some other and easier way I am overlooking to access array elements) or it's an issue with the type.

Returning PAnsiChar instead of PChar

Hi,
On this file: https://github.com/ev1313/Pascal-SDL-2-Headers/blob/master/sdlfilesystem.inc

SDL_GetBasePath()
SDL_GetPrefPat()

Both functions are currently returning PChar, but that was giving me many headaches with unreadable foreign language strings, I just changed both to PAnsiChar on my fork and everything works fine since then.
Specs: Windows 7 Pro 64bits, Delphi XE3 and 10.2 developing Win32 application.

I have not better arguments to suggest a change. That's what I let this here as a suggestion or comment.

Regards.

Lib name for SDL2 image under Linux(Ubuntu at least)

Hi !

Under my Ubuntu 14.04 64b, SDL2 image installs:
libSDL2_image-2.0.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0
libSDL2_image-2.0.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libSDL2_image-2.0.so

You have libSDL_image-2 for both Linux and Darwin, is there a "2" missing after libSDL?
Have changed the lib name to "libSDL2_image.so" and it works, but does not link with "libSDL2_image-2.so"

Cheers,
Gus

sdl2.0.8 crashes with software rasterizer

Hi
i've built sdl2 from git yesterday , the surprise is if i use this new sdll2.dll , the app crashes if i use software rasterizer but with opengl or d3d9 it works ok !!

this is the example :
program test;
{$ifdef FPC}{$mode objfpc}{$h+}{$endif}
{$apptype gui}
uses sdl2;
var
m_window : PSDL_Window;
m_renderer : PSDL_Renderer;
event : TSDL_Event;
running : boolean = true;
begin

SDL_Init( SDL_INIT_VIDEO );
m_window := SDL_CreateWindow('test',SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
1024,600, SDL_WINDOW_SHOWN );
m_renderer := SDL_CreateRenderer(m_window,-1,SDL_RENDERER_SOFTWARE );

while (running) do begin
if SDL_PollEvent(@event) > 0 then begin
case event.type_ of
SDL_QUITEV: begin
running := false;
end;
end;
end;
SDL_SetRenderDrawColor( m_renderer, 40, 40, 50, 255 );
SDL_RenderClear( m_renderer );
SDL_RenderPresent( m_renderer );
end;
end.

error

the line 27 point to SDL_RenderClear( m_renderer );
any clue ?
thanks

more of s uggestion than a bug

sdl v1 has managed sources. I feel that sdl v2 should as well. oddly sdl-gfx is broken out- but your code seems to merge it back. thanks.

swore it was available in fpc. saves a ton of time.

anyway..try this, luke.
sdl2.pas.zip

incompatible types

function SDL_RWtell(ctx: PSDL_RWops): SInt64;
begin
Result := ctx^.seek(ctx, 0, RW_SEEK_CUR);
end;
[dcc32 Error] SDL2.pas(253): E2010 Incompatible types: 'Int64' and 'Integer'

same problem with Kotai's headers

What OpenGL headers to use?

what OpenGL headers do you suggest to use in combination with these Pascal-SDL-2-Headers?
I am currently using an own heavily modified version of the jedi-sdl headers but they only sorta work with up to OpenGL 2 stuff.
I also tried dglOpenGL headers but they use different types in many places so I was not able to hand over the opengl context from SDL_GL_CreateContext to be used by the dglOpenGL code.

Bug in SDL.pas C Macro conversions

Unit SDL.pas;

SDL_BITSPERPIXEL()
SDL_PIXELLAYOUT()
SDL_PIXELORDER()
SDL_PIXELTYPE()
SDL_PIXELFLAG()

Macro conversions are incorrect and should not return a bool but an Integer or Cardinal.

Further the Result should be AND'd with the mask not equated.

e.g of correct

Function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
Begin
Result := (X Shr 8) And $FF;
End;

SDL audio callback doesn't work on Windows

The basic audio callback procedure works correctly on fpc/linux, but not on fpc/windows.

To fix, the definition of TSDL_AudioCallback in sdlaudio.inc:118 must be given the cdecl modifier.

(The TSDL_AudioFilter definition on line 138 probably needs cdecl too, though I didn't test that.)

Doesn't Compile.

I'm using FreePascal version 2.6.4 on x86_64, on Linux Mint 17 x86_64.

When I try to compile the following test program from http://www.freepascal-meets-sdl.net/ :

program Chapter3_SDL2;
uses SDL2;
begin
  //initilization of video subsystem
  if SDL_Init( SDL_INIT_VIDEO ) < 0 then HALT;
  {your SDL2 application/game}
  //shutting down video subsystem
  SDL_Quit;
end.

I get the following error:

me@computer ~/pascal/game/Pascal-SDL-2-Headers $ fpc test.pas 
Free Pascal Compiler version 2.6.4 [2014/04/20] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
Compiling sdl2.pas
jedi.inc(55,4) Warning: Misplaced global compiler switch
jedi.inc(328,7) Error: Compile time expression: Wanted STRING but got INTEGER at "RTLVERSION >= 26"
jedi.inc(344,7) Warning: Illegal identifier "UNSAFE_TYPE" for $WARN directive
sdl2.pas(200,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.