SDL_Viewport oddity?

I’m leafing through the LazyFoo SDL2.0 ( tutorials to get a grip on all the changes from SDL1.2, and I came upon an oddity on tutorial 9 ( which involves viewports. Tutorial 8 ( 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


SDL_Rect v0;
SDL_Rect position;

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

That gives this result:
[Image: ]
If I change position.y=100; and position.x=100;, I get the following result:
[Image: ]
If I copy the LazyFoo tutorial 9 code, I get this:
[Image: ]
Whereas the LazyFoo tutorial gives this image:
[Image: ]

I have posted the full source at 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:


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