System Tutorial - EdgarReynaldo/EagleGUI GitHub Wiki

EagleSystem

The most important part of Eagle is a working system driver. At this time, our Allegro 5 backend provides the implementation for our EagleSystem class.

Basic EagleSystem setup

Here is the most basic setup for an EagleSystem driver using the Allegro 5 backend.

Full source is included in the repository here :

https://github.com/EdgarReynaldo/EagleGUI/blob/master/docs/src/EagleSystemTutorial.cpp

And the code is quoted here :




/// We need to include the main Eagle header.
/// This gives us access to everything Eagle has to offer.
#include "Eagle.hpp"

/// We need to include the backend header that we are going to use. 
/// It imports all of the necessary system and graphics code to use Allegro 5.
#include "Eagle/backends/Allegro5Backend.hpp"

int main(int argc , char** argv) {
   
   /// To do most anything in Eagle, we need a system driver
   Allegro5System* sys = GetAllegro5System();
   EAGLE_ASSERT(sys);/// EAGLE_ASSERT is a regular assert but it logs and
                     /// throws an exception if null. EAGLE_DEBUG must
                     /// be defined or it will reduce to nothing.
   
   /// Now we have to initialize the system. Generally EAGLE_FULL_SETUP is used
   int sysret = sys->Initialize(EAGLE_FULL_SETUP);/// Return value is the
                                                  /// degree of success
   if (EAGLE_FULL_SETUP != sysret) {
      /// Some part of setup failed
      PrintFailedEagleInitStates(EAGLE_FULL_SETUP , sysret);/// Log the failure
      /// Test for essentials
      if (!(sysret & EAGLE_STANDARD_SETUP)) {
         /// Failed to init an essential service
         return -1;
      }
      /// Just keep going. Either touch or shaders failed but we don't need
      /// them in this case
   }
   
   EagleLog() << "Setup eagle successfully" << std::endl;
   sys->Rest(3.0);
   
   return 0;
}

Follow along in the code above.

First we include the headers necessary to use the Allegro 5 driver and the Eagle library.

Second we retrieve the Allegro 5 driver and store it in our sys variable.

Then we initialize the Eagle library using System::Initialize(int state). This will call the Allegro5System::Initialize method because we have an Allegro5System object pointer.

If all goes well we get back the value we passed in to the Initialize function. If not we print the failed eagle init states. All of the setup will be in the log by default, and the default log goes to std::cout. If init was successful we print out success, rest for 3 seconds and then return 0 to indicate success. If important modules were not initialized (anything other than shaders and touch in this case) we return -1.

It's ok to simply return without disposing of the Allegro5System* we acquired earlier. Eagle sets up atexit routines to shut the library down for us.

This concludes the basic system tutorial. Keep reading for more advanced techniques.

Advanced System Tutorial

WIP.