Jump to content
  • Advertisement

Archived

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

Insomnia

TOWTPG - erm, buggy demos?

This topic is 6428 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

Hey all, I''ve recently migrated from DOS to Win32 programming (mainly because djgpp doesn''t work anymore... grumble), and it''s all going fine. I''ve been bashing out a few functions to make my DirectX life easier, and today got on to getting a fully working bitmap loading system. I''ve been pretty much following Lamothe''s code, although adapting it in places and making functions to suit my needs. Loading the bitmap and unloading the bitmap is all fine, as is creating new surfaces. The problem comes with copying a bitmap to a LPDIRECTDRAW7 surface. The resulting surface comes out mangled, to say the least. Not a very technical description, but it''s the best I can do . I''m working with 8bit bitmaps here, by the way. It''s not that i''m implementing the functions wrong, because Lamothe''s demo7_13.exe, in which he uses the function to scan a bitmap into three surfaces has the same problem... the guy''s own bloody demos don''t even work properly! Anyway, the long and short of it is, i''m stuck. I''ll post the code from his version, although I find it rather hard to read with his comments in odd places. I''ve no idea why it doesn''t work, but then i''ve never done anything with graphics before (used allegro in the old days, ya see ). I''m guessing those who have TOTWPG have run into this problem before, and I guess you''ll have solved it too . Here''s his function:
  

int Scan_Image_Bitmap(BITMAP_FILE_PTR bitmap,     // bitmap file to scan image data from

                      LPDIRECTDRAWSURFACE4 lpdds, // surface to hold data

                      int cx, int cy)             // cell to scan image from

{
// this function extracts a bitmap out of a bitmap file


UCHAR *source_ptr,   // working pointers

      *dest_ptr;

DDSURFACEDESC2 ddsd;  //  direct draw surface description 


// get the addr to destination surface memory


// set size of the structure

ddsd.dwSize = sizeof(ddsd);

// lock the display surface

lpdds->Lock(NULL,
            &ddsd,
            DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
            NULL);

// compute position to start scanning bits from

cx = cx*(ddsd.dwWidth+1) + 1;
cy = cy*(ddsd.dwHeight+1) + 1;

gwidth  = ddsd.dwWidth;
gheight = ddsd.dwHeight;

// extract bitmap data

source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx;

// assign a pointer to the memory surface for manipulation

dest_ptr = (UCHAR *)ddsd.lpSurface;

// iterate thru each scanline and copy bitmap

for (int index_y=0; index_y < ddsd.dwHeight; index_y++)
    {
    // copy next line of data to destination

    memcpy(dest_ptr, source_ptr, ddsd.dwWidth);

    // advance pointers

    dest_ptr   += (ddsd.dwWidth);
    source_ptr += bitmap->bitmapinfoheader.biWidth;
    } // end for index_y


// unlock the surface 

lpdds->Unlock(NULL);

// return success

return(1);

} // end Scan_Image_Bitmap


  
Sorry if I haven''t described the problem properly, but as I said, those who have TOTWPG should know what I mean. Thanks for any help . Insomnia

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I have not had any problems with Lamothe''s code. Are you sure it is not your code. He uses dx6.1, maybe it has something to do with that.

Share this post


Link to post
Share on other sites
I think this has been covered on the message board recently, try searching. If I remember correcly changing all ddsd.dwWidth to ddsd.dwPitch fixed it.

Micah

Share this post


Link to post
Share on other sites
Anon Poster: Nope, it wasn''t because of my code. That''s why I posted his funciton, because HIS demo suffered the same problem.

MicahJon: Thankyou . It was a case of changing the dwWidth to lPitch after all. I suppose I should have figured that one out... thanks though .

Cheers all !

Insomnia

Share this post


Link to post
Share on other sites
I had this problem before, and was able to fix it when I found out that all bitmap files must have widths on DWORD boundaries (that is, divisible by 4).

Good luck.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!