4

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.

Android quarter sized viewport

iOS

iOS quarter size viewport

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.

WoutervD
  • 2,139
  • 2
  • 13
  • 13

2 Answers2

7

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.

WoutervD
  • 2,139
  • 2
  • 13
  • 13
0

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.

Sam
  • 2,579
  • 17
  • 27
  • I am using the iPhone Simulator without the retina display. The iOS version looks exactly the same as the version of my app with a viewport of (1,1). I'll add an image of the fullscreen viewport. The quad is still centered to the screen and not to the viewport like in the android version. Scaling wont solve this. – WoutervD Apr 03 '12 at 19:10
  • The simulator will masquerade as a retina screen. This issue is very obviously a scaling issue. Examine closely the two graphics and see that the iOS version is scaled +200%. – Sam Apr 03 '12 at 19:11
  • Very strange. I was using the scissor test as well which kind of hid the real problem. glViewport was not working at all, at least not where I used it. It now works well. Still got a few glClear issues but I will have them sorted out soon. Still thanks for pointing out that scaling stuff. As iOS gives me a size of 480, 320 even with retina on. Which is an issue. Thing is. Stuff is smaller when I dont account for retina. Seems like I should use something else than to get the right resolution... or multiply them myself. self.view.bounds.size.width, self.view.bounds.size.height – WoutervD Apr 03 '12 at 19:44
  • Sure not a problem. I think doing the multiplication in your code is certainly an option, but I believe there are better alternatives. Review this link and you might find exactly what you're looking for. http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html – Sam Apr 03 '12 at 19:46