Best Practices for landscaped mode on iOS

Yep, it sounds like it might be a bug in SDL code. Feel free to dig
deeper, and if you can send a reproducible case I’m happy to poke at it.

One thing I haven’t tried is explicitly setting the orientation when an
iOS window is shown.

What orientation is your device when you start? If you hold it in
landscape mode at the start, does it have the same problem?

I’m having problems too with the new orientation code, just pulled from hg.

App is PORTRAIT only, the window is not resizable (SDL_WINDOW_FULLSCREEN)
and xcode summary allows only for portrait as orientation.

The app start ok, but without status bar shown (and there is no
SDL_WINDOW_BORDERLESS flag specified).

If i double click on the top of the screen, the “handle” to "pull down"
notification center appears and the view is shifted 20 pixels (like if the
status bar is shown), the view remains shifted all the time, but finger
pressures return coordinates as if it’s not.On Mon, Sep 24, 2012 at 5:50 PM, Sam Lantinga wrote:


Bye,
Gabry

I am so happy someone else is also experiencing this. What I have found out so far:

  1. in applicationDidFinishLaunching, iOS sets up portrait mode. This is regardless of what the plist file says, if it was in landscape during load

  2. SDL sets of window in landscape mode as asked, however the EACGLayer still gets the wrong width and height initially when asking for the size of the backing buffer for the render target.

If any one has more time to look at this, it would be immensely helpful

Sam, yeah, same problem if I hold the device in landscape mode initially.

::GormOn Thursday, September 27, 2012 at 4:41 PM, Gabriele Greco wrote:

On Mon, Sep 24, 2012 at 5:50 PM, Sam Lantinga <slouken at libsdl.org (mailto:slouken at libsdl.org)> wrote:

Yep, it sounds like it might be a bug in SDL code. Feel free to dig deeper, and if you can send a reproducible case I’m happy to poke at it.

One thing I haven’t tried is explicitly setting the orientation when an iOS window is shown.

What orientation is your device when you start? If you hold it in landscape mode at the start, does it have the same problem?

I’m having problems too with the new orientation code, just pulled from hg.

App is PORTRAIT only, the window is not resizable (SDL_WINDOW_FULLSCREEN) and xcode summary allows only for portrait as orientation.

The app start ok, but without status bar shown (and there is no SDL_WINDOW_BORDERLESS flag specified).

If i double click on the top of the screen, the “handle” to “pull down” notification center appears and the view is shifted 20 pixels (like if the status bar is shown), the view remains shifted all the time, but finger pressures return coordinates as if it’s not.


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

The fullscreen flag implies borderless, FYI.

What resolution are you asking for? What version of Xcode are you using?
What version of iOS are you testing on? Are you testing on simulator
and/or device?

Do you have a simple test case that reproduces the problem?On Thu, Sep 27, 2012 at 8:41 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

On Mon, Sep 24, 2012 at 5:50 PM, Sam Lantinga <@slouken> wrote:

Yep, it sounds like it might be a bug in SDL code. Feel free to dig
deeper, and if you can send a reproducible case I’m happy to poke at it.

One thing I haven’t tried is explicitly setting the orientation when an
iOS window is shown.

What orientation is your device when you start? If you hold it in
landscape mode at the start, does it have the same problem?

I’m having problems too with the new orientation code, just pulled from hg.

App is PORTRAIT only, the window is not resizable (SDL_WINDOW_FULLSCREEN)
and xcode summary allows only for portrait as orientation.

The app start ok, but without status bar shown (and there is no
SDL_WINDOW_BORDERLESS flag specified).

If i double click on the top of the screen, the “handle” to "pull down"
notification center appears and the view is shifted 20 pixels (like if the
status bar is shown), the view remains shifted all the time, but finger
pressures return coordinates as if it’s not.


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

What resolution are you asking for? What version of Xcode are you using?
What version of iOS are you testing on? Are you testing on simulator
and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every
version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using
the optimal resolution for the device, the app plist lists portrait as the
only display mode.

The yellow square moves every time you create an event (touch the screen
for instance). If you pull down once the notification center (works in
simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work
without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, {
640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,
res_->width, res_->height,
SDL_WINDOW_FULLSCREEN))) {
std::cerr << “Unable to open display.\n”;
return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}–
Bye,
Gabry

I haven’t tried running it yet, but I have a silly question… All those
resolutions you have listed are portrait resolutions, which SDL will try to
set up in portrait mode. Have you tried flipping the width and height?On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

What resolution are you asking for? What version of Xcode are you using?
What version of iOS are you testing on? Are you testing on simulator
and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every
version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using
the optimal resolution for the device, the app plist lists portrait as the
only display mode.

The yellow square moves every time you create an event (touch the screen
for instance). If you pull down once the notification center (works in
simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work
without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, {
640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,
res_->width, res_->height,
SDL_WINDOW_FULLSCREEN))) {
std::cerr << “Unable to open display.\n”;
return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Oh, I see you’re reporting a separate bug from the thread title here.On Sat, Sep 29, 2012 at 12:28 AM, Sam Lantinga <@slouken> wrote:

I haven’t tried running it yet, but I have a silly question… All those
resolutions you have listed are portrait resolutions, which SDL will try to
set up in portrait mode. Have you tried flipping the width and height?

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

What resolution are you asking for? What version of Xcode are you
using? What version of iOS are you testing on? Are you testing on
simulator and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every
version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using
the optimal resolution for the device, the app plist lists portrait as the
only display mode.

The yellow square moves every time you create an event (touch the screen
for instance). If you pull down once the notification center (works in
simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work
without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 },
{ 640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,
res_->width, res_->height,
SDL_WINDOW_FULLSCREEN))) {
std::cerr << “Unable to open display.\n”;
return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
     std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I must be missing something. It looks like it’s working okay here?On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

What resolution are you asking for? What version of Xcode are you using?
What version of iOS are you testing on? Are you testing on simulator
and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every
version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using
the optimal resolution for the device, the app plist lists portrait as the
only display mode.

The yellow square moves every time you create an event (touch the screen
for instance). If you pull down once the notification center (works in
simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work
without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, {
640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,
res_->width, res_->height,
SDL_WINDOW_FULLSCREEN))) {
std::cerr << “Unable to open display.\n”;
return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: Screen Shot 2012-09-29 at 12.34.33 AM.png
Type: image/png
Size: 87636 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120929/9ca23e94/attachment-0001.png

as I understand it, iOS 6.0 actually obeys what you set for orientation in the plist. Earlier versions only do it for the splash screen.

Can this be difference here?On Saturday, September 29, 2012 at 8:37 AM, Sam Lantinga wrote:

I must be missing something. It looks like it’s working okay here?

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it (mailto:gabriele.greco at darts.it)> wrote:

What resolution are you asking for? What version of Xcode are you using? What version of iOS are you testing on? Are you testing on simulator and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every version of simulator (I tried 5.1 normal/retina and 6.0 normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using the optimal resolution for the device, the app plist lists portrait as the only display mode.

The yellow square moves every time you create an event (touch the screen for instance). If you pull down once the notification center (works in simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, { 640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);    
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' << SDL_GetPixelFormatName(mode.format) << '\n';
    
    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                 res_->width, res_->height, SDL_WINDOW_FULLSCREEN))) {
    std::cerr << "Unable to open display.\n";
    return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;
    
    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);
    
    SDL_Event e;
    
    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Attachments:

  • Screen Shot 2012-09-29 at 12.34.33 AM.png

Hi Sam,

I managed to make a minimal sample to reproduce the problem with the initial rotation. Attached :)On Saturday, September 29, 2012 at 10:09 AM, Gorm Lai wrote:

as I understand it, iOS 6.0 actually obeys what you set for orientation in the plist. Earlier versions only do it for the splash screen.

Can this be difference here?

On Saturday, September 29, 2012 at 8:37 AM, Sam Lantinga wrote:

I must be missing something. It looks like it’s working okay here?

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it (mailto:gabriele.greco at darts.it)> wrote:

