Difference between revisions of "FPC and SDL"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
<br><br>
+
 
 
I assume that you already have atleast minimal knowlidge of what SDL is and it's basic functions.<br>
 
I assume that you already have atleast minimal knowlidge of what SDL is and it's basic functions.<br>
 
For those who want to learn more I suggest to visit the [http://www.libsdl.org SDL homepage].<br>
 
For those who want to learn more I suggest to visit the [http://www.libsdl.org SDL homepage].<br>
This page is going to explain how to use SDL with Free Pascal, where to obtain the pascal headers etc.<br>
+
This page is going to explain how to use SDL with Free Pascal, where to obtain the pascal headers etc.
<br><br>
+
 
 
==Obtaining FPC headers for SDL==
 
==Obtaining FPC headers for SDL==
<br><br>
+
 
 
After installing SDL itself on your system you'll need pascal headers to be able to use SDL with FPC.<br>
 
After installing SDL itself on your system you'll need pascal headers to be able to use SDL with FPC.<br>
 
There are 2 known(to me ) sources. 1st is the original JEDI SDL project at [http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME this page].<br>
 
There are 2 known(to me ) sources. 1st is the original JEDI SDL project at [http://www.delphi-jedi.org/Jedi:TEAM_SDL_HOME this page].<br>
 
These headers were ment for Delphi and while they work with delphi compatibility mode (-Sd) I'd suggest<br>
 
These headers were ment for Delphi and while they work with delphi compatibility mode (-Sd) I'd suggest<br>
 
(from personal experience) to use the modified FPC version.<br>
 
(from personal experience) to use the modified FPC version.<br>
This can be obtained via CVS like so:<br>
+
 
<hr>
+
This can be obtained via CVS like so:
cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS login<br>
+
 
password is 'cvs'<br>
+
----
cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS -z3 co projects/contrib/sdl<br>
+
 
<hr>
+
cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS login
<br>
+
 
 +
password is 'cvs'
 +
 
 +
cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS -z3 co projects/contrib/sdl
 +
 
 +
----
 +
 
 +
 
 
This will download the FPC - SDL headers into the directory projects. The important part is in the<br>
 
This will download the FPC - SDL headers into the directory projects. The important part is in the<br>
''basesdl'' directory. You can use these headers directly with FPC without modification.<br>
+
''basesdl'' directory. You can use these headers directly with FPC without modification.
<br>
+
 
<br>
 
 
==Tips and tricks==
 
==Tips and tricks==
<br><br>
+
 
There is one more thing I'd like to point out. If you use SDL_mixer you'll notice that it's dependent<br>
+
There is one more thing I'd like to point out. If you use SDL_mixer you'll notice that it's dependent
 
on smpeg library. This can be a setback since this isn't a standard library and is hard to get(CVS only IMHO).<br>
 
on smpeg library. This can be a setback since this isn't a standard library and is hard to get(CVS only IMHO).<br>
 
However the SDL_mixer.pas header for it uses smpeg by default even if SDL_mixer itself isn't linked to it.<br>
 
However the SDL_mixer.pas header for it uses smpeg by default even if SDL_mixer itself isn't linked to it.<br>
 
To remove this you just need to remove smpeg.pas from it's uses and comment out one line in the sources mentioning<br>
 
To remove this you just need to remove smpeg.pas from it's uses and comment out one line in the sources mentioning<br>
 
mp3s (it's a case near the end). This way your app. won't use smpeg.so/dll anymore.
 
mp3s (it's a case near the end). This way your app. won't use smpeg.so/dll anymore.
 +
 +
== Examples ==
 +
 +
Creating an empty SDL window:
 +
 +
 +
----
 +
 +
program sdltest;
 +
 +
uses sdl;
 +
 +
var scr: PSDL_Surface; // Our main screen
 +
 +
begin
 +
SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
 +
scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
 +
SDL_FreeSurface(scr); // Free the surface
 +
SDL_Quit; // close the subsystems and SDL
 +
end.
 +
 +
You can then compile this code with "fpc -Fu<pathtosdl.h files> -Fi<pathtosdl.inc files> example.pas"<br>
 +
If you use lazarus make sure you fill the "other unit files" and "include files" properly.

Revision as of 23:48, 3 October 2004

Introduction

I assume that you already have atleast minimal knowlidge of what SDL is and it's basic functions.
For those who want to learn more I suggest to visit the SDL homepage.
This page is going to explain how to use SDL with Free Pascal, where to obtain the pascal headers etc.

Obtaining FPC headers for SDL

After installing SDL itself on your system you'll need pascal headers to be able to use SDL with FPC.
There are 2 known(to me ) sources. 1st is the original JEDI SDL project at this page.
These headers were ment for Delphi and while they work with delphi compatibility mode (-Sd) I'd suggest
(from personal experience) to use the modified FPC version.

This can be obtained via CVS like so:


cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS login

password is 'cvs'

cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS -z3 co projects/contrib/sdl



This will download the FPC - SDL headers into the directory projects. The important part is in the
basesdl directory. You can use these headers directly with FPC without modification.

Tips and tricks

There is one more thing I'd like to point out. If you use SDL_mixer you'll notice that it's dependent on smpeg library. This can be a setback since this isn't a standard library and is hard to get(CVS only IMHO).
However the SDL_mixer.pas header for it uses smpeg by default even if SDL_mixer itself isn't linked to it.
To remove this you just need to remove smpeg.pas from it's uses and comment out one line in the sources mentioning
mp3s (it's a case near the end). This way your app. won't use smpeg.so/dll anymore.

Examples

Creating an empty SDL window:



program sdltest;

uses sdl;

var scr: PSDL_Surface; // Our main screen

begin

SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
SDL_FreeSurface(scr); // Free the surface
SDL_Quit; // close the subsystems and SDL

end.

You can then compile this code with "fpc -Fu<pathtosdl.h files> -Fi<pathtosdl.inc files> example.pas"
If you use lazarus make sure you fill the "other unit files" and "include files" properly.