Allegro Console Program Error

I've got a problem here...
I get these errors when i want to make a console programs, using Allegro for an if(KeyDown) statement later.
http://p18.img-up.net/Unavngivetq0jl.png

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>     //For std::cout function
#include <allegro.h>    //For if(KeyDown) statement
#include <windows.h>    //For the Sleep() Function
using namespace std;    //For cout w/o "std::"

//Function declaration
void Changes();
void Refresh();

//Public Variables
string str1 = "XXXXXXXXXXX";
string str2 = "X         X";
string str3 = "X         X";
string str4 = "X         X";
string str5 = "X         X";
string str6 = "X         X";
string str7 = "X         X";
string str8 = "X         X";
string str9 = "X         X";
string str10 = "X         X";
string str11 = "XXXXXXXXXXX";


int main()
{
	//Start animation
	//Menu
	//Make level

	Changes();
}END_OF_MAIN()

void Changes()
{
	//Changes
}

void Refresh()
{
	cout<<endl;
	cout<<" "<<str1<<endl;
	cout<<" "<<str2<<endl;
	cout<<" "<<str3<<endl;
	cout<<" "<<str4<<endl;
	cout<<" "<<str5<<endl;
	cout<<" "<<str6<<endl;
	cout<<" "<<str7<<endl;
	cout<<" "<<str8<<endl;
	cout<<" "<<str9<<endl;
	cout<<" "<<str10<<endl;
	cout<<" "<<str11<<endl;
	system("pause");
}


What i see is errors in the Allegro files. Not in my script. I use version 1.4.4 i think.
Do i have to make graphics with Allegro? If so, can i make the graphics transparent, so i can see my Command prompt?
- Anders4000
Allegro is a 2d graphics library... what exactly are you trying to accomplish in the console?Without even looking into the allegro.h, you cannot utilize allegro until you initialize its subsystems with a call to allegro_init()();. You also will not be able to read in keys until you "install" the keyboard with a call to install_keyboard();

In addition if you need something from windows.h you must include the Windows-specific header file winalleg.h after the Allegro header. This should resolve your BITMAP redeclaration It must be placed before any Win32 API header file. winalleg.h includes the main Win32 C API header file windows.h. What do you need from windows.h??

Also... I recommend using SDL or SFML for 2d instead of Allegro.
Last edited on
After installing the keyboard and Allegro init, what should i do with the 2 Bitmap errors?
I'm going into Allegro, because i'm only gonna use it for this if(KeyDown) statement.
I'm gonna use it for Command Prompt games. And yes, i do know that these games are, maybe not hard, but takes very long to make. I think it's cool and that's why i'll make them (:
- Anders4000
See my edit above on resolving the BITMAP error. Let me know if that works.
I need the Sleep() func. Else i can't make a game.. I want to make a simple snake game. But Allegro will not allow me to use the console now (:

It just say:
Precess returned 0 <0x0> execution time : 0.062 s
Press any key to continue.

When i have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>     //For std::cout function
#include <allegro.h>    //For if(KeyDown) statement
#include <winalleg.h>
#include <windows.h>    //For the Sleep() Function
using namespace std;    //For cout w/o "std::"

//Function declaration
void Changes();
void Refresh();

//Public Variables
string str1 = "XXXXXXXXXXX";
string str2 = "X         X";
string str3 = "X         X";
string str4 = "X         X";
string str5 = "X         X";
string str6 = "X         X";
string str7 = "X         X";
string str8 = "X         X";
string str9 = "X         X";
string str10 = "X         X";
string str11 = "XXXXXXXXXXX";
int test = 1;


int main()
{
    allegro_init();
    install_keyboard();
	//Start animation
	//Menu
	//Make level

	Changes();
}END_OF_MAIN()

void Changes()
{
	if(test == 1){
        str2 = "X    X    X";
	test = 2;
	}else{
        str2 = "X         X";
	test = 1;
	}
	Refresh();
}

void Refresh()
{
	cout<<endl;
	cout<<" "<<str1<<endl;
	cout<<" "<<str2<<endl;
	cout<<" "<<str3<<endl;
	cout<<" "<<str4<<endl;
	cout<<" "<<str5<<endl;
	cout<<" "<<str6<<endl;
	cout<<" "<<str7<<endl;
	cout<<" "<<str8<<endl;
	cout<<" "<<str9<<endl;
	cout<<" "<<str10<<endl;
	cout<<" "<<str11<<endl;
	sleep(1000);
	changes();
}


Later i would actually like to start with 2D DirectX (Think it's called DirectDraw when it's 2D)... But i think that would be too hard for me atm. (:
Last edited on
But Allegro will not allow me to use the console now (:
That's because Allegro is not a console API. It handles managing the window. You're trying to mix a 2d graphics library with the console and it's just not going to work well, if at all. Note that winalleg.h already includes windows.h, so either way you should be able to remove windows.h.

Not sure how Allegro will react to this but, with SDL you can keep the console up in the background and continue to write to it, but you must first have an active managed window open. The game will continue to run until an exit function (user closed the window) is clicked or something occurs. There are certain things you can and cannot do with the console. There might be a way to check for key strokes with the ncurses library so I would start there. I know nothing of this library as I'm mainly into 3d programming... I know there are some on the forum that do though.

A note on 2d in directx, if you are purely planning to learn it for 2d programming and NOT 3d, you'll find it ridiculously easier to use SDL or SFML. Just something to think about.
Last edited on
Thank you so much (:
I will never be making games in the console again. Since i now know that i can't "include" a 2D lib for a KeyDown statement xD

Gonna try SDL. (Might have it installed allready. Tried to install it once b4, but it didn't work out. Now i installed Allegro correctly, so i should be able to do it with SDL too.)
- Anders4000
Sorry, didn't mean to discourage you. You are just very limited to what you can do on the console.
It's fine (: if i want to make some games text based 1 day, i can make it in 2D instead, if i learn SDL.. (:
Topic archived. No new replies allowed.