Неверная исходная ось SDL в разрешении 1080x1920 - PullRequest
0 голосов
/ 28 ноября 2018

У меня проблема с библиотекой SDL и разрешением, отличным от 1920x1080.

Я хочу скопировать изображение размером 1080x608 в центре экрана разрешение 1080х1920 (портрет).

У меня только один подключенный экран монитора.

Я использовал следующую команду для переключения экрана с 1920x1080 на 1080x1920 :

xrandr --output DP-1 --mode 1920x1080 --rotate left --primary

Я использую следующий код для инициализации средства визуализации SDL:

/**
 * initialize everything so we are ready to display
 */
int SdlHandler::initialize(
    unsigned int positionX,
    unsigned int positionY,
    unsigned int width,
    unsigned int height,
    bool showWindow,
    std::string name) {
    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
            std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl;

            return -1;
    }

    // Size if the window
    this->width = width;
    this->height = height;
    this->positionX = positionX;
    this->positionY = positionY;

    // Create the SDL window
    // 0 and 0 are the position in X and Y
    unsigned int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS;

    if (showWindow) {
            flags |= SDL_WINDOW_SHOWN;
    } else {
            flags |= SDL_WINDOW_HIDDEN;
    }

    this->window = SDL_CreateWindow(name.c_str(), this->positionX, this->positionY, this->width, this->height, flags);

    // If there had been a problem, leave
    if (!this->window) {
            return -1;
    }

    // Create a new renderer
    this->renderer = SDL_CreateRenderer(this->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

    // If there is an error creating it, just leave
    if (!this->renderer) {
            return -1;
    }

    // Setup the best for the SDL render quality
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");

    return 0;
}

Затем я вызываю функцию SDL_RenderCopy для отображения изображения.Я передаю ему созданное renderer, созданное с помощью SDL_CreateRenderer в приведенном выше коде:

// Create a window at 0,0 of dimension 1080x1920
this->initialize(0, 0, 1080, 1920, true, SDL_BASE_DISPLAY_WINDOW);

// Create the SDL Rectangle that will contain the image, at the center of the window
SDL_Rect *howToDraw = new SDL_Rect();
howToDraw->x = this->positionX + floor((this->width - this->imageWidth) / 2);
howToDraw->y = this->positionY + floor((this->height - this->imageHeight) / 2);
howToDraw->w = this->imageWidth;
howToDraw->h = this->imageHeight;

SDL_RenderCopy(this->renderer, this->texture, NULL, howToDraw);

Но ось, кажется, находится в неправильной позиции, получая следующий результат: enter image description here

РЕДАКТИРОВАНИЕ И РЕШЕНИЕ

Это ошибка, связанная с Compton, оконным менеджером, все работает хорошо без Compton ...

1 Ответ

0 голосов
/ 28 ноября 2018

Поскольку вы поворачиваете свой дисплей, используя xrandr, мы можем считать, что это шаг постобработки, который будет вращать все после рендеринга каждого кадрового буфера.

Поскольку на этом этапе постобработки принимается разрешение изображения 1920x1080, вы должны использовать SDL с этим разрешением.

Что если вы измените свой код для:

// Create a window at 0,0 of dimension 1920x1080
this->initialize(0, 0, 1920, 1080, true, SDL_BASE_DISPLAY_WINDOW);

РЕДАКТИРОВАТЬ: Я также понимаю, что вы хотите, чтобы ваше изображение начиналось в центре окна, но вы помещаете середину изображения в центр окна.

Вам также следует попробовать следующее:

howToDraw->x = this->positionX + this->imageWidth / 2;
...