Please help me check for DX the OGL

BlitzMax Forums/BlitzMax Programming/Please help me check for DX the OGL

Robert Cummings(Posted 2005) [#1]
Hi there,

I am trying to get Blitzmax to check for a valid DX 3D render, then fall back to OpenGL, then fall back to SDL

Does anyone know how I can do this without Graphics() calling a fatal exception?

(You can test this by turning off hardware acceleration in your troubleshooting tab).


klepto2(Posted 2005) [#2]
_Test:Idirect3d9 = Direct3DCreate9( $900 )

If _Test = Null Then
	Print "D3D not available"
Else
	Print "All OK"
EndIf

TestGL:Byte = bglCreateContext(0,0,0,-1)


If TestGL = Null Then
	Print "OpenGL not available"
Else
	Print "All OK"
EndIf
bglDeleteContext(testGL)



I hope this helps you.


Robert Cummings(Posted 2005) [#3]
Hi Klepto2, thanks for your message on IRC, unfortunately I wasn't around to recieve it.

Thanks for this code, I really appreicate it! I'm really pleased you've taken the time out to help me like this :)

One further question - can I change _Test:Idirect3d9 = Direct3DCreate9( $900 ) to check for DirectX7 instead (as that is what Blitzmax's DX is AFAIK (to lower the requirements)

Or doesn't it matter?

Many thanks!


skidracer(Posted 2005) [#4]
That won't work as such a call (which requires the directx .dll to be at least installed) will cause the entire app to fail if directx is not installed.

This is pbly the best test you can do at present:

Strict 

UseD3D7

If PrimaryDevice Notify "DX7 Primary Device Is Initialized"



Robert Cummings(Posted 2005) [#5]
Thanks skidracer, much appreciated.

[edit] I see it's for D3D - perfect, thanks much appreciated!


klepto2(Posted 2005) [#6]
Global	ddraw:IDirectDraw7
Global 	d3d:IDirect3D7
Global	device:IDirect3DDevice7
Global guid Ptr

Local res
res=DirectDrawCreateEx( guid,Varptr ddraw,IID_IDirectDraw7,Null )
If res = Null 
	Print "DirectDraw Init succesful" + res
EndIf
res=DDraw.QueryInterface( IID_IDirect3D7,Byte Ptr Ptr(Varptr D3D) )

If Res = Null
	Print "d3D7 Init succesful" + res
EndIf


This is just a test, I don't really know if it works
It checks for directdraw and direct3d7


Robert Cummings(Posted 2005) [#7]
Nice work Klepto! thank you very much as well!

Is this more reliable than skid's test above?


klepto2(Posted 2005) [#8]
I really don't know. In fact I have searched the Modules for the functions which returns errors if they coudn't init and changed them a bit to not returning an error.

For example the Direct7 code is based on the TD3D7Device.Init() Method you can found in the d3d7graphics.bmx of the brl.mod/dxgraphics.mod folder.
(This method is used by 'useD3D7')


Robert Cummings(Posted 2005) [#9]
Hi there - I just did some testing with the "troubleshoot" tab in windows.

Here, you can turn off 3D acceleration, and doing this, acceleration is still returned as true even though it is unavailable.

What I mean is, the system is reporting it can do DX and OpenGL fine using the above tests, but Graphics() still fails when I call it using bmax. I would like to be able to use Try() and Catch on Graphics() but it seems not to be able to catch Graphics()'s unhandled exception.

local catchString:String
try
	Graphics 800,600,0,-1|HARDSYNC
catch catchString$
	print "Switching to software acceleration"
endtry


Perhaps I'm doing it wrong? this is a final failsafe test... better safe than sorry as they say.


skidracer(Posted 2005) [#10]
Klepto, as I said before you can't call DirectDrawCreateEx on a machine without dx installed, it will simply exit your app, you need to link with the dll manually with GetProcAddress.

fish: are you saying my test fails with hardware acceleration disabled? also try catching with catch exception:Object instead of only catching thrown strings.


klepto2(Posted 2005) [#11]
It have to be somthing like this:
Local catchString:Object
Try
	Graphics 800,600,0,-1|HARDSYNC
	'g=CreateDisplayGraphics( 800,600,0,-1,0 )
	
Catch catchString:Object
	Print "Switching to software acceleration"
EndTry



@Skidracer:
Sorry I haven't seen your Post before.


Robert Cummings(Posted 2005) [#12]
Skidracer - your test is returning true with hardware acceleration disabled under windows.

Thanks klepto and skid. Tried the Try/Catch and it now catches with hardware acceleration disabled. But is this something you can recommend?