Page 1 of 3

OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 10:39
by Tiberius
Here comes a hardware-assisted OpenGL blitter for OpenTTD!
Why not hardware-'accelerated' you say? Because it's not necessarily faster 8)
Remember to disable VSync if you want to fast-forward beyond 60fps, and do not force texture AA since it'll blow up color indexes ...

And please notice, don't press the full-screen key like Alt+Enter, and don't choose prebaked resolution from options window, they simply don't work (yet) ...

Currently it supports Win32 platform, and those platforms with SDL OpenGL support.
(well SmatZ told me he successfully wine openttd.exe under Linux for this one :mrgreen: )

It needs multiple draw buffer and fragment program (pixel shader) support to correctly draw colored text, re-colored buildings, company colors, etc. Which means you must have at least NVIDIA GeForce 6100, ATI Radeon 9550 or Intel GMA X3100 to fully utilize it.

==========
CHANGE LOG

EDIT7:
Fixed a bug that sometimes cause repeatedly encoding of PNG sprites, possibly eat up all available memory ...
For binary please refer to my Patch Pack.

EDIT6: Updated the patch so that MinGW/Cygwin users can build it correctly. Also it won't compile OpenGL stuff anymore while OpenGL is not enabled. Bugfix in SDLGL driver too.
The OpenGL blitter itself isn't changed much however. I was trying MSAA but didn't get very pleasant results yet ...

EDIT5: Updated the patch to include SDL OpenGL video driver hacked by ccfreak2k :mrgreen: And also supported MinGW/Cygwin compiling. Just run ./configure with '--with-win32gl' or '--with-sdlgl' (or both) then 'make' as usual. Linux/Mac users please test if SDLGL driver works on your machines! And ... anyone wish to hack a OSX native OpenGL driver for us? :oops:

EDIT4: This version should do pretty well on both ATI/NV cards. And you could even try it on Intel 915/945 integrated graphics (but without palette animation ...)
ENJOY IT! :mrgreen:

EDIT3: ATI users please try the new binary and report if it displays anything. Be sure to disable force mipmap, texture anti-aliasing to get a pretty screen.

EDIT2: With ccfreak2k's help I've identified some potential fix to make it (partially) work in ATI cards, but by no means perfect. I'll update the patch once I got (at least) map panning works on a capable ATI card.

EDIT: bokkie reported that it DOES NOT WORK on ATI X1950PRO, and ccfreak2k reported it DOES NOT WORK on ATI X850XT either. Perhaps anything using ATI graphics chips have some degrees of problem ...
Since I don't have PCs with capable ATI cards nearby, any debugging assistances are welcomed. (Perhaps I did something strange with shaders?).

==========
You can run this little program to see if your system have needed extensions. (notice: it's a console/text mode program)
ext-check.zip
Extension checker
(172.51 KiB) Downloaded 718 times
If your system doesn't have needed extensions, it's better to stick with 32bpp-anim/32bpp-optimized blitter until you decided to upgrade your system/graphics card :wink:

Perhaps I will modify it later, so Intel 915G can at least display remapped colors correctly, but I'm gonna 'play' OTTD now :)

==========
You should use the supplied openttd.cfg or put these two lines in yours, to enable OpenGL blitter. You can also adjust the opacity of transparent objects (buildings) between 0-255, smaller values are more transparent, larger values will yield a more 'solid' black shadow.

Code: Select all

videodriver = win32gl
blitter = opengl
transparent_opacity = 64
You can also start openttd.exe with

Code: Select all

-v win32gl -b opengl
And since it's a 32-bit blitter, I strongly recommends to use a TrueType font with anti-aliasing enabled!

Code: Select all

medium_font = Arial
medium_size = 11
medium_aa = true
If you need Chinese/Japanese/Korean support, and you got MS Office installed, you can try 'Arial Unicode MS'. It works great too.

==========
If you want to compile it yourself, you'll need GLee (GL Easy Extension) library from http://elf-stone.com/glee.php. Extract GLee.c/GLee.h and put them in 'src' directory.

'opengl' blitter is platform-independent, with help from 'win32gl' video driver, which is hacked from 'win32' video driver, to do Windows-specific OpenGL initialization, and usual environment/input management. In theory we just need other platform-specific drivers to do OpenGL initialization and management, to use 'opengl' blitter on these platforms.

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 10:52
by kaan
This sounds interesting :)

Being a complete noob when it comes to this kind of stuff, makes me wonder why it is desireable.
Is it faster? pretty? geeky?

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 11:03
by Tiberius
Fixed case-sensitivity problems in the patch file.
kaan wrote: Being a complete noob when it comes to this kind of stuff, makes me wonder why it is desireable.
Is it faster? pretty? geeky?
Whether it's faster or not, depends on your system, graphics board etc.
(my C2D@2400 + NV 7600GT does 700fps with 32bpp + animated palette in a new game, so it's indeed faster :mrgreen: )

It's not 'prettier' than existing blitter for now, but it will be easier to do e.g. zooming, transparency effects in OpenGL later. However since we have to keep support original blitters, I don't think there will be many improvements here.

So in conclusion, yes, it's 'geeky' for now :D

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 11:22
by CommanderZ
Sounds great! This has awesome potential, especially when I see your FPS. My OTTD is with 8bpp laggy once there are several hundred trains and the map is zoomed out. I hope this will bring vast improvement on my Athlon XP 2500+ with GF 6200 GE. Gonna try it now!

EDIT: The speedup against default 8bpp blitter is brutal. How can I turn on FPS label?

But I see one downside: most graphics don't look very well when zoomed out, especially temperate terrain and maglev tracks look quite weird. The default downsizing algorythm seems to work better for OTTD gfx.

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 11:41
by Tiberius
Apparently the bottleneck of OTTD is not at blitter, and FPS is greatly affected by 'visible sprite count'.
I think it's quite reasonable since OTTD Z-sorts sprites itself before sending them to blitter, and do many redraws assuming blitter don't have Z-testing functionality (yeah! after all they're 2D 'blitters')

I tested with #openttdcoop Public Server Game 96 extensively when implementing it, and the performance on my computer FYI:

C2D @ 2400MHz, NVIDIA 7600GT

(window size 1024x768)
zoomed in: ~230fps
zoomed out 1 level: ~180fps
zoomed out 2 levels:~120fps
zoomed out 3 levels: ~20fps (!)

(window size 1680x1050)
zoomed in: ~130fps
zoomed out 1 level: ~120fps
zoomed out 2 levels:~60fps
zoomed out 3 levels: ~15fps

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 12:23
by Frostregen
Hmm, somehow my fps are capped at 96 FPS. (measuring with FRAPS)
VSync is "Forced Off" in NV-ControlPanel. (my monitor usually runs at 72Hz)

I remember the VSync options for openGL were on a special openGL menu within the ControlPanel.
Could this be my problem, and is this still the case for 175.19 drivers?

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 12:36
by bokkie
Sounds nice, I'm gonna try it. Is it possible to make zoom-out look like in this thread: http://www.tt-forums.net/viewtopic.php? ... it=blitter ? I'd guess it is, it looks much better than the original behavior but in the patch in the mentioned thread zooming in/out takes a sec, which maybe could be faster when using the graphics card.

EDIT: it doesn't seem to work on my ATI Radeon x1950pro... the check says it should work, but I only get a black window (sound is playing) with a fps counter (comes with Ati Tray Tools). I used your build.

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 13:51
by Tiberius
CommanderZ, bokkie:
I'll look into the zooming issue. Currently I'm using nearest neighborhood (no interpolation) since I like original 'blocky' (O)TT(D) feel, and I think original blitter didn't really do nearest neighborhood. (I think these white-blue strips along your tracks are fences rendered!)

Another reason I didn't do interpolation is that ... palette indexes can't be 'interpolated' at all. I used fragment program to do palette lookup/animation, so I must preserve exact color indexes or the screen will become a mess.

This is also the reason I can't "hide" palette-animated pixels when transparency is enabled. But personally I really like the effect of this "bug". :)

==
CommanderZ:
Fraps is your friend :mrgreen:

==
Frostregen:
How about the fast-forward button?
I think the "Force VSync Off" in NV Control Panel is enough. I'm currently away from my testing desktop, so I'll check my driver version later.

==
bookie:
Go for a NVIDIA GeForce 6200+ card ... 8)
Well just kidding. I don't have PCs with capable ATI cards nearby, therefore I can't check the situation nor provide help ... sorry for that :(

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 16:31
by CommanderZ
I tried to change the font to Calibri (I love that one!) and it looked fantastic, but as the font has slightly smaller letters than usual, I tried to increase the font to 12. And all texts in the game became unreadable (I can post screenshot) - the game displays just some block blurry things.

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 17:06
by Frostregen
Oh my... fast forward... ;)

thx... will test later at home

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 20:18
by Digitalfox
bokkie wrote:Sounds nice, I'm gonna try it. Is it possible to make zoom-out look like in this thread: http://www.tt-forums.net/viewtopic.php? ... it=blitter ? I'd guess it is, it looks much better than the original behavior but in the patch in the mentioned thread zooming in/out takes a sec, which maybe could be faster when using the graphics card.

EDIT: it doesn't seem to work on my ATI Radeon x1950pro... the check says it should work, but I only get a black window (sound is playing) with a fps counter (comes with Ati Tray Tools). I used your build.
Yes, just tried a Radeon 9800XT and also had that black window .. :?

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 21:00
by Tiberius
Updated the first post to clarify some status about ATI graphics card support.

More about zooming out quality: This blitter utilizes texture atlas to increase batch size, so mip-mapping will be a little difficult. I already have some thoughts about this, but don't have time to implement it right now, so please be patient ... :oops:

Re: OpenGL Blitter for OpenTTD

Posted: 24 Jun 2008 22:51
by Spaz O Mataz
this also shows a black screen on the RADEON 9550.

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 06:48
by peter1138
Generating mipmaps would help the zoom-out issue.

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 09:29
by wolf-kamikatze
On my Ati 3870, the screen keeps black too.

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 10:41
by connan
Hehe, thats cool 8)
How about anti aliasing?

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 10:46
by CommanderZ
I tested with #openttdcoop Public Server Game 96 extensively when implementing it, and the performance on my computer FYI:

C2D @ 2400MHz, NVIDIA 7600GT

(window size 1024x768)
zoomed in: ~230fps
zoomed out 1 level: ~180fps
zoomed out 2 levels:~120fps
zoomed out 3 levels: ~20fps (!)

(window size 1680x1050)
zoomed in: ~130fps
zoomed out 1 level: ~120fps
zoomed out 2 levels:~60fps
zoomed out 3 levels: ~15fps
My stats: 1280*1024 on GF 6200, Athlon XP 2500+ (single core 32 bit), 1500 MB RAM

Tested on the same map
zoomed in: ~25 fps
l1 zoom out: ~19 fps
l2 zoom out: ~16 fps
l3 zoom out: ~9 fps

Sadly no Fraps with no-opengl blitters :(

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 23:08
by ccfreak2k
This post intentionally left blank.

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 23:25
by Digitalfox
Here you go..

Tested on a Radeon 9800XT 256MB

Windows XP SP2

Hope it helps :mrgreen:

Re: OpenGL Blitter for OpenTTD

Posted: 25 Jun 2008 23:46
by Digitalfox
And this one from a Notebook with a Radeon 9600 64MB Mobility :)