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.19 by root, Mon Apr 10 19:34:03 2006 UTC vs.
Revision 1.22 by root, Tue Apr 11 13:14:36 2006 UTC

1=head1 NAME 1=head1 NAME
2 2
3Crossfire::Client - undocumented utility garbage for our crossfire client 3CFClient - undocumented utility garbage for our crossfire client
4 4
5=head1 SYNOPSIS 5=head1 SYNOPSIS
6 6
7 use Crossfire::Client; 7 use CFClient;
8 8
9=head1 DESCRIPTION 9=head1 DESCRIPTION
10 10
11=over 4 11=over 4
12 12
13=cut 13=cut
14 14
15package Crossfire::Client; 15package CFClient;
16 16
17BEGIN { 17BEGIN {
18 $VERSION = '0.1'; 18 $VERSION = '0.1';
19 19
20 use XSLoader; 20 use XSLoader;
21 XSLoader::load "Crossfire::Client", $VERSION; 21 XSLoader::load "CFClient", $VERSION;
22} 22}
23 23
24our %GL_EXT; 24our %GL_EXT;
25our $GL_VERSION; 25our $GL_VERSION;
26 26
30 $GL_VERSION = gl_version * 1; 30 $GL_VERSION = gl_version * 1;
31 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions; 31 %GL_EXT = map +($_ => 1), split /\s+/, gl_extensions;
32 32
33 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2; 33 $GL_NPOT = $GL_EXT{GL_ARB_texture_non_power_of_two} || $GL_VERSION >= 2;
34 34
35 Crossfire::Client::Texture::restore_state (); 35 CFClient::Texture::restore_state ();
36
37# $GL_NPOT=0;#d#
38} 36}
39 37
40sub find_rcfile($) { 38sub find_rcfile($) {
41 my $path; 39 my $path;
42 40
43 for (@INC) { 41 for (@INC) {
44 $path = "$_/Crossfire/resources/$_[0]"; 42 $path = "$_/CFClient/resources/$_[0]";
45 return $path if -r $path; 43 return $path if -r $path;
46 } 44 }
47 45
48 die "FATAL: can't find required file $_[0]\n"; 46 die "FATAL: can't find required file $_[0]\n";
49} 47}
78 } 76 }
79 77
80 close CFG; 78 close CFG;
81} 79}
82 80
83package Crossfire::Client::Texture; 81package CFClient::Texture;
84 82
85use Scalar::Util; 83use Scalar::Util;
86 84
87use SDL::OpenGL; 85use SDL::OpenGL;
88 86
131# width => $surface->width, 129# width => $surface->width,
132# height => $surface->height, 130# height => $surface->height,
133# ) 131# )
134#} 132#}
135 133
136sub new_from_text { 134sub new_from_layout {
137 my ($class, $text, $height) = @_; 135 my ($class, $layout) = @_;
138 136
139 my ($w, $h, $data) = Crossfire::Client::font_render $text, $height; 137 my ($w, $h, $data) = $layout->render;
140 138
141 $class->new ( 139 $class->new (
142 width => $w, 140 width => $w,
143 height => $h, 141 height => $h,
144 data => $data, 142 data => $data,
191 $data = $pb->get_pixels; 189 $data = $pb->get_pixels;
192 } 190 }
193 191
194 my ($tw, $th) = @$self{qw(width height)}; 192 my ($tw, $th) = @$self{qw(width height)};
195 193
196 unless ($NPOT) { 194 unless ($GL_NPOT) {
197 $tw = topot $tw; 195 $tw = topot $tw;
198 $th = topot $th; 196 $th = topot $th;
199 197
200 if (defined $data) { 198 if (defined $data) {
201 $data = pack "(a$tw)*", (unpack "(a$self->{width})*", $data); 199 my $bpp = (length $data) / ($self->{width} * $self->{height});
200 $data = pack "(a" . ($tw * $bpp) . ")*",
201 unpack "(a" . ($self->{width} * $bpp) . ")*", $data;
202 $data .= ("\x00" x $tw) x ($th - $self->{height}); 202 $data .= ("\x00" x ($tw * $bpp)) x ($th - $self->{height});
203 } 203 }
204 } 204 }
205 205
206 $self->{u} = $self->{width} / $tw; 206 $self->{s} = $self->{width} / $tw;
207 $self->{v} = $self->{height} / $th; 207 $self->{t} = $self->{height} / $th;
208 208
209 $self->{name} ||= (glGenTextures 1)->[0]; 209 $self->{name} ||= (glGenTextures 1)->[0];
210 210
211 glBindTexture GL_TEXTURE_2D, $self->{name}; 211 glBindTexture GL_TEXTURE_2D, $self->{name};
212 212
213 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; 213 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
214 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; 214 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
215 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 215 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
216 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 216 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
217 217
218 glGetError; 218 glGetError;
219 if (defined $data) { 219 if (defined $data) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines