glViewport 在 Android 和 iOS 中的不同结果 [英] glViewport different result in Android and iOS
问题描述
我刚刚开始使用 opengl 为我的跨平台框架(iOS 和 Android)开发渲染器.当我到达视口内容(分屏内容所需)时,注意到 iOS 和 Android 之间存在差异.这是两张图片.
I just got started on a renderer for my cross platform framework (iOS and Android) using opengl es. When I got to the viewport stuff (which is needed for splitscreen stuff) and noticed there is a difference between iOS and Android. Here are two images.
安卓实际上还有另一个故障.它似乎包装了.
Android There is actually another glitch. IT seems to wrap.
iOS
我的问题.两者哪个是正确的?我没有应用任何转换,而是将绘制的四边形带回来一点.glTranslatef(0.0f, 0.0f, -5.f);
My question. Which of the two is correct? I have no transformations applied but one to bring the drawn quad back a bit. glTranslatef(0.0f, 0.0f, -5.f);
初始化代码:
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH); //Enable Smooth Shading
glClearColor(0.f, 0.f, 0.f, 1.0f); //Black Background
glClearDepthf(1.0f); //Depth Buffer Setup
glEnable(GL_DEPTH_TEST); //Enables Depth Testing
glDepthFunc(GL_LEQUAL); //The Type Of Depth Testing To Do
//Really Nice Perspective Calculations
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
视口和项目代码
glViewport(viewportX, viewportY, viewportW, viewportH);.
glEnable(GL_SCISSOR_TEST);
glScissor(viewportX, viewportY, viewportW, viewportH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
... 最后计算截锥体并设置 glFrustrum.我也用过这个代码:
... And finally the frustrum is calculated and set glFrustrum. I have also used this code:
float widthH = width * .1f;
float heightH = height * .1f;
glOrthof(-widthH, widthH, -heightH, heightH, .1f, 100.f);
glScalef(widthH, heightH, 1.f);
也许 Android 或 iOS 有一些默认设置?我一无所知.
Maybe Android or iOS has something set by default? I am clueless.
推荐答案
为有同样问题的人回答我自己的问题.
Answering my own question for those who have the same issue.
我使用 GLKView,它显然在每次渲染调用时调用 glViewport,重置我在前一帧中所做的一切.因此,如果您使用 GLKView,请确保每帧都调用 glViewport!...或滚动您自己的 EAGLView 以获得一些我认为的真正控制权.
I use GLKView which apparently calls the glViewport on each render call, resetting what I just did in the previous frame. So if you use GLKView make sure to call glViewport each frame! ... or roll your own EAGLView to have some real control which I think, I am about to.
这篇关于glViewport 在 Android 和 iOS 中的不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!