PDA

View Full Version : Which libs to use ?



Lightning
11-01-2005, 10:47 AM
Which libraries are the "best" to use for crossplatform graphics/games ?
OpenGL for graphics + GLUT, GLFW, SDL ?
For audio OpenAL, is it complete, does it work with any sound card ?
Is there a sollution with small libs like GLFW or are there some units for window management, i hate external libs wich have to be packed with my apps.
Does anyone have experience with GLScene ?
What about performance in accelerated/nonaccelerated systems ?

I only used OpenGL with GLUT, GLFW(Win), pure winapi and VCL, but if someone has better ideas please share them, i don't know much about sound though. It would be nice to have a direct sollution without any external libs except the OpenGL(AL) ones, that would certainly increase the speed and would be easier to distribute.

Maybe others want to know this too, it would be nice to have a tutorial about games comparing many popular libs.

savage
11-01-2005, 10:49 AM
I think OpenGL works well with JEDI-SDL, but then I am probably biased about that. For sound you could use OpenAL, though SDL_Mixer ( also part of JEDI-SDL ) is another alternative.

Lightning
11-01-2005, 10:51 AM
You were fast, thanx savage.
Isn't SDL a BIG library ?
What license does it use ?
Is it slow ?

{MSX}
11-01-2005, 11:00 AM
I definely suggest (JEDI) SDL.


You were fast, thanx savage.
Isn't SDL a BIG library ?
What license does it use ?
Is it slow ?

How you define big ? DirectX come in many many MB. The needed DLL for SDL are at most 2 or 3 MB, depending of what components you need. Thay can fit without problem in your game packaging, if needed.

It uses a license that lets you use it in closed-source and commercial games.

It is not slow.. 3D part is based on Opengl, so it will be as fast as that. Generally it uses all hardware acceleration capabilities.

I think it's far better than GLUT or the like. It supports many other things: input, net, font, etc, etc.

GLScene should be good but it's Windows only AFAIK (maybe i'm wrong?).
Also, i don't like games to work on top of VCL. I prefer dedicated windows.

savage
11-01-2005, 11:15 AM
Nicola,
Just for your own info, there is a port of GLScene to Kylix and works under Linux. The latest news is that a small team of GLSceners has started work on integrating GLScene into Lazarus and therefore FreePascal, so theoretically that once that is done, it should work on most platforms that Lazarus supports.

Lightning
11-01-2005, 11:16 AM
GLScene should be good but it's Windows only AFAIK (maybe i'm wrong?).

You are :) it works in Delphi, Kylix and is being ported to Lazarus.
Go, go GLScene !!! 8)
I hate D3D but fortunately it's used by all DX games.
SDL is BIG allright, too big, look at GLFW, now that's a lib for my taste.
What about SDL calls, can i call OpenGL functions or do i have to call SDL ones.
I also hate VCL games :) i used VCL for terrain editing but hacked the TPanel message proc for a speed boost, because i was lazy to write a whole 3D GUI.
The fastest demos i've seen are those on Sulaco and the ones from FPC wich run extremly fast on Linux, i only need a lib for window management, the rest can be done with Pascal code(i wish everything could be done in Pascal code).
I could use the API on win but i don't know much about X calls/signals, if i knew that i could write my own crossplatform unit for window management.

Thank you guys ! :)

Sly
11-01-2005, 11:22 AM
SDL is a thin wrapper around OpenGL. You use OpenGL functions directly within an SDL application.

I've tested VCL and Win32 API-based 3D applications and there is no speed difference. The VCL application is bigger in file size, but speed-wise there is no difference.

Lightning
11-01-2005, 11:32 AM
I've tested VCL and Win32 API-based 3D applications and there is no speed difference. The VCL application is bigger in file size, but speed-wise there is no difference.

VCL intercepts a lot of messages especially paint ones and repaints your window more then necessary i used the messages to paint with OpenGL not GDI because on slow computers you see a flicker and drawing takes longer.

Sly
11-01-2005, 11:45 AM
Ahh. Don't use messages. Handle the TApplication.OnIdle event, set the Done parameter to False and do updates and draws in there. Now you have no speed difference between a VCL app and a Win32 API app that do the same thing.

