glViewport different result in Android and iOS

2019-05-11 23:21发布

问题:

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

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);

Initialisation code:

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);

Viewport and project code

glViewport(viewportX, viewportY, viewportW, viewportH);.

glEnable(GL_SCISSOR_TEST);
glScissor(viewportX, viewportY, viewportW, viewportH);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

... 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);

Maybe Android or iOS has something set by default? I am clueless.

回答1:

Answering my own question for those who have the same issue.

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.



回答2:

This looks like you are not accounting for the scale factor of the iOS device. Bear in mind that the most recent iOS devices have retina displays with an extremely high ppi. You can see this artifact in the bottom left of the iOS screenshot. It is only displaying the bottom 25% of your texture because the entire view has a scale factor of 2.

In short, ensure you account for the scaleFactor on iOS and use this factor in your glScalef call.