Archived

This topic is now archived and is closed to further replies.

Can anyone see what is wrong with this ?

This topic is 5824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

1stly, apologies for the length of the post. (& I cannot get code to appear in a nice window, how do I do this ?) I am trying to load bitmaps from my own resource files. The following code does not work, and causes an assertion error in wingdi.cpp line 1120 I suspect that I am Not loading in the bitmap data to the bitmap correctly, can anyone see anything obvious or recommend any good places to look for further information ? I Hope so as I have spent all day on this one and am really stumped now. Any comments, help or suggestions will be greatfully recieved.... TIA, Bp This is the Drawing Function BOOL CTileEngine::DrawMap(CDC* pDC) { CBitmap my_bitmap; LPBITMAP lpBitmap = new BITMAP; // If Retrieve Bitmap (i.e. Load from Resource is True, then Successful load, Create Bmp. if (RetrieveBitmap(lpBitmap)) { my_bitmap.CreateBitmap(lpBitmap->bmWidth,lpBitmap->bmHeight,lpBitmap->bmPlanes, lpBitmap->bmBitsPixel,lpBitmap->bmBits); } CBrush pBrush; CRgn rgn; rgn.CreateEllipticRgn(150,-150,200,-250); pBrush.CreatePatternBrush(&my_bitmap); CBrush * poldBrush = pDC->SelectObject(&pBrush); pDC->PaintRgn(&rgn); //Restore the old Context pDC->SelectObject(poldBrush); } This is the Bitmap Loading Function (I know the code is probably clumsy and is not optimised, but I want to get the thing to work before I try to make it elegant !) BOOL CTileEngine::RetrieveBitmap(LPBITMAP lpBitmap, CString afile) { BITMAPFILEHEADER bfh; BITMAPINFOHEADER bi; BITMAPINFO bmi; BOOL retval = true; FILE *ResFile = fopen(afile,"rb"); //Error Checking //Read Bitmap File Header if ((fread(&bfh,sizeof(BITMAPFILEHEADER),1,ResFile))==NULL) { retval=false; AfxMessageBox(("Failed to Read File Header - /n%s",afile),MB_OK,-1); } if ((fread(&bi,sizeof(BITMAPINFOHEADER),1,ResFile))==NULL) { retval=false; AfxMessageBox(("Failed to Read File Header - /n%s",afile),MB_OK,-1); } //Check for the "BM" at the start of the file. if (retval) { if (bfh.bfType != 0x4D42) { AfxMessageBox(("File Problem with File %s",afile),MB_OK,-1); } else { lpBitmap->bmType = bfh.bfType; lpBitmap->bmWidth = bi.biWidth; lpBitmap->bmHeight = bi.biHeight; lpBitmap->bmWidthBytes = (bi.biWidth/8); lpBitmap->bmPlanes = bi.biPlanes; lpBitmap->bmBitsPixel = bi.biBitCount; lpBitmap->bmBits = bmi.bmiColors; } } fclose(ResFile); return retval; }

Share this post


Link to post
Share on other sites
sorry, I can''t help you with the maibn post but to get the source code in the window you write

[ source ] and then to end u write [ / source]

(without the spaces....I added spaces to stop the board showing it as a window

like so:

  
int main()
{
do_menu();
return 0;
}



Dark Star
UK

Share this post


Link to post
Share on other sites
But I don''t want to use LoadImage as this can be used to load a single bitmap from a file, I am trying to write code that can load either an area of a bitmap, or a single bitmap out of a tileset, I don''t want to have to manage dozens of files, just the one !

Playing around with the code today, I have found that by watching the memory the my_bitmap.CreateBitmap(...) function seems to be altering the Bitmap in my lpBitmap

Any more ideas or help ?

Bp.

Share this post


Link to post
Share on other sites
Hi

LoadImage will work just fine for your purposes after all. You might not believe me, but just hear me out. You can arrange your tileset into a grid and store it as a single bitmap. Use LoadImage to load that tileset from a single bitmap, then write a cheap-and-dirty algo to select a sub-bitmap from the tileset bitmap and store it in an array of sub-bitmaps. If your tiles are of a uniform size, then you should have no problem at all with this scheme. Alternately, you can store the whole image in texture memory, and blit select portions of it on-screen. I know what you mean about not wanting to load a whole bunch of separate images. It''s a waste of time, space and is more CPU-intensive (imagine all those extra headers that are being loaded-in needlessly)...





Share this post


Link to post
Share on other sites