Landscape and Portrait modes with SDL and OpenGL ES

I am having problems when I change between Landscape and Portrait modes
under IOS and Android. I have Portrait and Landscape modes allowed for
both. I am setting the new aspect ratio of the camera and calling
glViewport with the new resolution. In my case Portrait is 640x1136 and
Landscape is the reverse 1136x640 .
This is how I am handling it at the moment. Is that the correct way of
doing it with SDL ?

SDL_DisplayMode displayMode;
SDL_GetDesktopDisplayMode(0, &displayMode);

SDL_Window* window = SDL_CreateWindow(NULL, 0, 0, displayMode.w,
displayMode.h, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN |
SDL_WINDOW_RESIZABLE);

SDL_GLContext gl = SDL_GL_CreateContext(window);

float width = displayMode.w;

float height = displayMode.h;

float aspect = width/height;
m_pCamera->SetAspect(aspect);

glViewport(0, 0, width, height);

while(game->running)
{
while (SDL_PollEvent(&event)) {
if (event.type == SDL_WINDOWEVENT && event.window.event ==
SDL_WINDOWEVENT_RESIZED)
{
width = event.window.data1;
height = event.window.data2;

            aspect = width/height;
            m_pCamera->SetAspect(aspect);

            glViewport(0, 0, width, height);
        }

}

This is my end result where in Portrait the Model is bigger compared to
Landscape.

The SDL output makes sense; the image on the Portrait screen is the same as
the Landscape one, but scaled vertically, with the viewport obscuring most
of the left and right hand sides. I would check the middleware you’re using
to set the projection matrix; you’re probably going to have to do more than
just set the aspect ratio to get the effect you’re looking for.On 20 July 2014 05:31, Alexander Chaliovski wrote:

I am having problems when I change between Landscape and Portrait modes
under IOS and Android. I have Portrait and Landscape modes allowed for
both. I am setting the new aspect ratio of the camera and calling
glViewport with the new resolution. In my case Portrait is 640x1136 and
Landscape is the reverse 1136x640 .
This is how I am handling it at the moment. Is that the correct way of
doing it with SDL ?

SDL_DisplayMode displayMode;
SDL_GetDesktopDisplayMode(0, &displayMode);

SDL_Window* window = SDL_CreateWindow(NULL, 0, 0, displayMode.w,
displayMode.h, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN |
SDL_WINDOW_RESIZABLE);

SDL_GLContext gl = SDL_GL_CreateContext(window);

float width = displayMode.w;

float height = displayMode.h;

float aspect = width/height;
m_pCamera->SetAspect(aspect);

glViewport(0, 0, width, height);

while(game->running)
{
while (SDL_PollEvent(&event)) {
if (event.type == SDL_WINDOWEVENT && event.window.event ==
SDL_WINDOWEVENT_RESIZED)
{
width = event.window.data1;
height = event.window.data2;

            aspect = width/height;
            m_pCamera->SetAspect(aspect);

            glViewport(0, 0, width, height);
        }

}

This is my end result where in Portrait the Model is bigger compared to
Landscape.


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

I am out of options I was trying to compensate with the Camera field of
view but I couldn’t get the ratio properly. Is there an SDL function that
can help for this. Maybe I can do something like crop to fit ?

Not really. SDL has minimal interaction with OpenGL, mostly from the
window-management side of things. The issue you’re having is caused by the
projection matrix set up by your Camera object middleware, which is
responsible for mapping the field-of-view in world space to normalized
screen coordinates. Perhaps if you can tell us what middleware you’re
using, the initial setup of your m_pCamera object (cropped out in your
original post), and a diagram of how you want things to look on screen, we
might be able to assist.On 20 July 2014 17:00, Alexander Chaliovski wrote:

I am out of options I was trying to compensate with the Camera field of
view but I couldn’t get the ratio properly. Is there an SDL function that
can help for this. Maybe I can do something like crop to fit ?


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