ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.