#include "basis.h"

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

GLint windW, windH;
GLfloat params[4];

static void Init(void)
{
  glClearColor(1.0f, 0.96f, 0.866f, 1.0f);
}

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

  glViewport(0, 0, width, height);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(60.0f, 1.5, 1.5f, 20.0f);
  glMatrixMode(GL_MODELVIEW);

}

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

  glColor3f(1.0f, 0.3f, 0.5f);
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_FLAT);
  glPushMatrix();
    glTranslatef(0.0f, 0.0f, -4.0f);
    glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
    glRotatef(-30.0f, 0.0f, 1.0f, 0.0f);
    // Определяем координаты вершин для треугольников
		glBegin(GL_QUAD_STRIP);
			glColor3f(1.0f, 0.0f, 0.0f);
			glVertex3f(-0.5f, 0.5f, 1.5f);
      glVertex3f(-0.5f, -0.5f, 1.5f);
			glVertex3f(0.5f, 0.5f, 1.5f);
      glVertex3f(0.5f, -0.5f, 1.5f);
			glVertex3f(0.5f, 0.5f, -10.0f);
      glColor3f(0.0f, 1.0f, 0.0f);
      glVertex3f(0.5f, -0.5f, -10.0f);
      glVertex3f(-0.5f, 0.5f, -10.0f);
      glVertex3f(-0.5f, -0.5f,  -10.0f);
			glVertex3f(-0.5f, 0.5f, 1.5f);
      glVertex3f(-0.5f, -0.5f, 1.5f);
		glEnd();

    glBegin(GL_QUADS);
			glColor3f(0.0f, 0.0f, 1.0f);
			glVertex3f(-0.5f, 0.5f, 1.5f);
			glVertex3f(0.5f, 0.5f, 1.5f);
			glVertex3f(0.5f, 0.5f, -10.0f);
      glVertex3f(-0.5f, 0.5f, -10.0f);
    glEnd();

    glBegin(GL_QUADS);
      glColor3f(0.0f, 1.0f, 0.0f);
      glVertex3f(-0.5f, -0.5f, 1.5f);
      glVertex3f(0.5f, -0.5f, 1.5f);
			glVertex3f(0.5f, -0.5f, -10.0f);
      glVertex3f(-0.5f, -0.5f,  -10.0f);
    glEnd();

  glPopMatrix();

  glFinish();
  auxSwapBuffers();
}

void main(int argc, char **argv)
{
    windW = 400;
    windH = 300;
    auxInitPosition(200, 100, windW, windH);

    auxInitDisplayMode(AUX_RGB | AUX_DOUBLE | AUX_DEPTH16);

    if (auxInitWindow("Первый трехмерный объект") == GL_FALSE) {
      auxQuit();
    }

    Init();

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