Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
-1.995, -1.995,
0.995, 0.005,
0.995, 0.995,
0.005, 0.995,
0.005, 0.005,
-0.5, -0.5,
1.5, -0.5,
1.5, 1.5,
-0.5, 1.5,
0.005, 0.005,
0.995, 0.005,
0.995, 0.995,
0.005, 0.995
);
my $texcoords = OpenGL::Array->new_list(GL_FLOAT,@texcoords);
my @indices = (0..23);
my $indices = OpenGL::Array->new_list(GL_UNSIGNED_INT,@indices);
my @xform =
(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
my $xform = OpenGL::Array->new_list(GL_FLOAT,@xform);
# ------
# Frames per second (FPS) statistic variables and routine.
use constant CLOCKS_PER_SEC => $hasHires ? 1000 : 1;
use constant FRAME_RATE_SAMPLES => 50;
my $FrameCount = 0;
my $FrameRate = 0;
my $last=0;
sub ourDoFPS
{
if (++$FrameCount >= FRAME_RATE_SAMPLES)
{
my $now = $hasHires ? gettimeofday() : time(); # clock();
my $delta= ($now - $last);
$last = $now;
$FrameRate = FRAME_RATE_SAMPLES / ($delta || 1);
$FrameCount = 0;
}
}
# ------
# String rendering routine; leverages on GLUT routine.
sub ourPrintString
{
my ($font, $str) = @_;
my @c = split '', $str;
for(@c)
{
glutBitmapCharacter($font, ord $_);
}
}
# ------
# Does everything needed before losing control to the main
# OpenGL event loop.
sub ourInitVertexBuffers
{
# Set initial colors for rainbow face
for (my $i=0; $i<16; $i++)
{
$rainbow[$i] = rand(1.0);
$rainbow_inc[$i] = 0.01 - rand(0.02);
}
# Initialize VBOs if supported
if ($hasVBO)
{
printf("Using VBOs\n");
($VertexObjID,$NormalObjID,$ColorObjID,$TexCoordObjID,$IndexObjID) =
glGenBuffersARB_p(5);
#glBindBufferARB(GL_ARRAY_BUFFER_ARB, $VertexObjID);
$verts->bind($VertexObjID);
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $verts, GL_STATIC_DRAW_ARB);
glVertexPointer_c(3, GL_FLOAT, 0, 0);
if (DO_TESTS)
{
print "\nTests:\n";
my $size = glGetBufferParameterivARB_p(GL_ARRAY_BUFFER_ARB,
GL_BUFFER_SIZE_ARB);
print " Vertex Buffer Size (bytes): $size\n";
my $count = $verts->elements();
print " Vertex Buffer Size (elements): $count\n";
my $test = glGetBufferSubDataARB_p(GL_ARRAY_BUFFER_ARB,12,3,GL_FLOAT);
my @test = $test->retrieve(0,3);
my $ords = join('/',@test);
print " glGetBufferSubDataARB_p: $ords\n";
}
#glBindBufferARB(GL_ARRAY_BUFFER_ARB, $NormalObjID);
$norms->bind($NormalObjID);
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $norms, GL_STATIC_DRAW_ARB);
glNormalPointer_c(GL_FLOAT, 0, 0);
#glBindBufferARB(GL_ARRAY_BUFFER_ARB, $ColorObjID);
$colors->bind($ColorObjID);
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $colors, GL_DYNAMIC_DRAW_ARB);
$rainbow->assign(0,@rainbow);
glBufferSubDataARB_p(GL_ARRAY_BUFFER_ARB, $rainbow_offset, $rainbow);
glColorPointer_c(4, GL_FLOAT, 0, 0);
#glBindBufferARB(GL_ARRAY_BUFFER_ARB, $TexCoordObjID);
$texcoords->bind($TexCoordObjID);
( run in 0.915 second using v1.01-cache-2.11-cpan-ceb78f64989 )