#!/usr/bin/perl -w
use strict;
use OpenGL qw/ :all /;
use Math::Trig;

use constant N_SHAPES => 7;
my $vertex = [
	[0.0, 0.0, 0.0],
	[1.0, 0.0, 0.0],
	[1.0, 1.0, 0.0],
	[0.0, 1.0, 0.0],
	[0.0, 0.0, 1.0],
	[1.0, 0.0, 1.0],
	[1.0, 1.0, 1.0],
	[0.0, 1.0, 1.0],
	];
my $edge = [
	[0, 1],
	[1, 2],
	[2, 3],
	[3, 0],
	[4, 5],
	[5, 6],
	[6, 7],
	[7, 4],
	[0, 4],
	[1, 5],
	[2, 6],
	[3, 7],
	];

glutInit();
glutInitDisplayMode(GLUT_RGBA);
glutCreateWindow('test');
glutDisplayFunc(\&display);
glutReshapeFunc(\&resize);
init();
glutMainLoop();


sub display
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#  glRotated(25.0, 0.0, 1.0, 0.0);
  glColor3d(0.0, 0.0, 0.0);
#GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP GL_TRIANGLES GL_QUADS 
#GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLE_FAN GL_POLYGON
  glBegin(GL_POLYGON);
    for(my $i = 0 ; $i < 12 ; $i++) {
    	glVertex3d($vertex->[$edge->[$i][0]][0], $vertex->[$edge->[$i][0]][1], $vertex->[$edge->[$i][0]][2]);
    	glVertex3d($vertex->[$edge->[$i][1]][0], $vertex->[$edge->[$i][1]][1], $vertex->[$edge->[$i][1]][2]);
    }
  glEnd();
  glFlush();
}

sub resize
{
	my ($w, $h) = @_;
# $w, $h: 表示ウインドウのサイズが入ってくる

#表示するサイズ
	glViewport(0, 0, $w, $h);
	glLoadIdentity();
#	glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
# カメラの画角(度)、画面のアスペクト比、手前位置、後方位置
#	gluPerspective(20,0, $w / $h, 1.0, 100.0);
	gluPerspective(20.0, $h ? $w/$h : 0, 1.0, 100.0);
	glTranslated(0.0, 0.0, -5.0);
	gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

sub init
{
	glClearColor(1.0, 1.0, 1.0, 1.0);
}