Lightning
11-01-2005, 12:10 PM
Ahh. Don't use messages. Handle the TApplication.OnIdle event, set the Done parameter to False and do updates and draws in there. Now you have no speed difference between a VCL app and a Win32 API app that do the same thing.
NO, the time it takes to paint is the same but CPU power is wasted wich reduces it's overall performance because of the high temperature, i used messages with good performance and a low CPU power, this might not be usual for games but if you can't detect movement you could put a timer message and get the same CPU hungry behaviour like the IDLE event.
Though i'm pretty sure you can always detect movement and paint only when necessary this will ensure that you don't use 100% CPU all the time and lower it's temperature. The 100% CPU philosophy is a DOS feature and i don't agree with it :)

TheLion
11-01-2005, 12:19 PM
I think OpenGL works well with JEDI-SDL, but then I am probably biased about that. For sound you could use OpenAL, though SDL_Mixer ( also part of JEDI-SDL ) is another alternative.

For graphics and input I would recommend SDL for crossplatform, maybe even with OpenGL support... For audio however I would stay far far away from SDL_Mixer... We used SDL_Mixer in the very first version of the Audio part of the Basilisk Engine and we ran into a lot of problems, especially considering the music playback, the SoundFX itself (as far as I can remember) was quite okay. After trying out a lot of libraries we ended up with OpenAL and I must admit we are very happy with it.

OpenAL works with (as far as there are sound drivers present) all soundcards as far as I am aware of. You can see OpenAL more or less as a wrapper library than a library itself, it wraps different sound libraries for different platforms into one standardized library. In Windows you have the choice between the default windows sound drivers (WinMM) or the DirectSound drivers and I noticed on the OpenAL website that there are even a few more drivers in Windows that are supported, in Linux you have the choice between a lot of the more popular sound drivers like ALSA and OSS and it supports many more platforms, for a list of platforms go to:

http://www.openal.org/platforms.html

for the OpenAL website visit:
http://www.openal.org/

There is one thing however I should mention about OpenAL, it's an SoundFX library only, so it doesn't come with any music support which you will have to write yourself for example by using streaming and the OGG Vorbis libraries. On Linux I think OpenAL supports MP3 if the right extension is installed, they are working on a Vorbis extension for Windows/Linux and MacOS but that is still in the beta stage... On Windows however EAX is supported... :)



Ahh. Don't use messages. Handle the TApplication.OnIdle event, set the Done parameter to False and do updates and draws in there. Now you have no speed difference between a VCL app and a Win32 API app that do the same thing.
NO, the time it takes to paint is the same but CPU power is wasted wich reduces it's overall performance because of the high temperature, i used messages with good performance and a low CPU power, this might not be usual for games but if you can't detect movement you could put a timer message and get the same CPU hungry behaviour like the IDLE event.
Though i'm pretty sure you can always detect movement and paint only when necessary this will ensure that you don't use 100% CPU all the time and lower it's temperature. The 100% CPU philosophy is a DOS feature and i don't agree with it :)

I had to go into this, you talk about a timer event to detect movement, you are aware that the Timer event is the worst timer out there? I once tried to get a timer event to return ever 3 ms it returned ever 10 ms and the accuracy is different for each machine and the amount of workload running in the back, for collision detection this can be a disaster! In Windows it's more or less impossible to get 100% CPU time since there is no true multi-tasking, with the OnIdle you just request as much time-slices as you can when your application does not get any messages... If you want to handle messages just call Sleep(0) or Sleep(1) at the end of your OnIdle and it will make sure other applications in the waiting queue will get their time slices, I have written applications this way and the Task Manager mostly shows 0 - 1% CPU usage this way (depending on how much you do in the loop)... :) However if you don't make a fast-paced game there is no reason not to use the timer event and of course it will always be your own choice, but if you want to make a fast-paced game I would strongely advice against it ...

Lightning
11-01-2005, 12:31 PM
Thanx,
Is EAX the Creative library ?
I'm still not sure if SDL is the right way for OpenGL wrapping.
I think OpenAL is good for the audio part.
About the timer you're right, i use high accuracy timers.
I meant the movement should generate an event(call a procedure), but if this is not possible you can always send a message if you don't want that speed, messages get quickly to the application you could use a windows timer but even windows has multimedia timers for fast stuff.

TheLion
11-01-2005, 12:34 PM
Both the OpenAL distributions have EAX I think but yeah it's the Creative EAX 1.0 and EAX 2.0.

