CLS problem - Null object

BlitzMax Forums/BlitzMax Beginners Area/CLS problem - Null object

LuckyBargee(Posted 2011) [#1]
Hi all! I was surprised when I had got this kind of CLS()-problem. After CLS() I had an error (Null object). Moreover I can't read the name of the driver!
Does anybody know how to make this code works properly? Thank you.

' ----------------------------------------------------
SuperStrict

Global width:Short=800, height:Short=600, depth:Short=0, freq:Short=60


If GLGraphicsDriver()<>Null
SetGraphicsDriver GLGraphicsDriver()
Print("<OpenGL> graphic driver can be used! It's name is " + GetGraphicsDriver().ToString()) 'CAN'T READ THE NAME!
Else
Print("* <OpenGL> graphics driver can't be used!")
End
EndIf

If GraphicsModeExists(width,height,depth,freq)
Print("<OpenGL> graphic mode is ... Ok!")
Else
Print("* <OpenGL> graphic mode not supported!")
End If

Graphics(width,height,depth,freq,GRAPHICS_BACKBUFFER)

Repeat
Cls ' UNHANDLED EXCEPTION: ... NULL OBJECT!
DrawText("Test",10,20)

Flip(-1)

Until KeyHit(KEY_ESCAPE) Or AppTerminate()

' ----------------------------------------------------


Jesse(Posted 2011) [#2]
The GlGraphicsDriver() is not supposed to be used that way, if you want to use the GLGraphicsDriver I suggest you look at the Nehe tutorials in the tutorials section.
the one you should be using for that example is the GLMax2DDriver().


LuckyBargee(Posted 2011) [#3]
Thanks Jesse,

However, what about GetGraphicsDriver().ToString()?

Could you run the code:

' -------------------
SetGraphicsDriver D3D7Max2DDriver()
Print("The driver name is " + GetGraphicsDriver().ToString())

SetGraphicsDriver GLMax2DDriver()
Print("The driver name is " + GetGraphicsDriver().ToString())

SetGraphicsDriver GLGraphicsDriver()
Print("The driver name is " + GetGraphicsDriver().ToString()) 'CAN'T READ THE NAME!
' ------------------


Jesse(Posted 2011) [#4]
since GLGraphicsDriver doesn't follow the Max2D standard, it also doesn't provide a "ToString" override. I would suggest you stay away from it unless you are trying to implement your own Max2D integration of it which is quite a bit of work. GLMax2DDriver is the GLGraphicsDriver implementation for Max2D.

Last edited 2011


LuckyBargee(Posted 2011) [#5]
Unfortunately, the help says nothing about it. It says "GetGraphicsDriver() returns the current graphics driver as selected by SetGraphicsDriver". In turn SetGraphicsDriver mentions GLGraphicsDriver() as normal to use.

Thank you a lot!


Jesse(Posted 2011) [#6]
Blitzmax Documentation is really bad, best thing to do is to look at the actual module source which can easily be accessible from the side bar home Tab of the IDE under module source. Careful not to try to compile(execute) any of them as you might start to get some weird performance from your executables if you do.


by the way, Welcome to the Forums!

Last edited 2011


Czar Flavius(Posted 2011) [#7]
Why do yo uwant to use GLGraphicsDriver instead of GLMax2DDriver?


LuckyBargee(Posted 2011) [#8]
The matter is each driver gives different performance of my program. So my algorithm was:
1. Find out how many drivers are available in computer of the customer.
2. Test each one by measuring, for example, the speed DrawText() function.
3. Choose the best one.

In my case D3D7Max2DDriver() was better than GLMax2DDriver() and I just tried to check GLGraphicsDriver()!


Jesse(Posted 2011) [#9]
1 the odds that one windows computer does not have either of the driver is almost none existing and I wouldn't worry about it. I highly believe that that is pointless.

2. don't worry about the speed unless your know for sure your program will not perform good on any of the drivers. Instead I wold worry about compatibility with certain computers. OGL is know to have incompatibility issues that cause the program to crash. Some portals even refuse to accept GL games. Keep that in mind.

3 if you are coding for windows, stick with the dx drivers. If you are coding for Mac or Linux your best and probably your only option is OGL.

if you know how to code in OGL than using the GLGraphicsDriver will be the faster because you can optimize it to your needs. the Max2DDrivers are not too well optimized for performance but for 99% of the uses the Max2dDrivers will be more than sufficient.

Last edited 2011

may I ask what kind of game/application are you working on that you need to determine the speed up to the millisecond of DrawText. That is odd to me as I doubt anyone can read that fast.

Last edited 2011


LuckyBargee(Posted 2011) [#10]
Hi Jesse,

Thank you for your explanation.

About "millisecond of DrawText". I have to put a big stuff at the screen between two flips(-1). So, I have just 16 msec to do it.

And I still have no idea how to do it with Cls function (see my post Cls-speed measuring)


Jesse(Posted 2011) [#11]
yes, I seen it. yet, it doesn't illustrate real world use.
can you provide a minimized example of what you are actually doing?
maybe I can help you work something out.


Czar Flavius(Posted 2011) [#12]
16 milliseconds is a very long time for a computer. You should write your program first, and then time it, and then optimize the slowest bits, until you are under 16 milliseconds. Otherwise you will never manage to finish your game.

GLGraphicsDriver is for advanced use for custom opengl. If you don't know how to code opengl directly, it's useless for you.

In my experience the performance of the 3 main drivers (dx7, dx9, glmax2d) varies across computers, so what you measure on your computer might not hold for other computers. I just give the option in my games for the user to select the one they want, with a note to try a different one if they have perfomance issues.


LuckyBargee(Posted 2011) [#13]
Thank you Jesse,

I see you point, I have to refuse to use GlGraphicsDriver() by common way. Ok.

You wrote "...99% of the uses the Max2dDrivers will be more than sufficient", but I afraid I have to refuse to use Max2dDriver() as well, because ..., it sounds unbelievable, but flip(-1) doesn't work in Max2dDriver() in Vista!

See a code below:

'-------------------------------------------
SuperStrict

Global width:Int=800, height:Int=600, depth:Int=16, freq:Int=60

Print"OpenGL:"
If OpenGL()=0
Print "Can't install OPENGL driver!"
End
EndIf

My()

Print"DirectX:"
If Directx()=0
Print "Can't install DirectX driver!"
End
EndIf

My()

End

'=============================================
Function My()
'=============================================
Local time:Long=0
Local n:Long=0

Graphics(width,height,depth,freq,GRAPHICS_BACKBUFFER)

time=MilliSecs()
Repeat
Cls()
DrawText("TEST...", 10, 10)

Flip(-1)
n=n+1
If n>=60 Exit
Until KeyHit(KEY_ESCAPE)
Print " Time=" + (MilliSecs() - time)

EndGraphics
End Function

'=============================================
Function DirectX:Byte()
'=============================================
If D3D7Max2DDriver()<>Null
SetGraphicsDriver D3D7Max2DDriver()
Else
Print("* F001: DirectX(): Couldn't set <DirectX> Driver!")
Return(0)
EndIf

If Not GraphicsModeExists(width,height,depth,freq)
Print("* F002: DirectX(): <DirectX> graphic mode not supported!")
Return (0)
End If

Return(1)

End Function


'=============================================
Function OpenGl:Byte()
'=============================================
If GLMax2DDriver()<>Null
SetGraphicsDriver GLMax2DDriver()
Else
Print("* F003: OpenGl(): Couldn't set <OPENGL> Driver!")
Return(0)
EndIf

If Not GraphicsModeExists(width,height,depth,freq)
Print("* F004: OpenGl(): <OpenGL> graphic mode not supported!")
Return (0)
End If

Return(1)

End Function

'-------------------------------------------

The result in this test should be very close to 1000 msec.

My Windows Vista result is:
- OpenGl time = 114 here flip(-1) doesn't work
- DirectX time = 1007

My Windows7 result is:
- OpenGl time = 951
- DirectX time = 979

Question is how to make flip(-1) to work properly in Vista?


Jesse(Posted 2011) [#14]

it sounds unbelievable, but flip(-1) doesn't work in Max2dDriver() in Vista!



not really! It's a common issue with graphic card settings and with the fact that direct x7 is only emulated from DX9 and above.

some graphics cards can be set to ignore refresh rate for certain applications so if you set to refresh your game at certain refresh rate it will completely be ignored if certain settings are not modified in your graphic card driver Settings. it has nothing to do with either of the dx modules and there is nothing that can really be done about it with in the game/application. an alternative and recommended way of handling all of your application speed issues is to use some kind of timing such as delta timing, interpolation etc...

have you tried the D3D9Max2DDriver. see if you get better performance.

Last edited 2011

Last edited 2011


Floyd(Posted 2011) [#15]
Question is how to make flip(-1) to work properly in Vista?


By using DirectX.

When Vista was new the support for OpenGL was notoriously bad. Over time this improved, but not with all hardware. Be sure you have the most recent driver for your graphics card. If that doesn't fix the problem then give up on OpenGL for your Vista PC.

Note: If you do not specify a Max2D driver then BlitzMax will choose one by default. Originally this was OpenGL for all platforms. But experience showed that on Windows it made more sense to default to DirectX, which was much more reliable. So now the default is DirectX for Windows, OpenGL otherwise.

In fact, I just tried Graphics, without setting a driver, on my Windows 7 PC. The driver is then DirectX9.

Last edited 2011


LuckyBargee(Posted 2011) [#16]
Thanks a lot, Czar,

You wrote "16 milliseconds is a very long time for a computer". On the one hand, you are right!

On the other hand, let's remember that Windows isn't a real time system. There are lots of background services, priorities and queues and ..., so we haven't got 16 msec at all, but 10msec or may be 5 ???!

Then, the program has to work properly in any modern computers and old computer as well. After that we hardly ever have 5 msec, but may be 1?

So, we have to be very attentive about the time!

We, probably, have to answer a number of questions (to yourself) BEFORE programming:
- Which function should I use to measure the time: Millisecs() or QueryPerformanceCounter(),
- How is quicker to output any messages at the screen: by Drawtext() or DrawImage(),
- What is better to use Cls(), ViewPort or DrawRect to clean a part of the screen,
- Which driver do I have to use,
- and many others...

May be are there any ideas (hints) how to come closer to a real time program (as a game is a real time task)? Could you share, pls?


LuckyBargee(Posted 2011) [#17]
It is a really important information! Thank you.

However, now I can't imagine how to prepare my program for any customer's computer!

What else should I put in the code below for it?

'=============================================
Function OpenGl:Byte()
'=============================================
If GLMax2DDriver()<>Null
SetGraphicsDriver GLMax2DDriver()
Else
Print("* F003: OpenGl(): Couldn't set <OPENGL> Driver!")
Return(0)
EndIf

If Not GraphicsModeExists(width,height,depth,freq)
Print("* F004: OpenGl(): <OpenGL> graphic mode not supported!")
Return (0)
End If

Return(1)

End Function

'---------------------

And the next a very critical question!
How to find out using BlitzMax in advance whether the flip(-1) will work properly or not (as "some graphics cards can be set to ignore refresh rate for certain applications")?

Thank you.


xlsior(Posted 2011) [#18]
What is better to use Cls(), ViewPort of DrawRect to clean a part of the screen,


Given that Viewports supposedly don't work properly on some of the craptacular low-end graphics cards, I'd skip that option if you're going to maximum compatibility.


Jesse(Posted 2011) [#19]
here are my suggestions:

make your game with with DX as your default with the option for OpenGL.

use flip(1) as default to prevent tearing and benefit with computer where the refresh rate works properly.

use a timing method to control the speed of the game regardless if the refresh rate works or not.

write your game/application then worry about anything else afterwords. profiling is your best friend but only after you have made your application. Only then will you be able to determine what works and what doesn't. Until then, you are just wasting time and no one will really be able to help you. Everything will all just be speculative talk.

everybody that has commented here have made at least a game or an application that works or at lest been here long enough to know what works or what doesn't so take these comments serious.

Last edited 2011


Czar Flavius(Posted 2011) [#20]
You can't really second guess your target computer like that. 16 millisecs is a totally meaningless unit. What if the computer has half the processing speed, now it's only 8. But what was the 16 from anyway? You are basing assumptions on assumptions.

Who exactly are your customers? What are you doing that is going to take so long? 16 milliseconds is enough time to draw a very complex scene.

Last edited 2011


xlsior(Posted 2011) [#21]
16 millisecs is a totally meaningless unit. What i fthe computer has half the processing speed, now it's only 8.


1000 milliseconds in a second, 60 frames a second, is 16.666 millisecond per frame. Regardless of how fast or slow your computer may be, that value won't change.


Czar Flavius(Posted 2011) [#22]
It was in reference to this, to show it doesn't make sense.
On the other hand, let's remember that Windows isn't a real time system. There are lots of background services, priorities and queues and ..., so we haven't got 16 msec at all, but 10msec or may be 5 ???!



LuckyBargee(Posted 2011) [#23]
Thank you, all!

I'm a little bit upset about Blitz. You see:

Viewports supposedly don't work properly on some of the craptacular low-end graphics cards, I'd skip that option if you're going to maximum compatibility


some graphics cards can be set to ignore refresh rate for certain applications so if you set to refresh your game at certain refresh rate it will completely be ignored

That is Flip(1) doesn't work!

I come up with thought I have to make an universal graphics test before any main code beginning. I believe, that everyone did it in your own program. Could you share your experience, pls, what else should I do in the such test in order to choose the right driver, which is the most compatible with other computers? Here the code:


 If OpenGl()=1
   ElseIf DirectX9()=1
   ElseIf DirectX7()=1
   Else
   Print("* FATAL ERROR! There is no avaiable drivers! Couldn't continue...!")	
 EndIf 	

'=============================================
Function OpenGl:Byte()
'=============================================
If GLMax2DDriver()<>Null	
SetGraphicsDriver GLMax2DDriver()
Else
Print("* OpenGl(): Couldn't set <OPENGL> Driver!")	
Return(0)
EndIf 

If Not GraphicsModeExists(width,height,depth,freq)
Print("* OpenGl(): <OpenGL> graphic mode not supported!")
Return (0)
End If 

Return(1)	

End Function


Thank you


Midimaster(Posted 2011) [#24]
We have a very lot of customers where our BMax software is running. And a lot of them have very old computers.

My experience is, that BMax runs without performance problems on min. 99% of the computers.

Of course it depents on what you are doing, f.e. if you add a modern 3D-Module in your BMax-Code you will get more problems. But if you only use the build in commands it will run! We also never thought about using a certain driver, but let decide always the programm which driver to use.

As a minimum requirement today I would say the graphic card should have 32MB RAM. We had users with onboard 2MB Cards and they had problems with our 3D games but not with our 2D's.

The computer should have 256 MB RAM and 1000MHz and Windows XP or higher. We had customers running it perfect on 128MB and 800MHz.

With this minimum requirements you close out 1% of the customers, but you will have no performance problems.

As a last solution you always have the opportunity to shrink down the FPS rate. On a lot of the 1% very old systems a 10FPS rate was a solution. But it depents on the game you are doing, if this still make fun or not...

Last edited 2011


col(Posted 2011) [#25]
Hiya,
Welcome to BlitzMax and the forums.

That process you are trying to achieve is already taken care of for you simply by the way the driver code is loaded and setup even before your very first line of code. There's a lot going on behind the scenes in your final executable code before it even reaches your 'If OpenGL()=1' statement.

Behind the scenes, the graphics drivers works like this (before your code even starts ) :-

if opengl is supported create and set opengl driver, if windows system and dx7 is supported create and set dx7 driver, if windows system and dx9 is supported create and set dx9 driver

This way if you are developing code on a Mac or Linux setup then OpenGL is default, otherwise if its windows and you have Dx9 its Dx9, otherwise if its windows and no Dx9 then its Dx7, otherwise if windows and no Dx9 and no Dx7 then its opengl . This covers pretty much every pc config that BMax caters. If that order of configuration doesnt work on someones pc then forget it, BMax does not cater for them.

Then in your code, if you want to, you can choose what graphics driver to use. Theres really no need, until IF someone plays your game and tells you that they have a graphics glitch. 99% of the time you won't get that, but it occasionally does happen for some people.

Some people are referencing very old hardware that have issues. You'll be lucky in any programming language if you can write a game that supports 100% every single graphics card available ever!

You don't need to worry so much about the 'hidden magic' that happens. Its there to make it easier for you to write your games without you needing to worry about what you're worrying about right now :D

Have fun.

Last edited 2011


H&K(Posted 2011) [#26]
You don't need to worry so much about the 'hidden magic' that happens. Its there to make it easier for you to write your games without you needing to worry about what you're worrying about right now :D
Good advice. And this includes mods or addons. Worry about IF it works not how or why.


LuckyBargee(Posted 2011) [#27]
Thanks you for your advices!