#include <stdlib.h>
#include "basis.h"

static void Init(void );
static void CALLBACK Reshape(int width,int height);
static void CALLBACK Draw(void );

GLint windW, windH;

static void Init(void)
{
  glClearColor(0.5f, 0.5f, 0.5f, .7f);
}

static void CALLBACK Reshape(int width, int height)
{
  windW = (GLint)width;
  windH = (GLint)height;
}

static void CALLBACK DrawAxies(int left)
{
  GLint x;

  glColor3f(0.0f, 0.0f, 0.0f);
  if(!left)
    x = windW/4;
  else
    x = -windW/4;
  glPushMatrix();
    glBegin(GL_LINES);
      glVertex2i(x, -windH/2);
      glVertex2i(x,  windH/2);
    glEnd();
  glPopMatrix();
}

static void CALLBACK InitViewport(int x, int y, int width, int height)
{
  glViewport(x, y, width, height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluOrtho2D(-windW/4, windW/4, -windH/2, windH/2);
  glMatrixMode(GL_MODELVIEW);
}

static void CALLBACK DrawScene(void)
{
  // Здесь вызываются команды рисования
  // ...

  int i;
  for(i = 0; i < 10; i++){
    glPointSize((i+1) * 2);
    glBegin(GL_POINTS);
      glVertex2f(-windW/4 + (GLfloat)i * windW/20,
                 -windH/2 + (GLfloat)i * windH/10);
    glEnd();  
  }
}

static void CALLBACK Draw(void)
{
  glClear(GL_COLOR_BUFFER_BIT);

  InitViewport(0,0, windW/2, windH);
  DrawAxies(0);

  glColor3f(0.0, 0.0, 1.0);
  DrawScene();
  
  InitViewport(windW/2, 0, windW/2, windH);
  DrawAxies(1);
  
  glEnable(GL_POINT_SMOOTH);
  glColor3f(.1,.1,1);
  DrawScene();
  glDisable(GL_POINT_SMOOTH);

  glFinish();
  auxSwapBuffers();
}

void main(int argc, char **argv)
{
  windW = 1024;
  windH = 768;
  auxInitPosition(0, 0, windW, windH);

  auxInitDisplayMode(AUX_RGB | AUX_DOUBLE |AUX_DEPTH24);

  if(auxInitWindow("") == GL_FALSE) {
    auxQuit();
  }

  Init();

  auxExposeFunc((AUXEXPOSEPROC)Reshape);
  auxReshapeFunc((AUXRESHAPEPROC)Reshape);
  auxMainLoop(Draw);
}
