B3DSDK with sources

Blitz3D SDK Forums/Blitz3D SDK Programming/B3DSDK with sources

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

@DGuy

Here is the code for DLL, I used Delphi since well its quick easy DLL and I had it handy since I am using Delphi with the SDK.

Easy port to C++ though. Note I translated the complex HRESULTS to simple constants to pass back to Blitz.

{$I DirectX.Inc}

library b3dfix;


uses
  DirectDraw,
  Direct3d,
  SysUtils,
  Classes;

{$R *.RES}
const
  INVALIDOBJECT = -1;
  EXCLUSIVEMODEALREADYSET = -2;
  NOEXCLUSIVEMODE = -3;
  WRONGMODE = -4;

function TestCooperativeLevel(directdraw7:IDirectDraw7) : Integer; stdcall;
begin
  Result := $FF;
  if directdraw7<>nil then
  begin
    case directdraw7.TestCooperativeLevel of
     0: Result := 0;
     DDERR_INVALIDOBJECT : Result := INVALIDOBJECT;
     DDERR_EXCLUSIVEMODEALREADYSET:Result := EXCLUSIVEMODEALREADYSET;
     DDERR_NOEXCLUSIVEMODE:Result := NOEXCLUSIVEMODE;
     DDERR_WRONGMODE:Result := WRONGMODE;
    end
  end;
end;

exports
  TestCooperativeLevel;

begin
end.



Now here is sample in Blitz3d since I am waiting for SystemProperty added to SDK.

Const INVALIDOBJECT = -1
Const EXCLUSIVEMODEALREADYSET = -2
Const NOEXCLUSIVEMODE = -3
Const WRONGMODE = -4
Global Camera
Global light
Global cone
Global DD7
Global pitch#,yaw#,roll#



Function CreateGraphics()
  EndGraphics
  Graphics3D 800,600,0,2
  dd7=SystemProperty("DirectDraw7") 
  DebugLog "CreateGraphics"
End Function


Function CreateScene()
  camera=CreateCamera()
  light=CreateLight()
  cone=CreateCone( 32 )
  PositionEntity cone,0,0,5
End Function

Function SaveScene()
End Function

Function RestoreScene()
  CreateScene()
  RotateEntity cone,pitch#,yaw#,roll#
End Function

Function UpdateScene()
   If KeyDown( 208 )=True Then pitch#=pitch#-1
   If KeyDown( 200 )=True Then pitch#=pitch#+1
   If KeyDown( 203 )=True Then yaw#=yaw#-1
   If KeyDown( 205 )=True Then yaw#=yaw#+1
   If KeyDown( 45 )=True Then roll#=roll#-1
   If KeyDown( 44 )=True Then roll#=roll#+1
   RotateEntity cone,pitch#,yaw#,roll#
End Function

Function RenderScene()
  hr=TestCooperativeLevel(dd7)
  If hr=0
   RenderWorld()
   Text 0,0,"Use cursor/Z/X keys to change cone rotation"             
   Text 0,20,"Pitch: "+pitch# 
   Text 0,40,"Yaw : "+yaw# 
   Text 0,60,"Roll : "+roll# 	
   Flip
  Else
    Select hr
    Case INVALIDOBJECT
     RuntimeError "Bad pointer to DirectD7"
    Case EXCLUSIVEMODEALREADYSET,NOEXCLUSIVEMODE
     DebugLog "Excluse Set"
     Repeat
      UpdateScene()
      Delay 1
     Until TestCooperativeLevel(dd7)=0 
     SaveScene()
     CreateGraphics()
     RestoreScene() 
    Case WRONGMODE
     DebugLog "Wrong Mode"
     SaveScene()
     CreateGraphics()
     RestoreScene() 
     DebugLog "Recreate Mode"
    Default
     DebugLog "HUH="+hr
   End Select
  End If
End Function

;======= MAIN

CreateGraphics()
CreateScene()
While Not KeyHit(1) 
  UpdateScene()
  RenderScene()
Wend
End


You'll notice I am not messing with Restoring Surfaces as you pointed out there is not much you can do to guarantee you get it all setback up correctly.

You'll also note I don't lock the main loop. You still want to be able to get application to process a slight delay to yield CPU is all you need. You need to do this if you have network game running and don't want to starve the network code while Testcooperative Level is failing.

This is pretty basic code, come straight from the SDK and I have used it since Dx7 was published with no problems. For some reason BRL never codes this correctly. Took forever to get the driver correct in BMAX.

This should work correctly for all cases Full Screen focus lost, window blitz app losing focus to other full screen dx application, etc. The SDK is real clear this function is the key to making DX7 work friendly with the OS and other applications. Blitz Handles surface lost internally although I doubt textures loaded into video memory are correctly restored. No solution to that other than no real reason to choose that option. Modern Video Cards have more than enough texture memory for us to worry about loading unloading textures.

You want to call this before your check for surface lost. As failure of this function means pretty much your screwed and need to rebuild the display device and reload everything its just needs to be called correctly until it gives you an OK.

Nice catch on the TopMost flag never noticed that.

Doug