SDL_Viewport oddity?

I’m leafing through the LazyFoo SDL2.0 (http://lazyfoo.net/tutorials/SDL/09_the_viewport/index.php) tutorials to get a grip on all the changes from SDL1.2, and I came upon an oddity on tutorial 9 (http://lazyfoo.net/tutorials/SDL/09_the_viewport/index.php) which involves viewports. Tutorial 8 (http://lazyfoo.net/tutorials/SDL/09_the_viewport/index.php) just mentioned how the coordinate system starts in the top left of the screen and how positive is considered right and down. Okay, no problem, and whenever I put rectangles/images on the screen that is exactly what I see. But when I adjust the viewport, it behaves as if the bottom left hand of the screen is the origin! I’m running Ubuntu. Could there have been a misstep in the Ubuntu implementation of this?

The following code produ

Code:

SDL_Rect v0;
v0.x=0;
v0.y=0;
v0.w=300;
v0.h=300;
SDL_Rect position;
position.x=0;
position.y=0;
position.w=300;
position.h=300;

SDL_RenderClear( gRenderer );
SDL_RenderSetViewport(gRenderer,&v0);
SDL_RenderCopy( gRenderer, myTexture, NULL, &position );

That gives this result:
[Image: http://i.imgur.com/MNJRC6W.png ]
If I change position.y=100; and position.x=100;, I get the following result:
[Image: http://i.imgur.com/XvkW40H.png ]
If I copy the LazyFoo tutorial 9 code, I get this:
[Image: http://i.imgur.com/QPCJHr9.png ]
Whereas the LazyFoo tutorial gives this image:
[Image: http://lazyfoo.net/tutorials/SDL/09_the_viewport/subviews.png ]

I have posted the full source at http://pastebin.com/YfrKcCA5. I’m not sure whether I’m being stupid, whether I’ve misunderstood the documentation somewhere, if this is evidence of a bug/misimplementation of SDL on Ubuntu, or if the Lazy Foo neglected to say that different results can be expected on different systems.

I am encountering the same issue. I have a small application which I run on Mac, Windows and Linux.

On Windows and Mac the coordinate system for the viewport has 0/0 in the upper left corner, whereas on Linux ( I tried only with Ubuntu 13.10) the origin is in the lower left corner and y expanding upwards.

I helped myself by changing the y oft the viewport accordingly but it is a pitty that thus feature is not really portable out oft the box… :frowning:

Update:

I just upgraded from Ubuntu 13.10 to Ubuntu 14.04 LTS and the issue with SDL_RenderSetViewport to use a different coordinate system than on Windows and Mac seems to be solved!

Very happy :slight_smile:

seems like a random bug in some Ubuntu driver, or maybe in the version of X server included in some specific versions of Ubuntu.

Something like this might be worthwhile looking into and accounting for on affected versions.------------------------
Nate Fries