OpenGL 和 SDL,在保持内部分辨率不变的情况下调整窗口大小?
我正在 OpenGL 中做一个游戏,并使用 SDL 来管理窗口、设置图标以及所有这些东西。 现在我已经将场景渲染设置为帧缓冲区,我想知道是否可以在保持起始 GL 设置的同时调整 SDL 窗口的大小(我正在尝试模拟精确的分辨率,因此窗口大小调整是将帧缓冲区重新调整为窗口大小)
我尝试将 SDL 窗口的分辨率设置为我传递给 glortho 的分辨率的两倍,但它给出了意想不到的结果©。这是否可能,或者我是否需要始终将工作分辨率调整为屏幕分辨率? 我使用此代码来初始化视频
SDL_SetVideoMode(XRES, YRES, bpp, SDL_OPENGL | SDL_HWPALETTE);
gl_init(XRES,YRES);
,并在 gl_init 中将 glortho 设置为 glOrtho(0, width, 0, height, -1, 1),然后将帧缓冲区“空白”纹理的大小设置为宽度和高度。
当像上面那样调用该函数时,一切都很好。但是,如果我尝试类似的方法,
SDL_SetVideoMode(XRES*2, YRES*2, bpp, SDL_OPENGL | SDL_HWPALETTE);
gl_init(XRES,YRES);
而不是得到预期的结果(缩放输出),我会发现输出位于 X 轴最左侧的某个位置和 Y 轴中间的某个位置,就像 GL 大小甚至大于屏幕,其余部分被裁剪掉。我有什么遗漏的吗?
I am doing a game in OpenGL and using SDL for managing the window, setting the icons, and all that stuff.
Now that I have set rendering the scene to a framebuffer, I wondered if I could resize the SDL window while keeping my starting GL settings (I am trying to emulate a exact resolution so window resizing is a rescale of the framebuffer to the window size)
I tried giving the SDL window double the resolution of the resolution I pass to glortho, but it gives unexpected results©. Is this possible at all, or do I need to adapt my working resolution to the screen resolution all the time?
I use this code to initialize video
SDL_SetVideoMode(XRES, YRES, bpp, SDL_OPENGL | SDL_HWPALETTE);
gl_init(XRES,YRES);
And into gl_init I set glortho to glOrtho(0, width, 0, height, -1, 1), and then the framebuffer "blank" texture to width and height in size, as well.
When the function is called as above, all is well. But if I try something like
SDL_SetVideoMode(XRES*2, YRES*2, bpp, SDL_OPENGL | SDL_HWPALETTE);
gl_init(XRES,YRES);
Instead of getting my expected results (scaled output) I find out that the output is somewhere at the far left on X axis and somewhere in the middle of the Y axis, like if GL size was even bigger than the screen and the rest was cropped out. Is there anything I am missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试简单地将FBO纹理大小设置为窗口大小的1/4(其边缘长度的1/2),然后将FBO的颜色缓冲区纹理渲染到整个SDL窗口。
Try to simply set the FBO texture size to 1/4 of the window size (1/2 of its edge lengths), then render the FBO's color buffer texture to the entire SDL window.
我知道这是一个老问题,但它是谷歌上的最高结果,并且没有答案。
您需要调用
glViewport()
。假设您希望内部分辨率为 1024x768,窗口分辨率为 windowWidth 和 windowHeight。在写入 FBO 之前,请调用glViewport(0, 0, 1024, 768)
。然后,在将 FBO 写入窗口之前,调用glViewport(0, 0, windowWidth, windowHeight)
。I know this is an old question, but it is a top result on Google and does not have an answer.
You'll need to call
glViewport()
. Suppose you want your internal resolution as 1024x768, and your window resolution is windowWidth and windowHeight. Before you write to your FBO, callglViewport(0, 0, 1024, 768)
. Then, before writing your FBO to the window, callglViewport(0, 0, windowWidth, windowHeight)
.您在游戏循环中使用此代码
You use this code in your game loop