bool lock(LPDIRECTDRAWSURFACE dd,_TPixelsRef& out_pixelsRef){ DDSURFACEDESC ddsdDest; memset(&ddsdDest,0,sizeof(ddsdDest)); ddsdDest.dwSize=sizeof(ddsdDest); //ddsdDest.dwFlags=DDSD_LPSURFACE | DDSD_PITCH | DDSD_WIDTH | DDSD_HEIGHT; HRESULT ddrval=dd->Lock(NULL,&ddsdDest,DDLOCK_WAIT,NULL); if( ddrval == DDERR_SURFACELOST ) { ddrval = m_ddsprimary->Restore(); if( ddrval!= DD_OK ) return false; dd->Lock(NULL,&ddsdDest,DDLOCK_WAIT,NULL); } if (ddsdDest.lpSurface==0) return false; if (ddsdDest.lPitch<=4){ out_pixelsRef.pdata=ddsdDest.lpSurface;//获得页面首地址 out_pixelsRef.width=ddsdDest.dwHeight; out_pixelsRef.height=ddsdDest.dwWidth; out_pixelsRef.byte_width=-out_pixelsRef.width*ddsdDest.lPitch; ((Pixels32Ref&)out_pixelsRef).reversal(); }else{ out_pixelsRef.pdata=ddsdDest.lpSurface;//获得页面首地址 out_pixelsRef.width=ddsdDest.dwWidth; out_pixelsRef.height=ddsdDest.dwHeight; out_pixelsRef.byte_width=ddsdDest.lPitch; } return true; }
void dd_Window::flip_fullscreen() { int i=0; HRESULT hr; //hack for 320x200 letterboxing if(xres == 320 && yres == 200) { hr = dx_bs->BltFast(0,20,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); DDBLTFX ddbltfx; memset(&ddbltfx, 0, sizeof(DDBLTFX)); ddbltfx.dwSize = sizeof(DDBLTFX); ddbltfx.dwFillColor = 0; RECT rBlit; rBlit.left = 0; rBlit.top = 0; rBlit.right = 320; rBlit.bottom = 20; dx_bs->Blt(&rBlit, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); rBlit.left = 0; rBlit.top = 220; rBlit.right = 320; rBlit.bottom = 240; dx_bs->Blt(&rBlit, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); } //regular case else hr = dx_bs->BltFast(0,0,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); if(hr==DDERR_SURFACELOST) { dx_bs->Restore(); dx_os->Restore(); dx_bs->BltFast(0,0,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); } hr=dx_ps->Flip(0,DDFLIP_WAIT | DDFLIP_NOVSYNC); //dx_ps->Flip(0,0); if(hr==DDERR_SURFACELOST) { dx_ps->Restore(); hr=dx_ps->Flip(0,DDFLIP_WAIT | DDFLIP_NOVSYNC); } hr=dx_os->Lock(0,&dx_osd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT,0); if(hr==DDERR_SURFACELOST) { dx_os->Restore(); hr=dx_os->Lock(0,&dx_osd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT,0); } dx_os->Unlock(0); img->data=(quad*)dx_osd.lpSurface; img->pitch=dx_osd.lPitch/vid_bytesperpixel; }
BOOL DrawBegin() { DDSURFACEDESC ddsd; HRESULT result; if (bSaveFramebuffer || !useDirectDraw) { scrpitch = scratch_pitch; scrbuf = scratch_buffer; return TRUE; } if (BackSurface == NULL) { return FALSE; } ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); result = BackSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); if (result != DD_OK) { scrpitch = scratch_pitch; scrbuf = scratch_buffer; return TRUE; } scrpitch = ddsd.lPitch; scratch_pitch = scrpitch; scrbuf = (BYTE*)ddsd.lpSurface; return TRUE; }
/* * DDColorMatch: * Matches a color (RGB) with a surface */ DWORD DDColorMatch(LPDIRECTDRAWSURFACE pdds, COLORREF rgb) { COLORREF rgbT; HDC hdc; DWORD dw = CLR_INVALID; DDSURFACEDESC ddsd; HRESULT hres; // use GDI SetPixel to color match for us if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK) { rgbT = GetPixel(hdc, 0, 0); // save current pixel value SetPixel(hdc, 0, 0, rgb); // set our value pdds->ReleaseDC(hdc); } // now lock the surface so we can read back the converted color ddsd.dwSize = sizeof(ddsd); while ((hres = pdds->Lock(NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING); if (hres == DD_OK) { dw = *(DWORD *)ddsd.lpSurface; // get DWORD if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32) { dw &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; // mask it to bpp } pdds->Unlock(NULL); } // now put the color that was there back. if (rgb != CLR_INVALID && pdds->GetDC(&hdc) == DD_OK) { SetPixel(hdc, 0, 0, rgbT); pdds->ReleaseDC(hdc); } return dw; }
static void clear_buffers(void) { LPDIRECTDRAWSURFACE surfs[] = {BackSurface, PrimarySurface}; LPDIRECTDRAWSURFACE surf; DDSURFACEDESC ddsd; BYTE* psurf; int i, y; for (i = 0; i < 2; i++) { ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); surf = surfs[i]; if (surf->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) != DD_OK) { continue; } for (y = 0; y < SCRHEIGHT; y++) { psurf = (BYTE*)ddsd.lpSurface + y*ddsd.lPitch; ZeroMemory(psurf, 2*SCRWIDTH); } surf->Unlock(NULL); } }
static gxj_pixel_type* startDirectPaint(int &dstWidth, int &dstHeight, int &dstYPitch) { gxj_pixel_type *dst = NULL; #if JWC_WINCE_USE_DIRECT_DRAW if (isScreenRotated() || !isScreenFullyVisible() || editBoxShown) { /* DDraw is not very reliable on an rotated screen. Use GDI instead. */ return NULL; } if (g_pDD == NULL) { /* DirectDraw failed to initialize. Let's use GDI to Blit to the LCD. */ return NULL; } HRESULT hRet; DDSURFACEDESC surfaceDesc; DDSURFACEDESC ddsd; if (g_pDDSPrimary == NULL) { /* Create the primary surface with 0 back buffer */ memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE ; hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL); if (hRet != DD_OK) { g_pDDSPrimary = NULL; return NULL; } } surfaceDesc.dwSize = sizeof(surfaceDesc); hRet = g_pDDSPrimary->Lock(NULL, &surfaceDesc, DDLOCK_DISCARD | DDLOCK_WRITEONLY, NULL); if (hRet == DD_OK) { dst = (gxj_pixel_type*)surfaceDesc.lpSurface; dstWidth = surfaceDesc.dwWidth; dstHeight = surfaceDesc.dwHeight; dstYPitch = surfaceDesc.lPitch; } else { /* Release the DD resources. Maybe we'd get lucky and can allocate * it next time. */ g_pDDSPrimary->Release(); g_pDDSPrimary = NULL; return NULL; } #else if (editBoxShown) { return NULL; } dstWidth = gxDispProps.cxWidth; dstHeight = gxDispProps.cyHeight; dstYPitch = gxDispProps.cbyPitch; dst = (gxj_pixel_type*)GXBeginDraw(); #endif return dst; }
LPDIRECTDRAWSURFACE CreateSurfPCXResource(WORD PCXNum, bool VidMem) { HRSRC FResource = FindResource(HInstance, MAKEINTRESOURCE(PCXNum), RT_RCDATA); if(FResource == NULL) IDDrawSurface::OutptTxt("FResource NULL"); HGLOBAL LResource = LoadResource(HInstance, FResource); if(LResource == NULL) IDDrawSurface::OutptTxt("LResource NULL"); LPVOID PCXBuf = LockResource(LResource); if(PCXBuf == NULL) IDDrawSurface::OutptTxt("PCXBuf NULL"); pcx_picture_typ PCXPic; //PCXPic.buffer= (unsigned char *)malloc ( SizeofResource ( HInstance, FResource)); PCX2BitMap((unsigned char*)PCXBuf, &PCXPic, 0); int Height = PCXPic.header.height-PCXPic.header.y+1; int Width = PCXPic.header.width-PCXPic.header.x+1; LPDIRECTDRAWSURFACE RetSurf; DDSURFACEDESC ddsd; DDRAW_INIT_STRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; if(VidMem) ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; else ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = Width; ddsd.dwHeight = Height; if( DD_OK!=((LPDIRECTDRAW)LocalShare->TADirectDraw)->CreateSurface(&ddsd, &RetSurf, NULL)) { return NULL; } DDRAW_INIT_STRUCT(ddsd); RetSurf->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); unsigned char *SurfPTR = (unsigned char*)ddsd.lpSurface; if (NULL!=PCXPic.buffer) { if (NULL!=SurfPTR) { for(int i=0; i<Height; i++) { memcpy(&SurfPTR[i*ddsd.lPitch], &PCXPic.buffer[i*Width], Width); } } delete [] PCXPic.buffer; } RetSurf->Unlock(NULL); return RetSurf; }
//loads the PCX picture onto an existing surface void RestoreFromPCX(WORD PCXNum, LPDIRECTDRAWSURFACE lpSurf) { HRSRC FResource = FindResource(HInstance, MAKEINTRESOURCE(PCXNum), RT_RCDATA); if(FResource == NULL) IDDrawSurface::OutptTxt("FResource NULL"); HGLOBAL LResource = LoadResource(HInstance, FResource); if(LResource == NULL) IDDrawSurface::OutptTxt("LResource NULL"); LPVOID PCXBuf = LockResource(LResource); if(PCXBuf == NULL) IDDrawSurface::OutptTxt("PCXBuf NULL"); pcx_picture_typ PCXPic; PCX2BitMap((unsigned char*)PCXBuf, &PCXPic, 0); int Height = PCXPic.header.height-PCXPic.header.y+1; int Width = PCXPic.header.width-PCXPic.header.x+1; DDSURFACEDESC ddsd; DDRAW_INIT_STRUCT(ddsd); lpSurf->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL); unsigned char *SurfPTR = (unsigned char*)ddsd.lpSurface; if ((NULL!=PCXPic.buffer)) { if ((NULL!=SurfPTR)&&(NULL!=PCXPic.buffer)) { for(int i=0; i<Height; i++) { memcpy(&SurfPTR[i*ddsd.lPitch], &PCXPic.buffer[i*Width], Width); } } delete [] PCXPic.buffer; } lpSurf->Unlock(NULL); }
bool WinDrawDDS::Update(LPDIRECTDRAWSURFACE dds, const RECT& rect) { if (rect.left >= rect.right || rect.top >= rect.bottom) return false; HRESULT r; DDSURFACEDESC ddsd; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); RECT rectdest; rectdest.left = ltc.x + rect.left; rectdest.right = ltc.x + rect.right; rectdest.top = ltc.y + rect.top; rectdest.bottom = ltc.y + rect.bottom; r = dds->Lock(&rectdest, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, 0); LOGDDERR("ddsk->Lock", r); if (r != DD_OK) return false; const uint8* src = image + rect.left + (rect.top * width); uint8* dest = (uint8*) ddsd.lpSurface; for (int y = rect.top; y < rect.bottom; y++) { uint8 *d = dest; for (int x =0; x < (rect.right - rect.left); x++) { *d++ = palentry[src[x]].peBlue; *d++ = palentry[src[x]].peGreen; *d++ = palentry[src[x]].peRed; if (m_bpp == 4) { *d++ = 00; } } dest += ddsd.lPitch; src += width; } dds->Unlock(ddsd.lpSurface); return true; }
static u8 *screen_lock(u32 *pitch) { HRESULT ret; DDSURFACEDESC ddsc; dd_restore(); ddsc.dwSize = sizeof(ddsc); ret = lpDDSPrimary->Lock(&screenrect, &ddsc, DDLOCK_WAIT, 0); if (ret != DD_OK) { module_logger(&win32DirectDrawVideo, _L|LOG_ERROR|LOG_USER, _("error in Lock with %8X\n"),ret); return NULL; } /* locked */ //log("lpSurface = %p\n", ddsc.lpSurface); *pitch = ddsc.lPitch; return (u8 *)ddsc.lpSurface; }
void q_lock() { if (locked) { qWarning("Direct Painter already locked (QDirectPainter::lock())"); return; } locked = true; memset(&ddsSurfaceDesc, 0, sizeof(ddsSurfaceDesc)); ddsSurfaceDesc.dwSize = sizeof(ddsSurfaceDesc); HRESULT h = g_pDDSSurface->Lock(0, &ddsSurfaceDesc, DDLOCK_WRITEONLY, 0); if (h != DD_OK) qDebug() << "GetSurfaceDesc failed!"; width = ddsSurfaceDesc.dwWidth; height = ddsSurfaceDesc.dwHeight; bitCount = ddsSurfaceDesc.ddpfPixelFormat.dwRGBBitCount; pitch = ddsSurfaceDesc.lPitch; buffer = ddsSurfaceDesc.lpSurface; }
DWORD GetPitch() { DDSURFACEDESC ddsd; HRESULT result; if (BackSurface == NULL) { return FALSE; } ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); result = BackSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); if (result != DD_OK) { return 0; } DWORD pitch = ddsd.lPitch; BackSurface->Unlock(NULL); return pitch; }
void mfc_render_do(void *mfc_render_handle, unsigned char *pImg, int width, int height, int img_type) { _MFC_RENDER_OVERLAY *pMFC_RENDER_OVERLAY; DDSURFACEDESC ddsd; HRESULT hRet; LPDIRECTDRAWSURFACE pDDSOverlay; // Overlay Surface. unsigned char *pSurf; int y_size, u_size; switch (img_type) { case MFC_RENDER_IMAGE_TYPE_YUV420: case MFC_RENDER_IMAGE_TYPE_RGB565: case MFC_RENDER_IMAGE_TYPE_YV12: break; default: PRINT_ERRMSG(TEXT("img_type is not supported.")); return; } if (mfc_render_handle == NULL) { PRINT_ERRMSG(TEXT("\nmfc_render_handle is NULL.")); return; } if (pImg == NULL) { PRINT_ERRMSG(TEXT("Input image is NULL.")); return; } pMFC_RENDER_OVERLAY = (_MFC_RENDER_OVERLAY *) mfc_render_handle; if (pMFC_RENDER_OVERLAY->which == 1) { pDDSOverlay = pMFC_RENDER_OVERLAY->pDD; } else if (pMFC_RENDER_OVERLAY->which == 0) { pDDSOverlay = pMFC_RENDER_OVERLAY->pDD_back; } memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); // Lock down the surface so we can modify it's contents. hRet = pDDSOverlay->Lock( NULL, &ddsd, DDLOCK_WAITNOTBUSY, NULL); if (hRet != DD_OK) { PRINT_ERRMSG(TEXT("Unable to show overlay surface!")); return; } pSurf = (LPBYTE)ddsd.lpSurface; y_size = width * height; u_size = y_size >> 2; switch (pMFC_RENDER_OVERLAY->surface_type) { case MFC_RENDER_SURFACE_TYPE_YV12: // YV12의 경우는 그대로 복사한다. if (img_type == MFC_RENDER_IMAGE_TYPE_YUV420) { memcpy(pSurf, pImg, y_size); memcpy(pSurf + y_size, pImg + y_size + u_size, u_size); memcpy(pSurf + y_size + u_size, pImg + y_size, u_size); } else if (img_type == MFC_RENDER_IMAGE_TYPE_YV12) { memcpy(pSurf, pImg, y_size + (u_size << 1)); } else if (img_type == MFC_RENDER_IMAGE_TYPE_RGB565) { PRINT_ERRMSG(TEXT("This case is not supported. : (Surface type is YV12 and Image type is RGB565)")); } break; case MFC_RENDER_SURFACE_TYPE_RGB565: // RGB565의 경우는 SW YUV->RGB 변환 수행 if (img_type == MFC_RENDER_IMAGE_TYPE_YUV420) { _yuv420ToRgb565(pImg, pImg + y_size, pImg + y_size + u_size, width, height, pSurf, width, height, 0); } else if (img_type == MFC_RENDER_IMAGE_TYPE_YV12) { _yuv420ToRgb565(pImg, pImg + y_size + u_size, pImg + y_size, width, height, pSurf, width, height, 0); } else if (img_type == MFC_RENDER_IMAGE_TYPE_RGB565) { memcpy(pSurf, pImg, y_size << 1); } break; default: break; } pDDSOverlay->Unlock(NULL); }
static int RenderSmallFontString(char *textPtr,int sx,int sy,int alpha, int red, int green, int blue) { DDSURFACEDESC ddsdimage; unsigned short *destPtr; unsigned short *srcPtr; int extra = 0; int alphaR = MUL_FIXED(alpha,red); int alphaG = MUL_FIXED(alpha,green); int alphaB = MUL_FIXED(alpha,blue); AVPMENUGFX *gfxPtr; LPDIRECTDRAWSURFACE surface; gfxPtr = &AvPMenuGfxStorage[AVPMENUGFX_SMALL_FONT]; surface = gfxPtr->ImagePtr; memset(&ddsdimage, 0, sizeof(ddsdimage)); ddsdimage.dwSize = sizeof(ddsdimage); /* lock the image */ while (surface->Lock(NULL, &ddsdimage, DDLOCK_WAIT, NULL) == DDERR_WASSTILLDRAWING); while( *textPtr ) { char c = *textPtr++; if (c>=' ') { int topLeftU = 1+((c-32)&15)*16; int topLeftV = 1+((c-32)>>4)*16; srcPtr = (unsigned short *)(ddsdimage.lpSurface) + (topLeftU)+(topLeftV*ddsdimage.lPitch/2); int x,y; for (y=sy; y<HUD_FONT_HEIGHT+sy; y++) { destPtr = (unsigned short *)(ScreenBuffer + sx*2 + y*BackBufferPitch); for (x=0; x<HUD_FONT_WIDTH; x++) { if (*srcPtr) { unsigned int srcR,srcG,srcB; unsigned int destR,destG,destB; destR = (int)(*destPtr) & DisplayPixelFormat.dwRBitMask; destG = (int)(*destPtr) & DisplayPixelFormat.dwGBitMask; destB = (int)(*destPtr) & DisplayPixelFormat.dwBBitMask; srcR = (int)(*srcPtr) & DisplayPixelFormat.dwRBitMask; srcG = (int)(*srcPtr) & DisplayPixelFormat.dwGBitMask; srcB = (int)(*srcPtr) & DisplayPixelFormat.dwBBitMask; destR += MUL_FIXED(alphaR,srcR); if (destR>DisplayPixelFormat.dwRBitMask) destR = DisplayPixelFormat.dwRBitMask; else destR &= DisplayPixelFormat.dwRBitMask; destG += MUL_FIXED(alphaG,srcG); if (destG>DisplayPixelFormat.dwGBitMask) destG = DisplayPixelFormat.dwGBitMask; else destG &= DisplayPixelFormat.dwGBitMask; destB += MUL_FIXED(alphaB,srcB); if (destB>DisplayPixelFormat.dwBBitMask) destB = DisplayPixelFormat.dwBBitMask; else destB &= DisplayPixelFormat.dwBBitMask; *destPtr = (short)(destR|destG|destB); } destPtr++; srcPtr++; } srcPtr += (ddsdimage.lPitch/2) - HUD_FONT_WIDTH; } sx += AAFontWidths[c]; #if 0 if(c!=32) { extra += 8-AAFontWidths[c]; } else { sx+=extra+8-AAFontWidths[c]; extra=0; } #endif } }
void IndexedFont_Kerned :: RenderString_Unclipped ( struct r2pos& R2Pos_Cursor, int FixP_Alpha, const SCString& SCStr ) const #if 1 { ProjChar* pProjChar_I = SCStr . pProjCh(); const LPDIRECTDRAWSURFACE image_ptr = GetImagePtr(); DDSURFACEDESC ddsdimage; memset(&ddsdimage, 0, sizeof(ddsdimage)); ddsdimage.dwSize = sizeof(ddsdimage); /* lock the image */ while (image_ptr->Lock(NULL, &ddsdimage, DDLOCK_WAIT, NULL) == DDERR_WASSTILLDRAWING); while ( *pProjChar_I ) { const ProjChar ProjCh = *pProjChar_I; if ( bCanRender( ProjCh ) ) { #if 0 textprint("printable \'%c\'\n",ProjCh); #endif #if 0 RenderChar_Clipped ( R2Pos_Cursor, R2Rect_Clip, FixP_Alpha, ProjCh ); #else if (ProjCh != ' ') { unsigned int theOffset=ProjCh - 32; int width = GetWidth(ProjCh); /* if ( GetOffset ( theOffset, ProjCh ) ) */ { if ( width>0 ) { { // This code adapted from DrawGraphicWithAlphaChannel(); // it assumes you're in a 16-bit mode... // okay, now we have the surfaces, we can copy from one to the other, // darkening pixels as we go { long fontimagePitchInShorts = (ddsdimage.lPitch/2); long backbufferPitchInShorts = (BackBufferPitch/2); unsigned short* fontimageRowStartPtr = ( ((unsigned short *)ddsdimage.lpSurface) + (GetHeight()*theOffset*fontimagePitchInShorts) ); unsigned short* backbufferRowStartPtr = ( ((unsigned short *)ScreenBuffer) + (R2Pos_Cursor.y*backbufferPitchInShorts) + (R2Pos_Cursor.x) ); int screenY = R2Pos_Cursor.y; for (int yCount=GetHeight(); yCount>0; yCount--) { unsigned short* fontimagePtr = fontimageRowStartPtr; unsigned short* backbufferPtr = backbufferRowStartPtr; int xIndex = R2Pos_Cursor.x+CloakingPhase/64; int yIndex = (screenY+CloakingPhase/128)&127; // if (screenY >= R2Rect_Clip.y0 && screenY <= R2Rect_Clip.y1) for (int xCount=width; xCount>0;xCount--) { int r = CloudTable[(xCount+xIndex)&127][yIndex]; // b += CloudTable[((xCount+R2Pos_Cursor.x)/2-CloakingPhase/96)&127][((yCount+R2Pos_Cursor.y)/4+CloakingPhase/64)&127]/4; // b += CloudTable[((xCount+R2Pos_Cursor.x+10)/4-CloakingPhase/64)&127][((yCount+R2Pos_Cursor.y-50)/8+CloakingPhase/32)&127]/8; // if (b>ONE_FIXED) b = ONE_FIXED; r = MUL_FIXED(FixP_Alpha,r); //int r = FixP_Alpha; if (*fontimagePtr) { unsigned int backR = (int)(*backbufferPtr) & DisplayPixelFormat.dwRBitMask; unsigned int backG = (int)(*backbufferPtr) & DisplayPixelFormat.dwGBitMask; unsigned int backB = (int)(*backbufferPtr) & DisplayPixelFormat.dwBBitMask; unsigned int fontR = (int)(*fontimagePtr) & DisplayPixelFormat.dwRBitMask; unsigned int fontG = (int)(*fontimagePtr) & DisplayPixelFormat.dwGBitMask; unsigned int fontB = (int)(*fontimagePtr) & DisplayPixelFormat.dwBBitMask; backR += MUL_FIXED(r,fontR); if (backR>DisplayPixelFormat.dwRBitMask) backR = DisplayPixelFormat.dwRBitMask; else backR &= DisplayPixelFormat.dwRBitMask; backG += MUL_FIXED(r,fontG); if (backG>DisplayPixelFormat.dwGBitMask) backG = DisplayPixelFormat.dwGBitMask; else backG &= DisplayPixelFormat.dwGBitMask; backB += MUL_FIXED(r,fontB); if (backB>DisplayPixelFormat.dwBBitMask) backB = DisplayPixelFormat.dwBBitMask; else backB &= DisplayPixelFormat.dwBBitMask; *backbufferPtr = (short)(backR|backG|backB); } fontimagePtr++; backbufferPtr++; } screenY++; fontimageRowStartPtr += fontimagePitchInShorts; backbufferRowStartPtr += backbufferPitchInShorts; } } } } } } #endif } else { #if 0 textprint("unprintable \'%c\'\n",ProjCh); #endif } R2Pos_Cursor . x += 1+GetXInc ( ProjCh, *(pProjChar_I+1) ); // this takes responsibility for updating cursor pos, // rather than the RenderChar function pProjChar_I++; } image_ptr->Unlock((LPVOID)ddsdimage.lpSurface); }
/******************************************************************** * Function : SimLoop() * Purpose : Performs a single Simulation Loop iteration. Includes * drawing. ********************************************************************/ int SimLoop(void) { static int nFramesPerSecond = 0; static int nFramesSinceLastTick; static DWORD LastTicks = 0; DWORD Ticks; HDC hDC; HFONT hOldFont; char s[80]; int slen; DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; /* Perform a single step in our world. */ if (StepWorld(bForwardKey, bBackKey, bLeftKey, bRightKey, nState, nGauge)) { if (lpPrimary->IsLost() == DDERR_SURFACELOST) lpPrimary->Restore(); /* Clear the backbuffer. */ #if CLEARBCKGRND BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpBackbuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); #else ddreturn = DD_OK; #endif if (ddreturn == DD_OK) { /* While this is running, prepare * the drawing. */ if (PrepDrawWorld()) { /* Lock the surface. */ memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; static unsigned char dummy; unsigned char ni; ni = 0; for (nY = 0; nY < 16; nY++) for (nX = 0; nX < 16; nX++) { /* Draw a small block at (nX * 3, nY * 3) */ ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3 + 1)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3 + 1)] = ni; ni++; } lpBackbuffer->Unlock(NULL); /* And now write Frames per second. */ /* Increment Frame counter. */ nFramesSinceLastTick++; /* Get system tick count. */ Ticks = GetTickCount(); /* Update fps value every second. */ if (Ticks > (LastTicks + 1000)) { nFramesPerSecond = nFramesSinceLastTick; nFramesSinceLastTick = 0; LastTicks = Ticks; } /* Get a DC to the buffer & write count. */ if (DD_OK == lpBackbuffer->GetDC(&hDC)) { SetBkMode(hDC, TRANSPARENT); hOldFont = SelectObject(hDC, AppFont); /* Build a string for display. */ slen = wsprintf(s, "FPS : %d", nFramesPerSecond); /* And draw the text. */ SetTextColor(hDC, RGB(0,0,0)); SIZE sz; GetTextExtentPoint32(hDC, s, slen, &sz); RECT rc; rc.top = 0; rc.left = 16 * 3; rc.right = 16 * 3 + sz.cx + 10; rc.bottom = sz.cy + 10; DrawFrameControl(hDC, &rc, DFC_BUTTON, DFCS_BUTTONPUSH); TextOut(hDC, 16*3 + 5, 5, s, slen); SelectObject(hDC, hOldFont); lpBackbuffer->ReleaseDC(hDC); } /* Perform required pageflipping to make the surface * we drawed visible. */ ddreturn = lpPrimary->Flip(NULL, DDFLIP_WAIT); if (ddreturn == DD_OK) { return 1; } } } } } return 0; }
int dd_Window::set_win(int w, int h, int bpp) { // RECT r, r2; HRESULT hr; shutdown_win(); dx_win_bsd.dwWidth = w; dx_win_bsd.dwHeight = h; hr = dx_dd->CreateSurface(&dx_win_bsd, &dx_win_bs, NULL); if (hr != DD_OK) { return 0; } hr = dx_win_bs->Lock(0, &dx_win_bsd, 0, 0); if (hr != DD_OK) { DX_RELEASE(dx_win_bs); return 0; } dx_win_bs->Unlock(0); hr = dx_dd->CreateClipper(0, &clipper, 0); if (hr != DD_OK) { DX_RELEASE(dx_win_bs); return 0; } hr = clipper->SetHWnd(0, hwnd); if (hr != DD_OK) { DX_RELEASE(dx_win_bs); DX_RELEASE(clipper); return 0; } if(bGameWindow) { int ws = GetWindowLong(hwnd,GWL_STYLE); ws &= ~WS_POPUP; ws |= WS_OVERLAPPEDWINDOW | WS_THICKFRAME; SetWindowLong(hwnd, GWL_STYLE, ws); } //set pixelformat parameters //if(bGameWindow) //{ // DDPIXELFORMAT ddpf; // ddpf.dwSize = sizeof(ddpf); // ddpf.dwFlags = DDPF_RGB; // hr = dx_win_ps->GetPixelFormat(&ddpf); // if (hr != DD_OK) err("Could not get pixel format!"); // //if (ddpf.dwRBitMask == 0x7C00 && bpp == 16) // // vid_bpp = 15, vid_bytesperpixel = 2; // //else // // vid_bpp = bpp, vid_bytesperpixel = bpp / 8; //} delete img; img = new image(); img->width = w; img->height = h; img->cx1 = 0; img->cx2 = w-1; img->cy1 = 0; img->cy2 = h-1; if(vid_bpp == DesktopBPP) { img->shell = true; img->data = (quad*)dx_win_bsd.lpSurface; img->pitch = dx_win_bsd.lPitch / vid_bytesperpixel; } else { img->alloc_data(); } SetHandleImage(imgHandle,img); if(bGameWindow) { SetHandleImage(1,img); screen = img; } return 1; }
void PlatformSpecificEnteringDatabase(void) { // lets make a copy of the back buffer, and in the process darken the // colours by half // first, take a lock for both surfaces DDSURFACEDESC ddsdback; DDSURFACEDESC ddsdmenu; unsigned char *src, *dest, *srcStart, *destStart; long srcPitch, destPitch; HRESULT ddrval; memset(&ddsdback, 0, sizeof(ddsdback)); ddsdback.dwSize = sizeof(ddsdback); memset(&ddsdmenu, 0, sizeof(ddsdmenu)); ddsdmenu.dwSize = sizeof(ddsdmenu); // take a lock of the back buffer while ((ddrval = lpDDSBack->Lock(NULL, &ddsdback, DDLOCK_WAIT, NULL)) == DDERR_WASSTILLDRAWING) { LOGDXERR(ddrval); ReleaseDirect3D(); exit(0x2021); } LOGDXERR(ddrval); if (ddrval != DD_OK) { #if debug ReleaseDirect3D(); exit(ddrval); #else return; #endif } /* ddsdback now contains my lpSurface)*/ src = srcStart = (unsigned char *)ddsdback.lpSurface; srcPitch = ddsdback.lPitch - ddsdback.dwWidth; // take a lock of the menubackdrop buffer while ((ddrval = lpDDSInGameMenuBackdrop->Lock(NULL, &ddsdmenu, DDLOCK_WAIT, NULL)) == DDERR_WASSTILLDRAWING) { LOGDXERR(ddrval); ReleaseDirect3D(); exit(0x2022); } LOGDXERR(ddrval); if (ddrval != DD_OK) { #if debug ReleaseDirect3D(); exit(ddrval); #else return; #endif } destStart = (unsigned char *)ddsdmenu.lpSurface; destPitch = ddsdmenu.lPitch - ddsdmenu.dwWidth; // okay, now we have the surfaces, we can copy from one to the other, // darkening pixels as we go { int i = 0, j = 0; extern int VideoModeColourDepth; switch(VideoModeColourDepth) { case 8: { unsigned char* dest = (unsigned char *)ddsdmenu.lpSurface; unsigned char* src = (unsigned char *)ddsdback.lpSurface; for(j=0; j < ScreenDescriptorBlock.SDB_Height; j++) { for(i=0;i < ScreenDescriptorBlock.SDB_Width; i++) { extern unsigned char* TextureLightingTable; *dest++ = *(TextureLightingTable + (32 * 256) + *src++); } dest += destPitch; src += srcPitch; } break; } #if 1 case 16: { short r,g,b; short *destShort = (short*)ddsdmenu.lpSurface; short *srcShort = (short*)ddsdback.lpSurface; for(j=0; j < ScreenDescriptorBlock.SDB_Height; j++) { destShort = (short*)(((char*)ddsdmenu.lpSurface) + ddsdmenu.lPitch * j); srcShort = (short*)(((char*)ddsdback.lpSurface) + ddsdback.lPitch * j); for(i=0;i < ScreenDescriptorBlock.SDB_Width; i++) { r = (*srcShort & DisplayPixelFormat.dwRBitMask)>>1; g = (*srcShort & DisplayPixelFormat.dwGBitMask)>>1; b = (*srcShort & DisplayPixelFormat.dwBBitMask)>>1; srcShort++; r &= DisplayPixelFormat.dwRBitMask; g &= DisplayPixelFormat.dwGBitMask; b &= DisplayPixelFormat.dwBBitMask; *destShort++ = r|g|b; } } break; } case 32: { int *destInt = (int*)ddsdmenu.lpSurface; int *srcInt = (int*)ddsdback.lpSurface; int r,g,b; for(j=0; j < ScreenDescriptorBlock.SDB_Height; j++) { for(i=0;i < ScreenDescriptorBlock.SDB_Width; i++) { r = (*srcInt & DisplayPixelFormat.dwRBitMask)>>1; g = (*srcInt & DisplayPixelFormat.dwGBitMask)>>1; b = (*srcInt++ & DisplayPixelFormat.dwBBitMask)>>1; r &= DisplayPixelFormat.dwRBitMask; g &= DisplayPixelFormat.dwGBitMask; b &= DisplayPixelFormat.dwBBitMask; *destInt++ = r|g|b; } destInt += (destPitch >> 2); srcInt += (srcPitch >> 2); } break; } #endif default: break; } } // unlock the two surfaces ddrval = lpDDSInGameMenuBackdrop->Unlock((LPVOID)destStart); LOGDXERR(ddrval); #if debug if (ddrval != DD_OK) { ReleaseDirect3D(); exit(ddrval); } #endif ddrval = lpDDSBack->Unlock((LPVOID)srcStart); LOGDXERR(ddrval); #if debug if (ddrval != DD_OK) { ReleaseDirect3D(); exit(ddrval); } #endif }
void UpdateFrame2(HWND hWnd, void* videoMem) { static BYTE phase = 0; HRESULT hRet; LPDIRECTDRAWSURFACE pdds; DDBLTFX ddbltfx; static int cnt = 0; memset(&ddbltfx, 0, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwROP = SRCCOPY; if (phase) { pdds = g_pDDSTwo; phase = 0; } else { pdds = g_pDDSOne; phase = 1; } #if 1 DDSURFACEDESC ddsd; ddsd.dwSize = sizeof(ddsd); while (true) { WaitForSingleObject(g_hRefreshScreen, INFINITE); hRet = g_pDDSPrimary->Lock(NULL, &ddsd, DDLOCK_WAITNOTBUSY | DDLOCK_DISCARD | DDLOCK_WRITEONLY, NULL); if (hRet == DD_OK) { //memcpy((char*)ddsd.lpSurface, g_videoMem, (ddsd.dwHeight - 26) * ddsd.lPitch); memcpy((char*)ddsd.lpSurface + ddsd.lPitch * 26, g_videoMem, (ddsd.dwHeight - 26) * ddsd.lPitch); //memcpy((char*)ddsd.lpSurface, videoMem, ddsd.dwHeight * ddsd.lPitch); hRet = g_pDDSPrimary->Unlock(NULL); } } //hRet = g_pDDSPrimary->Blt(NULL, g_pDDSBack, NULL, DDBLT_ROP, &ddbltfx);//dwTransType, NULL); #else while (TRUE) { hRet = g_pDDSBack->Blt(NULL, pdds, NULL, DDBLT_ROP, &ddbltfx); if (hRet == DD_OK) break; if (hRet == DDERR_SURFACELOST) { hRet = RestoreAll(); if (hRet != DD_OK) break; } if (hRet != DDERR_WASSTILLDRAWING) break; Sleep(10); } while (TRUE) { hRet = g_pDDSPrimary->Flip(NULL, 0); if (hRet == DD_OK) break; if (hRet == DDERR_SURFACELOST) { hRet = RestoreAll(); if (hRet != DD_OK) break; } if (hRet != DDERR_WASSTILLDRAWING) break; Sleep(10); } #endif }
/******************************************************************** * Function : WindowProc() * Purpose : Receive and handle windows messages. ********************************************************************/ long FAR PASCAL WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; switch (message) { case WM_ACTIVATEAPP : ActiveApp = wParam; break; case WM_CREATE : break; case WM_KEYDOWN : switch (wParam) { case VK_PAUSE : /* Start or Stop realtime. */ RealTime = !RealTime; break; case VK_SPACE : /* Flip a single frame. */ SimLoop(); break; case VK_ESCAPE : DestroyWindow(hwnd); break; case VK_LEFT : bLeftKey = TRUE; break; case VK_RIGHT : bRightKey = TRUE; break; case VK_UP : bForwardKey = TRUE; break; case VK_DOWN : bBackKey = TRUE; break; case VK_ADD : nGauge++; break; case VK_SUBTRACT : nGauge--; break; case VK_HOME : nGauge = 0; break; } break; case WM_KEYUP : switch (wParam) { case VK_F1 : nState = 1; break; case VK_F2 : nState = 2; break; case VK_F3 : nState = 3; break; case VK_F4 : nState = 4; break; case VK_F5 : nState = 5; break; case VK_F6 : nState = 6; break; case VK_F7 : nState = 7; break; case VK_F8 : nState = 8; break; case VK_F9 : nState = 9; break; case VK_F10 : nState = 0; break; case VK_LEFT : bLeftKey = FALSE; break; case VK_RIGHT : bRightKey = FALSE; break; case VK_UP : bForwardKey = FALSE; break; case VK_DOWN : bBackKey = FALSE; break; case 'S' : // Screen Snapshot. // This is not done very reliably, infact, it's more of a hack so // I can show some Chrome snapshots on my website. // Open a file named "Snapshot.tga" and write the current content // of the screen as a targa file. HANDLE hFile; hFile = CreateFile("Snapshot.tga", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != NULL) { // Write the Targa header, as appropriate for the current // screen type. DWORD dwWritten; /* Targa File Header : (Little Endian / Intel) * Offset Length Description * 0 1 ID field length * 1 1 Color map type. * 2 1 Image type. * 3 2 First color map entry. * 5 2 Color map length. * 7 1 Color map entry size. * 8 2 Image X origin. * 10 2 Image Y Origin. * 12 2 Image Width. * 14 2 Image Height. * 16 1 Bits per pixel. * 17 1 Image descriptor bits. * (from : "Graphics File Formats", David C. Kay and John R. Levine) */ # define OutB(b)\ { unsigned char b2;\ b2 = b;\ WriteFile(hFile, &b2, sizeof(b2), &dwWritten, NULL);\ } # define OutW(w)\ { unsigned short w2;\ w2 = w;\ WriteFile(hFile, &w2, sizeof(w2), &dwWritten, NULL);\ } OutB(0); // No message ID field length. OutB(0); // Colormap type = 0; true color. OutB(2); // Image type = 2, True color, uncompressed. OutW(0); // First colormap entry is 0, (Because Cmap type = 0). OutW(0); // Colormap length = 0, (CMap type = 0). OutB(0); // CMap entry size is 0 (because CMap type = 0) OutW(0); // OriginX = 0; OutW(0); // OriginY = 0; OutW(XRES); // Image Width is the value of the XRES constant. OutW(YRES); // Image Height is the value of the YRES constant. OutB(24); // Bits per pixel. OutB(0x20); // Image Descriptor Bits (0x20 = left to right, top to bottom). // Each pixel is written as a Blue Green Red triple. // Lock the surface & write each byte. DDSURFACEDESC ddsd; memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_READONLY | DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { //DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; for (nY = 0; nY < YRES; nY++) { for (nX = 0; nX < XRES; nX++) { unsigned char ucByte; ucByte = *(((unsigned char *)ddsd.lpSurface) + ddsd.lPitch * nY + nX); // Index the colormap & write the BGR triple. OutB(WinColormap[ucByte].peBlue); OutB(WinColormap[ucByte].peGreen); OutB(WinColormap[ucByte].peRed); } } lpBackbuffer->Unlock(NULL); } // Close the file, we're done... CloseHandle(hFile); } } break; case WM_DESTROY : if (lpDirectDrawObject != NULL) { if (lpBackbuffer != NULL) lpBackbuffer->Release(); if (lpPrimary != NULL) lpPrimary->Release(); if (lpPalette != NULL) lpPalette->Release(); lpDirectDrawObject->Release(); } /* Free the world. */ EndWorld(); /* Free the font. */ if (AppFont != NULL) DeleteObject(AppFont); ShowCursor(TRUE); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0L; }
extern "C" HRESULT InitDirectDraw(HWND hWnd, int w, int h, void* pixelData) { WNDCLASS wc; DDSURFACEDESC ddsd; HRESULT hRet; hRet = DirectDrawCreate(NULL, &g_pDD, NULL); if (hRet != DD_OK) return InitFail(hWnd, hRet, szDDrawFailedMsg); // Get exclusive mode hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN); //DDSCL_NORMAL);// if (hRet != DD_OK) return InitFail(hWnd, hRet, szSetCooperativeFailMsg); #if 0 DDCAPS ddCaps; DDCAPS ddHelCaps; g_pDD->GetCaps(&ddCaps, &ddHelCaps); if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)) { return InitFail(hWnd, E_FAIL, szNoBackBufferMsg); } if (!(ddCaps.ddsCaps.dwCaps & DDSCAPS_FLIP)) { return InitFail(hWnd, E_FAIL, szNoFlipSurfacesMsg); } #endif // Create the primary surface with 1 back buffer memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS;// | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; //| DDSCAPS_FLIP; //ddsd.dwBackBufferCount = 1; hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL); if (hRet != DD_OK) { return InitFail(hWnd, hRet, szCreateSurfaceFailMsg); } DWORD dwID; g_hRefreshScreen = CreateEvent(NULL, FALSE, FALSE, NULL); CreateThread(NULL, 0, ScreenRefresThread, NULL, 0, &dwID); return DD_OK; #if 0 #define WIDTH w // in pixels #define HEIGHT h #define DEPTH 2 // in bytes (2 bytes == 16 bits) if (ddsd.dwBackBufferCount > 0) { hRet = g_pDDSPrimary->EnumAttachedSurfaces(&g_pDDSBack, EnumFunction); if (hRet != DD_OK) return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg); } ZeroMemory(&ddsd, sizeof(DDSURFACEDESC)); ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); ddsd.dwSize = sizeof(ddsd); hRet = g_pDDSBack->Lock(NULL, &ddsd, DDLOCK_WAITNOTBUSY, NULL); g_pDDSPrimary->Unlock(NULL); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT; ddsd.dwWidth = WIDTH; ddsd.dwHeight= HEIGHT; //ddsd.lPitch = (LONG)DEPTH * WIDTH; ddsd.lpSurface = pixelData; /* // Set up the pixel format for 24-bit RGB (8-8-8). ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)DEPTH*8; ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;//surface->format->Rmask; ddsd.ddpfPixelFormat.dwGBitMask = 0x07E0;//surface->format->Gmask; ddsd.ddpfPixelFormat.dwBBitMask = 0x001F;//surface->format->Bmask; //ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000; //ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00; //ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF; */ // Create the surface hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack, NULL); if (hRet != DD_OK) return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg); return DD_OK; #endif if (ddsd.dwBackBufferCount > 0) { hRet = g_pDDSPrimary->EnumAttachedSurfaces(&g_pDDSBack, EnumFunction); if (hRet != DD_OK) return InitFail(hWnd, hRet, szEnumAttachedSurfacesFailMsg); } return DD_OK; #if 1 ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PITCH | DDSD_LPSURFACE | DDSD_PIXELFORMAT); ddsd.dwWidth = w; ddsd.dwHeight= h; #if defined(NONAMELESSUNION) ddsd.u1.lPitch = SDL_CalculatePitch(w, 2);; #else ddsd.lPitch = SDL_CalculatePitch(w, 2);; #endif ddsd.lpSurface = pixelData; const int SDL_HWSURFACE = 1; int flag = 1; if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) { ddsd.ddsCaps.dwCaps = (/*DDSCAPS_OFFSCREENPLAIN | */DDSCAPS_VIDEOMEMORY); } else { ddsd.ddsCaps.dwCaps = (/*DDSCAPS_OFFSCREENPLAIN | */DDSCAPS_SYSTEMMEMORY); } ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB; // if ( surface->format->palette ) { // ddsd.ddpfPixelFormat.dwFlags |= DDPF_PALETTEINDEXED8; // } #if defined(NONAMELESSUNION) ddsd.ddpfPixelFormat.u1.dwRGBBitCount = surface->format->BitsPerPixel; ddsd.ddpfPixelFormat.u2.dwRBitMask = surface->format->Rmask; ddsd.ddpfPixelFormat.u3.dwGBitMask = surface->format->Gmask; ddsd.ddpfPixelFormat.u4.dwBBitMask = surface->format->Bmask; #else ddsd.ddpfPixelFormat.dwRGBBitCount = 16;//surface->format->BitsPerPixel; ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;//surface->format->Rmask; ddsd.ddpfPixelFormat.dwGBitMask = 0x07E0;//surface->format->Gmask; ddsd.ddpfPixelFormat.dwBBitMask = 0x001F;//surface->format->Bmask; #endif /* Create the DirectDraw video surface */ //if ( requested != NULL ) { // g_pDDSOne = requested; //} else { hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack, NULL); #if 0 if ( hRet != DD_OK ) { SetDDerror("DirectDraw2::CreateSurface", hRet); goto error_end; } hRet = g_pDDSBack->QueryInterface( &IID_IDirectDrawSurface3, (LPVOID *)&g_pDDSOne); g_pDDSBack->Release(); if ( hRet != DD_OK ) { SetDDerror("DirectDrawSurface::QueryInterface", hRet); goto error_end; } #endif } #if 0 if ( (flag & SDL_HWSURFACE) == SDL_HWSURFACE ) { /* Check to see whether the surface actually ended up in video memory, and fail if not. We expect the surfaces we create here to actually be in hardware! */ hRet = g_pDDSOne->GetCaps(&ddsd.ddsCaps); if ( hRet != DD_OK ) { //SetDDerror("DirectDrawSurface3::GetCaps", hRet); goto error_end; } if ( (ddsd.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) != DDSCAPS_VIDEOMEMORY ) { //SDL_SetError("No room in video memory"); goto error_end; } } else { /* Try to hook our surface memory */ ddsd.dwFlags = DDSD_LPSURFACE; ddsd.lpSurface = pixelData;//surface->pixels; hRet = g_pDDSOne->SetSurfaceDesc( &ddsd, 0); if ( hRet != DD_OK ) { //SetDDerror("DirectDraw2::SetSurfaceDesc", hRet); goto error_end; } } /* Make sure the surface format was set properly */ SDL_memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); hRet = IDirectDrawSurface3_Lock(g_pDDSOne, NULL, &ddsd, (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); if ( hRet != DD_OK ) { //SetDDerror("DirectDrawSurface3::Lock", hRet); goto error_end; } IDirectDrawSurface3_Unlock(g_pDDSOne, NULL); if ( (flag & SDL_HWSURFACE) == SDL_SWSURFACE ) { if ( ddsd.lpSurface != surface->pixels ) { //SDL_SetError("DDraw didn't use SDL surface memory"); goto error_end; } if ( #if defined(NONAMELESSUNION) ddsd.u1.lPitch #else ddsd.lPitch #endif != (LONG)surface->pitch ) { //SDL_SetError("DDraw created surface with wrong pitch"); goto error_end; } } else { #if defined(NONAMELESSUNION) surface->pitch = (Uint16)ddsd.u1.lPitch; #else surface->pitch = (Uint16)ddsd.lPitch; #endif } #if defined(NONAMELESSUNION) if ( (ddsd.ddpfPixelFormat.u1.dwRGBBitCount != surface->format->BitsPerPixel) || (ddsd.ddpfPixelFormat.u2.dwRBitMask != surface->format->Rmask) || (ddsd.ddpfPixelFormat.u3.dwGBitMask != surface->format->Gmask) || (ddsd.ddpfPixelFormat.u4.dwBBitMask != surface->format->Bmask) ){ #else if ( (ddsd.ddpfPixelFormat.dwRGBBitCount != surface->format->BitsPerPixel) || (ddsd.ddpfPixelFormat.dwRBitMask != surface->format->Rmask) || (ddsd.ddpfPixelFormat.dwGBitMask != surface->format->Gmask) || (ddsd.ddpfPixelFormat.dwBBitMask != surface->format->Bmask) ){ #endif //SDL_SetError("DDraw didn't use SDL surface description"); goto error_end; } if ( (ddsd.dwWidth != (DWORD)surface->w) || (ddsd.dwHeight != (DWORD)surface->h) ) { //SDL_SetError("DDraw created surface with wrong size"); goto error_end; } /* Set the surface private data */ surface->flags |= flag; surface->hwdata->dd_surface = g_pDDSOne; if ( (surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { LPDIRECTDRAWSURFACE3 dd_writebuf; ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; hRet = IDirectDrawSurface3_GetAttachedSurface(g_pDDSOne, &ddsd.ddsCaps, &dd_writebuf); if ( hRet != DD_OK ) { //SetDDerror("DirectDrawSurface3::GetAttachedSurface", hRet); } else {