コード例 #1
0
// initialization
STDMETHODIMP 
CDirect2DRMDevice::InitFromSurface(LPDIRECTDRAWSURFACE pdds)
{
	HRESULT hr;
	if (pdds == NULL)
		return E_NULLPOINTER;

//	if (m_pddsBackBuffer)
//		return E_ALREADYINITIALIZED;

	// release the old surface
	MMRELEASE(m_pddsBackBuffer);

	pdds->AddRef();
	m_pddsBackBuffer = pdds;

	if (FAILED(hr = pdds->GetSurfaceDesc(&m_ddsd)) ||
		FAILED(hr = m_pixi.Init(m_ddsd.ddpfPixelFormat)))
		return hr;

	// notify the viewports that the device has been resized
	for(DWORD i = 0, cLimit = m_dsViewports.Items(); i < cLimit; i++) {
		if (FAILED(hr = m_dsViewports[i]->DeviceResized()))
			return hr;
	}
	return S_OK;
}
コード例 #2
0
ファイル: dodddraw.cpp プロジェクト: mreiferson/dod
/*
 * GetRGB16:
 *    Must run this function to fill the RGB16 struct with the information needed to plot a pixel
 *      To call this, you must have rgb16 defined as a global (unless you want to modify this) variable
 *      RGB16 rgb16;
 */
void DDGetRGB16(void)
{
    DDSURFACEDESC   ddsd;       // DirectDraw Surface Description
    BYTE            shiftcount; // Shift Counter
    
    // get a surface despriction
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_PIXELFORMAT;
    lpDDSPrimary->GetSurfaceDesc(&ddsd);
    
    // Fill in the masking values for extracting colors
    rgb16.Mask.rgbRed = ddsd.ddpfPixelFormat.dwRBitMask;
    rgb16.Mask.rgbGreen = ddsd.ddpfPixelFormat.dwGBitMask;
    rgb16.Mask.rgbBlue = ddsd.ddpfPixelFormat.dwBBitMask;
    
    // get red surface information
    shiftcount = 0;
    while (!(ddsd.ddpfPixelFormat.dwRBitMask & 1)) {
        ddsd.ddpfPixelFormat.dwRBitMask >>= 1;
        shiftcount++;
    }
    rgb16.depth.rgbRed = (BYTE)ddsd.ddpfPixelFormat.dwRBitMask;
    rgb16.Position.rgbRed = shiftcount;
    rgb16.Amount.rgbRed = (ddsd.ddpfPixelFormat.dwRBitMask == 0x1f) ? 3 : 2;
    
    // get green surface information
    shiftcount = 0;
    while (!(ddsd.ddpfPixelFormat.dwGBitMask & 1)) {
        ddsd.ddpfPixelFormat.dwGBitMask >>= 1;
        shiftcount++;
    }
    rgb16.depth.rgbGreen = (BYTE)ddsd.ddpfPixelFormat.dwGBitMask;
    rgb16.Position.rgbGreen = shiftcount;
    rgb16.Amount.rgbGreen = (ddsd.ddpfPixelFormat.dwGBitMask == 0x1f) ? 3 : 2;
    
    // get Blue surface information
    shiftcount = 0;
    while (!(ddsd.ddpfPixelFormat.dwBBitMask & 1)) {
        ddsd.ddpfPixelFormat.dwBBitMask >>= 1;
        shiftcount++;
    }
    rgb16.depth.rgbBlue = (BYTE)ddsd.ddpfPixelFormat.dwBBitMask;
    rgb16.Position.rgbBlue = shiftcount;
    rgb16.Amount.rgbBlue = (ddsd.ddpfPixelFormat.dwBBitMask == 0x1f) ? 3 : 2;
    
    // fill in variables so we dont' have to access the structure anymore
    mRed = rgb16.Mask.rgbRed;         // Red Mask
    mGreen = rgb16.Mask.rgbGreen;     // Green Mask
    mBlue = rgb16.Mask.rgbBlue;       // Blue Mask
    pRed = rgb16.Position.rgbRed;     // Red Position
    pGreen = rgb16.Position.rgbGreen; // Green Position
    pBlue = rgb16.Position.rgbBlue;   // Blue Position
}
コード例 #3
0
ファイル: dodddraw.cpp プロジェクト: mreiferson/dod
/*
 * DDCopyBitmap:
 *     draw a bitmap into a DirectDrawSurface
 */
HRESULT DDCopyBitmap(LPDIRECTDRAWSURFACE pdds, HBITMAP hbm, int x, int y, int dx, int dy)
{
    HDC                 hdcImage;
    HDC                 hdc;
    BITMAP              bm;
    DDSURFACEDESC       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);    // get size of bitmap
    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;
}