// set up and maintain view as window sizes change

#include "view.h"

// Apple's annoying non-standard GL include location
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/glu.h>
#else
#include <GL/glu.h>
#endif

int winWidth = 256, winHeight = 256;

float viewDistance = 400;

// this is called when window is created or resized
extern "C" void 
reshape(int width, int height)
{
  // copy width and height into global variables so other callback
  // functions can access them
  winWidth = width;
  winHeight = height;

  // this viewport makes a 1 to 1 mapping of physical pixels to GL
  // "logical" pixels
  glViewport(0, 0, (GLint) width, (GLint) height);

  // adjust region of 3D space projected into this window 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45,(float)width/height,1,1000);
  glTranslatef(0,0,-viewDistance);

  // switch back to "normal" transformation mode 
  glMatrixMode(GL_MODELVIEW);
}

