Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » I am looking for correct detailed instructions how to build Allegro....

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
I am looking for correct detailed instructions how to build Allegro....
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Chris Katko
Member #1,881
January 2002
avatar

it's funny how hard it is on windows.

on linux it's literally

git clone
cd build
cmake ..
make

and 1/4th of that was changing a directory.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Dizzy Egg
Member #10,824
March 2009
avatar

Yep, using your MingW and defining -DALLEGRO_STATICLINK worked fine for me using your binaries.

@takis76 - I suggest using the MingW files Edgar posted, should be able to build without issue.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

takis76
Member #1,419
July 2001
avatar

Well I got confused a little.

But first I download the MinGw64 from the link Edgar Reynaldo gave. It is MinGw 11.2
Then In my linker options I changed the option:

-lallegro_monolith-debug-static to -lallegro_monolith-static

I renamed the MinGw64 to MinGw.
I recompiled one simple hello world example.

And it run. So I will keep my current Allegro5 directory with the precompiled libraries.
And I will keep and this MimGw 11.2

Everything I knew back In allegro 4.2 have changed and I need to relearn everything again.

Of course I didn't manage to compile the Allegro from the source.
Also I do not have the source code of the Examples.

At least where do I will find the source code of the examples of version 5.2.7.1 and where do I will find some Allegro Tutorials.

It is something instead I am not able to make any Allegro game at all.
Thank you.

Chris Katko
Member #1,881
January 2002
avatar

I'm confused. Did you get Allegro up and running or not?

You can compile games, examples and everything, even with the "precompiled binaries" option.

Though I'd just suggest getting Visual Studio (it's free) and it's literally a one liner to get the NuGet packages of Allegro.

takis76 said:

Of course I didn't manage to compile the Allegro from the source.
Also I do not have the source code of the Examples.

At least where do I will find the source code of the examples of version 5.2.7.1 and

Source of all the examples are all on git.

https://github.com/liballeg/allegro5/tree/master/examples

You can download them all, or just look at them online.

Quote:

where do I will find some Allegro Tutorials.

https://github.com/liballeg/allegro_wiki/wiki/Allegro-Vivace

Quote:

It is something instead I am not able to make any Allegro game at all.

I don't understand what this means. ???

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

takis76
Member #1,419
July 2001
avatar

Hehe!!

<quote name="Chris Katko" "">It is something instead I am not able to make any Allegro game at all.</quote>

I mean instead not able to do nothing, at least I managed to compile something from the precompiled libraries. I compiled some source code but not the Allegro source code itself.

And thank you very much for your help you provided. And there are many other things now I will need to learn.

I am encountering and another one problem.
when I am typing something and the code autocomple presents the small menu with suggested codes when I am choosing a code from the menu, always it selects the first one.

Code Autocomplete

For example you type al_ and the suggested code menu appears.
And if for example you choose something from the list you highlight it and you click on it with the mouse (In this case let's say I will select "al_add_timer_count", it always selects the first from the list "al_acknowledge_drawing_halt" or other times selects nonsense or pastes something from my clipboard or the last typed command.

How do I will fix this problem?

Thank you.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

takis76
Member #1,419
July 2001
avatar

I am already have the 20.03 version.
Where can I find this nightly compiled version of Codeblocks?
Is there any newer one?

I found this link:
https://forums.codeblocks.org/index.php/topic,24794.0.html

Well, I downloaded and works nice. The bug with code autocomplete I think was fixed.
I did a quick test. when you choose some command from the list it selects the highlighted one correctly.

But Encountering problems, the IDE sometimes crash or becomes unresponsible.

I have another one question.

It is language related question and I want to check my C++ knowledge.

As I know if I will place variables at the top of the source code outside of the main() function these variables should be global to all scope.

I placed all allegro variables at the top (I mean not before the #include header files).

Let's say these:

#SelectExpand
1ALLEGRO_DISPLAY * display; 2ALLEGRO_EVENT_QUEUE *event_queue; 3ALLEGRO_EVENT event; 4ALLEGRO_TIMER *timer; 5ALLEGRO_FS_ENTRY *entry; 6ALLEGRO_FONT *font01; 7ALLEGRO_BITMAP *mouse_pointer_hand = NULL;

And I have one project with multiple source codes:

Draw_Interface.cpp
Load_Data.cpp
main.cpp
Prototypes.cpp

The source code "Prototypes.cpp" declares all the functions that the game will have.

#SelectExpand
1int Load_Data(); 2void Draw_Interface();

Because I have 2 functions the Load_Data() and the Draw_Interface() in separated files inside the project. I do not want to have one huge source code and I would like
to manage my whole project in multiple smaller source code files.

The file "Load_Data.cpp" contains this code:

#SelectExpand
1int Load_Data(void) 2{ 3font01 = al_load_font("Lbrite.ttf",16,0); 4mouse_pointer_hand = al_load_bitmap("Hand.png"); 5return 0; 6}

This code it loads some game data, in my example I am loading one font and one hand image that I will use it as a mouse pointer for the game.

The file "Draw_Interface.cpp" contains this code:

#SelectExpand
1void Draw_Interface() 2{ 3al_draw_text(font01,al_map_rgb(255,0,0),100,100,0,"Hello"); 4al_draw_bitmap(mouse_pointer_hand, 150, 150,0); 5}

This just draws a text on the screen and this mouse pointer on the screen too not yet on the mouse (I do not know the mouse position functions yet).

After the regular headers at the top of the source code of main.cpp I added and this:

#include "Prototypes.cpp"

which it will be called to declare my functions something like a prototype constructor of the functions because the program will need to know if they are exist and when I call them the source code will find them.

The code compiles correctly.
And I run it, but I have error:

Draw_Interface.cpp|11|error: 'font01' was not declared in this scope
Draw_Interface.cpp|12|error: 'mouse_pointer_hand' was not declared in this scope

Load_Data.cpp|13|error: 'font01' was not declared in this scope
Load_Data.cpp|14|error: 'mouse_pointer_hand' was not declared in this scope

These variables were initialized at the top of the source code outside of the main() function and they should be accessible by whole scope, they should be global.

Why my separated source files can't see them?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Global variables are generally frowned upon, but can be a good way to get going. The main danger is that they are global, and they can be changed by multiple modules.

To make a variable accessible outside it's source file, you must declare it as 'extern' in the header.

Example :
Header.h

extern int global_int;

Then it must be defined in exactly one source module :

Source.cpp

#include "Header.h"

int global_int = 0;

Then any source module that wants access to global_int must include Header.h .

To make a function accessible, you just need to include the header that declares the function prototype. Then you define the function in a single source module.

CB Nightlies can be unstable sometimes, read the release thread for more info.

I'm using 20.03 and it autocompletes allegro functions fine for me.

takis76
Member #1,419
July 2001
avatar

Well,
I created one header file with name "Variables.h"

#SelectExpand
1#ifndef HEADER_B4C03ECCD95CBCD7 2#define HEADER_B4C03ECCD95CBCD7 3 4 5 extern ALLEGRO_DISPLAY * display; 6 extern ALLEGRO_EVENT_QUEUE *event_queue; 7 extern ALLEGRO_EVENT event; 8 extern ALLEGRO_TIMER *timer; 9 extern ALLEGRO_FS_ENTRY *entry; 10 extern ALLEGRO_FONT *font01; 11 extern ALLEGRO_BITMAP *mouse_pointer_hand = NULL; 12 13 extern int running; 14 15#endif // header guard

The header guards added automatically even if I will remove them. (I do not know why do they added).

I included the "Variables.h" everywhere.
In the "main.cpp"
In the "Draw_Interface.cpp"
And in the "Load_Data.cpp"

I changed the "Prototypes.cpp" to "Prototypes.h" and I included it only in the main.cpp

The "Variables.h" Included everywhere and the "Prototypes.h" is included to "main.cpp" only.

It compiled and now there is an error: ld returned 1 exit status
And I can't find where this error is and debugger is not showing in which line this error generates.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

takis76
Member #1,419
July 2001
avatar

What extra definition of these ALLEGRO variables do I need. Don't they defined in "Variables.h"?

About initialization my "main.cpp" source code is this:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10#include "Prototypes.h" 11 12 13int main() 14{ 15 mouse_pointer_hand = NULL; 16 17 18 al_init(); 19 al_init_native_dialog_addon(); 20 al_install_keyboard(); 21 22 23 display = al_create_display(1024, 768); 24 al_clear_to_color(al_map_rgb(100, 0, 0)); 25 event_queue = al_create_event_queue(); 26 timer = al_create_timer(1.0 / 60.0); 27 28 al_register_event_source(event_queue, al_get_keyboard_event_source()); 29 al_register_event_source(event_queue, al_get_display_event_source(display)); 30 31 while (true) 32 { 33 al_wait_for_event(event_queue, &event); 34 35 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 36 { 37 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 38 } 39 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 40 41 42 } 43 44 45return 0; 46}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

DanielH
Member #934
January 2001
avatar

Declaration is not the same as definition

Declaring makes them visible to the compiler but they are not actually there until they are defined.

You are declaring them in the header, but never defining them.

Just some thoughts: Do not use global variables and do some error checking

takis76
Member #1,419
July 2001
avatar

You mean I didn't give them an initial value.
I will create another one module with name "Init_Variables.cpp" for the initializations.

"Init_Variables.cpp"

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <physfs.h> 7#include <string.h> 8 9#include "Variables.h" 10 11int Init_Variables() 12{ 13 14 display = 0; 15 event_queue = 0; 16 timer = 0; 17 fs_entry = 0; 18 font01 = 0; 19 mouse_pointer_hand = NULL; 20 21 running=1; 22 23return 0; 24}

The <Prototypes.h> was updated:

#SelectExpand
1#ifndef HEADER_C37A702D3435D66F 2#define HEADER_C37A702D3435D66F 3 4int Load_Data(); 5void Draw_Interface(); 6int Init_Variables(); 7 8#endif // header guard

My "main.cpp" code does this:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10#include "Prototypes.h" 11 12 13int main() 14{ 15 16 Init_Variables(); 17 18 19 al_init(); 20 al_init_native_dialog_addon(); 21 al_install_keyboard(); 22 23 24 display = al_create_display(1024, 768); 25 al_clear_to_color(al_map_rgb(100, 0, 0)); 26 event_queue = al_create_event_queue(); 27 timer = al_create_timer(1.0 / 60.0); 28 29 al_register_event_source(event_queue, al_get_keyboard_event_source()); 30 al_register_event_source(event_queue, al_get_display_event_source(display)); 31 32 while (true) 33 { 34 al_wait_for_event(event_queue, &event); 35 36 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 37 { 38 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 39 } 40 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 41 42 43 } 44 45 46return 0; 47}

It complains about the "Prototypes.h"

Prototypes.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

What's wrong with my "Prototypes.h"? File format not recognized? It is a normal text file with source code.

Dizzy Egg
Member #10,824
March 2009
avatar

Prototypes.h.gch

That should be Prototypes.h

Not sure what .gch is?

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

DanielH
Member #934
January 2001
avatar

takis76 said:

You mean I didn't give them an initial value.

Not quite. You need to define your variables.

#SelectExpand
1#ifndef HEADER_B4C03ECCD95CBCD7 2#define HEADER_B4C03ECCD95CBCD7 3 4 // declarations 5 extern ALLEGRO_DISPLAY * display; 6 extern ALLEGRO_EVENT_QUEUE *event_queue; 7 extern ALLEGRO_EVENT event; 8 extern ALLEGRO_TIMER *timer; 9 extern ALLEGRO_FS_ENTRY *entry; 10 extern ALLEGRO_FONT *font01; 11 extern ALLEGRO_BITMAP *mouse_pointer_hand = NULL; 12 13 extern int running; 14 15#endif // header guard

Somewhere GLOBALLY you need to DEFINE them. You can choose to initialize then to null or not but they must be DEFINED.

#SelectExpand
1 2#include <stdio.h> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_physfs.h> 6#include <allegro5/allegro_font.h> 7#include <physfs.h> 8#include <string.h> 9 10#include "Variables.h" 11 12// definitions 13ALLEGRO_DISPLAY * display; 14ALLEGRO_EVENT_QUEUE *event_queue; 15ALLEGRO_EVENT event; 16ALLEGRO_TIMER *timer; 17ALLEGRO_FS_ENTRY *entry; 18ALLEGRO_FONT *font01; 19ALLEGRO_BITMAP *mouse_pointer_hand; 20 21int running; 22 23int Init_Variables() 24{ 25 26 display = 0; 27 event_queue = 0; 28 timer = 0; 29 fs_entry = 0; 30 font01 = 0; 31 mouse_pointer_hand = NULL; 32 33 running=1; 34 35return 0; 36}

takis76
Member #1,419
July 2001
avatar

Why do I need to write my variables code 2 times.
Putting them in the "Variables.h" module they should be Defined.
But if I will have lots of variable and I do not want to have bulk them at the top of my main source code and have them inside a module? (For a code management).

Also I removed this "Prototypes.h" it was complained and I put them on the top of the main source code too. But if I like to have my Prototype functions inside a separated module file too? why the compiler is complaining about the file format in not recognized?

Put everything in one single huge source code may will work but I do not want something like that.

The "Prototypes.h" were removed.

The new "main.cpp" code it looks like this now:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8 9#include "Variables.h" 10 11 ALLEGRO_DISPLAY * display; 12 ALLEGRO_EVENT_QUEUE *event_queue; 13 ALLEGRO_EVENT event; 14 ALLEGRO_TIMER *timer; 15 ALLEGRO_FS_ENTRY *fs_entry; 16 ALLEGRO_FONT *font01; 17 ALLEGRO_BITMAP *mouse_pointer_hand; 18 19 int running; 20 21 int Load_Data(); 22 void Draw_Interface(); 23 int Init_Variables(); 24 25int main() 26{ 27 28 Init_Variables(); 29 30 31 al_init(); 32 al_init_native_dialog_addon(); 33 al_install_keyboard(); 34 35 36 display = al_create_display(1024, 768); 37 al_clear_to_color(al_map_rgb(100, 0, 0)); 38 event_queue = al_create_event_queue(); 39 timer = al_create_timer(1.0 / 60.0); 40 41 al_register_event_source(event_queue, al_get_keyboard_event_source()); 42 al_register_event_source(event_queue, al_get_display_event_source(display)); 43 44 while (true) 45 { 46 al_wait_for_event(event_queue, &event); 47 48 if (event.type == ALLEGRO_EVENT_KEY_DOWN) 49 { 50 if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { return 0; } 51 } 52 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { return 0; } 53 54 55 } 56 57 58return 0; 59}

Of course the "Variables.h" module still exists.

This was run, but I thought placing the variables in a header file they get declared once.
Now I wrote the variables 2 times one with the extern operator and one without.

UPDATE and STRANGE

I deleted my "Prototypes.h" file and I created a new one and I put the function prototype code and now it run without complain the file format is not recognized.

???

Another Problem:

al_draw_text(font01,al_map_rgb(255,0,0),0,0,  0,"Hello");

Presents nothing.

My "Load_Data.cpp" checks if the file was loaded.

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_native_dialog.h> 7#include <physfs.h> 8#include <string.h> 9 10#include "Variables.h" 11 12int Load_Data(void) 13{ 14 15 font01 = al_load_font("Lbrite.ttf",24,0); 16 if (!font01) 17 { 18 //int al_show_native_message_box(ALLEGRO_DISPLAY *display,char const *title, char const *heading, char const *text,char const *buttons, int flags) 19 al_show_native_message_box(display,"Adventure Maker","Warning","The file 'Lbrite.ttf' wasn't found",NULL,0); 20 } 21 22 mouse_pointer_hand = al_load_bitmap("Hand.png"); 23 if (!mouse_pointer_hand) 24 { 25 al_show_native_message_box(display,"Adventure Maker","Warning","The file 'Hand.png' wasn't found",NULL,0); 26 } 27 28return 0; 29}

I managed to place my mouse pointer hand on the mouse position x and y now I am looking how to make the color(255,0,255) transparent.

DanielH
Member #934
January 2001
avatar

Twice because declaration != definition.

Just like function declarations and definitions.

// declaration
int myfunc();

// definition
int myfunc()
{
    return 0;
}

Declarations are only needed if you plan to share the variables between multiple source files. Otherwise you don't need to declare them and won't need to write them twice.

takis76
Member #1,419
July 2001
avatar

I found how to draw transparent images, but I will need to run the

al_convert_mask_to_alpha(mouse_pointer_hand, al_map_rgb(255, 0, 255));

Each time I will need to draw an image. Is there any global function that will convert the color rgb(255,0,255) to transparent once in the whole program at once.
I remember there was a function set_image_colorkey in the old Allegro versions back in 4.2.0 and you set the transparent color globally to everything.

The manual is not good. You can't find things easily. Everything I found so far was from your help and searching in Google. You will say search in Google again, I am searching but I do both, I first search in Google and if I will not find the answer then I ask you to bother you as less as I can.

Practically I am going to create a small program that will have all the basic functions will be needed to create a game to have it as a working source code example and then copy the code from this program to design my future games.

;D

UPDATE
I fixed the error that the text wasn't present.

It needed an additional header file. The #include <allegro5/allegro_font.h> wasn't enough. It needs and #include <allegro5/allegro_ttf.h>

And it needs and the "al_init_ttf_addon();" too.

The global transparent color remains until the next question.

DanielH
Member #934
January 2001
avatar

You could set the transparency to the image itself before it is saved in the folder. I do that so I don't have to bother with al_convert_mask_to_alpha. Use an image format that handles transparencies like PNG and make sure your image editor can save transparencies.

takis76
Member #1,419
July 2001
avatar

So, you suggest to save the images transparent from the paint program. So there is not a way to set a global transparent color like we did in the past.

I have another one question about strings in C++ (I will check my c++ knowledge again).

I am using the "#include <iostream>" to activate the strings.

When I want to define a string variable I use this code:

#include <iostream>
using namespace std;

string is_running = "No";

blah blah Allegro initialization the code in main.cpp

I have defined and the variable as extern

extern string is_running;

And when I am trying to draw some string text

al_draw_text(font01,al_map_rgb(255,0,0),100,120,0, is_running);

I have a new error:
'string' does not name a type; did you mean 'stdin'?

I make the varialble is_running to be a global string. I thing. (Because was defined in "Variables.h" and of course initialized after was defined in "Init_Variables.cpp" as usual.

The error appears in "extern string is_running;" so the variable is_running wasn't defined and then another error says:

error: 'is_running' was not declared in this scope.

DanielH
Member #934
January 2001
avatar

No, there is no function to set transparent colors (Magic Pink) like in Allegro 4.

You have 2 options: Either save the transparency in the file itself or pick a color like magic pink and use al_convert_mask_to_alpha to set the alpha channel to transparent.

For the strings, did you include the iostream header in the source file so the source file knows what a string is? You should be using the string header file <string> to activate strings. Just because <iostream> also includes it you got away with it.

#include <string>

Also, remember Allegro is written in C so you need to use C style strings. You can use the string function cstr() to convert it to a C style string.

al_draw_text(font01,al_map_rgb(255,0,0),100,120,0, is_running.cstr());

If you insist on using global variables, put all "extern" declarations in your header. In one (and only one) source file you need to define them. Then you can use your global anywhere. Just make sure to include your variable header file in each source file you want to use those variables.

takis76
Member #1,419
July 2001
avatar

Using:

extern string is_running;

In my "Variables.h"

And initializing it:

string is_running = "No";

Drops an error In the "extern string is_running;"

'string' does not name a type; did you mean 'stdin'?|

I have included both <iostream> and <string> in all my source code modules.

#include <iostream>
#include <string>

DanielH
Member #934
January 2001
avatar

using namespace std;

// or use

std::string is_running = "No";

Do this for both the declaration and definition.

If you do this in the header, that will be sufficient because you are including the header. Am I correct?

// Variables.h
#include <string>
using namespace std;

extern string is_running;

// source file
#include "Variables.h"

string is_running = "No";

 1   2   3 


Go to: