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.28 by root, Wed Apr 12 20:06:36 2006 UTC vs.
Revision 1.31 by root, Fri Apr 14 14:55:27 2006 UTC

31sub gl_init { 31sub gl_init {
32 $GL_VERSION = gl_version * 1; 32 $GL_VERSION = gl_version * 1;
33 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; 33 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
34 34
35 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; 35 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2;
36
37 glClearColor 0.45, 0.45, 0.45, 1;
38 36
39 glEnable GL_TEXTURE_2D; 37 glEnable GL_TEXTURE_2D;
40 glEnable GL_COLOR_MATERIAL; 38 glEnable GL_COLOR_MATERIAL;
41 glShadeModel GL_FLAT; 39 glShadeModel GL_FLAT;
42 glDisable GL_DEPTH_TEST; 40 glDisable GL_DEPTH_TEST;
104 my ($class, %data) = @_; 102 my ($class, %data) = @_;
105 103
106 my $self = bless { 104 my $self = bless {
107 internalformat => GL_RGBA, 105 internalformat => GL_RGBA,
108 format => GL_RGBA, 106 format => GL_RGBA,
107 type => GL_UNSIGNED_BYTE,
109 %data, 108 %data,
110 }, $class; 109 }, $class;
111 110
112 push @textures, $self; 111 push @textures, $self;
113 Scalar::Util::weaken $textures[-1]; 112 Scalar::Util::weaken $textures[-1];
154 w => $w, 153 w => $w,
155 h => $h, 154 h => $h,
156 data => $data, 155 data => $data,
157 internalformat => GL_ALPHA4, 156 internalformat => GL_ALPHA4,
158 format => GL_ALPHA, 157 format => GL_ALPHA,
158 type => GL_UNSIGNED_BYTE,
159 ) 159 )
160} 160}
161 161
162sub new_from_opengl { 162sub new_from_opengl {
163 my ($class, $w, $h, $cb) = @_; 163 my ($class, $w, $h, $cb) = @_;
179 if (exists $self->{data}) { 179 if (exists $self->{data}) {
180 $data = $self->{data}; 180 $data = $self->{data};
181 181
182 } elsif (exists $self->{render_cb}) { 182 } elsif (exists $self->{render_cb}) {
183 glViewport 0, 0, $self->{w}, $self->{h}; 183 glViewport 0, 0, $self->{w}, $self->{h};
184 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
185 glMatrixMode GL_PROJECTION; 184 glMatrixMode GL_PROJECTION;
186 glLoadIdentity; 185 glLoadIdentity;
186 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
187 glMatrixMode GL_MODELVIEW; 187 glMatrixMode GL_MODELVIEW;
188 glLoadIdentity; 188 glLoadIdentity;
189 glClear GL_COLOR_BUFFER_BIT;
190 $self->{render_cb}->($self, $self->{w}, $self->{h}); 189 $self->{render_cb}->($self, $self->{w}, $self->{h});
191 190
192 } else { 191 } else {
193 use Gtk2;#d# TODO kill 192 ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type})
194 my $pb = new Gtk2::Gdk::PixbufLoader; 193 = CFClient::load_image_inline $self->{image};
195 $pb->write ($self->{image});
196 $pb->close;
197
198 $pb = $pb->get_pixbuf;
199 $pb = $pb->add_alpha (0, 0, 0, 0);
200
201 $self->{w} = $pb->get_width;
202 $self->{h} = $pb->get_height;
203
204 $data = $pb->get_pixels;
205 } 194 }
206 195
207 my ($tw, $th) = @$self{qw(w h)}; 196 my ($tw, $th) = @$self{qw(w h)};
208 197
209 unless ($tw && $th) { 198 unless ($tw && $th) {
240 glTexImage2D GL_TEXTURE_2D, 0, 229 glTexImage2D GL_TEXTURE_2D, 0,
241 $self->{internalformat}, 230 $self->{internalformat},
242 $tw, $th, # need to pad texture first 231 $tw, $th, # need to pad texture first
243 0, 232 0,
244 $self->{format}, 233 $self->{format},
245 GL_UNSIGNED_BYTE, 234 $self->{type},
246 $data; 235 $data;
247 glGetError and die; 236 glGetError and die;
248 } else { 237 } else {
249 glCopyTexImage2D GL_TEXTURE_2D, 0, 238 glCopyTexImage2D GL_TEXTURE_2D, 0,
250 $self->{internalformat}, 239 $self->{internalformat},
251 0, 0, 240 0, 0,
252 $tw, $th, 241 $tw, $th,
253 0; 242 0;
254 glGetError and die; 243 glGetError and die "glCopyTexImage2D $tw,$th";
255 } 244 }
256} 245}
257 246
258sub DESTROY { 247sub DESTROY {
259 my ($self) = @_; 248 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines