Building Direct3D Programs

We also use fg_ddsetup() to create Direct3D programs, just as we do for full screen DirectDraw programs. For Direct3D programs, we must specify FG_DX_FLIP to use DirectDraw page flipping. Fastgraph does not support DirectDraw blitting in Direct3D programs.

Programs linked with Fastgraph's DirectX libraries can use either Direct3D or Fastgraph's own rendering for their 3D operations. There are four additional fg_ddsetup() flags used with Direct3D programs that control what type of 3D rendering a DirectX application will use, and if we will be using a Direct3D z-buffer. The complete list of fg_ddsetup() flags is shown here:

Flag

Meaning

FG_DX_BLIT

Use DirectDraw blitting (default)

FG_DX_FLIP

Use DirectDraw page flipping (required for Direct3D)

FG_DX_RENDER_FG

Use Fastgraph rendering for 3D functions (default)

FG_DX_RENDER_SW

Use Direct3D software rendering if available

FG_DX_RENDER_HW

Use Direct3D hardware acceleration if available

FG_DX_ZBUFFER

Create a Direct3D z-buffer

FG_DX_TCDEPTH

Use specified true color bit depth only

The FG_DX_RENDER_xx flags define what types of 3D rendering a DirectX program can use. If FG_DX_RENDER_HW is specified but FG_DX_RENDER_SW is not, Fastgraph will try to use Direct3D hardware acceleration for 3D operations but use Fastgraph's 3D rendering if Direct3D hardware support is not available. Similarly, if FG_DX_RENDER_SW is specified but FG_DX_RENDER_HW is not, Fastgraph will try to use Direct3D software rendering but use Fastgraph's 3D rendering if Direct3D is not available. If both FG_DX_RENDER_HW and FG_DX_RENDER_SW are specified, Fastgraph will first try to use Direct3D hardware acceleration, then Direct3D software rendering, and finally Fastgraph's 3D rendering. Note that Fastgraph's 3D rendering will be used whenever all requested Direct3D methods fail, so we do not need to specify FG_DX_RENDER_FG, but this flag is provided for clarity. Here are four example fg_ddsetup() calls that initialize Direct3D:

C/C++ and Delphi:

fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_FLIP);
fg_ddsetup(640,480,16,FG_DX_RENDER_SW+FG_DX_FLIP);
fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_RENDER_SW+FG_DX_FLIP);
fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_ZBUFFER+FG_DX_FLIP);

Visual Basic:

Call fg_ddsetup(640, 480, 16, FG_DX_RENDER_HW + FG_DX_FLIP)
Call fg_ddsetup(640, 480, 16, FG_DX_RENDER_SW + FG_DX_FLIP)
Call fg_ddsetup(640, 480, 16,
                FG_DX_RENDER_HW + FG_DX_RENDER_SW + FG_DX_FLIP)
Call fg_ddsetup(640, 480, 16,
                FG_DX_RENDER_HW + FG_DX_ZBUFFER + FG_DX_FLIP)

The first call makes Fastgraph use Direct3D hardware acceleration if available, and if not, defaults to Fastgraph's 3D rendering. The second call is similar but checks for Direct3D software rendering instead of hardware acceleration. The third call uses Direct3D hardware acceleration if available, then checks for Direct3D software rendering, and finally defaults to Fastgraph's 3D rendering if Direct3D is not available. The fourth call is like the first, but it also creates a Direct3D z-buffer.

To use Direct3D in a Fastgraph application, it must be a full screen DirectDraw program with the following properties:

  • Direct3D programs must use DirectDraw page flipping. Fastgraph does not support DirectDraw blitting for Direct3D, or windowed Direct3D applications.

  • Fastgraph will only use Direct3D when drawing to the primary surface's back buffer (the back buffer is created in fg_vbinit() and uses virtual buffer handle 0). You can still create and access other virtual buffers in Direct3D programs, but Fastgraph will use its own 3D rendering when drawing to these buffers.

  • Direct3D programs must use a high color or true color DirectDraw display mode. Fastgraph does not support 256-color Direct3D programs.

  • All 3D polygon-drawing functions have a maximum of 320 vertices per polygon (for fg_polyline(), the maximum is 319 vertices). Polygons with more than 320 vertices must be split into smaller polygons.

The above list does not apply to DirectDraw programs created with Fastgraph, or to programs linked with Fastgraph's native libraries. Further, the fg_polyedge() and fg_tmspan() functions have no effect when used in Direct3D programs.

In Fastgraph's DirectX libraries, fg_vbinit() returns -1 if DirectX was not initialized successfully (which probably means DirectX isn't available on that system). If the DirectX initialization was successful, the return value indicates what type of 3D rendering Fastgraph will use in that program. In this case, the possible fg_vbinit() return values are 0 if the program is using Fastgraph's own 3D rendering, 1 for Direct3D software rendering, or 2 for Direct3D hardware acceleration. For example, here's how you could require a Fastgraph program to use Direct3D hardware acceleration:

C/C++:

fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_FLIP);
   .
   .
   .
Status = fg_vbinit();
if (Status != 2)
{
   MessageBox(hWnd,"Direct3D hardware required.","Error",MB_OK);
   DestroyWindow(hWnd);
   return 0;
}

C++Builder:

fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_FLIP);
   .
   .
   .
Status = fg_vbinit();
if (Status != 2)
{
   MessageDlg("Direct3D hardware required.",mtError,
      TMsgDlgButtons()<

Delphi:

fg_ddsetup(640,480,16,FG_DX_RENDER_HW+FG_DX_FLIP);
   .
   .
   .
Status := fg_vbinit;
if Status <> 2 then
begin
  MessageDlg('Direct3D hardware required.',mtError,[mbOK],0);
  Close;
  Exit;
end;

Visual Basic:

Call fg_ddsetup(640, 480, 16, FG_DX_RENDER_HW + FG_DX_FLIP)
   .
   .
   .
Status = fg_vbinit()
If Status <> 2 Then
   Call MsgBox("Direct3D hardware required.", vbCritical, "Error")
   Unload Me
   Exit Sub
End If

After a DirectX program calls fg_vbinit(), the fg_ddusage() function will return the same value fg_vbinit() did. The fg_ddusage() function has no parameters and has the same possible return values as fg_vbinit().

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.