ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC.pm (file contents):
Revision 1.3 by root, Fri Apr 7 18:20:13 2006 UTC vs.
Revision 1.4 by root, Fri Apr 7 18:49:52 2006 UTC

27 27
28use SDL::OpenGL; 28use SDL::OpenGL;
29 29
30my @textures; 30my @textures;
31 31
32sub _new {
33 my ($class, %data) = @_;
34
35 my $self = bless \%data, $class;
36
37 push @textures, $self;
38 Scalar::Util::weaken $textures[-1];
39
40 $self->upload;
41
42 $self
43}
44
45sub new_from_image {
46 my ($class, $image) = @_;
47
48 $class->_new (image => $image)
49}
50
32sub new_from_file { 51sub new_from_file {
33 my ($class, $path) = @_; 52 my ($class, $path) = @_;
34 53
35 open my $fh, "<:raw", $path 54 open my $fh, "<:raw", $path
36 or die "$path: $!"; 55 or die "$path: $!";
37 56
38 local $/; 57 local $/;
39 $class->new_from_data (<$fh>) 58 $class->new_from_image (<$fh>)
40} 59}
41 60
42sub new_from_image { 61sub new_from_surface {
43 my ($class, $image) = @_; 62 my ($class, $surface) = @_;
44 63
45 my $self = bless { 64 $surface->rgba;
46 image => $data,
47 };
48 65
49 push @textures, $self; 66 $class->_new (
50 Scalar::Util::weaken $textures[-1]; 67 data => $surface->pixels,
51 68 width => $surface->width,
52 $self->upload; 69 height => $surface->height,
53 70 )
54 $self
55} 71}
56 72
57sub upload { 73sub upload {
58 my ($self) = @_; 74 my ($self) = @_;
59 75
63 79
64 if (exists $self->{data}) { 80 if (exists $self->{data}) {
65 ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); 81 ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height});
66 } else { 82 } else {
67 my $pb = new Gtk2::Gdk::PixbufLoader; 83 my $pb = new Gtk2::Gdk::PixbufLoader;
68 $pb->write ($self->{data}); 84 $pb->write ($self->{image});
69 $pb->close; 85 $pb->close;
70 86
71 $pb = $pb->get_pixbuf; 87 $pb = $pb->get_pixbuf;
72 $pb = $pb->add_alpha (0, 0, 0, 0); 88 $pb = $pb->add_alpha (0, 0, 0, 0);
73 89

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines