title: Zooming in/out and painting in openGL
body: <p>I've recently had some issues implementing a zooming feature into a painting application. Please let me start off by giving you some background information.</p>
  
  <p>First, I started off by modifying Apple's glPaint demo app. I think it's a great source, since it shows you how to set up the EAGLView, etc...</p>
  
  <p>Now, what I wanted to do next, was to implement zooming functionality. After doing some research, I tried two different approaches.</p>
  
  <p>1) use glOrthof </p>
  
  <p>2) change the frame size of my EAGLView.</p>
  
  <p>While both ways allow me to perfectly zoom in / out, I experience different problems, when it actually comes to painting while zoomed in.</p>
  
  <p>When I use (1), I have to render the view like this:</p>
  
  <pre><code>glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrthof(left, right, bottom, top, -1.0f, 1.0f); //those values have been previously calculated
  glDisable(GL_BLEND);
  //I'm using Apple's Texture2D class here to render an image
  [_textures[kTexture_MyImage] drawInRect:[self bounds]];
  glEnable(GL_BLEND);
  [self swapBuffers];
  </code></pre>
  
  <p>Now, let's assume I zoom in a little, THEN I paint and after that, I want to zoom out again. In order to get this to work, I need to make sure that "kTexture_MyImage" always contains the latest changes. In order to do that, I need to capture the screen contents after changes have been made and merge them with the original image. The problem here is, that when I zoom in, my screen only shows part of the image (enlarged) and I haven't found a proper way to deal with this yet.</p>
  
  <p>I tried to calculate which part of the screen was enlarged, then do the capturing. After that I'd resize this part to its original size and use yet another method to paste it into the original image at the correct position.</p>
  
  <p>Now, I could go more into detail on how I achieved this, but it's really complicated and I figured, there has to be an easier way. There are already several apps out there, that perfectly do, what I'm trying to achieve, so it must be possible.</p>
  
  <p>As far as approach (2) goes, I can avoid most of the above, since I only change the size of my EAGLView window. However, when painting, the strokes are way off their expected position. I probably need take the zoom level into account when painting and re-calculate the CGPoints in a different way.</p>
  
  <p>However, if you have done similar things in the past or can give me a hint, how I could implement zooming into my painting app, I'd really appreciate it.</p>
  
  <p>Thanks in advance.</p>