Acme-MITHALDU-BleedingOpenGL
view release on metacpan or search on metacpan
# Clear the color and depth buffers.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
# Update Rainbow Cube Face
for (my $i=0; $i<scalar(@rainbow); $i++)
{
$rainbow[$i] += $rainbow_inc[$i];
if ($rainbow[$i] < 0)
{
$rainbow[$i] = 0.0;
}
elsif ($rainbow[$i] > 1)
{
$rainbow[$i] = 1.0;
}
else
{
next;
}
$rainbow_inc[$i] = -$rainbow_inc[$i];
}
if ($hasVBO)
{
glBindBufferARB(GL_ARRAY_BUFFER_ARB, $ColorObjID);
my $color_map = glMapBufferARB_p(GL_ARRAY_BUFFER_ARB,
GL_WRITE_ONLY_ARB,GL_FLOAT);
my $buffer = glGetBufferPointervARB_p(GL_ARRAY_BUFFER_ARB,
GL_BUFFER_MAP_POINTER_ARB,GL_FLOAT);
$color_map->assign($rainbow_offset,@rainbow);
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
}
else
{
$colors->assign($rainbow_offset,@rainbow);
glColorPointer_p(4, $colors);
}
# Render cube
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
for (my $i=0; $i<scalar(@indices); $i+=4)
{
glDrawArrays(GL_QUADS, $i, 4);
}
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
# Move back to the origin (for the text, below).
glLoadIdentity();
# We need to change the projection matrix for the text rendering.
glMatrixMode(GL_PROJECTION);
# But we like our current view too; so we save it here.
glPushMatrix();
# Now we set up a new projection for the text.
glLoadIdentity();
glOrtho(0,$Window_Width,0,$Window_Height,-1.0,1.0);
# Lit or textured text looks awful.
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
# We don'$t want depth-testing either.
glDisable(GL_DEPTH_TEST);
# But, for fun, let's make the text partially transparent too.
glColor4f(0.6,1.0,0.6,.75);
$buf = sprintf "TIME TO EXIT: %.1fs", $time_to_exit;
my $bufwidth = 6 * length $buf;
glRasterPos2i($Window_Width-4-$bufwidth,2); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
# Render our various display mode settings.
$buf = sprintf "Mode: %s", $TexModesStr[$Curr_TexMode];
glRasterPos2i(2,2); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "Alpha: %d", $Alpha_Add;
glRasterPos2i(2,14); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "Blend: %d", $Blend_On;
glRasterPos2i(2,26); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "Light: %d", $Light_On;
glRasterPos2i(2,38); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "Tex: %d", $Texture_On;
glRasterPos2i(2,50); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "FBO: %d", $FBO_On;
glRasterPos2i(2,62); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
$buf = sprintf "Inset: %d", $Inset_On;
glRasterPos2i(2,74); ourPrintString(GLUT_BITMAP_HELVETICA_12,$buf);
# Now we want to render the calulated FPS at the top.
# To ease, simply translate up. Note we're working in screen
# pixels in this projection.
glTranslatef(6.0,$Window_Height - 14,0.0);
# Make sure we can read the FPS section by first placing a
# dark, mostly opaque backdrop rectangle.
glColor4f(0.2,0.2,0.2,0.75);
glBegin(GL_QUADS);
glVertex3f( 0.0, -2.0, 0.0);
glVertex3f( 0.0, 12.0, 0.0);
glVertex3f(140.0, 12.0, 0.0);
glVertex3f(140.0, -2.0, 0.0);
glEnd();
( run in 1.533 second using v1.01-cache-2.11-cpan-39bf76dae61 )