PDA

View Full Version : Free Pascal, SDL and OpenGL in XCode 3.1 (OSX 10.5.6)



paulfjeld
04-03-2009, 07:54 PM
I wanted to report that my efforts to use FPC, SDL, and OpenGL on Xcode 3.1 (OSX 10.5.6 on an iMac 3.02GHz) were successful. I didn't want to use Lazarus since I don't do Delphi (I'm an old BP 7 guy...) and I kind of like Xcode now.

It was a close call but these posts on the Lazarus forum:
http://forum.lazarus.freepascal.org/index.php?topic=6192.0
helped a lot.

I used FPC 2.2.4RC1 and the (JEDI) SDL files >included< with that package. I downloaded SDL and other SDL libraries (TTF,Image etc.) and built them (./configure, make, sudo make install) and ended up with, among other versions, libSDL.a and libSDLmain.a in my /usr/local/lib directory. I fired up Xcode, chose New Project and selected the "FPC Standard Tool 2.2.0" from the Pascal template option. I right-clicked on my target app name and chose "add - Existing Frameworks...". The target info panel came up and I clicked the bottom left "+" button below the linked libraries pane, then the "Add Other..." on the next panel. I navigated to /System/Libary/Frameworks and double-clicked "Cocoa.framework" and entered it into my target. I did another "add Existing Frameworks..." and navigated to my /usr/local/lib and selected libSDL.a and libSDLmain.a and entered them into my target.

I converted some pure C code (a test I had written to stress OpenGL) into straight Pascal with no {$linklib...} compiler directives at all. Despite some weird warnings about unused vars (which were in fact used) and some bizarre behavior from some calls with "Random," it compiled and ran beautifully, both with debug and release versions under 10.4 and 10.5 SDKs.

So now I can use all my old code with a few changes for SDL and OpenGL, but still in Pascal! Now programming will be a joy again... Thanks to everyone involved in the FPC - SDL - Lazarus community. This is really great stuff. My pascal code ran nearly 90% of the speed of the pure C code!

--Paul

paulfjeld
10-03-2009, 02:46 PM
Quick update to my experience with FPC/SDL/OpenGL on XCode 3.1... I'm not using Xcode anymore. I didn't like the goofy syntax highlighting (doesn't work) and found a better solution for me with TextWrangler and invoking shell scripts for compiling and running.

TextWrangler doesn't seem to have code-folding or code completion, but it is a minor annoyance, if that (never had access to them before and found them marginally useful when I was using xcode - just habit I guess). The trick to making TextWrangle useful to me was in setting up the Unix shell scripts properly and you have to do this for every project.

My "domakerun.sh" script looks like this:

#!/bin/sh

touch ~/Documents/coding/fpc/test/test.pas
cd ~/Documents/coding/fpc/test/
make
~/Documents/coding/fpc/test/test

I could only get the scripts to work if I hard-coded the complete path. I assigned Cmd-Enter as the hot key (Window/Palettes/Unix Scripts - Set Key..) and opened the output window in a separate pane so I could jump back to my coding file with a "Cmd-1."

I forced a touch on it so that it would rebuild the project even if I was just checking on some changes to a Unit file. It takes an extra 0.1 seconds for the compilation probably (although that will change as I get a serious project going).

My Makefile looks like this:

test : test.pas
/usr/local/bin/fpc -ve -FEoutput -k-lSDL -k-lSDLmain -k-lSDL_ttf -k-framework -kCocoa test.pas

cp ~/Documents/coding/fpc/test/output/test ~/Documents/coding/fpc/test/


I have an /output sub-folder in my project folder, but wanted a copy of the executable in the project folder which is the reason for that last line. I have a Resources folder also where my font and other data for use by the program are. I have hard-coded that path in the program, but will explore how to do it by finding the app folder (equivalent of "pwd") and appending the Resources folder to that.

The scripts go in the TextWrangler scripts folder (~/Library/Application Support/TextWrangler/Unix Support/Unix Scripts) and I will have a set of subfolders for each project with the same project script files. When I change projects I'll have to copy the specific set to the main folder, over-writing the previous set (domake.sh,dorun.sh,domakerun.sh).

It's a bit more work, but it works. I tried the IDEs Lazarus, Lightweight IDE and Gladiator, and the other free text editor, Smultron, and though they have many neat bits to make all the above seamless (plus more), they were all flaky in some way and did not suit my tastes. This is probably a fogeyness creeping in, but I want to understand what I am working with and don't have time to delve into the magic tricks anymore.

I'm sure there are better ways to do this - I may invest in BBedit to get some advanced text features - and my understanding of FPC is only getting started. Any advice is welcome!

BTW: I'm writing a sim game which is why I post on PGD. Hopefully I'll get to write about that soon...

--Paul

Ingemar
05-05-2009, 04:14 AM
Quick update to my experience with FPC/SDL/OpenGL on XCode 3.1... I'm not using Xcode anymore. I didn't like the goofy syntax highlighting (doesn't work) and found a better solution for me with TextWrangler and invoking shell scripts for compiling and running.

TextWrangler doesn't seem to have code-folding or code completion, but it is a minor annoyance, if that (never had access to them before and found them marginally useful when I was using xcode - just habit I guess).

...

I tried the IDEs Lazarus, Lightweight IDE and Gladiator, and the other free text editor, Smultron, and though they have many neat bits to make all the above seamless (plus more), they were all flaky in some way and did not suit my tastes.

I see that you tried Lightweight IDE too. I am interested to hear what problems you ran into. Of course there are still problems, but you might have found some interesting shortcomings that could be fixed (or even have been fixed).

I havn't tried building Jedi-SDL with it. I should make a try. I tried Jedi-SDL in the past with no success, but that was either from Xcode or the command-line.

paulfjeld
29-05-2009, 12:35 AM
The last few examples of Lightweight IDE simply quit on me. I would load a program, and as soon as I hit the compile, it just all quit on me. Last year the versions worked okay, but I gave up trying it.

paulfjeld
29-11-2009, 10:26 PM
Another update: I am back to using XCode, mainly because I found Andrew Hall's excellent syntax file:

http://www.dejal.com/files/pascal.xclangspec.zip

I put it in my ~/Library/Application Support/Developer/Shared/Xcode/Specifications/ folder (note: that is from my home folder - /Users/homename/Library/Etc...) and it gives me reasonable syntax and code folding. I'm running 10.6.1 and XCode 3.2 and everything is moving along nicely!

--Paul

Ingemar
30-05-2011, 03:27 AM
The last few examples of Lightweight IDE simply quit on me. I would load a program, and as soon as I hit the compile, it just all quit on me. Last year the versions worked okay, but I gave up trying it.

Old thread, but... Yes, there are problems with the IDE crashing in some cases. The most likely reason is that file paths include foreign characters or too long file names. I am working on a much needed rewrite of the file handling to avoid those problems.