⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rw_ddraw.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    DDRAW_Shutdown;
    result := False;
    Exit;
  end;
  ri.Con_Printf(PRINT_ALL, 'ok ');

  (*
  ** create our DIRECTDRAWPALETTE
  *)
  ri.Con_Printf(PRINT_ALL, '...creating palette: ');
  ddrval := sww_state.lpDIRECTDraw.CreatePalette(DDPCAPS_8BIT or DDPCAPS_ALLOW256,
                                                 @palentries, sww_state.lpddpPalette,
                                                 nil);
  if (ddrval <> DD_OK) then
  begin
    ri.Con_Printf(PRINT_ALL, 'failed - %s', DDrawError(ddrval));
    DDRAW_Shutdown;
    result := False;
    Exit;
  end;
  ri.Con_Printf(PRINT_ALL, 'ok ');

  ri.Con_Printf(PRINT_ALL, '...setting palette: ');
  ddrval := sww_state.lpddsFrontBuffer.SetPalette(sww_state.lpddpPalette);
  if (ddrval <> DD_OK) then
  begin
    ri.Con_Printf(PRINT_ALL, 'failed - %s', DDrawError(ddrval));
    DDRAW_Shutdown;
    result := False;
    Exit;
  end;
  ri.Con_Printf(PRINT_ALL, 'ok ');

  DDRAW_SetPalette(@sw_state.currentpalette);

  (*
  ** lock the back buffer
  *)
  FillChar(ddsd, sizeof(ddsd), 0);
  ddsd.dwSize := sizeof(ddsd);

  ri.Con_Printf(PRINT_ALL, '...locking backbuffer: ');
  ddrval := sww_state.lpddsOffScreenBuffer.Lock(nil, ddsd, DDLOCK_WAIT, 0);
  if (ddrval <> DD_OK) then
  begin
    ri.Con_Printf(PRINT_ALL, 'failed - %s', DDrawError(ddrval));
    DDRAW_Shutdown;
    result := False;
    Exit;
  end;
  ri.Con_Printf(PRINT_ALL, 'ok ');

  ppbuffer^ := ddsd.lpSurface;
  ppitch^ := ddsd.lPitch;

  for i := 0 to vid.height - 1 do
    FillChar(PByteArray(ppbuffer^)^[i * ppitch^], ppitch^, 0);

  sww_state.palettized := true;
  Result := true;
end;

(*
** DDRAW_SetPalette
**
** Sets the color table in our DIB section, and also sets the system palette
** into an identity mode if we're running in an 8-bit palettized display mode.
**
** The palette is expected to be 1024 bytes, in the format:
**
** R := offset 0
** G := offset 1
** B := offset 2
** A := offset 3
*)

procedure DDRAW_SetPalette( palette: PByteArray);
var
  palentries: array[0..255] of TPALETTEENTRY;
  i: integer;
begin

  if not (sww_state.lpddpPalette = nil) then
    exit;

  for i := 0 to 255 do
  begin
    palentries[i].peRed := palette[0];
    palentries[i].peGreen := palette[1];
    palentries[i].peBlue := palette[2];
    palentries[i].peFlags := PC_RESERVED or PC_NOCOLLAPSE;
    Inc( palette, 4 );
  end;

  if (sww_state.lpddpPalette.SetEntries(0, 0, 256, @palentries) <> DD_OK) then
    ri.Con_Printf(PRINT_ALL, 'DDRAW_SetPalette - SetEntries failed ');
end;

(*
** DDRAW_Shutdown
*)

