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.25 by root, Tue Apr 11 19:31:17 2006 UTC vs.
Revision 1.31 by root, Fri Apr 14 14:55:27 2006 UTC

18 $VERSION = '0.1'; 18 $VERSION = '0.1';
19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "CFClient", $VERSION; 21 XSLoader::load "CFClient", $VERSION;
22} 22}
23
24use SDL::OpenGL;
23 25
24our %GL_EXT; 26our %GL_EXT;
25our $GL_VERSION; 27our $GL_VERSION;
26 28
27our $GL_NPOT; 29our $GL_NPOT;
29sub gl_init { 31sub gl_init {
30 $GL_VERSION = gl_version * 1; 32 $GL_VERSION = gl_version * 1;
31 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; 33 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
32 34
33 $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 glEnable GL_TEXTURE_2D;
38 glEnable GL_COLOR_MATERIAL;
39 glShadeModel GL_FLAT;
40 glDisable GL_DEPTH_TEST;
41 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
42
43 glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST;
34 44
35 CFClient::Texture::restore_state (); 45 CFClient::Texture::restore_state ();
36} 46}
37 47
38sub find_rcfile($) { 48sub find_rcfile($) {
92 my ($class, %data) = @_; 102 my ($class, %data) = @_;
93 103
94 my $self = bless { 104 my $self = bless {
95 internalformat => GL_RGBA, 105 internalformat => GL_RGBA,
96 format => GL_RGBA, 106 format => GL_RGBA,
107 type => GL_UNSIGNED_BYTE,
97 %data, 108 %data,
98 }, $class; 109 }, $class;
99 110
100 push @textures, $self; 111 push @textures, $self;
101 Scalar::Util::weaken $textures[-1]; 112 Scalar::Util::weaken $textures[-1];
142 w => $w, 153 w => $w,
143 h => $h, 154 h => $h,
144 data => $data, 155 data => $data,
145 internalformat => GL_ALPHA4, 156 internalformat => GL_ALPHA4,
146 format => GL_ALPHA, 157 format => GL_ALPHA,
158 type => GL_UNSIGNED_BYTE,
147 ) 159 )
148} 160}
149 161
150sub new_from_opengl { 162sub new_from_opengl {
151 my ($class, $w, $h, $cb) = @_; 163 my ($class, $w, $h, $cb) = @_;
158} 170}
159 171
160sub upload { 172sub upload {
161 my ($self) = @_; 173 my ($self) = @_;
162 174
163 return unless $SDL::App::USING_OPENGL; 175 return unless $GL_VERSION;
164 176
165 my $data; 177 my $data;
166 178
167 if (exists $self->{data}) { 179 if (exists $self->{data}) {
168 $data = $self->{data}; 180 $data = $self->{data};
169 181
170 } elsif (exists $self->{render_cb}) { 182 } elsif (exists $self->{render_cb}) {
171 glViewport 0, 0, $self->{w}, $self->{h}; 183 glViewport 0, 0, $self->{w}, $self->{h};
172 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
173 glMatrixMode GL_PROJECTION; 184 glMatrixMode GL_PROJECTION;
174 glLoadIdentity; 185 glLoadIdentity;
186 glOrtho 0, $self->{w}, 0, $self->{h}, -10000, 10000;
175 glMatrixMode GL_MODELVIEW; 187 glMatrixMode GL_MODELVIEW;
176 glLoadIdentity; 188 glLoadIdentity;
177 glClear GL_COLOR_BUFFER_BIT;
178 $self->{render_cb}->($self, $self->{w}, $self->{h}); 189 $self->{render_cb}->($self, $self->{w}, $self->{h});
179 190
180 } else { 191 } else {
181 my $pb = new Gtk2::Gdk::PixbufLoader; 192 ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type})
182 $pb->write ($self->{image}); 193 = CFClient::load_image_inline $self->{image};
183 $pb->close;
184
185 $pb = $pb->get_pixbuf;
186 $pb = $pb->add_alpha (0, 0, 0, 0);
187
188 $self->{w} = $pb->get_width;
189 $self->{h} = $pb->get_height;
190
191 $data = $pb->get_pixels;
192 } 194 }
193 195
194 my ($tw, $th) = @$self{qw(w h)}; 196 my ($tw, $th) = @$self{qw(w h)};
195 197
196 unless ($tw && $th) { 198 unless ($tw && $th) {
216 218
217 $self->{name} ||= (glGenTextures 1)->[0]; 219 $self->{name} ||= (glGenTextures 1)->[0];
218 220
219 glBindTexture GL_TEXTURE_2D, $self->{name}; 221 glBindTexture GL_TEXTURE_2D, $self->{name};
220 222
221 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 223 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
222 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; 224 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
223 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 225 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
224 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 226 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
225 227
226 if (defined $data) { 228 if (defined $data) {
227 glTexImage2D GL_TEXTURE_2D, 0, 229 glTexImage2D GL_TEXTURE_2D, 0,
228 $self->{internalformat}, 230 $self->{internalformat},
229 $tw, $th, # need to pad texture first 231 $tw, $th, # need to pad texture first
230 0, 232 0,
231 $self->{format}, 233 $self->{format},
232 GL_UNSIGNED_BYTE, 234 $self->{type},
233 $data; 235 $data;
234 glGetError and die; 236 glGetError and die;
235 } else { 237 } else {
236 glCopyTexImage2D GL_TEXTURE_2D, 0, 238 glCopyTexImage2D GL_TEXTURE_2D, 0,
237 $self->{internalformat}, 239 $self->{internalformat},
238 0, 0, 240 0, 0,
239 $tw, $th, 241 $tw, $th,
240 0; 242 0;
241 glGetError and die; 243 glGetError and die "glCopyTexImage2D $tw,$th";
242 } 244 }
243} 245}
244 246
245sub DESTROY { 247sub DESTROY {
246 my ($self) = @_; 248 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines