PDA

View Full Version : Jedi-SDL & FPC



IaxFenris
22-02-2006, 11:22 PM
Hi all,

I am taking my first steps with Jedi-SDL and unfortunatley, a few things didn't work the way they should (or as I think they should). Installing the SDL was quite easy and the included demos worked well using Delphi 6.

Afterwards I worked my way through the documentation and came to the following code example (Example 2-3. Loading and Displaying a BMP File):



(*
* Palettized screen modes will have a default palette (a standard
* 8*8*4 colour cube), but if the image is palettized as well we can
* use that palette for a nicer colour matching
*)
if (image.format.palette and screen_.format.palette) then
begin
SDL_SetColors(screen_, @image.format.palette.colors[0], 0, image.format.palette.ncolors);
end;


This can't be possible as image.format.palette and screen_.format.palette are of PSDL_Palette, so Delphi refuses to compile. Well thats my first problem. The second one has something to do with the free pascal compiler as I want to use the Jedi-SDL with Linux as well.

For now I have installed fpc under windows and set it up according to this article:
http://www.freepascal.org/wiki/index.php/FPC_and_SDL
I am able to compile the SDL demos without errors but and some of them execute without problems but the Oxygene Demo (...\JEDI-SDL\SDLSpriteEngine\Demos\Oxygene) crashes with the error that the entry point for "IMG_string_equals" was not found in "SDL_image.dll". When I compile it with Delphi it works like a charm.

Perhaps someone could give me a hint what I have done wrong.

Thanks in advance
iax

technomage
23-02-2006, 07:54 AM
I am able to compile the SDL demos without errors but and some of them execute without problems but the Oxygene Demo (...\JEDI-SDL\SDLSpriteEngine\Demos\Oxygene) crashes with the error that the entry point for "IMG_string_equals" was not found in "SDL_image.dll". When I compile it with Delphi it works like a charm.


I have come across this myself a few times, firstly make sure you are running the latest SDL_image.dll you can probably get this from libsdl.org. I think the error actually have something to do with the way smartlinking works under FPC (i could be wrong though), the function IMG_string_equals might not exist in SDL_image any more, Delphi probably just ignores the reference if it's not used, I'm not sure how FPC does this. But the easiest way isto commont out the function declaration in sdl_image.pas and see if it works. If it does then let use know so we can update the headers.

IaxFenris
23-02-2006, 11:55 AM
Thanks for your reply.

First I have tried to comment the dubious function out but this caused an access violation when starting oxygene.

Then I tried to update the SDL_image which caused a domino effect as it required a new sdl.dll then a libpng13.dll and finally a zlib1.dll. Once I have installed all these libraries I got the message that the entry point for IMG_string_equals was not found. Great.

I also tried to comment the function out using the new libraries but starting oxygene raised the visual studio jit-debugger so it wasn't successful as well :(

savage
23-02-2006, 12:39 PM
Hi Ian,
Can I ask which version of JEDI-SDL you are using? Is it v0.5 or 1.0beta?

IaxFenris
23-02-2006, 03:08 PM
I am using v0.5 of the Jedi-SDL and have now updated to 1.0beta. I also tried to reinstall the runtime libraries (which are only included in v0.5) and found a problem I must have overlooked the first time i intalled them.

The following compressed runtimes from the v0.5 download are damaged and couldn't be extracted:

sdl-1.2.2-win32.zip
sdl_image-1.2.0-win32.zip
sdl_mixer-1.2.0-win32.zip
sdl_net-1.2.2-win32.zip

Its very likely that these damaged zip-files caused the whole trouble.

The broken Jedi-SDL installation is downloaded from sourceforge, so are there any other sources where I can runtimes that work with Jedi-SDL ?

thanks
Michael

savage
23-02-2006, 03:23 PM
The best place to get the latest runtimes is from the SDL site itself..
http://www.libsdl.org/release/SDL-1.2.9-win32.zip
http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.4-win32.zip
http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.6-win32.zip
http://www.libsdl.org/projects/SDL_net/release/SDL_net-1.2.5-win32.zip
http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.7-win32.zip

JEDI-SDL 1.0beta should be a lot more FreePascal friendly.

IaxFenris
23-02-2006, 03:43 PM
Thanks a lot for the links, savage. I have installed the runtimes and now it works perfectly with fpc :)

Next step is installing the whole thing under Linux and I am confident that it will cause at least as much trouble as under Windows :o


Oh and maybe someone has an idea how the correct code for the above code fragment should look like, or am I missing the forest through the trees?

savage
23-02-2006, 03:59 PM
Thanks a lot for the ]

Good to know

[quote="IaxFenris"]Next step is installing the whole thing under Linux and I am confident that it will cause at least as much trouble as under Windows :o
Though JEDI-SDL 1.0 is still in beta is has been tested quite extensively on Linux and to a lesser extent on MacOS X with FPC. So I would hope that you won't have the same hassles. It's fairly stable ( actually more so that 0.5 ) and the only reason why it's not an offical release yet is that I have not had the time or motivation to remove it's beta status. I will get round to doing it, but not sure when.



Oh and maybe someone has an idea how the correct code for the above code fragment should look like, or am I missing the forest through the trees?

it should look something like this...


var
screen : PSDL_Surface;
colours : array[0..255] of TSDL_Color;
...
// Set palette
SDL_SetColors(screen, @colours[0], 0, 256);


This is pretty much off the top of my head, so you'll need to confirm if this compiles or not.

To ensure you have the all the latest bug fixs for JEDI-SDL you might want to consider syncing with CVS.

IaxFenris
23-02-2006, 04:16 PM
Thanks for your suggestion, I'll try to get the cvs updates up and running. TortoiseCVS is a good tool to do so, isn't it?


Considering the code example my SDLTest.dpr looks like this:



program SDLTest;

uses
windows,
SysUtils,
SDL;

var
screen_ : PSDL_Surface;

procedure display_bmp(file_name : PChar);
var
image : PSDL_Surface;
begin
// Load the BMP file into a surface
image := SDL_LoadBMP(file_name);
if (image = nil) then
begin
MessageBox(0, PChar(Format('Couldn''t load %s : %s',
[file_name, SDL_GetError])), 'Error', MB_OK or MB_ICONHAND);
exit;
end;
if (image.format.palette and screen_.format.palette) then
begin
SDL_SetColors(screen_, @image.format.palette.colors[0], 0, image.format.palette.ncolors);
end;
// Blit onto the screen surface
if &#40;SDL_BlitSurface&#40;image, nil, screen_, nil&#41; < 0&#41; then
MessageBox&#40;0, PCHar&#40;Format&#40;'BlitSurface error &#58; %s', &#91;SDL_GetError&#93;&#41;&#41;, 'Error', MB_OK or MB_ICONHAND&#41;;
SDL_UpdateRect&#40;screen_, 0, 0, image.w, image.h&#41;;
// Free the allocated BMP surface
SDL_FreeSurface&#40;image&#41;;
end;

begin
// Initialize the SDL library
if &#40;SDL_Init&#40;SDL_INIT_VIDEO&#41; < 0&#41; then begin
MessageBox&#40;0, PChar&#40;Format&#40;'Couldn''t initialize SDL &#58; %s',
&#91;SDL_GetError&#93;&#41;&#41;, 'Error', MB_OK or MB_ICONHAND&#41;;
// Clean up on exit
SDL_Quit;
exit;
end;

&#40;*
* Initialize the display in a 640x480 8-bit palettized mode,
* requesting a software surface
*&#41;
screen_ &#58;= SDL_SetVideoMode&#40;640, 480, 8, SDL_SWSURFACE or SDL_ANYFORMAT&#41;;
display_bmp&#40;'./auweia.bmp'&#41;;
if &#40;screen_ = nil&#41; then begin
MessageBox&#40;0, PChar&#40;Format&#40;'Couldn''t set 640x480x8 video mode &#58; %s',
&#91;SDL_GetError&#93;&#41;&#41;, 'Error', MB_OK or MB_ICONHAND&#41;;
SDL_Quit;
exit;
end;
end.


It is taken directly from the "Object Pascal SDL Doc.chm" file and Delphi complains about the following line:


if &#40;image.format.palette and screen_.format.palette&#41; then

with the message "Operator is not applicable to this operands." (hopefully proper translated from german)

jdarling
23-02-2006, 04:53 PM
To fix that in Delphi it should look as follows:


if &#40;image.format.palette and screen_.format.palette&#41; = screen_.format.palette then

You can and something that large, but you still have to compare it to something. The and gives you back a joined version of the two, then adding the = makes it a true/false comparason for the if statement. I'm not sure that screen_.format.palette belongs on the right hand side of the equal, but it at least gets the idea across.

savage
23-02-2006, 05:00 PM
Thanks for the quick reply there Jeremy. You took the words right out of my keyboard.

IaxFenris
23-02-2006, 05:01 PM
I understand that you have to make a comparision to give the statement a meaning.
This might be an error in the Jedi-SDL documentation.

Edit:

if &#40;image.format.palette and screen_.format.palette&#41; = screen_.format.palette then

I took a second look at your statement and I think you did not consider that and expects integer as operands and even your altered code fragment won't compile.

savage
23-02-2006, 05:36 PM
I typed too soon :)

If you have the 0.5 archive anywhere, have a look @
JEDI-SDL/Demos/2D/SDLTests/testwin/

That Delphi project makes use of SDL_SetColors()

The fix to your code is obvious if I had paid attention to what you had typed earlier about palette being a PSDL_Palette...


if &#40;image.format.palette <> nil &#41; and &#40; screen_.format.palette <> nil &#41; then
begin
SDL_SetColors&#40;screen_, @image.format.palette.colors&#91;0&#93;, 0, image.format.palette.ncolors&#41;;
end;

jdarling
23-02-2006, 05:51 PM
I understand that you have to make a comparision to give the statement a meaning.
This might be an error in the Jedi-SDL documentation.

Edit:

if &#40;image.format.palette and screen_.format.palette&#41; = screen_.format.palette then

I took a second look at your statement and I think you did not consider that and expects integer as operands and even your altered code fragment won't compile.

Actually I have never used SDL and made the mistake of taking for granted that .palette was an integer or an integer typeable item (such as a set witch you can also and on). Looks like savage posted what should be the proper version though :).

- Jeremy

IaxFenris
23-02-2006, 05:51 PM
This way it does work :)

Many thanks for all the great help.

Maybe the example in the documentation should be altered to prevent future problems.

savage
23-02-2006, 05:57 PM
Thanks for pointing it out and I will update the documentation appropriately for the official 1.0 release.

If you find any other mistakes in the docs, please let me know.

IaxFenris
24-02-2006, 11:39 AM
Finally i managed to have a working fpc, Lazarus and Jedi-SDL under Linux :D

The only downside is, that Lazarus crashes whenever I compile one of the included NeHe Demos, but using fpc via commandline it compiles just fine. :?

However it is sufficient to start with the basics.

savage
24-02-2006, 11:44 AM
Btw, when refering to documentation, please use the HTML files from 0.5, as that is what I plan to update and release with v1.0 and not the chm file. It's also less hassle to maintain. So if anyone spots any typos/error and out right lies, please let me know.

The html documentation will be migrated to the JEDI-SDLv1.0 branch this week-end.

IaxFenris
24-02-2006, 03:42 PM
Ok, I have switched to the html files of the documentation and I will tell you whenever I find an error.

At the moment I am working through it using Lazarus as IDE. Unfortunaltey I was not able to set up the included textbased IDE to properly use the Jedi-SDL. When I entered the SDL direcotries under Options|Directories it seams that the compiler can't find all the other units as he suddenly asks for pthreads which is located in fpcs own units directory (and he does not ask for it if I leave the directories blank).

However when typing the following code using Lazarus :




program SDLTest;

&#123;$mode objfpc&#125;&#123;$H+&#125;

uses
sysutils,
sdl; // All SDL App's need this

var
screen_ &#58; PSDL_Surface;
begin
// Initialize the SDL library
if &#40;SDL_Init&#40;SDL_INIT_VIDEO&#41; < 0&#41; then
begin
WriteLn&#40;PChar&#40;Format&#40;'Couldn''t initialize SDL &#58; %s',
&#91;SDL_GetError&#93;&#41;&#41;&#41;;
// Clean up on exit
SDL_Quit;
exit;
end;

// Have a preference for 8-bit, but accept any depth
screen_ &#58;= SDL_SetVideoMode&#40;640, 480, 8, SDL_SWSURFACE or SDL_ANYFORMAT&#41;;
if &#40;screen_ = nil&#41; then
begin
WriteLn&#40;PChar&#40;Format&#40;'Couldn''t set 640x480x8 video mode &#58; %s',
&#91;SDL_GetError&#93;&#41;&#41;&#41;;

SDL_Quit;

halt&#40;1&#41;;
end;
WriteLn&#40;PChar&#40;Format&#40;'Set 640x480 at %d bits-per-pixel mode',
&#91;screen_.format.BitsPerPixel&#93;&#41;&#41;&#41;;
end.


I get the error that screen_.format is an illegal qualifier. Using the code completion with screen_ I always get the result screen_.PSDL_Surface;
This happens with Lazarus under Windows as well but Delphi 6 does not have any problems with it. Does anyone have an idea whats the problem with this? Oh and I tried to turn the Delphi compatibility mode on but it did not change the result.

A little side question: is open kylix worth the download?

thanks
Michael

savage
24-02-2006, 04:03 PM
Sorry I can't help with Lazarus as I use Delphi or Kylix for my coding and then I use FPC via command line on both Win32 and Linux to test compilation and that the resulting exes work.

IaxFenris
24-02-2006, 05:56 PM
Well, after hours of trying I finally found out what my mistake was. In fact, the solution has been quite easy, I only had to delete the {$mode objfpc} statement and it compiled without problems :)

Meanwhile I also tried out Open Kylix 3, which unfortunaltey crashes whenever I compile a program without errors :D.

IaxFenris
28-02-2006, 03:39 PM
I have to make an addition to my previous post, as the removal {$mode objfpc} did not solve all problems. While the program could compile without problems, Lazarus' code insight did not work with serveral types of the Jedi-SDL.



screen_ &#58; PSDL_Surface;
screen_.format.BitsPerPixel

Above, you can see a code fragment, where the code completion of Lazarus fails.
If you would write
screen_. and call the code completion, Lazarus would add
screen_.PSDL_Surface;

The last few days I spent some time searching for the solution, and after the hours I spent with this problem I wished that it would have been a more complex one.

Types of Jedi-SDL starting with the prefix P (like PSDL_Surface or PSDL_SysWMmsg) are pointer. If you want to access the members of the type the pointer is referencing to, you have to dereference it first. To make the above code work with code insight you have to dereference the pointer:

screen_^.format^.BitsPerPixel;

This is a problem you will not experience with Delphi, as it automatically dereferences pointer. FreePascal does not allow this unless you use the -Sd switch when compiling. Unfortunatley, Lazarus' code insight does not have a delphi mode (as far as i know) and thus does not accept the delphi syntax but if you dereference the pointer manually everything works fine.


Michael

savage
28-02-2006, 03:45 PM
Thanks for pointing it out.