What resolution are you asking for? What version of Xcode are you using? What version of iOS are you testing on? Are you testing on simulator and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every version of simulator (I tried 5.1 normal/retina and 6.0 normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using the optimal resolution for the device, the app plist lists portrait as the only display mode.

The yellow square moves every time you create an event (touch the screen for instance). If you pull down once the notification center (works in simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, { 640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);    
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' << SDL_GetPixelFormatName(mode.format) << '\n';
    
    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                 res_->width, res_->height, SDL_WINDOW_FULLSCREEN))) {
    std::cerr << "Unable to open display.\n";
    return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;
    
    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);
    
    SDL_Event e;
    
    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Attachments:

  • Screen Shot 2012-09-29 at 12.34.33 AM.png

-------------- next part --------------
A non-text attachment was scrubbed…
Name: MinimalSDLSample.zip
Type: application/zip
Size: 6854 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120929/f7b94b98/attachment-0001.zip

So I spent all day on this and the problem has something to do with
creating a new context after creating a renderer. SDL creates an OpenGL
view when you request a context on iOS, and for some reason the second view
that gets added to the window is different from the first one and doesn’t
have the same frame or transformation applied.

This is a common problem, as I found when searching, but none of the
recommended workarounds took care of things and I’m not sure why.

Since creating a renderer already creates an OpenGL context and makes it
current, you can blithely do other OpenGL calls afterwards on iOS and it
will work just fine. I tested this in the sample app you sent and it
worked great if I removed other context handling.

As a bonus I made some orientation aware versions of the width and height
functions for ya:

unsigned int GetWidth()
{
unsigned int width;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]
statusBarOrientation]))
width = SDL_max(size.width, size.height);
else
width = SDL_min(size.width, size.height);

if([[UIScreen mainScreen]
respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES
)
width = width * [[UIScreen mainScreen] scale];
return width;
}

unsigned int GetHeight()
{
unsigned int height;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]
statusBarOrientation]))
height = SDL_min(size.width, size.height);
else
height = SDL_max(size.width, size.height);

if([[UIScreen mainScreen]
respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES
)
height = height * [[UIScreen mainScreen] scale];

return height;

}

Cheers!On Sat, Sep 29, 2012 at 7:59 AM, Gorm Lai wrote:

Hi Sam,

I managed to make a minimal sample to reproduce the problem with the
initial rotation. Attached :slight_smile:

On Saturday, September 29, 2012 at 10:09 AM, Gorm Lai wrote:

as I understand it, iOS 6.0 actually obeys what you set for orientation
in the plist. Earlier versions only do it for the splash screen.

Can this be difference here?

On Saturday, September 29, 2012 at 8:37 AM, Sam Lantinga wrote:

I must be missing something. It looks like it’s working okay here?

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it>wrote:

What resolution are you asking for? What version of Xcode are you using?
What version of iOS are you testing on? Are you testing on simulator
and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every
version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using
the optimal resolution for the device, the app plist lists portrait as the
only display mode.

The yellow square moves every time you create an event (touch the screen
for instance). If you pull down once the notification center (works in
simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work
without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, {
640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,
res_->width, res_->height,
SDL_WINDOW_FULLSCREEN))) {
std::cerr << “Unable to open display.\n”;
return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
     std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Attachments:

  • Screen Shot 2012-09-29 at 12.34.33 AM.png

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi Sam,

Thank you very much for spending all this time on this, and thank you for the work around.

I am not sure how this will work when/if the context is ever lost on a mobile device. I will try to give it a kick and see what happens.

Cheers,
Gorm

PS. Thank you for the height/width functions :)On Sunday, September 30, 2012 at 10:51 AM, Sam Lantinga wrote:

So I spent all day on this and the problem has something to do with creating a new context after creating a renderer. SDL creates an OpenGL view when you request a context on iOS, and for some reason the second view that gets added to the window is different from the first one and doesn’t have the same frame or transformation applied.

This is a common problem, as I found when searching, but none of the recommended workarounds took care of things and I’m not sure why.

Since creating a renderer already creates an OpenGL context and makes it current, you can blithely do other OpenGL calls afterwards on iOS and it will work just fine. I tested this in the sample app you sent and it worked great if I removed other context handling.

As a bonus I made some orientation aware versions of the width and height functions for ya:

unsigned int GetWidth()
{
unsigned int width;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
width = SDL_max(size.width, size.height);
else
width = SDL_min(size.width, size.height);

if([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES )
width = width * [[UIScreen mainScreen] scale];
return width;
}

unsigned int GetHeight()
{
unsigned int height;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]))
height = SDL_min(size.width, size.height);
else
height = SDL_max(size.width, size.height);

if([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES )
height = height * [[UIScreen mainScreen] scale];

return height;

}

Cheers!

On Sat, Sep 29, 2012 at 7:59 AM, Gorm Lai <@Gorm_Lai (mailto:@Gorm_Lai)> wrote:

Hi Sam,

I managed to make a minimal sample to reproduce the problem with the initial rotation. Attached :slight_smile:

On Saturday, September 29, 2012 at 10:09 AM, Gorm Lai wrote:

as I understand it, iOS 6.0 actually obeys what you set for orientation in the plist. Earlier versions only do it for the splash screen.

Can this be difference here?

On Saturday, September 29, 2012 at 8:37 AM, Sam Lantinga wrote:

I must be missing something. It looks like it’s working okay here?

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco <gabriele.greco at darts.it (mailto:gabriele.greco at darts.it)> wrote:

What resolution are you asking for? What version of Xcode are you using? What version of iOS are you testing on? Are you testing on simulator and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with every version of simulator (I tried 5.1 normal/retina and 6.0 normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display using the optimal resolution for the device, the app plist lists portrait as the only display mode.

The yellow square moves every time you create an event (touch the screen for instance). If you pull down once the notification center (works in simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app work without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768, 1024 }, { 640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);    
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' << SDL_GetPixelFormatName(mode.format) << '\n';
    
    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height << '\n';
if (!(screen_ = SDL_CreateWindow("Solit", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                 res_->width, res_->height, SDL_WINDOW_FULLSCREEN))) {
    std::cerr << "Unable to open display.\n";
    return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/, 0))) {
    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;
    
    SDL_SetRenderDrawColor(renderer_, 255, 255, 0, SDL_ALPHA_OPAQUE);
    SDL_RenderFillRect(renderer_, &r);
    
    SDL_Event e;
    
    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Attachments:

  • Screen Shot 2012-09-29 at 12.34.33 AM.png

SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org (mailto:SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

On iOS if the context is lost the system kills your app…so I
guess…don’t worry about it? :slight_smile:

El sep 30, 2012 7:13 a.m., “Gorm Lai” escribi?:

Hi Sam,

Thank you very much for spending all this time on this, and thank you for
the work around.

I am not sure how this will work when/if the context is ever lost on a
mobile device. I will try to give it a kick and see what happens.

Cheers,
Gorm

PS. Thank you for the height/width functions :slight_smile:

So I spent all day on this and the problem has something to do with
creating a new context after creating a renderer. SDL creates an OpenGL
view when you request a context on iOS, and for some reason the second view
that gets added to the window is different from the first one and doesn’t
have the same frame or transformation applied.

This is a common problem, as I found when searching, but none of the
recommended workarounds took care of things and I’m not sure why.

Since creating a renderer already creates an OpenGL context and makes it
current, you can blithely do other OpenGL calls afterwards on iOS and it
will work just fine. I tested this in the sample app you sent and it
worked great if I removed other context handling.

As a bonus I made some orientation aware versions of the width and
height functions for ya:

unsigned int GetWidth()
{
unsigned int width;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication
sharedApplication] statusBarOrientation]))

  width = SDL_max(size.width, size.height);

else
width = SDL_min(size.width, size.height);

if([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES
)

width = width * [[UIScreen mainScreen] scale];

return width;
}

unsigned int GetHeight()
{
unsigned int height;

CGSize size = [UIScreen mainScreen].bounds.size;
if (UIInterfaceOrientationIsLandscape([[UIApplication
sharedApplication] statusBarOrientation]))

  height = SDL_min(size.width, size.height);

else
height = SDL_max(size.width, size.height);

if([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]==YES
)

height = height * [[UIScreen mainScreen] scale];

return height;

}

