DirectX7 vs. DirectX9

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

DirectX7 vs. DirectX9

Post by Michael Vogel »

Hi,

I was trying hard to write a (hopefully) useful program for runners, i posted from time to time a link to the actual version (Website) and got cool tips from so many user here when I had coding problems... :)

But there's still one issue which I am not able to eliminate: the default renderer DirectX7 crashes on certain PCs (Intel G965) and DirectX9 corrupts the calculation of double precision floats. :cry:

Will there be any chance to get a crash free version of DirectX7 or a DX9 which allows correct calculations?

Thanks,
Michael
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It's probably possible to make a workaround for the DX9 issue. Can you post a sample?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Trond wrote:It's probably possible to make a workaround for the DX9 issue. Can you post a sample?
Would be great, I already gave up :?
My program source reaches the 10.000 line border now and uses some threads also, so I'm not sure, if the following small example will include all the given issues. Anyhow it has been extracted (and simplified) directly from the original source and produces wrong results, when DirectX9 will be used:

Code: Select all

Global ScreenX=GetSystemMetrics_(#SM_CXSCREEN)
Global ScreenY=GetSystemMetrics_(#SM_CYSCREEN)

#PIHalbe=#PI/2
#PiRadiant=#PI/180
#PiGrad=180/#PI
#GoogleMapSprite=1
Global Dim Polygon(8);            Eckpunkte für die Bodenplatte (2D)

Macro Radiant(x)
	(x*#PiRadiant)
	;Procedure.d Radiant(x.d)
	;   ProcedureReturn x*#PiRadiant
	;EndProcedure
EndMacro

Procedure.d Distanz(l1.d,b1.d,l2.d,b2.d)
	; Rechenungenauigkeit ist bei Float zu groß, somit alle Variablen in Double!
	;Debug "D:"+StrD(l1,10)+" | "+StrD(b1,10)+" | "+StrD(l2,10)+" | "+StrD(b2,10)+" | "+StrD(ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0,10)
	Debug StrD(ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0,10)
	b1=Radiant(b1)
	b2=Radiant(b2)
	ProcedureReturn ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0
EndProcedure

InitSprite()

#winID=1
win=OpenWindow(#winID,0,0,ScreenX,ScreenY,"*",#PB_Window_ScreenCentered | #PB_Window_BorderLess)
OpenWindowedScreen(win,0,0,ScreenX,ScreenY,0,0,0)

CorrectGraphicCard=#True
#TransparentColor=$FF00FF;		Farbe, die hoffentlich nie in einer Google-Karte auftaucht

;***Google Maps***
If CorrectGraphicCard
	!FSTCW word[v_fpu_bug]
	If InitSprite3D()
		; Testen, ob 3D-Sprite erstellt werden kann...
		Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
		;CatchSprite(#GoogleMapSprite,?Splash,#PB_Sprite_Texture)
		CreateSprite(#GoogleMapSprite,256,256,#PB_Sprite_Texture)
		TransparentSpriteColor(#GoogleMapSprite,#TransparentColor)
		If CreateSprite3D(#GoogleMapSprite,#GoogleMapSprite)
			GoogleMapFlag=#True
		EndIf
		!FLDCW word[v_fpu_bug]
	EndIf
EndIf


For OptGoogleMap =0 To 1


	If OptGoogleMap
		Debug "ON"
		If CorrectGraphicCard
			Global fpu_bug.w
			!FSTCW word[v_fpu_bug]
			If Start3D()
				TransformSprite3D(#GoogleMapSprite,Polygon(0),Polygon(1),4,Polygon(6),Polygon(7),2,Polygon(4),Polygon(5),1,Polygon(2),Polygon(3),3)
				DisplaySprite3D(#GoogleMapSprite,0,0,OptGoogleGlas<<5+63)
				Stop3D()
				!FLDCW word[v_fpu_bug]
			EndIf
		EndIf
	EndIf

	Distanz(0.0000000000000000, 48.4540170000000000, 1.0000000000000000, 48.4540170000000000)
	Distanz(15.9881449999999990, 48.4506650000000010, 15.9882010000000000, 48.4505649999999970)
	Debug "---"

Next OptGoogleMap
The (correct) output using DirectX7 is:

Code: Select all

26.4907943097
0.6368017799
---
ON
26.4907943097
0.6368017799
---
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Just use one

Code: Select all

!FSTCW word[v_fpu_bug] 
before or after initsprite() and remove the others.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

djes wrote:Just use one

Code: Select all

!FSTCW word[v_fpu_bug] 
before or after initsprite() and remove the others.
Had no luck here, as soon I compile this source using DirectX9 I get wrong results :(
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

djes's solution is working fine here:

Code: Select all

Global ScreenX=GetSystemMetrics_(#SM_CXSCREEN) 
Global ScreenY=GetSystemMetrics_(#SM_CYSCREEN) 

#PIHalbe=#PI/2 
#PiRadiant=#PI/180 
#PiGrad=180/#PI 
#GoogleMapSprite=1 
Global Dim Polygon(8);            Eckpunkte für die Bodenplatte (2D) 

Macro Radiant(x) 
   (x*#PiRadiant) 
   ;Procedure.d Radiant(x.d) 
   ;   ProcedureReturn x*#PiRadiant 
   ;EndProcedure 
EndMacro 

Procedure.d Distanz(l1.d,b1.d,l2.d,b2.d) 
   ; Rechenungenauigkeit ist bei Float zu groß, somit alle Variablen in Double! 
   ;Debug "D:"+StrD(l1,10)+" | "+StrD(b1,10)+" | "+StrD(l2,10)+" | "+StrD(b2,10)+" | "+StrD(ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0,10) 
   Debug StrD(ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0,10) 
   b1=Radiant(b1) 
   b2=Radiant(b2) 
   ProcedureReturn ACos(Cos(#PIHalbe-b2)*Cos(#PIHalbe-b1)+Sin(#PIHalbe-b2)*Sin(#PIHalbe-b1)*Cos(Radiant(l2)-Radiant(l1)))*6368.0 
EndProcedure 

!FSTCW word[v_fpu_bug] 
InitSprite() 

#winID=1 
win=OpenWindow(#winID,0,0,ScreenX,ScreenY,"*",#PB_Window_ScreenCentered | #PB_Window_BorderLess) 
OpenWindowedScreen(win,0,0,ScreenX,ScreenY,0,0,0) 

CorrectGraphicCard=#True 
#TransparentColor=$FF00FF;      Farbe, die hoffentlich nie in einer Google-Karte auftaucht 

;***Google Maps*** 
If CorrectGraphicCard 
 
   If InitSprite3D() 
      ; Testen, ob 3D-Sprite erstellt werden kann... 
      Sprite3DQuality(#PB_Sprite3D_BilinearFiltering) 
      ;CatchSprite(#GoogleMapSprite,?Splash,#PB_Sprite_Texture) 
      CreateSprite(#GoogleMapSprite,256,256,#PB_Sprite_Texture) 
      TransparentSpriteColor(#GoogleMapSprite,#TransparentColor) 
      If CreateSprite3D(#GoogleMapSprite,#GoogleMapSprite) 
         GoogleMapFlag=#True 
      EndIf 
      !FLDCW word[v_fpu_bug] 
   EndIf 
EndIf 


For OptGoogleMap =0 To 1 


   If OptGoogleMap 
      Debug "ON" 
      If CorrectGraphicCard 
         Global fpu_bug.w 
         If Start3D() 
            TransformSprite3D(#GoogleMapSprite,Polygon(0),Polygon(1),4,Polygon(6),Polygon(7),2,Polygon(4),Polygon(5),1,Polygon(2),Polygon(3),3) 
            DisplaySprite3D(#GoogleMapSprite,0,0,OptGoogleGlas<<5+63) 
            Stop3D() 
            !FLDCW word[v_fpu_bug] 
         EndIf 
      EndIf 
   EndIf 

   Distanz(0.0000000000000000, 48.4540170000000000, 1.0000000000000000, 48.4540170000000000) 
   Distanz(15.9881449999999990, 48.4506650000000010, 15.9882010000000000, 48.4505649999999970) 
   Debug "---" 

Next OptGoogleMap
More instances of FSTCW would just be moving a corrupted word to your safe variable, right? It should only be done once.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Oiy, I moved it on top of the InitSprite3D() instead of the InitSprite() command :x

Now this works fine - so I'll try to to that also in the real program, I will post the results soon...

Are there some other functions known, which need to be fixed that way?

Thanks,
Michael
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Works now, thanks! :D

It took me quite long, there's another issue now when using DirectX7 or DirectX9 - the following code lines...

Code: Select all

	CreateSprite(#GoogleMapSprite,MapY,MapX,#PB_Sprite_Texture)
	StartDrawing(SpriteOutput(#GoogleMapSprite))
...did show an error like "no sprite available for StartDrawing" from time to time, when I made debugging tests of my code changing between DirectX7 and DirectX9. At the moment I am not able to reproduce the problems :?

Michael
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

MapY,MapX
Likely not the problem, but are you sure of this?
BERESHEIT
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

shouldn't that be

!FCLEX ;clear pending interrupts
!FLDCW word[v_fpu_bug]
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

idle wrote:shouldn't that be

!FCLEX ;clear pending interrupts
!FLDCW word[v_fpu_bug]
See http://www.website.masmforum.com/tutori ... uchap3.htm
Digital Wargames
Enthusiast
Enthusiast
Posts: 203
Joined: Sat May 23, 2009 4:39 am

Post by Digital Wargames »

But there's still one issue which I am not able to eliminate: the default renderer DirectX7 crashes on certain PCs (Intel G965) and DirectX9 corrupts the calculation of double precision floats.
Have you tried the OpenGL subsystem?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

netmaestro wrote:Likely not the problem, but are you sure of this?
Thanks netmaestro, you have sharp eyes like sherlock holmes :wink:

MapY/X is correct here, I built up my whole 3D scenario 90° rotated to the "real" world :(
So I have to rotate the loaded google maps also. Even I don't like this, it's quite complicate to "repair" the whole other stuff now - the imagerotating procedure seems to be kept as a permanent workaround :roll:
Digital Wargames wrote:Have you tried the OpenGL subsystem?
Not now, I just started (naive) without using any subsystem, now I just switched to DX9 - and saw how many differences are between these already :shock:, maybe I'll try also OpenGL later on...
In general it would be fine to include more than one subsystem in an application to allow the user selecting the best one

Michael
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Still wondering, why DirectX7 and DirectX9 has so many differencies here :evil:

Within a thread, CreateSprite works 100% when using DirectX7, but only around 90% when DirectX9 is activated - I am using the following code now, but I feel lousy :cry:

Code: Select all

If CreateSprite(#GoogleMapSprite,MapX,MapY,#PB_Sprite_Texture)=0
	CreateSprite(#GoogleMapSprite,MapX,MapY,#PB_Sprite_Texture)
EndIf
Michael
Post Reply