Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:55+00:00 2026-06-09T01:15:55+00:00

I have been writing my own library using Direct X and have hit an

  • 0

I have been writing my own library using Direct X and have hit an odd issue. Whilst trying to render an animating sprite I am simply seeing a big black square:

Direct X Rendering Issue

I have stepped through the code obsessively and have concluded that it must be something about the loading of the actual sprites, because everything that I can see in my code is fine. Obviously, I cannot step into the functions such as BltFast, and so cannot tell if my sprite surfaces are being blitted onto the backbuffer successfully.

Here are my load and render functions for the sprite:

SPRITE::LOAD

/**
 *  loads a bitmap file and copies it to a directdraw surface
 *
 *  @param  pID             wait
 *  @param  pFileName       name of the bitmap file to load into memory
 */
void Sprite::Load (const char *pID, const char *pFileName)
{
    //  initialises the member variables with the new image id and file name
    mID                 = pID;
    mFileName           = pFileName;

    //  creates the necessary variables
    HBITMAP             tHBM;
    BITMAP              tBM;
    DDSURFACEDESC2      tDDSD;
    IDirectDrawSurface7 *tDDS;

    //  stores bitmap image into HBITMAP handler
    tHBM                    = static_cast<HBITMAP> (LoadImage (NULL, pFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION));

    GetObject (tHBM, sizeof (tBM), &tBM);

    //  create surface for the HBITMAP to be copied onto
    ZeroMemory (&tDDSD, sizeof (tDDSD));
    tDDSD.dwSize            = sizeof (tDDSD);
    tDDSD.dwFlags           = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
    tDDSD.ddsCaps.dwCaps    = DDSCAPS_OFFSCREENPLAIN;
    tDDSD.dwWidth           = tBM.bmWidth;
    tDDSD.dwHeight          = tBM.bmHeight;
    DirectDraw::GetInstance ()->DirectDrawObject()->CreateSurface (&tDDSD, &tDDS, NULL);

    //  copying bitmap image onto surface
    CopyBitmap(tDDS, tHBM, 0, 0, 0, 0);

    //  deletes bitmap image now that it has been used
    DeleteObject(tHBM);

    //  stores the new width and height of the image
    mSpriteWidth            = tBM.bmWidth;
    mSpriteHeight           = tBM.bmHeight;

    //  sets the address of the bitmap surface to this temporary surface with the new bitmap image
    mBitmapSurface          = tDDS;
}

SPRITE::RENDER

/**
 *  renders the sprites surface to the back buffer
 *
 *  @param  pBackBuffer     surface to render the sprite to
 *  @param  pX              x co-ordinate to render to (default is 0)
 *  @param  pY              y co-ordinate to render to (default is 0)
 */
void Sprite::Render (LPDIRECTDRAWSURFACE7 &pBackBuffer, float pX, float pY)
{
    if (mSpriteWidth > 800)     mSpriteWidth = 800;

    RECT            tFrom;

    tFrom.left      = tFrom.top     =   0;
    tFrom.right     = mSpriteWidth;
    tFrom.bottom    = mSpriteHeight;

    //  bltfast parameters are (position x, position y, dd surface, draw rect, wait flag)
    //  pBackBuffer->BltFast (0 + DirectDraw::GetInstance()->ScreenWidth(), 0, mBitmapSurface, &tFrom, DDBLTFAST_WAIT);
    pBackBuffer->BltFast (static_cast<DWORD>(pX + DirectDraw::GetInstance()->ScreenWidth()), 
        static_cast<DWORD>(pY), mBitmapSurface, &tFrom, DDBLTFAST_WAIT);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:15:57+00:00Added an answer on June 9, 2026 at 1:15 am

    The surfaces were simply not a compatible format.

    Here’s the fixed copybitmap function which I now call in the load function:

    extern "C" HRESULT
    DDCopyBitmap(IDirectDrawSurface7 * pdds, HBITMAP hbm, int x, int y,
                 int dx, int dy)
    {
        HDC                     hdcImage;
        HDC                     hdc;
        BITMAP                  bm;
        DDSURFACEDESC2          ddsd;
        HRESULT                 hr;
    
        if (hbm == NULL || pdds == NULL)
            return E_FAIL;
        //
        // Make sure this surface is restored.
        //
        pdds->Restore();
        //
        // Select bitmap into a memoryDC so we can use it.
        //
        hdcImage = CreateCompatibleDC(NULL);
        if (!hdcImage)
            OutputDebugString("createcompatible dc failed\n");
        SelectObject(hdcImage, hbm);
        //
        // Get size of the bitmap
        //
        GetObject(hbm, sizeof(bm), &bm);
        dx = dx == 0 ? bm.bmWidth : dx;     // Use the passed size, unless zero
        dy = dy == 0 ? bm.bmHeight : dy;
        //
        // Get size of surface.
        //
        ddsd.dwSize = sizeof(ddsd);
        ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH;
        pdds->GetSurfaceDesc(&ddsd);
    
        if ((hr = pdds->GetDC(&hdc)) == DD_OK)
        {
            StretchBlt(hdc, 0, 0, ddsd.dwWidth, ddsd.dwHeight, hdcImage, x, y,
                       dx, dy, SRCCOPY);
            pdds->ReleaseDC(hdc);
        }
        DeleteDC(hdcImage);
        return hr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing a SOAP client application in C++ on Ubuntu using OpenSSL
I have been writing unit tests using NUnit and Moq with my Silverlight code
I have been writing an application using ASP.Net MVC4, where the majority of the
I have been writing my own Lightbox script (to learn more about jQuery). My
I've been considering writing my own UI framework. This is mostly because I have
I'm from a Windows programming background when writing tools, but have been programming using
I have been writing a JavaScript library for a few weeks now and it
I have been trying to do a fill using the open source Srecord Program.
I have been writing linear winforms for couple of months and now I am
I have been writing C++ Console/CMD-line applications for about a year now and would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.