LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-04-2007, 03:33 AM   #1
mmmmtmmmm
LQ Newbie
 
Registered: Aug 2007
Posts: 24

Rep: Reputation: 15
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
 
Old 09-04-2007, 08:24 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
You could ask the specialists here: http://www.perlmonks.org/
 
Old 09-04-2007, 10:27 PM   #3
mmmmtmmmm
LQ Newbie
 
Registered: Aug 2007
Posts: 24

Original Poster
Rep: Reputation: 15
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
 
  


Reply

Tags
3d, graphics, opengl, perl, sdl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SDL/OpenGL, need help. kornerr Programming 33 11-19-2005 11:19 PM
sdl / opengl - cant press up and right atrain Linux - Games 2 03-27-2005 11:29 PM
Question about SDL OpenGL and -lglut doody Programming 2 11-16-2004 04:17 PM
Using OpenGL (+SDL) for 2D programs R00ts Programming 4 07-16-2004 12:33 PM
OpenGL lighting with SDL MadCactus Programming 0 09-21-2003 11:52 AM


All times are GMT -5. The time now is 01:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration