|
-
February 3rd, 2012, 04:49 AM
#1
GDI+ renders properly on Windows 7 but not XP
Sorry if this is double-posted. I don't see my original post after waiting 2 days.
I am using DrawCachedBitmap in a simple game. On Windows 7 it works fine but when I test it on Windows XP there is a problem. Any parts of the image I draw that have transparency are drawn at 0,0 and any part without transparency is drawn in the correct place. It does this both for bitmaps I load from resources and change in memory to be partially transparent and with bitmaps I create only in memory using rectangles and text. Here is the relevant code for drawing text and rectangles:
void Item::LoadToolTip()
{
//All these variables are members of Item
MaxWidth=0;
text=new wstringstream;
TempBmp=new Bitmap(TOOLTIP_BASE_WIDTH,TOOLTIP_BASE_HEIGHT,PixelFormat32bppPARGB);
TempGfx=new Graphics(TempBmp);
brush=new SolidBrush(TOOLTIP_BACK_COLOR);
font=new Font(_T(TOOLTIP_FONT_NAME),10,FontStyleBold);
TextRect=new RectF(0,TOOLTIP_TOP_BORDER,TOOLTIP_BASE_WIDTH,TOOLTIP_BASE_HEIGHT);
format=new StringFormat();
text->precision(2);
TempGfx->FillRectangle(brush,0,0,TOOLTIP_BASE_WIDTH,TOOLTIP_BASE_HEIGHT);
format->SetAlignment(StringAlignmentCenter);
brush->SetColor(TOOLTIP_COMMON_COLOR);
*text<<name.c_str();DrawToolTipText();
brush->SetColor(TOOLTIP_ATTRIBUTE_COLOR);
delete font;font=new Font(_T(TOOLTIP_FONT_NAME),8);
if (def!=0) {*text<<"Defense: "<<def;DrawToolTipText();}
if (dmg_high!=0) {*text<<"Damage: "<<dmg_low<<"-"<<dmg_high;DrawToolTipText();}
tooltip=new SpriteElement(&Globals->Buffer->graph);
tooltip->LoadBitmap(TempBmp,int(TOOLTIP_BASE_WIDTH-MaxWidth)/2-TOOLTIP_SIDE_BORDER,0,int(MaxWidth+TOOLTIP_SIDE_BORDER*2),int(TextRect->Y)+TOOLTIP_BOTTOM_BORDER);
}
void Item: rawToolTipText(string msg="")
{
if (msg!="")
{
text->str(_T(""));
*text<<msg.c_str();
}
if (text->str().length()==0) return;
TempGfx->DrawString(text->str().c_str(),-1,font,*TextRect,format,brush);
TempGfx->MeasureString(text->str().c_str(),-1,font,*TextRect,&compute);
TextRect->Y+=compute.Height;
if (compute.Width>MaxWidth) MaxWidth=compute.Width;
text->str(_T(""));
}
//SpriteElement contains a Bitmap, CachedBitmap, and a few other variables like x and y
//It also has some functions for drawing and processing images
void SpriteElement::LoadBitmap(Bitmap *Src, int fx, int fy, int fwidth, int fheight)
{
if ((fx<0)||(fy<0)) return;
if (UINT(fwidth) > Src->GetWidth() || UINT(height) > Src->GetHeight()) return;
RawBitmap=Src->Clone(fx,fy,fwidth,fheight,PixelFormat32bppPARGB);
}
//Buffer is type GraphicsPlane
void SpriteElement::ProcessImage()
{
width = RawBitmap->GetWidth();
height = RawBitmap->GetHeight();
image = new CachedBitmap(RawBitmap,&Globals->Buffer->graph);
}
class GraphicsPlane
{
public:
HDC hdc;
HBITMAP bmp;
HANDLE oldhandle;
Graphics graph;
HWND hWnd;
GraphicsPlane(HWND h,int bmpwidth=WindowWidth,int bmpheight=WindowHeight);
private:
HDC init(HWND nh,int bw,int bh);
}
HDC GraphicsPlane::init(HWND nh,int bw,int bh)
{
hdc = CreateCompatibleDC(GetDC(nh));
bmp = CreateCompatibleBitmap(GetDC(nh),bw,bh);
oldhandle = SelectObject(hdc,bmp);
return hdc;
}
GraphicsPlane::GraphicsPlane(HWND h,int bmpwidth,int bmpheight):graph(init(h,bmpwidth,bmpheight))
{
hWnd=h;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|