[英]game displayed in the bottom-left quarter of my screen in SDL2
I recently updated my mac and the code that was normally running stopped functioning.我最近更新了我的 mac,正常运行的代码停止运行。 When I now run my program (a game) the window still has the right dimensions but the elements are displayed in the bottom-left quarter of my screen.
当我现在运行我的程序(一个游戏)时,窗口仍然具有正确的尺寸,但元素显示在我屏幕的左下角四分之一处。
I don't understand where it comes from.我不明白它来自哪里。
here is the .cpp that I used in the exemple:这是我在示例中使用的 .cpp:
#include "../../include/game.h"
int main(int argc, char **argv)
{
SDL_Window *window;
SDL_Renderer *render;
int w;
int h;
(void)argc;
(void)argv;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
window = SDL_CreateWindow("lul", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_W, WINDOW_H, 0);
render = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_GetWindowSize(window, &w, &h);
SDL_Surface *surface;
SDL_Texture *texture;
surface = IMG_Load("FondHome2.jpg");
texture = SDL_CreateTextureFromSurface(render, surface);
SDL_Event event;
bool close_requested = false;
while (!close_requested)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
close_requested = true;
}
}
SDL_RenderCopy(render, texture, NULL, NULL);
SDL_RenderPresent(render);
}
return(0);
}
and here is the .h used:这是使用的.h:
#ifndef GAME_H
# define GAME_H
# include <SDL2/SDL.h>
# include <SDL2/SDL_timer.h>
# include <SDL2/SDL_image.h>
# include <SDL2/SDL_ttf.h>
# include <fstream>
# include <iostream>
# include <string>
# include <vector>
# include <stdarg.h>
# include <math.h>
# define WINDOW_W 400
# define WINDOW_H 300
#endif
See content related to High-DPI differences when working with Retina displays on Mac: SDL_GL_GetDrawableSize .在 Mac 上使用 Retina 显示器时查看与高 DPI 差异相关的内容: SDL_GL_GetDrawableSize 。 Pass the
SDL_WINDOW_ALLOW_HIGHDPI
flag to SDL_CreateWindow
, and the SDL_Render API should do the right thing.将
SDL_WINDOW_ALLOW_HIGHDPI
标志传递给SDL_CreateWindow
,并且 SDL_Render API 应该做正确的事情。
The problem is that without high DPI enabled, the actual width and height of your SDL_Window
correspond to more pixels than you passed to SDL_CreateWindow
(2X width and height, in this case).问题在于,如果没有启用高 DPI,则
SDL_Window
的实际宽度和高度对应的像素比传递给SDL_CreateWindow
像素多(在本例中为 2X 宽度和高度)。 It seems like SDL_RenderCopy
still thinks the target framebuffer is 400x300, which is correct when the DPI scaling factor is 1. When the image is drawn, only 1/4 of the physical space is covered.好像
SDL_RenderCopy
还是认为目标framebuffer是400x300,在DPI比例因子为1的情况下是正确的。当绘制图像时,只覆盖了1/4的物理空间。
I can't tell you exactly where the scaling issue happens without reading the SDL2 source, since it could be happening with an internal framebuffer or during the final blit, but the issue is the assumption of a DPI scaling factor of 1. Passing the SDL_WINDOW_ALLOW_HIGHDPI
flag during window creation tells SDL to query the actual monitor DPI to be used.我无法在不读取 SDL2 源的情况下准确告诉您缩放问题发生在哪里,因为它可能发生在内部帧缓冲区或最终 blit 期间,但问题是假设 DPI 缩放因子为 1。传递
SDL_WINDOW_ALLOW_HIGHDPI
窗口创建期间的标志告诉 SDL 查询要使用的实际监视器 DPI。
Related issue: SDL 2.0 retina mac相关问题: SDL 2.0 Retina mac
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.