title: openGL drawing distorted sprites (images) in psuedo-3d perspective
body: <p>Alright so this is going to be a doozy to explain. I'm making a very basic "pseudo-3d" racing game for Android using AndEngine (and in turn, openGL - I think). I don't believe using AndEngine really has anything to do with this problem though, because I'm directly accessing openGL functions to accomplish my drawing.</p>
  
  <p>Anyways, I copy-pasta'd some code that allowed the normally 2d AndEngine to have a 3d perspective (tutorial for such can be found <a href="http://www.andengine.org/forums/tutorials/3d-perspective-tutorial-t1790.html" rel="nofollow noreferrer">here</a>. This works pretty well, and I also don't believe this has much to do with my problem, but I don't fully understand openGL so it's a little hard for me to say. Here's the code from the onLoadEngine (called when app starts) that sets up the camera with a 3d perspective:</p>
  
  <pre><code>this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT) {
      //other methods...
      private void setFrustum(GL10 pGL) {
          // set field of view to 60 degrees
          float fov_degrees = 60;
          float fov_radians = fov_degrees / 180 * (float)Math.PI;                        
  
          // set aspect ratio and distance of the screen
          float aspect = this.getWidth() / (this.getHeight());
          float camZ = this.getHeight()/2 / (float)Math.tan(fov_radians/2);                              
  
          // set projection
          GLHelper.setProjectionIdentityMatrix(pGL);
          GLU.gluPerspective(pGL, fov_degrees, aspect, camZ/10, camZ*10); 
  
          // set view
          GLU.gluLookAt(pGL, 0,120f, camZ, 0, 0, 0f, 0, 1, 0); // move camera back+up
          pGL.glScalef(1,-1,1); // reverse y-axis
          pGL.glTranslatef(-CAMERA_WIDTH/2,-CAMERA_HEIGHT/2,0); // origin at top left
      }
  };
  </code></pre>
  
  <p>Then later in the onLoadScene (where the drawing takes place), I draw a bunch of my images like so:</p>
  
  <pre><code>for (int n=0;n&lt;=100;n++) {
      final int k = n;
  
      final Sprite line = new Sprite(0, 0,CAMERA_WIDTH,16f, [AndEngine texture holding road img]) {
      @Override
          protected void applyTranslation(GL10 pGL) {
              pGL.glTranslatef(this.mX, 120f, 15f*k); //16*k causes a sliver of a space between each segment
              pGL.glRotatef(90f, 1, 0, 0); //**MAY BE MY ISSUE**
          }           
      };
      scene.attachChild(line); //actually draws the image to the screen           
  }
  </code></pre>
  
  <p>Which works pretty darn well as well, except for one thing! It distorts the shit out of my images. The images are simple pngs, both matching the CAMERA_WIDTH, and both looking similar to this:
  <img src="https://i.stack.imgur.com/du6NK.png" alt="&quot;road&quot; segment - 320 x 16"></p>
  
  <p>And when I draw it without the rotate line, I get this:
  <img src="https://i.stack.imgur.com/mKNQu.png" alt="without the rotating"></p>
  
  <p>Which has a decently straight middle line (tbh I'd be happy with them this way), but then you can see the edges of the road are all facing basically the exact opposite way they should be facing. I figured why not just flip them? I thought I would have to rotate them 180 degrees around the x axis, but instead that just makes them disappear, and instead I found that 90 degrees works (???). Anyways, Here's what I get:</p>
  
  <p><img src="https://i.stack.imgur.com/lalYA.png" alt="final product"></p>
  
  <p>So yeah. Here's where my problem lies - the middle lane divider is distorted as crap!! The lines marking the edge of the road line up wonderfully, but for whatever reason its really messing with that middle line. I get most of the math behind the 3d, but I really don't know what to make of this...it's almost like the image is being compressed because its being viewed at such a sharp angle, but I don't really know how the hell I could solve that without simply making it a top-down view? :S</p>
  
  <p>Anyways... any ideas or guidance is welcome. Sorry this is such a long and convoluted post - it makes it hard when I really have no idea where the problem lies.</p>
  
  <p>Also - It might be worth noting I have little to no experience with openGL or 3d graphics, and have even less interest in learning much about them in depth. I need a band-aid to this problem!</p>