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