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


Writing to a DirectDraw surface

Recommended Posts

I''m having trouble with writing my loaded bitmap to a DirectX surface. The bitmap loads fine, however when I try to copy the loaded stuff into an offscreen plain the application violently quits without errors. Log file reports that the bitmap loading has begun but never ended. When I logged all steps in the function it turned out to crash when writing to the mem. I''ve used several calculations to get it to work, all failed. This is the code:
// Locking code:

        // Failed to lock. Release the surface, make it NULL and return error

        BitmapSurface = NULL;
        return (FAILED_SURFACE_LOCK);

    // Reserve data for the bitmap. BitmapData is for the bitmap read from

    // the file, BitmapFlipped is the mem for the correct bitmap

    BitmapData    = (WORD *) ddsd.lpSurface;

// Last attempt:

BitmapData[X + (Y * ddsd.lPitch >> 1)] = RGB24TO16(Red, Green, Blue);

// Previous attempt:

BitmapData[Y * (ddsd.lPitch / 2) + X] = RGB24TO16(Red, Green, Blue);
The RGB24TO16 macro:
// Convert 24 bit pixel to 16 bit

#define RGB24TO16(red, green, blue) ( ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3))  
---------------- -Earth is 98% full. Please delete anybody you can.
My Site

Share this post

Link to post
Share on other sites