Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm new to Directx and i want to render Cylinder using "D3DXCreateCylinder" function. I using Delphi Xe2 and JEDI for DirectX9.

share|improve this question

closed as not a real question by bummzack, Sean Middleditch, Josh Petrie, Byte56, John McDonald Apr 5 '13 at 17:41

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

You all are not knowing what is Delphi and Jedi, so you should not close the question. Don’t CLOSE question for some reputation only. – Gani Apr 8 '13 at 6:54
up vote 0 down vote accepted

First declare direct3D Object, RenderingDevice and Mesh as global variable. In order to use DirectX in the Delphi - Pascal, add Direct3D9, D3DX9, DXTypes in USES clause.

uses Winapi.Direct3D9, Winapi.D3DX9, Winapi.DXTypes;

Global Declaration:

   objD3D: IDirect3D9 = nil;
   dvcRender: IDirect3DDevice9 = nil;
   vbD3D: IDirect3DVertexBuffer9;
   mesh: ID3DXMesh;

Create Function for Initialization of Direct3D:

function TfrmDirectX.initD3D(hWindow: HWND): HRESULT;
   paramD3D: TD3DPresentParameters;
   Result := E_FAIL;
   objD3D := Direct3DCreate9(D3D_SDK_VERSION);
   if (objD3D = nil) then Exit;

   FillChar(paramD3D, SizeOf(paramD3D), 0);
   paramD3D.Windowed := True;
   paramD3D.SwapEffect := D3DSWAPEFFECT_DISCARD;
   paramD3D.BackBufferFormat := D3DFMT_UNKNOWN;
   paramD3D.EnableAutoDepthStencil := True;
   paramD3D.AutoDepthStencilFormat := D3DFMT_D16;
   Result := objD3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWindow,
                             @paramD3D, dvcRender);
   if Failed(Result) then Exit;
   dvcRender.SetRenderState(D3DRS_ZENABLE, iTrue);
   Result := S_OK;

I will render 3D on TPanel component of the Delphi. So i passing Handle of TPanel Component as parameter. Another Function to setup a Matrix:

procedure TfrmDirectX.setupMatrices();
   vEyePt, vLookatPt, vUpVec: TD3DVector;
   matView: TD3DMatrix;
   matProj: TD3DMatrix;
   vEyePt:= D3DXVector3(spnCX.Value, spnCY.Value, spnCZ.Value);
   vLookatPt:= D3DXVector3(spnLX.Value, spnLY.Value, spnLZ.Value);
   vUpVec:= D3DXVector3(0.0, 1.0, 0.0);
   D3DXMatrixLookAtLH(matView, vEyePt, vLookatPt, vUpVec);
   dvcRender.SetTransform(D3DTS_VIEW, matView);

   D3DXMatrixPerspectiveFovLH(matProj, D3DX_PI/4, 1.0, 1.0, 100.0);
   dvcRender.SetTransform(D3DTS_PROJECTION, matProj);

And Last procedure for Rendering:

procedure TfrmDirectX.render();
   // Call function to create Cylinder and return Mesh.
   D3DXCreateCylinder(dvcRender, 1, 1, 2, 8, 8, mesh, nil);
   dvcRender.Clear(0, nil, D3DCLEAR_TARGET OR D3DCLEAR_ZBUFFER,
              D3DCOLOR_XRGB(255, 0, 0), 1.0, 0);
   if Succeeded(dvcRender.BeginScene) then begin
   dvcRender.Present(nil, nil, 0, nil);

D3DXCreateCylinder Function

Uses a left-handed coordinate system to create a mesh containing a cylinder.


FLOAT Radius1,
FLOAT Radius2,
FLOAT Length,
UINT Slices,
UINT Stacks,
LPD3DXBUFFER *ppAdjacency


pDevice [in] Pointer to an IDirect3DDevice9 interface, representing the device associated with the created cylinder mesh.

Radius1 [in] Radius at the negative Z end. Value should be greater than or equal to 0.0f.

Radius2 [in] Radius at the positive Z end. Value should be greater than or equal to 0.0f.

Length [in] Length of the cylinder along the z-axis.

Slices [in] Number of slices about the main axis.

Stacks [in] Number of stacks along the main axis.

ppMesh [out] Address of a pointer to the output shape, an ID3DXMesh interface.

ppAdjacency [out] Address of a pointer to an ID3DXBuffer interface. When the method returns, this parameter is filled with an array of three DWORDs per face that specify the three neighbors for each face in the mesh. NULL can be specified.

Return Value: If the function succeeds, the return value is D3D_OK.

After Creating All the Function and Procedure first call InitD3D(hWindow) and then call Render().

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.