I'm in the process of writing an application that uses wxWidgets. It compiles and
runs fine using msys2 and wx library 3.1.5. I am having problems, however when I try
to compile the code under Ubuntu/wx 3.1.5. Although the app itself runs fine, the
display window just outputs a plain black window.
I using wxNativePixelData to draw on a bitmap that I then blit onto the display window
in the onpaint event.
The Display initialisation code looks like this:
class CDisplayWX: public CTV
{
public:
~CDisplayWX();
void Initialise(void *Handle);
void UpdateDisplay(wxDC *DC);
void End(void);
void ReSize(int Width, int Height);
void Plot(unsigned int color);
void NewLine();
void Refresh();
private:
wxBitmap *Bitmap=nullptr;
wxMemoryDC *SrcDC=nullptr;
wxNativePixelData *PixelData=nullptr;
wxNativePixelData::Iterator *Pixel=nullptr;
};
and the code that draws onto the bitmap, and blits it to the window looks like
void CDisplayWX::Initialise(void *Handle)
{
End();
Bitmap = new wxBitmap(FrameMaxW, FrameMaxH, 24);
SrcDC=new wxMemoryDC(*Bitmap);
PixelData = new wxNativePixelData(*Bitmap);
Pixel = new wxNativePixelData::Iterator(*PixelData);
Pixel->MoveTo(*PixelData, 0, 0);
ScanLineX = 0;
ScanLineY = 0;
}
// If we have finished rendering - either quitting, or
// changed some setting, release all handles and memory used.
void CDisplayWX::End()
{
if (Pixel) { delete Pixel; Pixel=nullptr; }
if (PixelData) { delete PixelData; PixelData=nullptr; }
if (SrcDC) {delete SrcDC; SrcDC=nullptr; }
if (Bitmap) { delete Bitmap; Bitmap=nullptr; }
}
// UpdateDisplay - called from onPaint event to blit the bitmap
// onscreen.
void CDisplayWX::UpdateDisplay(wxDC *DC)
{
DC->StretchBlit (0, 0, WindowWidth, WindowHeight,
SrcDC, FrameX, FrameY, FrameW, FrameH);
if (CreatedDC) delete DC;
Pixel->MoveTo(*PixelData, 0, 0);
ScanLineX = 0;
ScanLineY = 0;
}
void CDisplayWX::Plot(unsigned int color)
{
Pixel->Red() = (color >> 16) & 255;
Pixel->Green() = (color >> 8) & 255;
Pixel->Blue() = color & 255;
(*Pixel)++;
ScanLineX++;
if (ScanLineX >= FrameMaxW) NewLine();
}
If I draw on the bitmap using SrcDC, I can see my drawing onscreen so i know
bit bitmap itself is OK and the blit operation is working, which leaves the
raw data bit...
Can anyone suggest what I'm doing wrong and why I'm such a numpty...
Mike