DirectX Delphi -



: (JINX)
Delphi

, .
. . :-) , :

  • blitting - blit "bit block transfer" .
  • flip
  • Surface ""
DirectDraw Delphi. , DirectX DirectDraw , , - DirectX ( Microsoft , , ), - DirectX , - DelphiX Hiroyuki Hori , , Borland' DirectX, "JEDI" (http://www.delphi-jedi.org/DelphiGraphics/).

( ) COM- (- COM- Interface, ).

DirectDraw DirectX, , , .

, DirectDraw ( ). DirectDraw hardware abstraction layer (HAL) ( ). hardware emulation layer (HEL) ( ) , ( ). , , hardware blitting DirectDraw HAL HEL ( ). SDK DirectDraw, GDI, HAL HEL.

DirectDraw GUI. DirectDraw , (device context, Windows-), GDI (, TextOut)

DirectDraw Windows . ( ).

.

, ( ) ( 6404808). , , .

(palettized) (non-palettized). , 8- , , 256 . (8 256 , 16 65535 ..)
IDirectDraw4::EnumDisplayModes.

:

{ DirectX headers JEDI}


function MyEnumFunction(const lpDDSurfaceDesc: TDDSurfaceDesc; lpContext:
Pointer): HResult; stdcall
var
SMode: string;
begin
SMode := IntToStr(lpDDSurfaceDesc.dwWidth) + ' X ';
SMode := SMode + IntToStr(lpDDSurfaceDesc.dwHeight) + ' X ';
SMode := SMode + IntToStr(lpDDSurfaceDesc.ddpfPixelFormat.dwRGBBitCount);
Form1.ListBox1.Items.Append(SMode);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
DD: IDirectDraw;
hr: HRESULT;
begin
hr := DirectDrawCreate(nil, DD, nil);
if (hr = DD_OK) then
begin
ListBox1.Clear;
DD.EnumDisplayModes(0, nil, nil, MyEnumFunction);
end;
end;

{ DelphiX}


procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
SMode: string;
begin
ListBox1.Clear;
for i := 0 to DXDraw1.Display.Count - 1 do
begin
SMode := IntToStr(DXDraw1.Display.Modes[i].Width) + ' X ';
SMode := SMode + IntToStr(DXDraw1.Display.Modes[i].Height) + ' X ';
SMode := SMode + IntToStr(DXDraw1.Display.Modes[i].BitCount);
ListBox1.Items.Append(SMode);
end;
end;

Hiroyuki Hori DelphiX? :-) , , DelphiX ( ). , DirectDraw JEDI DelphiX.

IDirectDraw4::SetDisplayMode.

640x480x8 { DirectX headers JEDI}


procedure TForm1.Button1Click(Sender: TObject);
var
DD: IDirectDraw;
DD4: IDirectDraw4;
hr: HRESULT;
begin
hr := DirectDrawCreate(nil, DD, nil);
if (hr = DD_OK) then
begin
DD.QueryInterface(IID_IDirectDraw4, DD4);
DD4.SetCooperativeLevel(Self.Handle, DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN);
DD4.SetDisplayMode(640, 480, 8, 0, 0);
//DD4.RestoreDisplayMode;
end;
end;

{ DelphiX}


procedure TForm1.Button1Click(Sender: TObject);
begin
DXDraw1.Display.Width := 640;
DXDraw1.Display.Height := 480;
DXDraw1.Display.BitCount := 8;
DXDraw1.Options := DXDraw1.Options + [doFullScreen];
DXDraw1.Initialize;
end;

, SetDisplayMode IDirectDraw4::RestoreDisplayMode. , .

JEDI- , IDirectDraw IDirectDraw4 QueryInterface IDirectDraw (IDirectDraw ( ) DirectDraw; IDirectDraw4 DirectX 6). IDirectDraw , , DirectDraw DirectDraw (Surface', ..). IDirectDraw , 1- :-) ( COM- DirectDraw GUID ). DirectDraw .

Hori' DelphiX DXDraw , create release. :-)

, .

Surface'. ( , ). Surface ( DirectDrawSurface) , . ( Surface' ) Surface , , ( AGP) ( ). DirectDrawSurface ( ) Surface' (blitting), Surface' fliping, .

? Surface' . - Surface' - . Surface' , . Surface 640X480X8 640 . 640 ( , ). Pitch . Pitch :

Front-bufera - , ( ) ( ). Pitch, .

, Front-bufer' , Surface, PrimarySurface, - Surface, Surface'.

Surface' flip-. flip Surface' Surface, , , flip' .. . Surface' flip' . flip' Surface' , flip . ( Surface', HEL ). C flip , - , BackBuffer'e - , flip, - BackBuffer'e, flip .. .

Flip- Surface', IDirectDrawSurface4.

( Surface' FPrimarySurface FbackSurface)
( -, 169K)
{ JEDI DirectX}


uses ... DDraw;
var
hr: HRESULT;
SurfaceDesc: TDDSurfaceDesc2;
DDSCaps: TDDSCAPS2;
DD: IDirectDraw;
begin
///  ..., 
hr := DirectDrawCreate(nil, DD, nil); /// DirectDraw
if (hr = DD_OK) then
begin
//   IDirectDraw4
DD.QueryInterface(IID_IDirectDraw4, FDirectDraw);
//  DirecDraw1    
DD := nil;
//       
hr := FDirectDraw.SetCooperativeLevel(Handle, DDSCL_EXCLUSIVE or
DDSCL_FULLSCREEN);
if (hr = DD_OK) then
begin
hr := FDirectDraw.SetDisplayMode(640, 480, 8, 0, 0);
///   640X480X8
if (hr = DD_OK) then
begin
//   surface   back buffer'
FillChar(SurfaceDesc, SizeOf(SurfaceDesc), 0);
SurfaceDesc.dwSize := SizeOf(SurfaceDesc);
///    back buffer'
SurfaceDesc.dwFlags := DDSD_CAPS or DDSD_BACKBUFFERCOUNT;
////    Surface
SurfaceDesc.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE
or DDSCAPS_FLIP ////  Flip-
or DDSCAPS_COMPLEX; ////      Surface'
////     - 1
SurfaceDesc.dwBackBufferCount := 1;
/// ,  Surface'     FPrimarySurface
hr := FDirectDraw.CreateSurface(SurfaceDesc, FPrimarySurface, nil);
if (hr = DD_OK) then
begin
//      back buffer (-  Surface'a )
ddscaps.dwCaps := DDSCAPS_BACKBUFFER;
///    FBackSurface
hr := FPrimarySurface.GetAttachedSurface(ddscaps, FBackSurface);
if (hr = DD_OK) then
begin
{  - Surface'  - }
exit;
end;
end;
end;
end;
end;
{-   -     }
MessageBox(Self.Handle, PChar('   DirectDraw! ' +
ErrorString(Hr)), 'ERROR', MB_OK);
Close();
end;

Surface'. - . .
Surface' Lock TDDSURFACEDESC2, .

Surface' , .


var
i, j: integer;
AdresVideo: PByteArray;
SurfaceDesc: TDDSURFACEDESC2;
HR: HResult;
begin
//    
FillChar(SurfaceDesc, SizeOf(SurfaceDesc), 0);
SurfaceDesc.dwSize := SizeOf(SurfaceDesc);
HR := FPrimarySurface.Lock(nil, SurfaceDesc, {DDLOCK_WAIT or}
DDLOCK_SURFACEMEMORYPTR, 0);
if (HR = DD_OK) then
begin
AdresVideo := SurfaceDesc.lpSurface;
for i := 0 to SurfaceDesc.dwHeight - 1 do
begin
for j := 0 to SurfaceDesc.dwWidth - 1 do
begin
AdresVideo[j + i * SurfaceDesc.lPitch] := $FF;
end;
end;
FPrimarySurface.Unlock(nil);
end;
end;

- , Pitch. Surface'a Surface IDirectDrawSurface4.Blt, DDBLT_COLORFILL. Surface GDI TextOut' :


var
DC: HDC;
begin
if (FPrimarySurface.GetDC(DC) = DD_OK) then
begin
{   1- surface,  GDI- TextOut}
SetBkColor(DC, RGB(255, 255, 255));
SetTextColor(DC, RGB(255, 0, 0));
TextOut(DC, 10, 20, '  ', Length('  '));
FPrimarySurface.ReleaseDC(DC);
end;
end;

LOCK UNLOCK, GetDC ReleaseDC ( ). - , , ( Kernel-debuger').

flip' Surface'. Surface

hr := FPrimarySurface.Flip(nil, 0);
Flip flip' , , :
  • DDERR_NOEXCLUSIVEMODE , . , flip' , - , Alt-TAB. , , , Sleep(0) WaitMessage.
  • DDERR_SURFACELOST Surface' , , Surface' , IDirectDraw4.RestoreAllSurfaces, .
DirectDraw JEDI. Hori' DelphiX c Surface' TDXDraw.DDraw.SurfaceCount, TDXDraw.DDraw.Surfaces, TDXDraw.Flip .

, ( , , , , , ) :-).
. - .

[email protected] [email protected] ( - ) :-).


: DXInput »»