Clootie graphics pages

Home | Articles | Projects | Delphi | C++Builder | Free Pascal | TMT pascal | Links | About
 

Delphi resources - Custom DirectX examples

  
Info field below contains Name / Date / Size with links to file and description field contains some notes about sample and screenshot from run-time.

Custom DirectX examples

Notes: All examples can be compiled either in Delphi or C++ Builder. Go to how to compile page for additional details. You will need Direct3D headers and - for some examples - D3DFramework adaptation from DirectX 8 SDK. All these files can be found at either DirectX 8.0 or DirectX 8.1 download pages. To determine if example used D3DFramework you can look at uses clause of units for any of these files: D3DApp, D3DFont, D3DUtils, D3DFile.

Direct3D 9.0 examples

Info Description
Templates.zip

26-Jan-2004
130Kb
TemplateVCL image Templates - contains two Direct3D template projects - you can use these projects as starting point for you own Direct3D applications. There are two templates as one is using Win32 API only and other is using VCL library. Both projects show "The Teapot" model and allows to resize window and go to fullscreen mode.

Download source with EXE.
VCLfullscreenD3D.zip

26-Jan-2004
245Kb
VCLfullscreenD3D image VCLfullscreenD3D - this sample shows how to use Delphi VCL dialogs in Direct3D 9.0 fullscreen mode.

Download source with EXE.
MeshHierarchy.zip

30-Apr-2003
326Kb
MeshHierarchy image MeshHierarchy - loading and saving hierarchical meshes - even with custom data

This sample shows how to load and save hierarchical meshes using D3DX9 functionality. Sample can load and save not only "standart" data but also custom (user supplied) data.
Sample was used as testbed for testing correctness of D3DX9 header conversion for support of animated / hierarchical meshes. But final decision was made what there are definetly some bugs hinded inside D3DX9.0 implementation. Or I'm really mad - in that case mail me.
Demonstrated bits: inheritage of TD3DXFrame, ID3DXAllocateHierarchy, ID3DXLoadUserData, ID3DXSaveUserData and usage of D3DXLoadMeshHierarchyFromX, D3DXSaveMeshHierarchyToFile.

Download source with EXE.
Note: to run this sample you will need any skinnedmesh - like tiny.x supplied with DirectX SDK. You can find copy of it included in SkinnedMesh DirectX9 SDK sample.

Direct3D 8.x examples

Info Description
ParticleSystem1.zip

16-Dec-2002
54Kb
ParticleSystem1 image ParticleSystem1 - unidirectional generator sample

Main idea of this sample was to demonstrate right and wrong ways of generating uniform distribution of unit length vectors - so end-points formed by these vectors forms sphere surface. But in process of providing visual feedback for user some other interesting techniques appeared.
I try to list them below (in advanced - beginner order):
  1. Vertex shader assembler code for particle systems with particle size calculation.
  2. Stencil buffer / matrix operations for mirror rendering.
  3. Various frame buffer blending modes.
  4. Rendering graphs with with transformed and lit vertices.
  5. Usage of DrawPrimitiveUP D3DDevice method (for graph rendering).
Download source with EXE.
DebugRuntime.zip

27-Nov-2002
10Kb
DebugRuntime sample

This simple application detect is Direct3D8 or Direct3D9 debug runtime activated. It check registry key "HKEY_LOCAL_MACHINE\SOFTWARE\ Microsoft\Direct3D\LoadDebugRuntime" for what.

Download source with EXE.
GifBlender2.zip

03-Oct-2002
119Kb
GifBlender image GifBlender2 sample

This sample is sequel to "GifBlender" sample, below you can find list of changes:
  1. GIF's are rendered by blending two nearest frames of GIF animation on multitexture capable hardware
  2. 3 different texture pipeline setups tested for best quality rendering result: (a) simplest NVIDIA TNT class, (b) Matrox G400 class, (c) NVIDIA GeForce, ATi Radeon - 3 stage setup.
  3. GIF handling/rendering moved to separate portable between applications Delphi class
  4. Usage of Ander's Melander TGifImage component is reduced to loading stage - animation frames loaded to Direct3D textures, timing info retrieved to internal data structure. All rendering and timing after that is handled by TD3D8GifImage class.
This sample as "GifBlender" also uses Ander Melander's TGIFImage component. You can find Delphi6+ compatible version of TGifImage component here on mine site.

Download source with EXE.
GifBlender.zip

03-Oct-2002
113Kb
GifBlender sample

GifBlender image This simple sample show how to draw animated GIF on Direct3D texture using Ander Melander's TGIFImage component. You can find Delphi6+ compatible version of TGifImage component here on mine site.

Download source with EXE.
WVPick.zip

02-Sep-2002
93Kb
WVPick sample

Pick image This sample is based on MS DirectX SDK Pick sample demostrating how to "Pick" what triangle is pointed by mouse pointer on rotating object. This sample goes further so object is rotated by both WORLD and VIEW matrices (in original sample object was rotating only in VIEW space) AND user can move object in view space by dragging it with right mouse button.

This sample requires DirectX 8.1 headers and libs.

Download source with EXE.
DepthColoring.zip

14-Sep-2002
72Kb
DepthColoring sample

Direct3D DepthColoring sample demonstrate how to convert depth information to color during vertex processing by various techniques.
    DepthColoring image This effect generated in demo using one of 3 different methods:
  1. Good old texture matrix transformation using DX7 style fixed function T&L and accessing small pre-rendered texture while pixel shading.
  2. Modern style DX8 VertexShader version of first method - 40% faster on GF3 on complex meshes. Also accesses prerendered texture later.
  3. Calculating color (hue channel of HSL color model) completely in vertex shader. Pros: no texture needed - ouputs standart diffuse color; Cons: more complex calculations required - less vertex processing speed.