Cheers!

Hi Sam,

I managed to make a minimal sample to reproduce the problem with the
initial rotation. Attached :slight_smile:

as I understand it, iOS 6.0 actually obeys what you set for
orientation in the plist. Earlier versions only do it for the splash screen.

Can this be difference here?

I must be missing something. It looks like it’s working okay here?

What resolution are you asking for? What version of Xcode are you
using? What version of iOS are you testing on? Are you testing on
simulator and/or device?

XCode 4.5, iOS sdk 6.0, deployment target 5.0, the bug occurs with
every version of simulator (I tried 5.1 normal/retina and 6.0
normal/retina/retina 4") and on real devices (I tried on 3GS and 5).

Here is a sample stupid application that opens a fullscreen display
using the optimal resolution for the device, the app plist lists portrait
as the only display mode.

The yellow square moves every time you create an event (touch the
screen for instance). If you pull down once the notification center (works
in simulator too) the yellow rectangle is shifted by 20 pixel.

Removing SDL_WINDOW_FULLSCREEN the status bar is shown and the app
work without “unwanted” shifting.

#include
#include “SDL.h”

struct ResSize { int width, height; };

struct ResSize ressize[5] = { { 320, 480 }, { 640, 960 }, { 768,
1024 }, { 640, 1136 }, { 1536, 2048 } };

int main(int argc, char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << “Unable to initialize SDL\n”;
return -1;
}

int available_displays = SDL_GetNumDisplayModes(0);
ResSize *res_ = NULL;

for (int i = 0; i < available_displays; ++i)  {
    SDL_DisplayMode mode;
    SDL_GetDisplayMode(0, i, &mode);
    std::cerr << i << ") " << mode.w << 'x' << mode.h << '/' <<

SDL_GetPixelFormatName(mode.format) << ‘\n’;

    for (int j = 0; j < 5; ++j)
        if (mode.w == ressize[j].width &&
            mode.h == ressize[j].height) {
            if (!res_ || res_->width < mode.w)
                res_ = &(ressize[j]);
        }
}

if (!res_) {
    std::cerr << "No valid resolution found.\n";
    return -2;
}

SDL_Window *screen_;
SDL_Renderer *renderer_;

std::cerr << "Res:" << res_->width << 'x' << res_->height <<

‘\n’;

if (!(screen_ = SDL_CreateWindow("Solit",

SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,

                                 res_->width, res_->height,

SDL_WINDOW_FULLSCREEN))) {

    std::cerr << "Unable to open display.\n";
    return -3;
}

if (!(renderer_ = SDL_CreateRenderer(screen_, -1 /*selected*/,

0))) {

    std::cerr << "Unable to create renderer\n";
    return -4;
}

SDL_ShowWindow(screen_);

SDL_Rect r = { 0, 0, 64, 64 };

while (1) {
    SDL_SetRenderDrawColor(renderer_, 0, 200, 0,

SDL_ALPHA_OPAQUE);

    SDL_RenderClear(renderer_);
    r.x += 64;
    if (r.x >= res_->width)
        r.x = 0;

    SDL_SetRenderDrawColor(renderer_, 255, 255, 0,

SDL_ALPHA_OPAQUE);> On Sunday, September 30, 2012 at 10:51 AM, Sam Lantinga wrote:

On Sat, Sep 29, 2012 at 7:59 AM, Gorm Lai wrote:

On Saturday, September 29, 2012 at 10:09 AM, Gorm Lai wrote:

On Saturday, September 29, 2012 at 8:37 AM, Sam Lantinga wrote:

On Fri, Sep 28, 2012 at 3:22 AM, Gabriele Greco < gabriele.greco at darts.it> wrote:

    SDL_RenderFillRect(renderer_, &r);

    SDL_Event e;

    if (SDL_WaitEvent(&e)) {
        if (e.type == SDL_QUIT)
            exit(0);
    }
    SDL_RenderPresent(renderer_);
}

}


Bye,
Gabry


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Attachments:

  • Screen Shot 2012-09-29 at 12.34.33 AM.png

SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org