Lightning
11-01-2005, 12:49 PM
It seems all of you use SDL, i don't like it because it's too big so i will try with GLFW on Linux or GLScene if they get it to work, until then i'll stick to GLUT wich is included by default in the OS and i don't have to distribute it.
OpenAL seems a good choice for the audio part, i think i can convert mp3, wav to ogg so i don't have any pattent issues.

TheLion
11-01-2005, 01:14 PM
It seems all of you use SDL, i don't like it because it's too big so i will try with GLFW on Linux or GLScene if they get it to work, until then i'll stick to GLUT wich is included by default in the OS and i don't have to distribute it.
OpenAL seems a good choice for the audio part, i think i can convert mp3, wav to ogg so i don't have any pattent issues.

I'm not sure but I think when it comes to the patents of MP3 and games you only have to buy a license if you distribute over 5.000 copies of your game... question of course is what do they mean with distribute, freeware downloads as well or only sales! ;)

more info here:
http://www.mp3licensing.com/

however OGG is quite nice, and 100% free to use! ;)

savage
11-01-2005, 01:18 PM
Lion, Could you please point out what issues you had with SDL_Mixer, the only playback issue I am aware of is that on Win32 you need to drop the sampling rate down to 22050. If you leave it at 44100 it will sound horrible and crackly. 22050 and it should sound fine. On Linux, 44100 works and sounds fine.

TheLion
11-01-2005, 01:55 PM
pfff, that has been a while and it was with an older version of SDL_Mixer so it might be that they fixed some of them, I remember that the MP3 playback was not too good, most of my MP3 collection didn't get played back correctly (okay that is SMPEG but still)... I remember that MIDI playback had some issues, not entirely sure what issues anymore, we also needed 44100 Sample rate, however I cannot remember the problem you speak of but it could be that it occured, which would also have been a reason to drop the library... I also remember being annoyed by the fact that there is a volume setting for MIDI which doesn't appear to work in Win32 (it's an empty function ... at least it was back then), but there was nothing about that in the manual.

However It's hard to remember exactly what problems occured since it's been about 2 years ago and I've seen quite a few libraries pass by. I remember we wrote some work-arounds for some of the bugs but in the end there where a few very stubbern bugs we just couldn't work-around and so we decided to steer away from it... I wanted to inform the JEDI-SDL group back then and we even talked about providing you guys with the sound engine code, however I had to start working on a new sound engine back then and we had to start looking for a new sound library that due to some weird reason I totally forgot to notify you guys and now I only vaguely remember some of the problems we had back then... :-/ I think I can still find and send you the sound engine code, however I think it's a bit outdated now with the new SDL versions... :)

I must admit though that the CD Playback functions of SDL itself where quite good... :) I have never used SDLs own sound features but I do know that I won't touch SDL_Mixer anymore unless I don't have any other choice! ;)

Lightning
11-01-2005, 03:09 PM
A little off-topic but if you guys are interested OGG is one of the best audio formats, why use MP3s then ?

http://www.litexmedia.com/article/tests.html
http://www.litexmedia.com/article/comparison.html

You can search the web and many say OGG is comparable to MP3PRO and WMA
I found many converters on the web and i'm thinking i might convert my music files too but this format is great for anything :)

{MSX}
11-01-2005, 05:57 PM
GLScene should be good but it's Windows only AFAIK (maybe i'm wrong?).

You are :)

Ops :king: :cherry: :joker: :clown:

Chebmaster
20-05-2006, 07:57 AM
I use OpenGL, but I had a bad, *very* bad experience with GLUT. It crashed very often, locking up my Windows 98 (at the time), and the Linux version of GLUT just plain refused to start.

So I decided "to hell with it", and wrote my own window manager. Two window managers in fact - one for Windows, other for Linux. It was a pain, and the functionality is still very limited (for example, you cannot hide mouse pointer in current version yet, and the typing isn't implemented for Linux) - but its pluses are that
a). It's entirely in FreePascal.
b). The code size is infinitesimal (my program with the built-in window manager is only 100K in size - and that includes full OpenGL interaction, fullscreen mode switching, etc.)
c). It really doesn't require anything except gl/glu, which, you may presume, are already installed on any machine. Thus your entire installation package can be as small as 100k.

I know of one other man who built his own window manager - Michalis Kamburelis with his KambiLib. I used his code as a reference when I was researching the video mode switching under Linux.

My library (http://www.chebmaster.narod.ru/_winman_cl_old/cheblib_winman_e.html)
Michalis Kamburelis' Page (http://www.camelot.homedns.org/~michalis/)

aidave
20-05-2006, 04:13 PM
Whats a good alternative to Timer?

JSoftware
20-05-2006, 04:41 PM
QueryPerformanceCounter :mrgreen:

Robert Kosek
20-05-2006, 04:54 PM
QueryPerformanceCounter :mrgreen:

Written for Delphi, but easy to adapt to FPC. My "Quick Timers" unit:
(************************************************* *****************************
* The contents of this file are subject to the Mozilla Public License *
* Version 1.1 (the "License"); you may not use this file except in *
* compliance with the License. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
* *
* Software distributed under the License is distributed on an "AS IS" *
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the *
* License for the specific language governing rights and limitations *
* under the License. *
* *
* The Original Code is uQTimers.pas. *
* *
* The Initial Developer of the Original Code is Robert "The Wicked Flea" *
* Kosek. Portions created by Robert Kosek are Copyright (C) May 2006. *
* All Rights Reserved. *
************************************************** ****************************)
unit uQTimers;

interface

uses Windows;

type
TQuickTimer = record
Start, Stop: Int64;
end;

{ Returns a number for the running timer. }
function StartTimer: Integer;
{ When given a number the timer will be removed and the result will be
the seconds elapsed. }
function StopTimer(which: Integer): Extended;

var ProcessorSpeed: Int64;
QTimers: array of TQuickTimer;

implementation

function StartTimer: Integer;
begin
Result := length(QTimers);
SetLength(QTimers,length(QTimers)+1);
QueryPerformanceCounter(QTimers[Result].Start);
end;

function StopTimer(which: Integer): Extended;
procedure RemoveIndex(Index: Integer);
var i: integer;
begin
for i := Index to Length(QTimers)-1 do
QTimers[i] := QTimers[i+1];

SetLength(QTimers,Length(QTimers)-1);
end;
begin
QueryPerformanceCounter(QTimers[which].Stop);
Result := (QTimers[which].Stop - QTimers[which].Start) / ProcessorSpeed;

if which = length(QTimers) then
SetLength(QTimers,length(QTimers)-1)
else
RemoveIndex(which);
end;

procedure KillTimers;
begin
SetLength(QTimers,0);
end;

initialization
QueryPerformanceFrequency(ProcessorSpeed);
finalization
KillTimers;
end.

JSoftware
20-05-2006, 06:58 PM
Robert, your unit seems usable but it has some serious bugs. Take for instance:

i := starttimer;
i2 := starttimer;
stoptimer(i);
stoptimer(i2);

this would make the procedure try to access the value in QTimers[i2] which would be QTimers[1]. This array entry does however not exist due to that we set the length of the array to 1 when we stopped timer i.

WILL
20-05-2006, 07:25 PM
Robert: Well thats one way to distribute your code. :lol:

Chebmaster
21-05-2006, 04:09 AM
QueryPerformanceCounter(
AFAIK, there is no such function in unix :?

Robert Kosek
21-05-2006, 05:29 AM
Robert, your unit seems usable but it has some serious bugs. Take for instance:

i := starttimer;
i2 := starttimer;
stoptimer(i);
stoptimer(i2);

this would make the procedure try to access the value in QTimers[i2] which would be QTimers[1]. This array entry does however not exist due to that we set the length of the array to 1 when we stopped timer i.It's not a bug, it's the design purpose that I had in mind. Such as nested timers. The simple way to fix that would be to implement a timer_kill function so that you could deallocate the entry when it's not in use. The use I happened to design it for would be:

i := StartTimer;
i2 := StartTimer;
StopTimer(i2);
StopTimer(i);This way you could have a timer within a loop, and one without. So you could easily find both the mean and total time, mean of execution and the total time the loop took to execute.

WILL: LOL, Yup. I figured I'd help someone who is looking for snippets. ;)

JSoftware
21-05-2006, 10:59 AM
QueryPerformanceCounter(
AFAIK, there is no such function in unix :?

How about using rdtsc instead? Doesn't that work in unix?

Chebmaster
21-05-2006, 01:50 PM
It should, but... The asm potentially limits the code portability, by tying it to Intel-32 bit platforms. Not that it matters too much, though.

But i heard, using RDTSC on a multi-processor system can royally screw things up.

JSoftware
21-05-2006, 02:12 PM
But i heard, using RDTSC on a multi-processor system can royally screw things up.
I think sly or Will or someone else on this forum presented a way to get around that problem some time ago