All pastes #403447 Raw Edit

Mine

public text v1 · immutable
·published 2007-03-20 11:39 UTC
rendered paste body
#!/usr/bin/env perl
use strict;
use warnings;
use OpenGL::Simple qw( :all );
use OpenGL::Simple::GLUT qw( :all );
use Time::HiRes qw( usleep );
use UnitCube;

my $rotate_angle_z = 0;
my $rotate_angle_y = 0;

glutInit(@ARGV);

glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("3D OpenGL Cube with Lighting");

glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

my @light_position0 = (  0, 0, -1, 0 );
glLight(GL_LIGHT0, GL_POSITION, @light_position0);

my @light_model_ambient = ( 0.17, 0.17, 0.17, 1.0 );
glLightModel(GL_LIGHT_MODEL_AMBIENT, @light_model_ambient);

glutDisplayFunc(\&draw_screen);
glutMainLoop();

sub draw_screen {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    $rotate_angle_z += 0.65;
    $rotate_angle_y += 1.15;

    glLoadIdentity();

    glRotate($rotate_angle_y, 0, 1, 0);
    glRotate($rotate_angle_z, 0, 0, 1);
    UnitCube::unit_cube();

    glutSwapBuffers();
    usleep(1000000/60);
    glutPostRedisplay();
}