OpenGL Blitter for OpenTTD

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Tiberius
Engineer
Engineer
Posts: 86
Joined: 17 Sep 2004 03:15

OpenGL Blitter for OpenTTD

Post 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 715 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.
Attachments
opengl-080711_r13691.patch
(144.38 KiB) Downloaded 880 times
Last edited by Tiberius on 11 Jul 2008 15:12, edited 21 times in total.
I may implement/fix/tweak/eat/ditch it soon (or in distant future, if at all, so don't hold your breath).
If anyone want to be the one please implement it for us all 8)
kaan
Route Supervisor
Route Supervisor
Posts: 399
Joined: 02 Apr 2007 20:13
Location: Nørup, Denmark

Re: OpenGL Blitter for OpenTTD

Post 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?

Code: Select all

if (YouAreHappyAndYouKnowIt) {
    ClapYourHands();
}
Tiberius
Engineer
Engineer
Posts: 86
Joined: 17 Sep 2004 03:15

Re: OpenGL Blitter for OpenTTD

Post 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
I may implement/fix/tweak/eat/ditch it soon (or in distant future, if at all, so don't hold your breath).
If anyone want to be the one please implement it for us all 8)
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: OpenGL Blitter for OpenTTD

Post 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.
Attachments
Führer's Travel Corp., 18. zář 2263.png
With OpenGL
(686.97 KiB) Downloaded 872 times
Führer's Travel Corp., 18th Sep 2263.png
8bpp blitter
(425.51 KiB) Downloaded 714 times
Last edited by CommanderZ on 24 Jun 2008 11:46, edited 1 time in total.
Tiberius
Engineer
Engineer
Posts: 86
Joined: 17 Sep 2004 03:15

Re: OpenGL Blitter for OpenTTD

Post 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
I may implement/fix/tweak/eat/ditch it soon (or in distant future, if at all, so don't hold your breath).
If anyone want to be the one please implement it for us all 8)
Frostregen
Transport Coordinator
Transport Coordinator
Posts: 340
Joined: 06 Feb 2006 23:58

Re: OpenGL Blitter for OpenTTD

Post 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?
bokkie
Transport Coordinator
Transport Coordinator
Posts: 327
Joined: 19 Jan 2007 19:26

Re: OpenGL Blitter for OpenTTD

Post 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.
Tiberius
Engineer
Engineer
Posts: 86
Joined: 17 Sep 2004 03:15

Re: OpenGL Blitter for OpenTTD

Post 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 :(
I may implement/fix/tweak/eat/ditch it soon (or in distant future, if at all, so don't hold your breath).
If anyone want to be the one please implement it for us all 8)
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: OpenGL Blitter for OpenTTD

Post 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.
Frostregen
Transport Coordinator
Transport Coordinator
Posts: 340
Joined: 06 Feb 2006 23:58

Re: OpenGL Blitter for OpenTTD

Post by Frostregen »

Oh my... fast forward... ;)

thx... will test later at home
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: OpenGL Blitter for OpenTTD

Post 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 .. :?
Tiberius
Engineer
Engineer
Posts: 86
Joined: 17 Sep 2004 03:15

Re: OpenGL Blitter for OpenTTD

Post 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:
I may implement/fix/tweak/eat/ditch it soon (or in distant future, if at all, so don't hold your breath).
If anyone want to be the one please implement it for us all 8)
Spaz O Mataz
Engineer
Engineer
Posts: 52
Joined: 08 Mar 2004 21:14
Location: Sunderland UK

Re: OpenGL Blitter for OpenTTD

Post by Spaz O Mataz »

this also shows a black screen on the RADEON 9550.
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1729
Joined: 30 Mar 2005 09:43

Re: OpenGL Blitter for OpenTTD

Post by peter1138 »

Generating mipmaps would help the zoom-out issue.
He's like, some kind of OpenTTD developer.
wolf-kamikatze
Engineer
Engineer
Posts: 1
Joined: 12 Mar 2006 14:43
Location: Naumburg (S.) (Germany)

Re: OpenGL Blitter for OpenTTD

Post by wolf-kamikatze »

On my Ati 3870, the screen keeps black too.
connan
Engineer
Engineer
Posts: 18
Joined: 08 May 2007 20:46
Location: Germany, Dresden

Re: OpenGL Blitter for OpenTTD

Post by connan »

Hehe, thats cool 8)
How about anti aliasing?
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: OpenGL Blitter for OpenTTD

Post 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 :(
ccfreak2k
Engineer
Engineer
Posts: 9
Joined: 25 Jun 2008 23:01
Location: California, United States

Re: OpenGL Blitter for OpenTTD

Post by ccfreak2k »

This post intentionally left blank.
Last edited by ccfreak2k on 26 Jun 2008 14:26, edited 3 times in total.
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: OpenGL Blitter for OpenTTD

Post by Digitalfox »

Here you go..

Tested on a Radeon 9800XT 256MB

Windows XP SP2

Hope it helps :mrgreen:
Attachments
Command line!
Command line!
Command.PNG (11.28 KiB) Viewed 24255 times
How Intro looks!
How Intro looks!
Intro.PNG (206.95 KiB) Viewed 24302 times
User avatar
Digitalfox
Chief Executive
Chief Executive
Posts: 708
Joined: 28 Oct 2004 04:42
Location: Catch the Fox if you can... Almost 20 years and counting!

Re: OpenGL Blitter for OpenTTD

Post by Digitalfox »

And this one from a Notebook with a Radeon 9600 64MB Mobility :)
Attachments
Command line!
Command line!
Command.PNG (10.28 KiB) Viewed 24279 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 10 guests