FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DerelictAllegro

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Thu May 05, 2011 7:25 am    Post subject: DerelictAllegro Reply with quote

I decided recently that, after over a decade, I wanted to check out the Allegro library again, particularly given that they've recently overhauled the API. I thought, wouldn't it be nice to use it from D? There are already D bindings for Allegro 4.x, maintained by Trasser. But I didn't see anything for 5.0. And besides, Trasser's bindings aren't Derelictified.

So, with some time on my hands today, I knocked out the first part of DerelictAllegro. It's incomplete, but enough of it is there to do some simple tests. I still need to get the Image and Font addons bound in order to do anything interesting with it.

Given what I've got so far, though, I've encountered an issue I've so far been unable to solve. Any app I make that uses an ALLEGRO_EVENT_QUEUE bombs on exit with an Access Violation. The programs run fine (I ported the opengl example from the Allegro download using DerelictGL, rendering to a texture via FBO, and it works perfectly until the crash on exit ). Even the simplest test case of just processing an event queue gives the error. If any of you have the time and/or inclination to check it out, I'd love to have more eyes on it.

Currently, it only knows how to load on Windows. Specifically "allegro-5.0.2-mt.dll" or, alternatively, "allegro-5.0.2-md.dll". If you want to try it on another platform, you'll need to pass in the DLL name explicitly to the load function.

I should be using my free time to work on the docs instead of adding new packages, but that's just soooo boring.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Thu May 05, 2011 9:30 am    Post subject: Reply with quote

And now I've added support for the font and image addons in the form of DerelictAllegroFont (derelict.allegro.font) and DerelictAllegroImage (derelict.allegro.image). Unfortunately, I'm getting more weird errors and bugs. Never had this much trouble getting a binding off the ground before. But I'm done for the night. I'll get back to in a day or two.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Mon May 09, 2011 7:23 pm    Post subject: Reply with quote

I should note that, for the most part, it seems to be working fine. The problems come when using DerelictAllegro together with DerelictGL. I'll have to investigate that. But if you just want to use allegro only, you should be good to go.

The only major issue I've seen so far is that it doesn't work with DLLs compiled with MSVC. You should use the MingW binaries available at allegro.cc. The MSVC binaries will cause a crash.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
bioinfornatics



Joined: 22 Jun 2010
Posts: 90

PostPosted: Sat Nov 12, 2011 2:45 pm    Post subject: Reply with quote

hi what is the depency for allegro (or which i can used), on my system i have
Code:
allegro5-debuginfo.x86_64 : Debug information for package allegro5
allegro5.i686 : A game programming library
allegro5.x86_64 : A game programming library
allegro5-addon-acodec.i686 : Audio codec addon for the Allegro 5 library
allegro5-addon-acodec.x86_64 : Audio codec addon for the Allegro 5 library
allegro5-addon-acodec-devel.i686 : Header files for the Allegro 5 audio
                                 : codec addon
allegro5-addon-acodec-devel.x86_64 : Header files for the Allegro 5 audio
                                   : codec addon
allegro5-addon-audio.i686 : Audio addon for the Allegro 5 library
allegro5-addon-audio.x86_64 : Audio addon for the Allegro 5 library
allegro5-addon-audio-devel.i686 : Header files for the Allegro 5 audio addon
allegro5-addon-audio-devel.x86_64 : Header files for the Allegro 5 audio
                                  : addon
allegro5-addon-dialog.i686 : Dialog addon for the Allegro 5 library
allegro5-addon-dialog.x86_64 : Dialog addon for the Allegro 5 library
allegro5-addon-dialog-devel.i686 : Header files for the Allegro 5 dialog
                                 : addon
allegro5-addon-dialog-devel.x86_64 : Header files for the Allegro 5 dialog
                                   : addon
allegro5-addon-image.i686 : Image addon for the Allegro 5 library
allegro5-addon-image.x86_64 : Image addon for the Allegro 5 library
allegro5-addon-image-devel.i686 : Header files for the Allegro 5 image addon
allegro5-addon-image-devel.x86_64 : Header files for the Allegro 5 image
                                  : addon
