title: Object projection in openGL ES 2
body: <p>I want to draw object within ar but got unexpected result - gl mashine  think that i see object from another side (or from inside).</p>
  
  <p>Here image what i want to draw (taken from separate project)</p>
  
  <p><a href="https://i.stack.imgur.com/XHyI2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XHyI2.png" alt="enter image description here"></a></p>
  
  <p>And here - what i got when try to draw this object in my ar (inside of the sphere)</p>
  
  <p><a href="https://i.stack.imgur.com/D8miD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8miD.png" alt="enter image description here"></a></p>
  
  <p>So I guess that problem is that because I put object inside sphere and adjust position of obj using base mat from sphere obj. </p>
  
  <p>Camera positioned in the center of the sphere - so for this obj I use same mat - just scale/rotate/translate it.</p>
  
  <p>This is how I calculate projection mat</p>
  
  <pre><code>CGRect viewFrame = self.frame;
  if (!CGSizeEqualToSize(self.newSize, CGSizeZero){
      size = self.newSize;
  }
  CGFloat aspect = viewFrame.size.width / viewFrame.size.height;
  CGFloat scale = self.interractor.scale;
  CGFloat FOVY = DEGREES_TO_RADIANS(self.viewScale) / scale;
  
  CGFloat cameraDistanse = -(1.0 / [Utilities FarZ]);
  GLKMatrix4 cameraTranslation = GLKMatrix4MakeTranslation(0, 0, cameraDistanse);
  GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(FOVY, aspect, NearZ, [Utilities FarZ]);
  projectionMatrix = GLKMatrix4Multiply(projectionMatrix, cameraTranslation);
  //and also here added some code for modifying, but I skip it here
  </code></pre>
  
  <p>For this obj I just calculate new scale and position of obj - looks like it's correct because I able to see obj and change his position etc, so skip this part.</p>
  
  <p>In the second project where I got correct result of displaying obj I calculate projection mat in similar way, but with a little bit less calculation:</p>
  
  <pre><code>float aspect = self.glView.frame.size.width / self.glView.frame.size.height;
  GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.01f, 100);
  //scale
  //rotate
  //translate
  GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f);
  modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, projectionMatrix);
  
  GLfloat scale = 0.5 *_scale;
  GLKMatrix4 scaleMatrix = GLKMatrix4MakeScale(scale, scale, scale);
  
  modelViewMatrix = GLKMatrix4Translate(modelViewMatrix, _positionX, _positionY, -5);
  modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotationX, 0.0f, 1.0f, 0.0f);
  modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotationY, 1.0f, 0.0f, 0.0f);
  
  modelViewMatrix = GLKMatrix4Multiply(scaleMatrix, modelViewMatrix);
  </code></pre>
  
  <p>In first project (correct one) I also use</p>
  
  <pre><code>glEnable(GL_DEPTH_TEST);
  glDepthMask(GL_TRUE);
  glDisable(GL_CULL_FACE);
  </code></pre>
  
  <p>In second with few obj - depend from obj that I want to draw:</p>
  
  <pre><code>glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glDisable(GL_SCISSOR_TEST);
  
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE);
  
  //call sphere draw
  
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);
  
  //call obj draw
  
  glEnable(GL_SCISSOR_TEST);
  </code></pre>
  
  <p>So as I sad before, I guess that the problem is that openGL "think" that we are looking to obj from another side, but I'm not sure. And if i'm right how can i fix this? Or whats done incorrect?</p>
  
  <hr>
  
  <p>Update</p>
  
  <p>@codetiger I check ur suggestions: </p>
  
  <p>1) Wrong face winding order - recheck it again and try to inverse order, also try to build same model in another project (all works perfect) - result i guess that order is ok;</p>
  
  <p>2) Wrong Culling - check all combinations of </p>
  
  <pre><code>glDisable / glEnable with argument GL_CULL_FACE
  glCullFace  with argument GL_FRONT, GL_BACK or GL_FRONT_AND_BACK 
  glFrontFace with argument GL_CW or GL_CCW
  </code></pre>
  
  <p>What i see - a little bit change but i see still incorrect obj (or wrong side or partial obj etc)</p>
  
  <p>3) vertices are flipped - try to flip them, as result - even worse than before</p>
  
  <p>4) try to combine this 3 suggestion one with another - result not acceptable</p>