So, general recomendations: on hardware capable of VS use (2) else (1), if you need many textures when (3) may be win for your setup. Methods can be switched in runtime.

This sample requires DirectX 8.1 headers and libs.

Download source with EXE.
TextDot3.zip

29-May-2002
54Kb
DotProduct Bumpmapped Font rendering class

DotProduct text image This sample requires DirectX 8.1 or higher.


Direct3D sample for DirectX 8.1 demostrating how to create and render Dot product (Dot3) bumpmapped / modulated font. Font normal map generated with D3DX8.1 function D3DXComputeNormalMap which itself requires height map. So height map is generated from font bitmap by averaging intensivity of 3x3 square of pixels.
Lighting is controlled by moving mouse cursor. Different blending modes can be switched at runtime.

Download source with EXE.
XFileSmooth.zip

11-Apr-2002
107Kb
Processing X-files with Direct3DX 8.x

In previous sample (generating X-files inside your program) "human face" is looking unnatural - like it's brushed out of stone. After some investigation I've discovered what normals in this model were calculated against single triangles and not smoothed over the face. Probably it was modeller intention, but I decided to correct this.
Generate X-File image So this sample shows how to use D3DXComputeNormals and D3DXWeldVertices functions of D3DX8 library to process meshes. On picture you can see (from left to right): original mesh, after D3DXComputeNormals and after D3DXWeldVertices.

Sample allows you modify input parameters to processing functions in realtime, see mesh statistics after processing, apply normal lighting or environment mapping on meshes, visualize mesh normals (right "face" on picture) and save processed meshes to disk.
Sample comes in two compiled versions: against Direct3DX 8.0 and against Direct3DX 8.1. So you can see difference between different versions (and it exists - DirectX 8.1 rocks).

Download source with EXE.
GenXFile.zip

08-Apr-2002
67Kb
Generate X-File inside your program

Generate X-File image Sample demonstrate how to fill ID3DXMesh object from D3DX8 helper classes with your custom data and save final mesh to disk in either binary or text format. As user data face_data.pas was taken, containing data in pascal arrays from Jan Horm site. After generating files in current directory sample loads generated text format x-file "FaceText.x" and display it on screen.

Download source with EXE.
NitroFont.zip

19-Mar-2002
80Kb
Yet another bitmap font format / now with alpha

NitroFont image 1 These two samples demonstrate rendering of bitmap font format originally introduced by Nitro in FontStudio font editor and demonstrated in OpenGL FontTest application. Pros of font format: image with alpha channel, letter positions are stored in font file itself; cons: big file size, FontStudio generates monospace fonts.

NitroFont image 2 As shown in right picture DirectX font renderer class can be used to repeat all features of original OpenGL demo.
Font renderer is realized as class with functionality equivalent to CD3DFont from MS DirectX SDK samples, so in addition to Nitro way of rendering text you can also draw text scaled to window dimentions, pure 2D font (with positions pointed in 2D viewport window) and "pure" 3D rendering. This is demostrated in other sample - slightly modified Text3D sample from MS DirectX 8.0 SDK - shown on left.

Note: If you ever wandered how to use memory mapped files - you may look in NitroFnt.pas font loading routine.
Font renderer class is DirectX 8.0 and DirectX 8.1 compatible.

Download EXE's with source.
BitmapFont.zip

11-Nov-2001
19Kb
Rendering text with bitmap font (loaded from disk)

BitmapFont image This example demonstrates use of TD3DTextureFont class which has syntax very close to CD3DFont from DirectX 8 SDK samples framework, but instead of GDI fonts uses monospace bitmap based font. Sample itself is modified version if Text3D DirectX SDK sample - this can really help you to switch using it from CD3DFont class.
DirectX 8.0 and DirectX 8.1 compatible.

Download it.

DirectShow examples

Info Description
DMOTexture3D.zip

14-May-2002
259Kb
DMO Filters in Delphi / Direct3D 8.x and DirectShow integration

Updated (May-2002). Changed filter implementation, so now it can play just every video file (supported by DirectShow), not limited to plain AVI files. Also possibility to open another video file was added.

DMOTexture3D image Example is actually not DirectShow, but fusion of DirectShow/Direct3D8.
This sample shows how to seamlessly integrate DirectShow and Direct3D 8.x in one package. DirectShow interfaces supplied with DirectX 8.1 are not compatible with Direct3D8. This is known problem and promized to change with DirectX 9, but now we should manually convert DirectShow resources to Direct3D 8. This example show how to convert video clip frame data to Direct3D8 texture. So we could do any transformations assosiated with 3D graphics on video clip.

Second thing to note about this example: it uses DMO filter implemented in Delphi (DMO - DirectX Media Objects). DMO filter implementation is based on helper class from DMOimpl C++ code in DirectX8 SDK (included in DirectShow.pas). Example now can register / unregister DMO filter itself.

And yet another side of example: it shows how to implement some cool 2D/3D transition effects using destination alpha in backbuffer (note: destination alpha can be unsupported on some video cards). To see this examle should run in 32bit - truecolor windowed display mode. Tested on GeForce2MX, should work on any NVIDIA GeForce X and ATi Radeon XXXX series of cards.

Example already includes compiled EXE and DLL filter library files. This sample requries DirectX 8.1 to run. Also sample uses 'skiing.avi' from DirectX SDK (7 - 8.1), so if you do not have SDK installed either supply other video file or download it. Also D3DX8 wrapper DLL for DirectX 8.1 is required (d3dx81ab.dll), as for all Direct3D 8.1 examples.

Download source with EXE and filter DLL.


Please inform me of any grammar or general errors, contained on these pages, Alexey Barkovoy
Last updated: 26-Jan-2004