allegro5-addon-physfs.i686 : Physfs addon for the Allegro 5 library
allegro5-addon-physfs.x86_64 : Physfs addon for the Allegro 5 library
allegro5-addon-physfs-devel.i686 : Header files for the Allegro 5 physfs
                                 : addon
allegro5-addon-physfs-devel.x86_64 : Header files for the Allegro 5 physfs
                                   : addon
allegro5-addon-ttf.i686 : TTF addon for the Allegro 5 library
allegro5-addon-ttf.x86_64 : TTF addon for the Allegro 5 library
allegro5-addon-ttf-devel.i686 : Header files for the Allegro 5 TTF addon
allegro5-addon-ttf-devel.x86_64 : Header files for the Allegro 5 TTF addon
allegro5-devel.i686 : Development files for the Allegro 5 library
allegro5-devel.x86_64 : Development files for the Allegro 5 library
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sat Nov 12, 2011 7:49 pm    Post subject: Reply with quote

You have everything you need. DerelictAllegro includes the following bindings:

DerelictAllegro -> allegro5
DerelictAllegroAcodec -> acodec addon
DerelictAllegroAudio -> audio addon
DerelictAllegroFont -> font addon
DerelictAllegroImage -> image addon

Eventually, I'll add bindings for the ttf and dialog addons as well.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
bioinfornatics



Joined: 22 Jun 2010
Posts: 90

PostPosted: Sun Nov 13, 2011 4:15 am    Post subject: Reply with quote

Thanks i have add derelict to my fedora repo: http://repos.fedorapeople.org/repos/bioinfornatics/D/fedora-16/x86_64/

Wink
Back to top
View user's profile Send private message
joelcnz



Joined: 23 Feb 2009
Posts: 76

PostPosted: Sat Jan 14, 2012 2:20 pm    Post subject: Reply with quote

I'm trying to compile a program in just DerelictAllegro, but am having trouble.

I'm using OSX 10.7. I compiled the Allegro for the dylib files. And have got Derelict2 compiled for the import and *.a files. I got SDL and OpenGL working another time though.

Quote:

folder stucture:
derelict/allegro
lib/libDerelict*.a
example.d


Code:

pragma(lib, "dl");
pragma(lib, "lib/libDerelictAllegro.a");
pragma(lib, "lib/libDerelictUtil.a");

import derelict.allegro.allegro;
import derelict.util.compat;

void main() {
   DerelictAllegro.load("lib/liballegro.5.0.5.dylib");
   al_init();   
}



Any way, here's what I get:

Quote:

Joels-MacBook-Pro:jecax joelcnz$ rdmd example.d
ld: duplicate symbol _D8derelict4util6loader15SharedLibLoader6__initZ in lib/libDerelictUtil.a(loader_b3_5c5.o) and /tmp/.rdmd/rdmd-example.d-A74DD879880B9B7B5FDEBF14E9BE6AF9/example.d.o for architecture x86_64
collect2: ld returned 1 exit status
--- errorlevel 1
Joels-MacBook-Pro:jecax joelcnz$ dmd example.d
Joels-MacBook-Pro:jecax joelcnz$ ./example
objc[352]: Object 0x10901e710 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901ec00 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f340 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f380 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Joels-MacBook-Pro:jecax joelcnz$


Is there some example code of a DerelictAllegro program? I run on examples Smile
[/code]
Back to top
View user's profile Send private message MSN Messenger
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sat Jan 14, 2012 9:37 pm    Post subject: Reply with quote

Code:

ld: duplicate symbol _D8derelict4util6loader15SharedLibLoader6__initZ in lib/libDerelictUtil.a(loader_b3_5c5.o) and /tmp/.rdmd/rdmd-example.d-A74DD879880B9B7B5FDEBF14E9BE6AF9/example.d.o for architecture x86_64
collect2: ld returned 1 exit status
--- errorlevel 1


I believe this problem can be solved if you take out the pragmas to link the libraries. RDMD will automatically parse imported modules and pass them on to DMD to be compiled into the final executable. By linking with the Derelict libraries, you are pulling the same symbols into the executable again, hence the duplicate symbol error.

When compiling with DMD, you *will* need to link with Derelict, since it will only compile the modules you tell it to.