procedure DDRAW_Shutdown;
begin
  if (sww_state.lpddsOffScreenBuffer <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...releasing offscreen buffer ');
    sww_state.lpddsOffScreenBuffer.Unlock(vid.buffer);
//    sww_state.lpddsOffScreenBuffer.Release(sww_state.lpddsOffScreenBuffer);
    sww_state.lpddsOffScreenBuffer := nil;
  end;

{$IFDEF DIRECTX_WINDOWMODE}
  if (sww_state.lpddsClipper <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...releasing clipper');
    sww_state.lpddsClipper := nil;
  end;
{$ENDIF}

  if (sww_state.lpddsBackBuffer <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...releasing back buffer ');
//    sww_state.lpddsBackBuffer.Release(sww_state.lpddsBackBuffer);
    sww_state.lpddsBackBuffer := nil;
  end;

  if (sww_state.lpddsFrontBuffer <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...releasing front buffer ');
//    sww_state.lpddsFrontBuffer.Release(sww_state.lpddsFrontBuffer);
    sww_state.lpddsFrontBuffer := nil;
  end;

  if (sww_state.lpddpPalette <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...releasing palette ');
//    sww_state.lpddpPalette.Release(sww_state.lpddpPalette);
    sww_state.lpddpPalette := nil;
  end;

  if (sww_state.lpDIRECTDraw <> nil) then
  begin
    ri.Con_Printf(PRINT_ALL, '...restoring display mode ');
    sww_state.lpDIRECTDraw.RestoreDisplayMode;
    ri.Con_Printf(PRINT_ALL, '...restoring normal coop mode ');
    sww_state.lpDIRECTDraw.SetCooperativeLevel( sww_state.h_Wnd, DDSCL_NORMAL);
    ri.Con_Printf(PRINT_ALL, '...releasing IDIRECTDraw ');
//    sww_state.lpDIRECTDraw.lpVtbl.Release(sww_state.IDIRECTDraw);
    sww_state.lpDIRECTDraw := nil;
  end;

  if (sww_state.hinstDDRAW <> 0 ) then
  begin
    ri.Con_Printf(PRINT_ALL, '...freeing library ');
    FreeLibrary(sww_state.hinstDDRAW);
    sww_state.hinstDDRAW := 0;
  end;
end;

function DDrawError(code: integer): string;
begin
  case (code) of
    DD_OK:
      result := 'DD_OK';
    DDERR_ALREADYINITIALIZED:
      result := 'DDERR_ALREADYINITIALIZED';
    DDERR_BLTFASTCANTCLIP:
      result := 'DDERR_BLTFASTCANTCLIP';
    DDERR_CANNOTATTACHSURFACE:
      result := 'DDER_CANNOTATTACHSURFACE';
    DDERR_CANNOTDETACHSURFACE:
      result := 'DDERR_CANNOTDETACHSURFACE';
    DDERR_CANTCREATEDC:
      result := 'DDERR_CANTCREATEDC';
    DDERR_CANTDUPLICATE:
      result := 'DDER_CANTDUPLICATE';
    DDERR_CLIPPERISUSINGHWND:
      result := 'DDER_CLIPPERUSINGHWND';
    DDERR_COLORKEYNOTSET:
      result := 'DDERR_COLORKEYNOTSET';
    DDERR_CURRENTLYNOTAVAIL:
      result := 'DDERR_CURRENTLYNOTAVAIL';
    DDERR_DIRECTDRAWALREADYCREATED:
      result := 'DDERR_DIRECTDRAWALREADYCREATED';
    DDERR_EXCEPTION:
      result := 'DDERR_EXCEPTION';
    DDERR_EXCLUSIVEMODEALREADYSET:
      result := 'DDERR_EXCLUSIVEMODEALREADYSET';
    DDERR_GENERIC:
      result := 'DDERR_GENERIC';
    DDERR_HEIGHTALIGN:
      result := 'DDERR_HEIGHTALIGN';
    DDERR_HWNDALREADYSET:
      result := 'DDERR_HWNDALREADYSET';
    DDERR_HWNDSUBCLASSED:
      result := 'DDERR_HWNDSUBCLASSED';
    DDERR_IMPLICITLYCREATED:
      result := 'DDERR_IMPLICITLYCREATED';
    DDERR_INCOMPATIBLEPRIMARY:
      result := 'DDERR_INCOMPATIBLEPRIMARY';
    DDERR_INVALIDCAPS:
      result := 'DDERR_INVALIDCAPS';
    DDERR_INVALIDCLIPLIST:
      result := 'DDERR_INVALIDCLIPLIST';
    DDERR_INVALIDDIRECTDRAWGUID:
      result := 'DDERR_INVALIDDIRECTDRAWGUID';
    DDERR_INVALIDMODE:
      result := 'DDERR_INVALIDMODE';
    DDERR_INVALIDOBJECT:
      result := 'DDERR_INVALIDOBJECT';
    DDERR_INVALIDPARAMS:
      result := 'DDERR_INVALIDPARAMS';
    DDERR_INVALIDPIXELFORMAT:
      result := 'DDERR_INVALIDPIXELFORMAT';
    DDERR_INVALIDPOSITION:
      result := 'DDERR_INVALIDPOSITION';
    DDERR_INVALIDRECT:
      result := 'DDERR_INVALIDRECT';
    DDERR_LOCKEDSURFACES:
      result := 'DDERR_LOCKEDSURFACES';
    DDERR_NO3D:
      result := 'DDERR_NO3D';
    DDERR_NOALPHAHW:
      result := 'DDERR_NOALPHAHW';
    DDERR_NOBLTHW:
      result := 'DDERR_NOBLTHW';
    DDERR_NOCLIPLIST:
      result := 'DDERR_NOCLIPLIST';
    DDERR_NOCLIPPERATTACHED:
      result := 'DDERR_NOCLIPPERATTACHED';
    DDERR_NOCOLORCONVHW:
      result := 'DDERR_NOCOLORCONVHW';
    DDERR_NOCOLORKEY:
      result := 'DDERR_NOCOLORKEY';
    DDERR_NOCOLORKEYHW:
      result := 'DDERR_NOCOLORKEYHW';
    DDERR_NOCOOPERATIVELEVELSET:
      result := 'DDERR_NOCOOPERATIVELEVELSET';
    DDERR_NODC:
      result := 'DDERR_NODC';
    DDERR_NODDROPSHW:
      result := 'DDERR_NODDROPSHW';
    DDERR_NODIRECTDRAWHW:
      result := 'DDERR_NODIRECTDRAWHW';
    DDERR_NOEMULATION:
      result := 'DDERR_NOEMULATION';
    DDERR_NOEXCLUSIVEMODE:
      result := 'DDERR_NOEXCLUSIVEMODE';
    DDERR_NOFLIPHW:
      result := 'DDERR_NOFLIPHW';
    DDERR_NOGDI:
      result := 'DDERR_NOGDI';
    DDERR_NOHWND:
      result := 'DDERR_NOHWND';
    DDERR_NOMIRRORHW:
      result := 'DDERR_NOMIRRORHW';
    DDERR_NOOVERLAYDEST:
      result := 'DDERR_NOOVERLAYDEST';
    DDERR_NOOVERLAYHW:
      result := 'DDERR_NOOVERLAYHW';
    DDERR_NOPALETTEATTACHED:
      result := 'DDERR_NOPALETTEATTACHED';
    DDERR_NOPALETTEHW:
      result := 'DDERR_NOPALETTEHW';
    DDERR_NORASTEROPHW:
      result :=
        'Operation could not be carried out because there is no appropriate raster op hardware present or available.\0';
    DDERR_NOROTATIONHW:
      result :=
        'Operation could not be carried out because there is no rotation hardware present or available.\0';
    DDERR_NOSTRETCHHW:
      result :=
        'Operation could not be carried out because there is no hardware support for stretching.\0';
    DDERR_NOT4BITCOLOR:
      result :=
        'DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette.\0';
    DDERR_NOT4BITCOLORINDEX:
      result :=
        'DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette.\0';
    DDERR_NOT8BITCOLOR:
      result := 'DDERR_NOT8BITCOLOR';
    DDERR_NOTAOVERLAYSURFACE:
      result :=
        'result :=ed when an overlay member is called for a non-overlay surface.\0';
    DDERR_NOTEXTUREHW:
      result :=
        'Operation could not be carried out because there is no texture mapping hardware present or available.\0';
    DDERR_NOTFLIPPABLE:
      result := 'DDERR_NOTFLIPPABLE';
    DDERR_NOTFOUND:
      result := 'DDERR_NOTFOUND';
    DDERR_NOTLOCKED:
      result := 'DDERR_NOTLOCKED';
    DDERR_NOTPALETTIZED:
      result := 'DDERR_NOTPALETTIZED';
    DDERR_NOVSYNCHW:
      result := 'DDERR_NOVSYNCHW';
    DDERR_NOZBUFFERHW:
      result :=
        'Operation could not be carried out because there is no hardware support for zbuffer blitting.\0';
    DDERR_NOZOVERLAYHW:
      result :=
        'Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays.\0';
    DDERR_OUTOFCAPS:
      result :=
        'The hardware needed for the requested operation has already been allocated.\0';
    DDERR_OUTOFMEMORY:
      result := 'DDERR_OUTOFMEMORY';
    DDERR_OUTOFVIDEOMEMORY:
      result := 'DDERR_OUTOFVIDEOMEMORY';
    DDERR_OVERLAYCANTCLIP:
      result := 'The hardware does not support clipped overlays.\0';
    DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
      result :=
        'Can only have ony color key active at one time for overlays.\0';
    DDERR_OVERLAYNOTVISIBLE:
      result :=
        'result :=ed when GetOverlayPosition is called on a hidden overlay.\0';
    DDERR_PALETTEBUSY:
      result := 'DDERR_PALETTEBUSY';
    DDERR_PRIMARYSURFACEALREADYEXISTS:
      result := 'DDERR_PRIMARYSURFACEALREADYEXISTS';
    DDERR_REGIONTOOSMALL:
      result := 'Region passed to Clipper.GetClipList is too small.\0';
    DDERR_SURFACEALREADYATTACHED:
      result := 'DDERR_SURFACEALREADYATTACHED';
    DDERR_SURFACEALREADYDEPENDENT:
      result := 'DDERR_SURFACEALREADYDEPENDENT';
    DDERR_SURFACEBUSY:
      result := 'DDERR_SURFACEBUSY';
    DDERR_SURFACEISOBSCURED:
      result := 'Access to surface refused because the surface is obscured.\0';
    DDERR_SURFACELOST:
      result := 'DDERR_SURFACELOST';
    DDERR_SURFACENOTATTACHED:
      result := 'DDERR_SURFACENOTATTACHED';
    DDERR_TOOBIGHEIGHT:
      result := 'Height requested by DirectDraw is too large.\0';
    DDERR_TOOBIGSIZE:
      result :=
        'Size requested by DirectDraw is too large, but the individual height and width are OK.\0';
    DDERR_TOOBIGWIDTH:
      result := 'Width requested by DirectDraw is too large.\0';
    DDERR_UNSUPPORTED:
      result := 'DDERR_UNSUPPORTED';
    DDERR_UNSUPPORTEDFORMAT:
      result := 'FOURCC format requested is unsupported by DirectDraw.\0';
    DDERR_UNSUPPORTEDMASK:
      result :=
        'Bitmask in the pixel format requested is unsupported by DirectDraw.\0';
    DDERR_VERTICALBLANKINPROGRESS:
      result := 'Vertical blank is in progress.\0';
    DDERR_WASSTILLDRAWING:
      result := 'DDERR_WASSTILLDRAWING';
    DDERR_WRONGMODE:
      result :=
        'This surface can not be restored because it was created in a different mode.\0';
    DDERR_XALIGN:
      result :=
        'Rectangle provided was not horizontally aligned on required boundary.\0';
  else
    result := 'UNKNOWN';
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -