why is TEXT so slow...? and ZOOMing help?

Blitz3D Forums/Blitz3D Programming/why is TEXT so slow...? and ZOOMing help?

Vorderman(Posted 2006) [#1]
I can half the framerate in SRX just by printing 10 lines of text to the sceen - why is it soooooo slow????

I'll have to use sprites parented to the camera to display HUD info such as speed, framerate etc.., but for different cameras I have different zoom levels (typically 1.0 to 1.6), and some external cameras having a constantly adjusting zoom to track the car.

Does anyone know how I can attach and position a sprite relative to the camera so it always appears the same on-screen, no matter what the zoom is set to?


David819(Posted 2006) [#2]
I'm not sure why your frame rate would slow to such an extent, if you put up some code of the text and relative data i might be able to help. I'll have a look about the camera zoom and sprites, i'll post up some code if i come up with anything for you.


Beaker(Posted 2006) [#3]
Why not have a seperate HUD cam that has a fixed zoom? (and render it last of course)


Vorderman(Posted 2006) [#4]
i'll post up some code if i come up with anything for you.

Thanks Kain. As far as my game code goes, it's just a typical 3d rendertweening game loop with 10 TEXT commands to print a load of stuff, nothing fancy. Without the TEXT commands, I get 60fps, with the TEXT commands I get 30fps. I knew TEXT was slow, but I wasn't expecting it to be THAT slow.

Why not have a seperate HUD cam that has a fixed zoom? (and render it last of course)

I don't quite understand - how would I overlay that onto the normal game camera?

The effect I want to achieve would be same as using LOADIMAGE and then DRAWIMAGE to place an specific sized graphic onto the screen, but from what I remember DRAWIMAGE is slow also and using the 3D sprites is the best way to do this, but the camerazoom thing is messing it up.


David819(Posted 2006) [#5]
ok i have made some code of you based on Beaker's idea: basically i have created two camera's the main one and one to display the hud with a sprite, i've positioned the hud camera behind the main camera so the sprite does not get in the way of the main camera. here it is:

Graphics3D 640,480,32,2
SetBuffer BackBuffer()

;create main camera
cam=CreateCamera()
PositionEntity cam,0,0,0

;create camera for hud
;positions the hud camera behind the main one
camdis=CreateCamera()
CameraViewport camdis,0,0,128,128
PositionEntity camdis,EntityX(cam),EntityY(cam),EntityZ(cam)-1

;load sprite and make it linked to hud camera
spr=LoadSprite("test.jpg")
EntityParent spr,camdis

;create random object ot zoom into
sp=CreateSphere()
PositionEntity sp,0,0,10

While Not KeyHit(1)

If pzo <-3 Then pzo =-3
If pzo >-2 Then pzo=-2
If pzo2 >3 Then pzo2 =3
If pzo2 <2 Then pzo2=2

; Change zoom value depending on key pressed
If KeyDown( 208 )=True Then zoom#=zoom#-0.1
If KeyDown( 200 )=True Then zoom#=zoom#+0.1

; Put a minimum and maximum cap on zoom value
If zoom#<1 Then zoom#=1
If zoom#>1.6 Then zoom#=1.6

; Set camera zoom
CameraZoom cam,zoom#

RenderWorld
Flip
Wend
End

Hope this helps.


Vorderman(Posted 2006) [#6]
Hmm, thanks anyway but that's not really the right effect, because the sprite is not overlayed on the main camera, it's in a seperate viewport in the top left.

Also, I already have 2 cameras (main cam and rear-view mirror) so adding a third is likely to slow things down even more.

I think what I need to do is position and scale the sprite in such as way as to cancel out the effect of the zoom...


big10p(Posted 2006) [#7]
I think what Beaker meant is to have a separate HUD cam which you hide when rendering the main scene. Then, you set CameraClsMode to not clear the color buffer, hide the main cam, show the HUD cam and RenderWorld again.

This method should have very little impact on overall render speed - if any at all.


Paolo(Posted 2006) [#8]
Vorderman,
I have that same effect with text, but only when I use
the VWait command at the end of the code, if I remove
the vwait and use only Flip it is back to normal again ... just a thought ...

Paolo.


Sir Gak(Posted 2006) [#9]
After you putting your Text commands *after* UpdateWorld() and RenderWorld()?
setbuffer backbuffer()
While not keyhit(1)
; do stuff
     UpdateWorld()
     RenderWorld()
     Text x,y,mytext$
     Flip
Wend



Vorderman(Posted 2006) [#10]
After you putting your Text commands *after* UpdateWorld() and RenderWorld()?


Yes, otherwise the text is overwritten by the 3d update.

I have that same effect with text, but only when I use the VWait command

Hmm, I'll try that and see what happens...

no, makes no difference. I can run 1 or 3 full-physics cars with no probs, but print the FPS and the framerate is halfed.


Andy(Posted 2006) [#11]
It's an old issue. When it was first discovered the powers that be said that it was a driver issue and that neither ATI or nVidia was responding to inquiries.

In other words, an issue that must be worked around by using quads with text as you suggested.


Andy


David819(Posted 2006) [#12]
Ok, i'll try and have a go at making the sprite adjust correctly for you, i made some code that moved the sprite when you zoomed in and out but it's got quite abit of work to be done on it before it will work correctly.


Matty(Posted 2006) [#13]
What big10p and beaker say is probably the best solution.

Basically something like this:

repeat

UpdateAllYourGameStuffInHere()
updateworld

cameraprojmode HUDCamera,0
cameraprojmode GAMECamera,1
renderworld

cameraclsmode HUDCamera,false,true
cameraprojmode HUDCamera,1
cameraprojmode GAMECamera,0
renderworld 

flip ;false ;if you want

forever



OJay(Posted 2006) [#14]
or use a simple image with maskcolor instead and draw the text to the image only, if something changes. otherwise just draw the image. should be faster than 10 text()-commands even with a screensize-image and you don't have to fiddle around with that sprite stuff!


Damien Sturdy(Posted 2006) [#15]
Vorderman, Youre definitely limiting your framerate- youre screen syncing somehow.

It might be forced on in the drivers, or you might be using VSync, or FLIP 1.

Either way, it waits for the next frame to begin before continuing.

a new frame at 60fps comes every 1000/60 milliseconds. if you miss one frame it waits for the next frame, another 1000/60 milliseconds away. (1000/60)*2=33.3333333, the same as 1000/30.

Thats what I see anyway.


Shifty Geezer(Posted 2006) [#16]
The HUD overlay was solved for me by someone (forget who!) providing source for a camera that draws second over the first scene cam. So if the first cam for the game is positioned at 0,0,-100 with range 1000, the UI camera is positioned at 0,0,5000 with range 1000. I think. That's how I did it, but this other system didn't use an orthographic camera as mine did. The scene is rendered, and then the UI camera. Pixel perfect sprites from the archive Pixie system provided textured quads. I use TEXT to write to a quad's texture whenever I want to update the text.


Vorderman(Posted 2006) [#17]
[quote]

I'm using the rendertweening framework from the code archives, with VWAIT : FLIP FALSE instead of FLIP, so according to the docs it should be CPU limited instead of GPU limited.

What base framework do you use?