Code:

Joels-MacBook-Pro:jecax joelcnz$ dmd example.d
Joels-MacBook-Pro:jecax joelcnz$ ./example
objc[352]: Object 0x10901e710 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901ec00 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f340 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f380 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug


DerelictAllegro is wholly untested on Mac. You're the first to report anything about it. These messages indicate that, like SDL, Allegro needs some special setup to run properly under the Cocoa Framework. I wasn't aware that this is the case. Until I (or someone else) get it sorted, DerelictAllegro isn't going to be usable on Mac.

Quote:

Is there some example code of a DerelictAllegro program?


What you have in your code is all you need to know. Import the right module and call the load method. That's all there is to any Derelict project. This time, the problem is beyond your control.

I ask that in the future, you post problems you have in their own thread. That will help keep threads focused and easier to track.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sun Jan 15, 2012 4:56 am    Post subject: Reply with quote

Code:
Joels-MacBook-Pro:jecax joelcnz$ dmd example.d
Joels-MacBook-Pro:jecax joelcnz$ ./example
objc[352]: Object 0x10901e710 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901ec00 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f340 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
objc[352]: Object 0x10901f380 of class __NSCFData autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Joels-MacBook-Pro:jecax joelcnz$

This error happens when there is no NSAutoreleasePool set up. I needs something similar as SDL for Mac OS X. What does the original code look like?
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Jan 15, 2012 6:03 am    Post subject: Reply with quote

The relevant bits appear to be in system.m and osx_app_delegate.m.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Mon Jan 16, 2012 1:51 pm    Post subject: Reply with quote

I guess we need to port those files and add them to the bindings.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Wed Jan 18, 2012 4:58 am    Post subject: Reply with quote

doob wrote:
I guess we need to port those files and add them to the bindings.


Actually, I think it might be simpler than that. The files I mentioned above are actually built into the library/framework. I was digging around some more and found a directory called "main" in the addons folder. There's a file there, osx_main.m, that contains this:

Code:

extern int _al_mangled_main(int, char **);

/* main:
*  Replacement for main function.
*/
int main(int argc, char *argv[])
{
   _al_osx_run_main(argc, argv, _al_mangled_main);
   return 0;
}


The real main function is renamed to _al_mangled_main in alosx.h:

Code:

#ifndef ALLEGRO_LIB_BUILD
   #ifndef ALLEGRO_NO_MAGIC_MAIN
      #define ALLEGRO_MAGIC_MAIN
      #if __GNUC__ >= 4
         #define main __attribute__ ((visibility("default"))) _al_mangled_main
      #else
         #define main _al_mangled_main
      #endif
      #ifdef __cplusplus
         extern "C" int _al_mangled_main(int, char **);
      #endif
   #endif
#endif



And _al_osx_run_main is declared in allegro5/platform/aintosx.h like so:

Code:

AL_FUNC(int, _al_osx_run_main, (int argc, char **argv,
   int (*real_main)(int, char **)));


So we should be able to pull that out of the shared library when the app starts up. As for what to pass as real_main... I don't see anyway around it except to require the user to provide a function callback to DerelictAllegro on Mac. Something like this:

Code:


void myMain(string[] args)
{
    ...
}

void main(string[] args)
{
    DerelictAllegro.load();
    version(OSX) DerelictAllegro.macRun(args, &myMain);
    else myMain(args);
}


Then, internally, DerelictAllegro.macRun passes an extern(C) function pointer along to _al_osx_run_main. That function in turn calls the myMain in D.

Does that sound feasible? It breaks the consistency with the rest of Derelict, but I don't see any other way to do it without reimplementing the Cocoa stuff like you did for DerelictSDL.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Mon Jan 23, 2012 1:38 pm    Post subject: Reply with quote

Sounds good. It will be a lot easier than porting the Objective-C code to D, Objective-C bindings are really verbose.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Mon Jan 23, 2012 1:46 pm    Post subject: Reply with quote

Hmm, I'm wondering if it would be possible to use the C main or D main function to get around that extra "main" function.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Mon Jan 23, 2012 8:19 pm    Post subject: Reply with quote

If it is, that would be awesome.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group