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.24 by root, Tue Apr 11 18:06:52 2006 UTC vs.
Revision 1.25 by root, Tue Apr 11 19:31:17 2006 UTC

77 77
78 close CFG; 78 close CFG;
79} 79}
80 80
81package CFClient::Texture; 81package CFClient::Texture;
82
83use strict;
82 84
83use Scalar::Util; 85use Scalar::Util;
84 86
85use SDL::OpenGL; 87use SDL::OpenGL;
86 88
162 164
163 my $data; 165 my $data;
164 166
165 if (exists $self->{data}) { 167 if (exists $self->{data}) {
166 $data = $self->{data}; 168 $data = $self->{data};
169
167 } elsif (exists $self->{render_cb}) { 170 } elsif (exists $self->{render_cb}) {
168 glViewport 0, 0, $self->{w}, $self->{h}; 171 glViewport 0, 0, $self->{w}, $self->{h};
172 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
169 glMatrixMode GL_PROJECTION; 173 glMatrixMode GL_PROJECTION;
170 glLoadIdentity; 174 glLoadIdentity;
171 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
172 glMatrixMode GL_MODELVIEW; 175 glMatrixMode GL_MODELVIEW;
173 glPushmatrix;
174 glLoadIdentity; 176 glLoadIdentity;
175 glClear GL_COLOR_BUFFER_BIT; 177 glClear GL_COLOR_BUFFER_BIT;
176
177 $self->{render_cb}->($self, $self->{w}, $self->{h}); 178 $self->{render_cb}->($self, $self->{w}, $self->{h});
179
178 } else { 180 } else {
179 my $pb = new Gtk2::Gdk::PixbufLoader; 181 my $pb = new Gtk2::Gdk::PixbufLoader;
180 $pb->write ($self->{image}); 182 $pb->write ($self->{image});
181 $pb->close; 183 $pb->close;
182 184
189 $data = $pb->get_pixels; 191 $data = $pb->get_pixels;
190 } 192 }
191 193
192 my ($tw, $th) = @$self{qw(w h)}; 194 my ($tw, $th) = @$self{qw(w h)};
193 195
194 unless ($tw || $th) { 196 unless ($tw && $th) {
195 $tw = $th = 1; 197 $tw = $th = 1;
196 $data = "\x00" x 64; 198 $data = "\x00" x 64;
197 } 199 }
198 200
199 unless ($GL_NPOT) { 201 unless ($GL_NPOT) {
200 # TODO: does not work for zero-sized textures 202 # TODO: does not work for zero-sized textures
201 $tw = topot $tw; 203 $tw = topot $tw;
202 $th = topot $th; 204 $th = topot $th;
203 205
204 if (defined $data) { 206 if ($tw != $self->{w} || $th != $self->{h} && defined $data) {
205 my $bpp = (length $data) / ($self->{w} * $self->{h}); 207 my $bpp = (length $data) / ($self->{w} * $self->{h});
206 $data = pack "(a" . ($tw * $bpp) . ")*", 208 $data = pack "(a" . ($tw * $bpp) . ")*",
207 unpack "(a" . ($self->{w} * $bpp) . ")*", $data; 209 unpack "(a" . ($self->{w} * $bpp) . ")*", $data;
208 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{h}); 210 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{h});
209 } 211 }
219 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 221 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
220 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; 222 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
221 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 223 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
222 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 224 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
223 225
224 glGetError;
225 if (defined $data) { 226 if (defined $data) {
226 glTexImage2D GL_TEXTURE_2D, 0, 227 glTexImage2D GL_TEXTURE_2D, 0,
227 $self->{internalformat}, 228 $self->{internalformat},
228 $tw, $th, # need to pad texture first 229 $tw, $th, # need to pad texture first
229 0, 230 0,
235 glCopyTexImage2D GL_TEXTURE_2D, 0, 236 glCopyTexImage2D GL_TEXTURE_2D, 0,
236 $self->{internalformat}, 237 $self->{internalformat},
237 0, 0, 238 0, 0,
238 $tw, $th, 239 $tw, $th,
239 0; 240 0;
240 glPopmatrix; 241 glGetError and die;
241 } 242 }
242} 243}
243 244
244sub DESTROY { 245sub DESTROY {
245 my ($self) = @_; 246 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines