LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl - SDL::OpenGL is not displaying graphics (https://www.linuxquestions.org/questions/programming-9/perl-sdl-opengl-is-not-displaying-graphics-582050/)

mmmmtmmmm 09-04-2007 03:33 AM

Perl - SDL::OpenGL is not displaying graphics
 
I am trying to run some Perl code that I found in a 3d graphics tutorial. It is supposed to create a window and display a blue cube in it. It is opening up the window, but is not displaying anything inside of it -- it's just black the whole time. Is there anything that you all can see that would make it not display? I am not getting any error messages. Here is the code:

Code:

#!/usr/bin/perl -w
use strict;

use SDL::App;
use SDL::OpenGL;

my ($done, $frame);

START: main();

sub main{
    init();
    main_loop();
    cleanup();
}

sub init{
    $| = 1;
    init_conf();
    init_window();
}

sub main_loop{
    while (not $done) {
        $frame++;
        do_frame();
    }
}

#config hash and SDL::App object
my ($conf, $sdl_app);

#Configuration for SDL::App Window created in init_window()
sub init_conf{
    $conf = {
        title  => 'Camel 3D',
        width  => 400,
        height => 400,
        fovy  => 90,
    };
}

#Creates an SDL::App object using values from init_conf()
sub init_window{
    my ($title, $w, $h) = @$conf{qw( title width height )};

    $sdl_app = SDL::App->new(-title  => $title,
                            -width  => $w,
                            -height => $h,
                            -gl    => 1,
                            );
    SDL::ShowCursor(0); #Toggles whether cursor appears in window
}

sub do_frame{
    prep_frame();
    draw_frame();
    end_frame();
}

sub prep_frame{
    glClear(GL_COLOR_BUFFER_BIT);
}

sub draw_frame{
    set_projection_3d();
    set_view_3d();
    draw_view();

    print '.';
    sleep 1;
    $done = 1 if $frame == 5;
}

sub set_projection_3d{
    my ($fovy, $w, $h) = @$conf{qw( fovy width height )};
    my $aspect = $w / $h;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity;
    gluPerspective($fovy, $aspect, 1, 1000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity;
}

sub set_view_3d
{
    # Move the viewpoint so we can see the origin
    glTranslate(0, -2, -10);
}

sub draw_view{
    draw_cube();
}

sub draw_cube
{
    # A simple cube
    my @indices = qw( 4 5 6 7  1 2 6 5  0 1 5 4
                      0 3 2 1  0 4 7 3  2 3 7 6 );
    my @vertices = ([-1, -1, -1], [ 1, -1, -1],
                    [ 1,  1, -1], [-1,  1, -1],
                    [-1, -1,  1], [ 1, -1,  1],
                    [ 1,  1,  1], [-1,  1,  1]);

    glBegin(GL_QUADS);
    foreach my $face (0 .. 5) {
        foreach my $vertex (0 .. 3) {
            my $index  = $indices[4 * $face + $vertex];
            my $coords = $vertices[$index];
            glVertex(@$coords);
        }
    }
    glEnd;
}

sub end_frame{
    $sdl_app->sync;
}

sub cleanup{
    print "\nDone.\n";
}

I would really appreciate any help you all can give me.

Thanks,
mmmmtmmmm

chrism01 09-04-2007 08:24 PM

You could ask the specialists here: http://www.perlmonks.org/

mmmmtmmmm 09-04-2007 10:27 PM

I tried there, and also on IRC. I am not sure whether it is a problem with Perl or with my graphics setup -- but OpenGL is working elsewhere, so I don't know why it wouldn't be working here.


Any help is appreciated...

---mmmmtmmmm


All times are GMT -5. The time now is 02:33 PM.