Allegro with wxWidgets
Samuli

Hey. I'm trying to get Allegro and wxWidgets work together in my program, but the program doesn't even compile. The error(s) I get look like this:

1245 C:\Dev-Cpp\include\wingdi.h conflicting declaration 'typedef struct tagBITMAP BITMAP'

The same problem was discussed in http://www.allegro.cc/forums/thread/329755/329755#target
and apparently the problem was eventually solved. Now I tried the same code with the given changes, but the error remained the same.

If I include winalleg.h the error is

203 C:\Dev-Cpp\include\wx\msw\private.h no matching function for call to `RGB::RGB(unsigned char, unsigned char, unsigned char)'

but apparently winalleg.h shouldn't be included.

I also read through threads
http://www.allegro.cc/forums/thread/495839 and
http://www.allegro.cc/forums/thread/585957/0

And tried to compile the code of the first one with no luck. The error was again with the BITMAP of RBG, depending on if winalleg.h was included.

Any thoughts? I'd appreciate any help whatsoever.

I can compile plain wxWidgets and Allegro programs. I use Dev-Cpp 4.9.9.2 and mingw32 3.4.2 on WinXP SP2.

BAF

You have to include allegro and winalleg before wx.

Samuli

I actually had it that way already. As I mentioned, I've tried the sources (that are supposed to work) from the other threads with no success.

Maybe I should try wxWidgets with some other library. Too bad none other that I know has easy datafile, bitmap, and sound routines and is cross platform.

amarillion

I've never tried compiling a wx-allegro program before, but I've got wxWidgets installed here. If you're willing to share your code I can give it a try. Maybe I stumble upon a solution...

Samuli

Well, actually I haven't even made any code of my own (at least nothing I have saved), just trying to compile other peoples code for starters. Just to see if I could compile the damn thing.

This is one of the many files I've been trying to compile. It's taken from http://www.allegro.cc/forums/thread/495839 and written by Slazer and modified by BAF. I hope they don't mind me sharing their code (I didn't see a licence agreement, that's what I'll tell them in court.)

1#define ALLEGRO_NO_MAGIC_MAIN
2#include <allegro.h>
3#include <winalleg.h>
4 
5#include <wx/wx.h>
6#include <wx/image.h>
7#include <wx/dc.h>
8 
9enum
10{
11 Wizard_Quit = 100,
12 Draw_It = 101
13};
14 
15void blit_from_allegro_to_wx(BITMAP *src, wxDC *target, int sx, int sy, int dx, int dy, int w, int h)
16{
17 //#ifndef WIN32
18 //wxPen *pen;
19 wxPen pn(wxColour(0,0,0), 1, wxDOT);
20 //wxColour cl;
21 for(int x = 0; x < w; ++x)
22 {
23 for(int y = 0; y < h; ++y)
24 {
25 // make the pen
26 /*
27 int color = getpixel(src, sx + x, sy + y);
28 int r = getr(color);
29 int g = getg(color);
30 int b = getb(color);
31 */
32
33 //pen = new wxPen(wxColour(r, g, b), 1, wxDOT);
34 //cl.Set((int **)src->line[y][x] >> 16, ((int **)src->line[y][x] >> 8) & 0xF, (int **)src->line[y][x] & 0xF);
35 pn.SetColour(((int **)src->line)[y][x] >> 16, (((int **)src->line)[y][x] >> 8) & 0xF, ((int **)src->line)[y][x] & 0xF);
36 // make it active
37 target->SetPen(pn);
38
39 // "putpixel"
40 target->DrawPoint(dx + x, dy + y);
41
42 // ok clear up the pen
43 //target->SetPen(wxNullPen);
44 //delete pen;
45 }
46 }
47 //#else
48 //#endif
49}
50 
51class MyApp : public wxApp
52{
53 public:
54 virtual bool OnInit();
55};
56 
57class MyFrame : public wxFrame
58{
59 public:
60 MyFrame(const wxString &title);
61 void OnDraw(wxCommandEvent &event);
62 void OnQuit(wxCommandEvent &event);
63 private:
64 DECLARE_EVENT_TABLE()
65};
66 
67BEGIN_EVENT_TABLE(MyFrame, wxFrame)
68 EVT_MENU(Draw_It, MyFrame::OnDraw)
69 EVT_MENU(Wizard_Quit, MyFrame::OnQuit)
70END_EVENT_TABLE()
71 
72IMPLEMENT_APP(MyApp)
73 
74 
75bool MyApp::OnInit()
76{
77
78 install_allegro(SYSTEM_NONE, &errno, atexit);
79 set_color_depth(32);
80
81 MyFrame *frame = new MyFrame(_T("Allegro-wxWidgets Text")); // make the frame
82
83 frame->Show(true); // show the frame
84
85 return true;
86}
87 
88MyFrame::MyFrame(const wxString &title) : wxFrame((wxFrame *)NULL, -1, title, wxDefaultPosition, wxSize(800,800))
89{
90 wxMenu *FileMenu = new wxMenu; // make the file menu
91 FileMenu->Append(Draw_It, _T("&Draw It\tAlt-D"), _("Draw the bitmap"));
92 FileMenu->Append(Wizard_Quit, _T("E&xit\tAlt-X"), _T("Quit the test program"));
93
94 wxMenuBar *MenuBar = new wxMenuBar(); // make the menu bar
95 MenuBar->Append(FileMenu, _T("&File"));
96
97 SetMenuBar(MenuBar); // use the menu bar
98
99 CreateStatusBar(); // make the status bar
100}
101 
102void MyFrame::OnDraw(wxCommandEvent &WXUNUSED(event))
103{
104 wxString filename = wxFileSelector(_("Open a BITMAP FILE... like now."), wxT(""), wxT(""), wxT(""), wxT("Bitmap Files|*.bmp"));
105 if (filename == wxEmptyString)
106 {
107 wxMessageBox(_T("You didnt choose a file, silly, try again (File -> Draw)"), _T(":p"), wxOK);
108 return ;
109 }
110 BITMAP *testbmp = load_bitmap(filename.c_str(), NULL);
111 if(testbmp == NULL)
112 {
113 wxMessageBox(_T("Couldn't load iamge"), _T("Error"), wxICON_ERROR | wxOK);
114 return;
115 }
116 // void blit_to_hdc(BITMAP *bitmap, HDC dc, int sx, sy, dx, dy, w, h);
117 /*PAINTSTRUCT ps;
118 HDC hdc;
119 HWND hwnd = (HWND)GetHandle();
120 hdc = BeginPaint(hwnd, &ps);
121 blit_to_hdc(testbmp, hdc, 0, 0, 0, 0, testbmp->w, testbmp->h);
122 EndPaint(hwnd, &ps);*/
123
124 /*wxScreenDC *bdest = new wxScreenDC;
125 int x, y;
126 GetPosition(&x, &y);
127 //blit_from_allegro_to_wx(testbmp, bdest, 0, 0, x+10, y+10, testbmp->w, testbmp->h);
128 delete bdest;*/
129
130 wxClientDC *bdest = new wxClientDC(this);
131 blit_from_allegro_to_wx(testbmp, bdest, 0, 0, 0, 0, testbmp->w, testbmp->h);
132 delete bdest;
133
134 destroy_bitmap(testbmp);
135}
136 
137void MyFrame::OnQuit(wxCommandEvent &WXUNUSED(event))
138{
139 Close(true); // close the app
140}

Felipe Maia

I know how to make both compile, just show your code and error and we'll figure it out.

[edit]
Tell us the error code you get.
[edit2]
Are you going to use it only in windows?

BAF

What's your problem? It could be your link order. You need -lalleg then the wx stuff.

Felipe Maia

Actually, he's having problem with the definitions of BITMAPs and RGBs, I had the same problem sometime before and managed to compile it, but I lost the code.

Samuli

Felipe, can you make the code in my previous post compile? The error was in the first post, but I assume you mean the whole error message. Here's the compiler log:

1Compiler: Default compiler
2Building Makefile: "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win"
3Finding dependencies for file: C:\Dev-Cpp\Projects\WxTest\Allegro\main.cc
4Executing make...
5make.exe -f "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win" all
6g++.exe -c main.cc -o main.obj -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/wx/msw" -I"C:/Dev-Cpp/include/wx/generic" -I"C:/Dev-Cpp/include/wx/animate" -I"C:/Dev-Cpp/include/wx/fl" -I"C:/Dev-Cpp/include/wx/gizmos" -I"C:/Dev-Cpp/include/wx/html" -I"C:/Dev-Cpp/include/wx/mmedia" -I"C:/Dev-Cpp/include/wx/net" -I"C:/Dev-Cpp/include/wx/ogl" -I"C:/Dev-Cpp/include/wx/plot" -I"C:/Dev-Cpp/include/wx/protocol" -I"C:/Dev-Cpp/include/wx/stc" -I"C:/Dev-Cpp/include/wx/svg" -I"C:/Dev-Cpp/include/wx/xml" -I"C:/Dev-Cpp/include/wx/xrc" -I"C:/Dev-Cpp/include/wx" -D_X86_=1 -DWIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -mthreads -DSTRICT -D__WXMSW__ -D__WINDOWS__ -Wall -fno-pcc-struct-return -O2 -fno-rtti -fno-exceptions -fexpensive-optimizations -O3
7 
8In file included from C:/Dev-Cpp/include/wx/filefn.h:173,
9 from C:/Dev-Cpp/include/wx/utils.h:32,
10 from C:/Dev-Cpp/include/wx/cursor.h:37,
11 from C:/Dev-Cpp/include/wx/event.h:32,
12 from C:/Dev-Cpp/include/wx/wx.h:23,
13 from main.cc:5:
14C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToRGB(const wxColour&)':
15C:/Dev-Cpp/include/wx/msw/private.h:203: error: no matching function for call to `RGB::RGB(unsigned char, unsigned char, unsigned char)'
16C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/palette.h:27: note: candidates are: RGB::RGB()
17C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/palette.h:27: note: RGB::RGB(const RGB&)
18C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToPalRGB(const wxColour&)':
19C:/Dev-Cpp/include/wx/msw/private.h:208: error: no matching function for call to `RGB::RGB(unsigned char, unsigned char, unsigned char)'
20C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/palette.h:27: note: candidates are: RGB::RGB()
21C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/palette.h:27: note: RGB::RGB(const RGB&)
22 
23make.exe: *** [main.obj] Error 1
24 
25Execution terminated

So there's something wrong with the RGB thingy..

Kitty Cat

It appears both Allegro and wxWidgets define RGB. Try this:

#define RGB AL_RGB
#include <allegro.h>
#inlcude <winalleg.h>
#undef RGB

#include <wx stuff>

Then use AL_RGB if you ever need to use Allegro's RGB struct.

Samuli

Thanks Kitty, that fixed one problem, but now it gives me following error log (actually this is exactly same error log I get if I use the code above without the line #include <winalleg.h>):

1Compiler: Default compiler
2Building Makefile: "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win"
3Finding dependencies for file: C:\Dev-Cpp\Projects\WxTest\Allegro\main.cc
4Executing make...
5make.exe -f "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win" all
6g++.exe -c main.cc -o main.obj -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/wx/msw" -I"C:/Dev-Cpp/include/wx/generic" -I"C:/Dev-Cpp/include/wx/animate" -I"C:/Dev-Cpp/include/wx/fl" -I"C:/Dev-Cpp/include/wx/gizmos" -I"C:/Dev-Cpp/include/wx/html" -I"C:/Dev-Cpp/include/wx/mmedia" -I"C:/Dev-Cpp/include/wx/net" -I"C:/Dev-Cpp/include/wx/ogl" -I"C:/Dev-Cpp/include/wx/plot" -I"C:/Dev-Cpp/include/wx/protocol" -I"C:/Dev-Cpp/include/wx/stc" -I"C:/Dev-Cpp/include/wx/svg" -I"C:/Dev-Cpp/include/wx/xml" -I"C:/Dev-Cpp/include/wx/xrc" -I"C:/Dev-Cpp/include/wx" -D_X86_=1 -DWIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -mthreads -DSTRICT -D__WXMSW__ -D__WINDOWS__ -Wall -fno-pcc-struct-return -O2 -fno-rtti -fno-exceptions -fexpensive-optimizations -O3
7 
8main.cc:5:2: invalid preprocessing directive #inlcude
9In file included from C:/Dev-Cpp/include/windows.h:52,
10 from C:/Dev-Cpp/include/wx/msw/wrapwin.h:47,
11 from C:/Dev-Cpp/include/wx/msw/private.h:17,
12 from C:/Dev-Cpp/include/wx/filefn.h:173,
13 from C:/Dev-Cpp/include/wx/utils.h:32,
14 from C:/Dev-Cpp/include/wx/cursor.h:37,
15 from C:/Dev-Cpp/include/wx/event.h:32,
16 from C:/Dev-Cpp/include/wx/wx.h:23,
17 from main.cc:8:
18C:/Dev-Cpp/include/wingdi.h:1245: error: conflicting declaration 'typedef struct tagBITMAP BITMAP'
19 
20C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: 'BITMAP' has a previous declaration as `typedef struct BITMAP BITMAP'
21C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
22 
23C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'
24C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
25C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'
26C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
27C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'
28
29make.exe: *** [main.obj] Error 1
30
31Execution terminated

Edit:

Felipe: First I'd like to make it work in Windows, but I'd like to leave the door open for cross platforming.

FMC
Quote:

main.cc:5:2: invalid preprocessing directive #inlcude

include, not inlcude ;)

Samuli

FMC: Blast! No wonder it acted so strangely. Ok, that solves the BITMAP issue, but there's still more to come. Now the problem seems to be in wx's RGB..

1Compiler: Default compiler
2Building Makefile: "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win"
3Finding dependencies for file: C:\Dev-Cpp\Projects\WxTest\Allegro\main.cc
4Executing make...
5make.exe -f "C:\Dev-Cpp\Projects\WxTest\Allegro\Makefile.win" all
6g++.exe -c main.cc -o main.obj -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/wx/msw" -I"C:/Dev-Cpp/include/wx/generic" -I"C:/Dev-Cpp/include/wx/animate" -I"C:/Dev-Cpp/include/wx/fl" -I"C:/Dev-Cpp/include/wx/gizmos" -I"C:/Dev-Cpp/include/wx/html" -I"C:/Dev-Cpp/include/wx/mmedia" -I"C:/Dev-Cpp/include/wx/net" -I"C:/Dev-Cpp/include/wx/ogl" -I"C:/Dev-Cpp/include/wx/plot" -I"C:/Dev-Cpp/include/wx/protocol" -I"C:/Dev-Cpp/include/wx/stc" -I"C:/Dev-Cpp/include/wx/svg" -I"C:/Dev-Cpp/include/wx/xml" -I"C:/Dev-Cpp/include/wx/xrc" -I"C:/Dev-Cpp/include/wx" -D_X86_=1 -DWIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -mthreads -DSTRICT -D__WXMSW__ -D__WINDOWS__ -Wall -fno-pcc-struct-return -O2 -fno-rtti -fno-exceptions -fexpensive-optimizations -O3
7 
8In file included from C:/Dev-Cpp/include/wx/filefn.h:173,
9 from C:/Dev-Cpp/include/wx/utils.h:32,
10 from C:/Dev-Cpp/include/wx/cursor.h:37,
11 from C:/Dev-Cpp/include/wx/event.h:32,
12 from C:/Dev-Cpp/include/wx/wx.h:23,
13 from main.cc:9:
14C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToRGB(const wxColour&)':
15C:/Dev-Cpp/include/wx/msw/private.h:203: error: `RGB' undeclared (first use this function)
16C:/Dev-Cpp/include/wx/msw/private.h:203: error: (Each undeclared identifier is reported only once for each function it appears in.)
17C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToPalRGB(const wxColour&)':
18C:/Dev-Cpp/include/wx/msw/private.h:208: error: `RGB' undeclared (first use this function)
19 
20make.exe: *** [main.obj] Error 1
21 
22Execution terminated

FMC

I think Kitty Cat meant this:

#define AL_RGB RGB 
#include <allegro.h>
#inlcude <winalleg.h>
#undef RGB

#include <wx stuff>

not

#define RGB AL_RGB //AL_RGB is still not defined 
#include <allegro.h>
#inlcude <winalleg.h>
#undef RGB

#include <wx stuff>

Felipe Maia

No FMC, Kitty Cat's code is right.

Show us your entire code now Samuli.

Samuli

Edit:

Ok, so the error is again this 'RGB' undeclared.

Man, I'm baffled.

Edit:

The entire code is there.

Felipe Maia

Ahhh, I get it now.

#define RGB AL_RGB
#include <allegro.h>
#undef RGB
#include <winalleg.h>

#include <wx stuff>

Change it to this.

Samuli

Errors, errors everywhere.. This time:

C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToRGB(const wxColour&)':
C:/Dev-Cpp/include/wx/msw/private.h:203: error: `RGB' undeclared (first use this function)
C:/Dev-Cpp/include/wx/msw/private.h:203: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:/Dev-Cpp/include/wx/msw/private.h: In function `COLORREF wxColourToPalRGB(const wxColour&)':
C:/Dev-Cpp/include/wx/msw/private.h:208: error: `RGB' undeclared (first use this function)

Edit: This I got with Felipes latest tips in the previous post.

Felipe Maia

Hrm, that's odd.
Try removing the winalleg include and see what happens.

Samuli

Ok, done. Now it gets conflicts with the BITMAP structure.

Can you compile the code I've posted earlier? Or maybe with those modifications?

Current error:

C:/Dev-Cpp/include/wingdi.h:1245: error: conflicting declaration 'typedef struct tagBITMAP BITMAP'
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: 'BITMAP' has a previous declaration as `typedef struct BITMAP BITMAP'
C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'
C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'
C:/Dev-Cpp/include/wingdi.h:1245: error: declaration of `typedef struct tagBITMAP BITMAP'
C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include/allegro/gfx.h:234: error: conflicts with previous declaration `typedef struct BITMAP BITMAP'

make.exe: *** [main.obj] Error 1

Execution terminated

Felipe Maia

Hrm, I can't compile because I haven't got both installed, and wxWidgets is too big for me to get just to try.

#define RGB AL_RGB
#define BITMAP AL_BITMAP
#include <allegro.h>
#undef BITMAP
#undef RGB

#include <wx stuff>

Try this now.

[edit]
And now, you need to use AL_BITMAP to use allegro bitmaps instead of just BITMAP.

Samuli

Now it works! Thanks all!

I'm off now to create the greatest spreadsheet computation/action game since MOO3!

FMC

But doesn't this code:
#define RGB AL_RGB
ask the compiler to define RGB as AL_RGB? But AL_RGB doesn't exist.. so?
What am i missing? ???

Felipe Maia

It changes the RGB of allegro to AL_RGB, so it doesn't conflict with windows RGB. The problem is that both use the same name.

FMC

but when was AL_RGB defined?

Michael Faerber
Quote:

but when was AL_RGB defined?

It WAS not defined, it IS defined here.

Thomas Fjellstrom

Instead of all that jazz, just include winalleg.h before anything that includes windows.h

Felipe Maia

Nope Thomas, won't work well with other libraries, why you ask? Because the other libraries might use windows's BITMAP, and then they'll be using allegro's BITMAP instead.

Thread #586520. Printed from Allegro.cc