SetViewPort Issues - Truth or Fiction?

BlitzMax Forums/BlitzMax Programming/SetViewPort Issues - Truth or Fiction?

therevills(Posted 2010) [#1]
Over the years Ive read that you shouldnt use SetViewPort for any games you release due to the fact it doesnt work well on certain graphics cards.

Recently Ive bought Playniax's awesome Ignition framework, but by looking in the framework it uses SetViewPort.

So I decided to search these forums to try and find what problems SetViewPort actually cause, since Ive never seen the problems and just taken the advise of others.

Here is what Ive found:

DrawPixmap don't work with SetViewport
http://www.blitzbasic.com/Community/posts.php?topic=52475#585878

the BlitzMax DirectX "SetViewport" command does not actually set the Viewport, it sets clip-planes

http://www.blitzbasic.com/Community/posts.php?topic=56006#623515

In Grey Alien's framework he has the following comment for this code:
'WARNING: SetViewport may not work on all graphics cards!

http://www.blitzbasic.com/Community/posts.php?topic=59108#658281

This could be related to a bug I reported where SetViewPort would break (on my machine) when I had screen cloning turned on (a feature of my gfx card).

http://www.blitzbasic.com/Community/posts.php?topic=59968#668863

I tried using SetViewPort but many people said this was not a reliable method of copying a texture

http://www.blitzbasic.com/Community/posts.php?topic=60166#671192

The SetViewport seems indeed to be ignored.

http://www.blitzbasic.com/Community/posts.php?topic=60604#676088

it seems that on some cards the lower viewport border isn't processed at all

http://www.blitzbasic.com/Community/posts.php?topic=61496#687273

BlitzMax's SetViewport() is misleading

http://www.blitzbasic.com/Community/posts.php?topic=62303#719445

The big viewport test!

http://www.blitzbasic.com/Community/posts.php?topic=62781#701367

DX clipping problem

http://www.blitzbasic.com/Community/posts.php?topic=62820#701959

on some old Geforce 2-GraphicCards the SetViewPort-Command from BlitzMax will be totaly ignored.

http://www.blitzbasic.com/Community/posts.php?topic=63264#706551

A HUGE post by IH:
http://www.blitzbasic.com/Community/posts.php?topic=63683#875956

definitely should have nothing to do with your scrolling

http://www.blitzbasic.com/Community/posts.php?topic=64364#718560

Don't use setviewport because it's unreliable on some PCs.

http://www.blitzbasic.com/Community/posts.php?topic=71131#795094

the SetViewPort() function, but that seems to be broken or not 100% gpu/cross platform compatible

http://www.blitzbasic.com/Community/posts.php?topic=72014#804925

reports of setviewport not working properly on some cards.

http://www.blitzbasic.com/Community/posts.php?topic=75141#839803

The viewport thing also doesn't work on my videocard (Geforce 4mx)..

http://www.blitzbasic.com/Community/posts.php?topic=75141#840655

SetViewPort doesn't work on some GeForce cards, either.

http://www.blitzbasic.com/Community/posts.php?topic=75787#847083

Some people says that it doesn't always work

http://www.blitzbasic.com/Community/posts.php?topic=77525#867550

It works correctly. But on DX7 it uses a technique that needs at least a GeForce 3 level card as it uses clipplanes for the cutting and cards lower than that like GF4 MX and some older intel and S3 only support 2 clip planes while 4 are needed.

http://www.blitzbasic.com/Community/posts.php?topic=77525#868915

I've been told to avoid SetViewport because it doesn't work on some cards. Is this true?

Yes it's true I've seen it with my own eyes.

http://www.blitzbasic.com/Community/posts.php?topic=79234#889658

SetViewport is unreliable on some hardware.

http://www.blitzbasic.com/Community/posts.php?topic=81225#914934

TileImage is dependent on SetViewport, which doesn't work correctly on all hardware.

http://www.blitzbasic.com/Community/posts.php?topic=84483#954524

SetViewport doesn't work on some hardware.

http://www.blitzbasic.com/Community/posts.php?topic=85478#967335

you shouldn't use SetViewport. I hear it doesn't work on all cards...

http://www.blitzbasic.com/Community/posts.php?topic=87151#987692

View Ports do not work for all video cards. They are not reliable. Do not use them. One person said the bug was a DirectX only problem and they work fine in OpenGL. I do not know this for sure.

You were right; I tried it on a different computer, and there was no problem.

http://www.blitzbasic.com/Community/posts.php?topic=87276#989030

From what I understand, SetViewPort() works in OpenGL. It is the DirectX version that does not work.

http://www.blitzbasic.com/Community/posts.php?topic=87765#995655

SetViewPort is not something you should rely on in a commercial game, according to everything I've read on it at least.

I had problems with setviewport on the DX7 drivers, but it seems to work great with the dx9 one on my machnine

http://www.blitzbasic.com/Community/posts.php?topic=90050#1025191

I notice that your iTPlayfield type rely quite a bit on your iSetViewport function which calls BlitzMax's own SetViewport... which has been known to cause issues on a few graphics cards - unless it has been fixed recently?

Yes, I believe the issue was negative coords I discovered on one of my computers but iSetViewPort fixes that problem.

http://www.blitzbasic.com/Community/posts.php?topic=92511#1055508


A lot of these are quite old (3+ years), but it seems to come down to:
* DX7
* Old GeForce Cards
* DX Viewport is different to OpenGL Viewport

Now Playniax's Ignition framework uses SetViewPort, is it safe for mass market use?


SLotman(Posted 2010) [#2]
That's a really good question.

Seeing the ammount of reports, it's hard to ignore it - but I can say I never saw it happening, and I generally test my games on 5 or more different computers.


Muttley(Posted 2010) [#3]
Fiction I think.

Most of the reports are of the "I heard there are problems" kind, which somehow have created a self-referential feedback loop here, but nobody has ever backed this up with hard data from their own experiences.

Certainly I've never seen a problem with it in my (albeit limited) testing.


Grafos(Posted 2010) [#4]
I used it on my game, no beta tester reported any problem, and it was tested on 10+ computers.


GfK(Posted 2010) [#5]
Most of the reports are of the "I heard there are problems" kind
Yep, I've recommended not using it in the past because so many others have claimed to have a problem with it. I'm not saying they're all pathological liars or anything - I just haven't seen the issue for myself but was put off by the number of others warning about it.

I'd like to know WHY it doesn't work on some hardware... and ultimately if the concerns about it are realistic in the scheme of things.


Yan(Posted 2010) [#6]
I seem to recall that nVidia implemented DX clipping planes in a non standard way with it's GF4(ish) offerings, which can, 'under certain circumstances'*, lead to problems. Also, really old nVidia cards (GF, GF2, GF4MX etc) don't support hardware clipping planes at all.

So it really depends on how compatible with 'old' hardware you want to be.



*No, I'm not entirely sure what that means either. ;o)

Last edited 2010


ima747(Posted 2010) [#7]
Not having seen any issues myself, I would chalk this up (just to not brush it off) as a legacy support issue. I have no doubt (just due to the number of "bad" graphics cards in existence) that it can cause problems, but on any remotely modern piece of kit I would not expect any ill effects. I think this is likely to be less prevalent than say issues with GLShareContext(), which I am very comfortable using despite it having known problems on some cards simply due to those known cards being both older and lower end, so it's fair to assume (for me) that the given project is not going to run well on those systems anyways (for ram/processor/etc. other reasons) so one MORE reason it won't run won't make a difference.

However in the interest of clarity as well as more backwards compatibility always being a good thing, some more exhaustive investigation would be great to see...

P.S. thanks for the exhaustive list of references to this issue, I am quite impressed :0)


Grey Alien(Posted 2010) [#8]
I saw it fail on an old PC a number of years ago.


_Skully(Posted 2010) [#9]
So if its that few, refund people that cant use it. We have to draw the line somewhere

I use viewports when creating multiple renderwindows

Last edited 2010


therevills(Posted 2010) [#10]
Portals wont except it... thats my concern.

Is there a replacement which is compatible with the old gpus?


Muttley(Posted 2010) [#11]
@therevills: Got any proof of that?


Tachyon(Posted 2010) [#12]
I use SetViewPort on Eschalon: Book II. Never had one complaint.


TaskMaster(Posted 2010) [#13]
Tachyon, no offense, but an RPG is not really a casual game that a grandma with a $199 emachine is going to be playing. ;)

I would also like to see us get to the bottom of this issue. Is it really an issue, or is such a small portion of users that we can just ignore it?!?!

Last edited 2010


Muttley(Posted 2010) [#14]
@TaskMaster: The style of game is pretty irrelevant, either the problem exists or it doesn't.

So far we have Gray Alien who has seen it fail once on a test machine and that's it.

@Tachyon: If you don't have a problem sharing that sort of information, do you have a rough ballpark figure of how many copies you've sold? Same goes for anyone else who's sold games that use ViewPorts.

It's possible that if there even is a real problem it's statistically neglibible.


TaskMaster(Posted 2010) [#15]
Muttley, my point is that if the problem exists on machines with wimpy built in intel graphics cards, then the problem is not likely to show up on Tachyon's player base. I did not say the problem had anything to do with the gameplay, it has to do with the hardware, a type of hardware not likely to be used by Tachyon's player base.

Anyway, it was meant more as a joke than anything else. Hence, the smiley.

I understand the problem, trust me. I wrote my ifsoGUI module specifically to not use SetViewPort. I wrote some functions to avoid it. It is extra problematic for people who write modules for others to use, as even if I don't care about the small percentage of people who can't run my program, it is not fair for me to tell people who purchase my module that they now can't support that minority of people.

Last edited 2010


Grey Alien(Posted 2010) [#16]
Depending on what you want to use SetViewPort for, there are alternatives, which I used. But I was only using it in a simple way.

Last edited 2010


TaskMaster(Posted 2010) [#17]
It is possible to make a setviewport that will work. But, you have to do all of the calculations yourself. All you have to do is adjust your sprite so that it does not draw out of the area. Either by using DrawSubImageRect if it isn't rotated, or if it is, you will have to manually add vertexes and adjust the texture. It is possible to do though, as we had a thread discussing how to do it a while back. I had dabbled with it, but never got around to making a module that did it.


therevills(Posted 2010) [#18]
@therevills: Got any proof of that?


Any bugs they find they will want you to fix, if you cant fix it I'm pretty sure they wont release it... but Im only guessing...

So far we have Gray Alien who has seen it fail once on a test machine and that's it.


Did you read any of the links I posted?

http://blitzbasic.com/Community/posts.php?topic=63264#706551

maverick69:
The GraphicCard is: nVidia GeForce2MX400



Muttley(Posted 2010) [#19]
That's a 4-year old post talking about a bug found with a 10-year old bit of hardware that hasn't had driver support for 4 years.

Last edited 2010


Oddball(Posted 2010) [#20]
I'm with muttley. If ten year old hardware is your target market then worry about this stuff. More modern setups should be fine.


GaryV(Posted 2010) [#21]
Any bugs they find they will want you to fix, if you cant fix it I'm pretty sure they wont release it... but Im only guessing...
As a developer, you can only fix bugs in your program. You can't fix bugs in graphics drivers provided by another company and you can't reverse engineer hardware and rebuild it to fix hardware bugs.


_Skully(Posted 2010) [#22]
Well I know I'm not removing multiple render windows from TileMax to support ancient hardware. My mother has better hardware than I do and I'm well behind the average setup. It keeps me efficient though ;)


therevills(Posted 2010) [#23]
This is what this whole post is about, "is it safe now to use SetViewPort" :)

Heres a more recent issue:

In my laptop with intel graphics, I noticed that it kind of pauses at times. It seems to me it's the SetViewPort function causing that


http://www.blitzbasic.co.nz/Community/posts.php?topic=88126#1001660

But thats sounds more like a performance issue...

On SetViewport borked: thats incorrect. It works correctly. But on DX7 it uses a technique that needs at least a GeForce 3 level card as it uses clipplanes for the cutting and cards lower than that like GF4 MX and some older intel and S3 only support 2 clip planes while 4 are needed.


http://blitzbasic.com/Community/posts.php?topic=77525#868915

Last edited 2010


Pierrou(Posted 2010) [#24]
I've seen it fail just 2 minutes ago while trying my new game on my 2001 Compaq laptop... (graphics card S3 twister K). It was just ignored...
Which means I have * quite a few things * to change right now if I want my game to work on any not so old PC... :(


Drackbolt(Posted 2010) [#25]
Personally (just to give feedback), I use Viewports all over the place in my projects, going on for several years with hundreds of players. Never had one problem reported due to it.


Muttley(Posted 2010) [#26]
@Pierrou: Are you absolutely sure that there a large enough amount of people using such an old piece of hardware that it is worth wasting your time supporting it? Going by the Steam stats the answer is definitely no.

The drivers are classed as legacy by S3, with the last being released over 7 years ago, and those drivers only support up to WinXP.

It's really not worth worrying about. This is what demo versions are for, so people can try it out and make sure it works before buying.


Beaker(Posted 2010) [#27]
I was the one that originally reported this bug (4 years ago!!), and the way I managed to stop it happening was by turning off multi-monitor support in my graphics card setup, specifically: turn off cloning, which I'd left on by mistake.

A 2001 laptop is very old.


Pierrou(Posted 2010) [#28]
Hi again everyone,

@ Muttley you're 100% right, people will probably download the demo before buying the game...
@ Beaker : I don't know if a 9 yrs old computer is very old, but I must admit it's almost unusable... And turning off multi-monitor does work indeed!

Thank you for saving my next few evenings. I'm gonna read some good book instead of rewriting the same piece of soft again and again!


ImaginaryHuman(Posted 2010) [#29]
There's a lot of misunderstanding about what happens when you SetViewport and what the viewport really is, which I wrote about at length elsewhere.

On the OpenGL side, SetViewport is actually a combination of two operations. One sets up the camera frustrum which determines how much of the game world can be seen and whether there is a perspective projection and how that view maps to a portion of the actual screen/window. The other part is to do with adding a scissor rectangle and switching on the scissor test, which is where every pixel to be drawn has to pass the test of being inside the rectangle. Blitz uses both of these in combination to create the appearance of what you familiarly refer to as setting the viewport.

ie for most people SetViewport means defining a rectangle of the screen into which the graphics will be drawn and defining what range of coordinates in the game world will map to that area - and that nothing should be drawn outside of that area.

You need to identify whether objects are not being clipped to within the viewport rectangle (which is a clipping/scissor issue), or whether the translation of game-to-screen coordinates is broken (which is a viewport issue).

You should also be aware that setting the viewport - not in the Blitz sense but in the OpenGL sense, does not mean defining a clipped rectangle. Although glViewport() (which Blitz uses) takes a rectangle which gives and *example of* how a portion of the game world maps to a portion of the screen, this example scaling operation is extrapolated to the entire screen. Setting up a viewport is therefore a matter of coordinate mapping across the whole screen and has nothing to do with clipping or rectangles.

If it's that the clipping/rectangle is not working, ie you can see graphics normally but objects draw outside of the rectangle then it's a problem with the clip planes/scissor testing.


Yan(Posted 2010) [#30]
I like turtles...


beanage(Posted 2010) [#31]
We should consider it working, until support releases a statement I guess.


ImaginaryHuman(Posted 2010) [#32]
An alternative to using viewports to clip regions of space you can also use the stencil buffer ... set the stencil up to record, draw to it the geometry shape you want for your window, switch off recording and leave stencil test on, then draw your stuff. It'll clip to the stencilled area. I used this in my snowballs scrolling game to do dynamic diagonal split-screens.


Playniax(Posted 2012) [#33]
okay! Wow, never had any complaint about the viewport system in Ignition. Maybe that's because I found a problem early on that I corrected. It had something today with clipping going wrong. So just for this case I will post some code from Ignition. Maybe this is the problem everyone was talking about :)


	Function iSetViewport (_x:Int, _y:Int, _Width:Int, _Height:Int)

	If _x < 0

		If -_x => _Width
			_x = 0
			_Width = 0
		Else
			_Width:+ _x
			_x = 0
		End If

	End If

	If _y < 0

		If -_y => _Height
			_y = 0
			_Height = 0
		Else
			_Height:+ _y
			_y = 0
		End If

	End If

	SetViewport _x, _y, _Width, _Height

	End Function



Last edited 2012


Armitage 1982(Posted 2012) [#34]
Nice to see updates for ignition !

Do you still plan to update it to reflect the Monkey engine to come ?

About the setViewport, I don't know about DX but there is absolutely no problem with OpenGL.
I try it on very old machines (pentium 100, win 98, old AMD K6, etc.) netbook with huge restrictions (GMA) and micro-computer : no problem at all.


Playniax(Posted 2012) [#35]
@Armitage 1982:

'Do you still plan to update it to reflect the Monkey engine to come ?'

Yes, I plan to do a major update after the Monkey release. I will try to reflect them as much as I can.