![]() |
|
Allegro with wxWidgets Bitmap converion |
Stepes
Member #10,390
November 2008
|
Hi, wanted to ask if there is any way to convert an Allegro Bitmap into a wxWidgets wxBitmap. Essentially I want to print my BITMAP* buffer onto a wxDC. VS2008 error: Unhandled exception at 0x00556ade in Test3.exe: 0xC0000005: Access violation reading location 0x00000000. in this function void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, bool useMask = false) { DoDrawBitmap(bmp, pt.x, pt.y, useMask); } seems like the dat is null I guess? Any help appreciated |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
You probably need to write a conversion function to grab the bitmap data from an allegro BITMAP and move it into a contiguous array. What is the data format of a wxBitmap (How are the color values arranged - RGBA / BGR / RGB / ARGB?) or rather, what format does the wxBitmap constructor expect? Also, I don't think bmp->dat is what you are looking for, but bmp->line[y].
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Stepes
Member #10,390
November 2008
|
Hm how can I know what the bitmap representation is of a wxBitmap? The constructor I try to use is: wxBitmap(void* data, int type, int width, int height, int depth = -1) Creates a bitmap from the given data which is interpreted in platform-dependent manner. What you were suggesting is copying every pixel from one bitmap to the other in a loop? That would propably not work for me since I want a realtime particle editor and such a big loop in every animation loop would propably bring down my fps to the ground.(Plus I don't know how to write pixels on a wxBitmap) Is the bitmap data representation in memory same for both libraries?(cant find documentation about it :/) How am I supposed to use the bmp->line? Copy each line of one bmp to the other? I'm starting to think I might just change the whole code to wxBitmaps after all |
anonymous
Member #8025
November 2006
|
Why don't you simply use wxWidgets' routines to load bitmap files? If you can't do that, the conversion function should probably use the wxBitmap public interface (to set pixels), rather than make assumptions about the underlying data layout. |
Stepes
Member #10,390
November 2008
|
(because if I use wxBitmap to load bitmaps then I can't blit them in allegro anymore) Hm now that I thought about it, is there perhaps a way for allegro to blit on a device context or a panel of wx? Edit: Hm I looked at the code of another guy on these forums and this function propably does a similar job to what I want. I'll give it a try void blit_from_allegro_to_wx(BITMAP *src, wxDC *target, int sx, int sy, int dx, int dy, int w, int h) { wxPen pn(wxColour(0,0,0), 1, wxDOT); for(int x = 0; x < w; ++x) { for(int y = 0; y < h; ++y) { pn.SetColour(((int **)src->line)[y][x] >> 16, (((int **)src->line)[y][x] >> 8) & 0xF, ((int **)src->line)[y][x] & 0xF); // make it active target->SetPen(pn); target->DrawPoint(dx + x, dy + y); } } }
Edit2: Damn this code prints the whole image red. :/ Edit3: WHY!?!?! WHY are allegro bitmaps in BGR format?? grrr took me 2 hours to figure out how it is. Finally it works now. void blit_from_allegro_to_wx(BITMAP *src, wxDC *target, int sx, int sy, int dx, int dy, int w, int h) { wxPen pn(wxColour(0,0,0), 1, wxDOT); for(int x = 0; x < w; ++x) { for(int y = 0; y < h; ++y) { pn.SetColour((((unsigned long **)src->line)[y][x]) & 0xFF, (((unsigned long **)src->line)[y][x]>> 8) & 0xFF,(((unsigned long **)src->line)[y][x] >> 16)); // make it active target->SetPen(pn); target->DrawPoint(dx + x, dy + y); } } }
The question remains though on if I can blit on wxDC's. |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Quote: Edit3: WHY!?!?! WHY are allegro bitmaps in BGR format?? grrr took me 2 hours to figure out how it is. Finally it works now. Allegro BITMAP's are in different formats for each color depth, and possibly even vary between platforms. So what you have might work for one color depth on your platform. That's why I suggested the getpixel, getr, getg, and getb functions. Quote:
The question remains though on if I can blit on wxDC's.
Well, there are several problems with that function that will slow it down or are incorrect : I rewrote it as well as I could. I was using function pointers for getpixel etc..., but since the get pixel/r/g/b functions are AL_INLINE functions I used a switch statement with a case for each color depth and used the faster functions _getpixel#, and get?# (_getpixel32 , getr32, so on...). Let me know if this speeds things up for you at all. I don't have WxWidgets installed, so let me know if it doesn't work - it's untested.
My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|