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.5 by root, Fri Apr 7 20:13:13 2006 UTC vs.
Revision 1.15 by root, Sun Apr 9 00:12:58 2006 UTC

53 53
54 open CFG, ">$file" 54 open CFG, ">$file"
55 or return; 55 or return;
56 56
57 { 57 {
58 require Data::Dumper;
58 local $Data::Dumper::Purity = 1; 59 local $Data::Dumper::Purity = 1;
59 $::CFG->{VERSION} = $::VERSION; 60 $::CFG->{VERSION} = $::VERSION;
60 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); 61 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]);
61 } 62 }
62 63
69 70
70use SDL::OpenGL; 71use SDL::OpenGL;
71 72
72my @textures; 73my @textures;
73 74
74sub _new { 75sub new {
75 my ($class, %data) = @_; 76 my ($class, %data) = @_;
76 77
77 my $self = bless \%data, $class; 78 my $self = bless {
79 internalformat => GL_RGBA,
80 format => GL_RGBA,
81 %data,
82 }, $class;
78 83
79 push @textures, $self; 84 push @textures, $self;
80 Scalar::Util::weaken $textures[-1]; 85 Scalar::Util::weaken $textures[-1];
81 86
82 $self->upload; 87 $self->upload;
85} 90}
86 91
87sub new_from_image { 92sub new_from_image {
88 my ($class, $image) = @_; 93 my ($class, $image) = @_;
89 94
90 $class->_new (image => $image) 95 $class->new (image => $image)
91} 96}
92 97
93sub new_from_file { 98sub new_from_file {
94 my ($class, $path) = @_; 99 my ($class, $path) = @_;
95 100
98 103
99 local $/; 104 local $/;
100 $class->new_from_image (<$fh>) 105 $class->new_from_image (<$fh>)
101} 106}
102 107
103sub new_from_surface { 108#sub new_from_surface {
104 my ($class, $surface) = @_; 109# my ($class, $surface) = @_;
105 110#
106 $surface->rgba; 111# $surface->rgba;
107 112#
108 $class->_new ( 113# $class->new (
109 data => $surface->pixels, 114# data => $surface->pixels,
110 width => $surface->width, 115# width => $surface->width,
111 height => $surface->height, 116# height => $surface->height,
117# )
118#}
119
120sub new_from_text {
121 my ($class, $text, $height) = @_;
122
123 my ($w, $h, $data) = Crossfire::Client::font_render $text, $height;
124
125 $class->new (
126 width => $w,
127 height => $h,
128 data => $data,
129 internalformat => GL_ALPHA8,
130 format => GL_ALPHA,
112 ) 131 )
132}
133
134sub new_from_opengl {
135 my ($class, $w, $h, $cb) = @_;
136
137 $class->new (width => $w, height => $h, rendercb => $cb)
113} 138}
114 139
115sub upload { 140sub upload {
116 my ($self) = @_; 141 my ($self) = @_;
117 142
118 return unless $SDL::App::USING_OPENGL; 143 return unless $SDL::App::USING_OPENGL;
119 144
120 my ($data, $width, $height); 145 my $data;
121 146
122 if (exists $self->{data}) { 147 if (exists $self->{data}) {
123 ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); 148 $data = $self->{data};
149 } elsif (exists $self->{rendercb}) {
150 glViewport 0, 0, $self->{width}, $self->{height};
151 glMatrixMode GL_PROJECTION;
152 glLoadIdentity;
153 glOrtho 0, $self->{width}, 0, $self->{height}, -100, 100;
154 glMatrixMode GL_MODELVIEW;
155 glPushmatrix;
156 glLoadIdentity;
157 glClear GL_COLOR_BUFFER_BIT;
158
159 $self->{rendercb}->($self, $self->{width}, $self->{height});
124 } else { 160 } else {
125 my $pb = new Gtk2::Gdk::PixbufLoader; 161 my $pb = new Gtk2::Gdk::PixbufLoader;
126 $pb->write ($self->{image}); 162 $pb->write ($self->{image});
127 $pb->close; 163 $pb->close;
128 164
129 $pb = $pb->get_pixbuf; 165 $pb = $pb->get_pixbuf;
130 $pb = $pb->add_alpha (0, 0, 0, 0); 166 $pb = $pb->add_alpha (0, 0, 0, 0);
131 167
132 ($data, $width, $height) = ($pb->get_pixels, $pb->get_width, $pb->get_height); 168 $self->{width} = $pb->get_width;
169 $self->{height} = $pb->get_height;
170
171 $data = $pb->get_pixels;
133 } 172 }
134 173
135 ($self->{name}) = @{glGenTextures 1}; 174 ($self->{name}) = @{glGenTextures 1};
136 175
137 glBindTexture GL_TEXTURE_2D, $self->{name}; 176 glBindTexture GL_TEXTURE_2D, $self->{name};
138 177
139 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 178 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
140 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; 179 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR;
141 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 180 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
142 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 181 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
143 182
183 if (defined $data) {
144 glTexImage2D GL_TEXTURE_2D, 0, 184 glTexImage2D GL_TEXTURE_2D, 0,
145 GL_RGBA8, 185 $self->{internalformat},
146 $width, $height, 186 $self->{width}, $self->{height},
147 0, 187 0,
148 GL_RGBA, 188 $self->{format},
149 GL_UNSIGNED_BYTE, 189 GL_UNSIGNED_BYTE,
150 $data; 190 $data;
191 } else {
192 glCopyTexImage2D GL_TEXTURE_2D, 0,
193 $self->{internalformat},
194 0, 0,
195 $self->{width}, $self->{height},
196 0;
197 glPopmatrix;
198 #SDL::GLSwapBuffers;
199 #sleep 1;
200 }
151} 201}
152 202
153sub DESTROY { 203sub DESTROY {
154 my ($self) = @_; 204 my ($self) = @_;
155 205

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines