Pb avec direct x, y'a pas d'erreur mais ça marche pas ! :-(
dweis
Messages postés1Date d'inscriptionmardi 31 décembre 2002StatutMembreDernière intervention31 décembre 2002
-
31 déc. 2002 à 17:19
cs_kokonut
Messages postés17Date d'inscriptiondimanche 16 mars 2003StatutMembreDernière intervention27 mai 2005
-
17 juin 2003 à 17:17
j'essaie de faire un truc assez simple mais j'ai du mal : je veux juste créer une fenetre et initialiser directx.
je me suis inspiré de ce code http://www.andypike.com/tutorials/directx8/001.asp et j'ai essayé de le traduire en delphi mais ça marche pas. ça me donne pas d'erreur non plus donc j'y pige rien :-(
merci bcp si qqun peut prendre 5mn pour regarder.
mon code :
program Project1;
{$APPTYPE CONSOLE}
uses
Windows,
Messages,
DXUtil,
{$I UseD3D8.inc};
var
g_pD3D : IDIRECT3D8;
g_pD3DDevice : IDIRECT3DDEVICE8;
function InitialiseD3D(hWnd : HWND) : HRESULT;
var
d3ddm : D3DDISPLAYMODE ;
d3dpp : D3DPRESENT_PARAMETERS ;
begin
//First of all, create the main D3D object. If it is created successfully we
//should get a pointer to an IDirect3D8 interface.
g_pD3D := Direct3DCreate8(D3D_SDK_VERSION);
if(g_pD3D = nil) then Result := E_FAIL;
//Get the current display mode
if(FAILED(g_pD3D.GetAdapterDisplayMode(D3DADAPTER_DEFAULT, d3ddm))) then Result := E_FAIL;
//Create a structure to hold the settings for our device
ZeroMemory(@d3dpp, sizeof(d3dpp));
//Fill the structure.
//We want our program to be windowed, and set the back buffer to a format
//that matches our current display mode
d3dpp.Windowed := TRUE;
d3dpp.SwapEffect := D3DSWAPEFFECT_COPY_VSYNC;
d3dpp.BackBufferFormat := d3ddm.Format;
//Create a Direct3D device.
if(FAILED(g_pD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, d3dpp, g_pD3DDevice))) then Result := E_FAIL;
Result := S_OK;
end;
procedure Render();
begin
if(g_pD3DDevice = nil) then exit;
//Clear the backbuffer to a green color
g_pD3DDevice.Clear(0, nil, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0, 0);
//Begin the scene
g_pD3DDevice.BeginScene();
//Rendering of our game objects will go here
//End the scene
g_pD3DDevice.EndScene();
//Filp the back and front buffers so that whatever has been rendered on the back buffer
//will now be visible on screen (front buffer).
g_pD3DDevice.Present(nil, nil, 0, nil);
end;
procedure CleanUp();
begin
if(g_pD3DDevice <> nil) then
begin
g_pD3DDevice._Release();
g_pD3DDevice := nil;
end;
if(g_pD3D <> nil) then
begin
g_pD3D._Release();
g_pD3D := nil;
end;
end;
procedure GameLoop();
var
msg : TMSG;
fMessage : bool;
begin
//Enter the game loop
PeekMessage(msg, 0, 0, 0, PM_NOREMOVE);
while(msg.message <> WM_QUIT) do
begin
fMessage := PeekMessage(msg, 0, 0, 0, PM_REMOVE);
if(fMessage) then
begin
//Process message
TranslateMessage(msg);
DispatchMessage(msg);
end
else
begin
//No message to process, so render the current scene
Render();
end;
end;
end;
function WinProc(hWnd : HWND; msg : UINT; wParam : WPARAM; lParam : LPARAM) : LRESULT;
begin
case msg of
WM_DESTROY:
begin
PostQuitMessage(0);
Result:= 0;
exit;
end;
WM_KEYUP:
begin
case (wParam) of
VK_ESCAPE:
begin
//User has pressed the escape key, so quit
DestroyWindow(hWnd);
Result:= 0;
exit;
end;
end;
exit;
end;
end;
Result := DefWindowProc(hWnd, msg, wParam, lParam);
end;
function WinMain(hInstance : HINST; hPrevInstance : HINST;
lpCmdLine : PChar; nCmdShow : Integer) : integer; stdcall;
var
wc: TWndClass;
h_Wnd : HWND;
begin
//Register the window class
with wc do // Set up the window class
begin
style := CS_CLASSDC;
lpfnWndProc := @WinProc;
hInstance := wc.hInstance;
hCursor := LoadCursor(0, IDC_ARROW);
lpszClassName := 'OpenGL';
end;
RegisterClass(wc);
//Create the application's window
h_Wnd := CreateWindow('DX Project 1', 'www.andypike.com: Tutorial 1',
WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
GetDesktopWindow(), 0, wc.hInstance, nil);
//Initialize Direct3D
if(SUCCEEDED(InitialiseD3D(h_Wnd))) then
begin
//Show our window
ShowWindow(h_Wnd, SW_SHOWDEFAULT);
UpdateWindow(h_Wnd);
//Start game running: Enter the game loop
GameLoop();
end;
CleanUp();
UnregisterClass('DX Project 1', wc.hInstance);
Result:= 0;
end;
begin
WinMain( hInstance, hPrevInst, CmdLine, CmdShow );
end.
cs_kokonut
Messages postés17Date d'inscriptiondimanche 16 mars 2003StatutMembreDernière intervention27 mai 2005 17 juin 2003 à 17:17
C'est pas compliqué, dans ces lignes :
//Begin the scene
g_pD3DDevice.BeginScene();
//Rendering of our game objects will go here
//End the scene
g_pD3DDevice.EndScene();
comme il est écrit, le code du rendu du jeu doit être entré entre BeginScene et EndScene donc s'il n'y a aucune procédure qui va effectuer le rendu, il n'y aura rien d'afficher.
Je n'ai pas eu le temps de regarder plus en détail car je suis au travail ... lol ;) ... donc je pense que le "bug" vient de là.
Essaye ce site ou sinon passe me voir sur mon site ici . Il n'est en ligne que depuis peu et l'objectif est de recueillir d'abord les demandes des utilisateurs avant de lancer un site plus complet.