Sign in to follow this  

Blt() not working

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

I'm trying to make a blackjack game. Could someone please tell me why my card images are not displaying? I am using DirectDraw in Windowed mode. I have been through so many tutorials that I am thoroughly confused. The function drawImg() should diplay a card bitmap in the proper location on the screen. I have included my code (which I have borrowed from various tutorials) to show how I'm setting things up.
bool InitDirectDraw(HWND hwnd)
{
  // create the main DirectDraw object
  DirectDrawCreateEx( NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL );

    ddrval = lpDD->SetCooperativeLevel( hwnd, DDSCL_NORMAL );
    if( ddrval != DD_OK )
    {
        lpDD->Release();
        return(false);
    }
	
    memset( &ddsd, 0, sizeof(ddsd) );
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE ;
	ddsd.dwWidth = WINDOW_WIDTH ; 
	ddsd.dwHeight = WINDOW_HEIGHT;
	
    // The primary surface is not a page flipping surface this time
    ddrval = lpDD->CreateSurface( &ddsd, &lpPrimary, NULL );
    if( ddrval != DD_OK )
    {
        lpDD->Release();
        return(false);
    }
	

    // Create a clipper to ensure that our drawing stays inside our window
    ddrval = lpDD->CreateClipper( 0, &lpddclipper, NULL );

    if( ddrval != DD_OK )
    {
        lpPrimary->Release();
        lpDD->Release();
        return(false);
    }

    // setting it to our hwnd gives the clipper the coordinates from our window
    ddrval = lpddclipper->SetHWnd( 0, hwnd );
    if( ddrval != DD_OK )
    {
        lpddclipper-> Release();
        lpPrimary->Release();
        lpDD->Release();
        return(false);
    }

    // attach the clipper to the primary surface
    ddrval = lpPrimary->SetClipper( lpddclipper );
    if( ddrval != DD_OK )
    {
        lpddclipper-> Release();
        lpPrimary->Release();
        lpDD->Release();
        return(false);
    }
	 
    memset( &ddsd, 0, sizeof(ddsd) );
    ddsd.dwSize = sizeof( ddsd );
    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

    ddsd.dwWidth = WINDOW_WIDTH ;
    ddsd.dwHeight = WINDOW_HEIGHT ; 
    
	// back buffer
    ddrval = lpDD->CreateSurface( &ddsd, &lpBackBuffer, NULL );

    if( ddrval != DD_OK )
    {
        lpddclipper-> Release();
        lpPrimary->Release();
        lpDD->Release();
        return(false);
    }
    return(true);

}

 void drawImg(LPCSTR szBitmap, HWND hwnd, int x, int y, int w, int h){

	if ( (lpPrimary = DDLoadBitmap(lpDD, szBitmap)) == NULL )
	   return ;

  	lpddpal = DDLoadPalette(lpDD, szBitmap); // Call the function above to load the palette

	if (lpddpal)
	    lpPrimary->SetPalette(lpddpal); // this sets the palette for the primary surface
				
	RECT rcFrom;

	SetRect(&rcFrom, 0, 0, w, h);
	

    RECT rcRectDest;
    POINT p;

	// first we need to figure out where on the primary surface our window lives
    p.x = x; p.y = y;

    ClientToScreen(hwnd, &p);
    GetClientRect(hwnd, &rcRectDest);
	rcRectDest.bottom = h ;
	rcRectDest.right = w ;
    OffsetRect(&rcRectDest, p.x, p.y);
    
	//ddrval = lpBackBuffer->BltFast( 0, 0, lpPrimary, &rcFrom,  DDBLTFAST_NOCOLORKEY | DDBLTFAST_WAIT); //DDBLTFAST_DONOTWAIT
	ddrval = lpPrimary->Blt( &rcRectDest,lpBackBuffer, NULL, DDBLT_WAIT, NULL );


	int i;
	if( ddrval != DD_OK ){
		i = 0  ;
	}
	return ;  

}

Share this post


Link to post
Share on other sites
I think you need to supply a source rect.
Try adding something like

RECT rcSrc;
CopyRect(&rcSrc,&rcRectDest);

ddrval = lpPrimary->Blt( &rcRectDest,lpBackBuffer, rcSrc, DDBLT_WAIT, NULL );

Share this post


Link to post
Share on other sites
Sure enough. That did it. Thank you very much. The game is coming out pretty cool. I'll post it to my website when I'm done.

Share this post


Link to post
Share on other sites

This topic is 4221 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this