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.29 by root, Wed Apr 12 20:42:52 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 glClearColor 0.45, 0.45, 0.45, 1;
38
39 glEnable GL_TEXTURE_2D;
40 glEnable GL_COLOR_MATERIAL;
41 glShadeModel GL_FLAT;
42 glDisable GL_DEPTH_TEST;
43 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
44
45 glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST;
34 46
35 CFClient::Texture::restore_state (); 47 CFClient::Texture::restore_state ();
36} 48}
37 49
38sub find_rcfile($) { 50sub find_rcfile($) {
92 my ($class, %data) = @_; 104 my ($class, %data) = @_;
93 105
94 my $self = bless { 106 my $self = bless {
95 internalformat => GL_RGBA, 107 internalformat => GL_RGBA,
96 format => GL_RGBA, 108 format => GL_RGBA,
109 type => GL_UNSIGNED_BYTE,
97 %data, 110 %data,
98 }, $class; 111 }, $class;
99 112
100 push @textures, $self; 113 push @textures, $self;
101 Scalar::Util::weaken $textures[-1]; 114 Scalar::Util::weaken $textures[-1];
142 w => $w, 155 w => $w,
143 h => $h, 156 h => $h,
144 data => $data, 157 data => $data,
145 internalformat => GL_ALPHA4, 158 internalformat => GL_ALPHA4,
146 format => GL_ALPHA, 159 format => GL_ALPHA,
160 type => GL_UNSIGNED_BYTE,
147 ) 161 )
148} 162}
149 163
150sub new_from_opengl { 164sub new_from_opengl {
151 my ($class, $w, $h, $cb) = @_; 165 my ($class, $w, $h, $cb) = @_;
158} 172}
159 173
160sub upload { 174sub upload {
161 my ($self) = @_; 175 my ($self) = @_;
162 176
163 return unless $SDL::App::USING_OPENGL; 177 return unless $GL_VERSION;
164 178
165 my $data; 179 my $data;
166 180
167 if (exists $self->{data}) { 181 if (exists $self->{data}) {
168 $data = $self->{data}; 182 $data = $self->{data};
176 glLoadIdentity; 190 glLoadIdentity;
177 glClear GL_COLOR_BUFFER_BIT; 191 glClear GL_COLOR_BUFFER_BIT;
178 $self->{render_cb}->($self, $self->{w}, $self->{h}); 192 $self->{render_cb}->($self, $self->{w}, $self->{h});
179 193
180 } else { 194 } else {
181 my $pb = new Gtk2::Gdk::PixbufLoader; 195 ($self->{w}, $self->{h}, $data, $self->{internalformat}, $self->{format}, $self->{type})
182 $pb->write ($self->{image}); 196 = 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 } 197 }
193 198
194 my ($tw, $th) = @$self{qw(w h)}; 199 my ($tw, $th) = @$self{qw(w h)};
195 200
196 unless ($tw && $th) { 201 unless ($tw && $th) {
216 221
217 $self->{name} ||= (glGenTextures 1)->[0]; 222 $self->{name} ||= (glGenTextures 1)->[0];
218 223
219 glBindTexture GL_TEXTURE_2D, $self->{name}; 224 glBindTexture GL_TEXTURE_2D, $self->{name};
220 225
221 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 226 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; 227 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, $::FAST ? GL_NEAREST : GL_LINEAR;
223 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 228 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
224 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 229 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
225 230
226 if (defined $data) { 231 if (defined $data) {
227 glTexImage2D GL_TEXTURE_2D, 0, 232 glTexImage2D GL_TEXTURE_2D, 0,
228 $self->{internalformat}, 233 $self->{internalformat},
229 $tw, $th, # need to pad texture first 234 $tw, $th, # need to pad texture first
230 0, 235 0,
231 $self->{format}, 236 $self->{format},
232 GL_UNSIGNED_BYTE, 237 $self->{type},
233 $data; 238 $data;
234 glGetError and die; 239 glGetError and die;
235 } else { 240 } else {
236 glCopyTexImage2D GL_TEXTURE_2D, 0, 241 glCopyTexImage2D GL_TEXTURE_2D, 0,
237 $self->{internalformat}, 242 $self->{internalformat},

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines