/*
 * a template file for ex2-1
 */

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>

static void
drawAxes(void)
{
  /* 座標軸を描画するコードを書く */
}

static void
displayCallback(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  glLoadIdentity();

  drawAxes();

  glFlush();
}

/* ここで投影方法を決めてください */
static void
SetProjection( const int width, const int height )
{
  /* glOrtho(); or gluPerspective(); を調べてください */
}

static
void initGL(void)
{
  int width, height;

  width = glutGet(GLUT_WINDOW_WIDTH);
  height = glutGet(GLUT_WINDOW_HEIGHT);
  
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  SetProjection( width, height );
  glMatrixMode(GL_MODELVIEW);
}

static void
keyboardCallback(unsigned char key, int x, int y)
{
  switch (key) {
  /* エスケープを押したらプログラムを終了する */
  case 27:
    glutDestroyWindow(glutGetWindow());
    exit(EXIT_SUCCESS);
    break;

  default:
    break;
  }
}

static void
reshapeCallback(int width, int height)
{
  glViewport(0, 0, width, height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  SetProjection( width, height );
  glMatrixMode(GL_MODELVIEW);
}

int
main(int argc, char **argv)
{
  int win;

  glutInit(&argc, argv);

  glutInitDisplayMode(GLUT_RGB);

  glutInitWindowSize( 400, 400 );
  win = glutCreateWindow("ex2-1");

  glutDisplayFunc(displayCallback); 
  /* キーが押されたらkeyboardCallback呼ばれる */
  glutKeyboardFunc(keyboardCallback);
  /* ウィンドウのサイズが変更されたらreshapeCallbackが呼ばれる */
  glutReshapeFunc(reshapeCallback);

  /* 初期化をする */
  initGL();
  
  glutMainLoop();
  
  return EXIT_SUCCESS;
}
