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.8 by root, Sat Apr 8 13:36:25 2006 UTC vs.
Revision 1.15 by root, Sun Apr 9 00:12:58 2006 UTC

53 53
54 open CFG, ">$file" 54 open CFG, ">$file"
55 or return; 55 or return;
56 56
57 { 57 {
58 require Data::Dumper;
58 local $Data::Dumper::Purity = 1; 59 local $Data::Dumper::Purity = 1;
59 $::CFG->{VERSION} = $::VERSION; 60 $::CFG->{VERSION} = $::VERSION;
60 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); 61 print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]);
61 } 62 }
62 63
69 70
70use SDL::OpenGL; 71use SDL::OpenGL;
71 72
72my @textures; 73my @textures;
73 74
74sub _new { 75sub new {
75 my ($class, %data) = @_; 76 my ($class, %data) = @_;
76 77
77 my $self = bless \%data, $class; 78 my $self = bless {
79 internalformat => GL_RGBA,
80 format => GL_RGBA,
81 %data,
82 }, $class;
78 83
79 push @textures, $self; 84 push @textures, $self;
80 Scalar::Util::weaken $textures[-1]; 85 Scalar::Util::weaken $textures[-1];
81 86
82 $self->upload; 87 $self->upload;
85} 90}
86 91
87sub new_from_image { 92sub new_from_image {
88 my ($class, $image) = @_; 93 my ($class, $image) = @_;
89 94
90 $class->_new (image => $image) 95 $class->new (image => $image)
91} 96}
92 97
93sub new_from_file { 98sub new_from_file {
94 my ($class, $path) = @_; 99 my ($class, $path) = @_;
95 100
98 103
99 local $/; 104 local $/;
100 $class->new_from_image (<$fh>) 105 $class->new_from_image (<$fh>)
101} 106}
102 107
103sub new_from_surface { 108#sub new_from_surface {
104 my ($class, $surface) = @_; 109# my ($class, $surface) = @_;
105 110#
106 $surface->rgba; 111# $surface->rgba;
107 112#
108 $class->_new ( 113# $class->new (
109 data => $surface->pixels, 114# data => $surface->pixels,
110 width => $surface->width, 115# width => $surface->width,
111 height => $surface->height, 116# height => $surface->height,
117# )
118#}
119
120sub new_from_text {
121 my ($class, $text, $height) = @_;
122
123 my ($w, $h, $data) = Crossfire::Client::font_render $text, $height;
124
125 $class->new (
126 width => $w,
127 height => $h,
128 data => $data,
129 internalformat => GL_ALPHA8,
130 format => GL_ALPHA,
112 ) 131 )
113}
114
115sub new_from_ttf {
116 my ($class, $ttf, $text) = @_;
117
118 utf8::encode $text;
119
120 my $surface = SDL::TTFRenderUTF8Blended $ttf, $text,
121 (new SDL::Color -r => 255, -g => 255, -b => 255);
122
123 $class->new_from_surface (bless \$surface, SDL::Surface::)
124} 132}
125 133
126sub new_from_opengl { 134sub new_from_opengl {
127 my ($class, $w, $h, $cb) = @_; 135 my ($class, $w, $h, $cb) = @_;
128 136
129 $class->_new (width => $w, height => $h, render => $cb) 137 $class->new (width => $w, height => $h, rendercb => $cb)
130} 138}
131 139
132sub upload { 140sub upload {
133 my ($self) = @_; 141 my ($self) = @_;
134 142
138 146
139 if (exists $self->{data}) { 147 if (exists $self->{data}) {
140 $data = $self->{data}; 148 $data = $self->{data};
141 } elsif (exists $self->{rendercb}) { 149 } elsif (exists $self->{rendercb}) {
142 glViewport 0, 0, $self->{width}, $self->{height}; 150 glViewport 0, 0, $self->{width}, $self->{height};
151 glMatrixMode GL_PROJECTION;
152 glLoadIdentity;
153 glOrtho 0, $self->{width}, 0, $self->{height}, -100, 100;
154 glMatrixMode GL_MODELVIEW;
155 glPushmatrix;
156 glLoadIdentity;
143 glClear GL_COLOR_BUFFER_BIT; 157 glClear GL_COLOR_BUFFER_BIT;
144 158
145 $self->{rendercb}->($self, $self->{width}, $self->{height}); 159 $self->{rendercb}->($self, $self->{width}, $self->{height});
146 } else { 160 } else {
147 my $pb = new Gtk2::Gdk::PixbufLoader; 161 my $pb = new Gtk2::Gdk::PixbufLoader;
159 173
160 ($self->{name}) = @{glGenTextures 1}; 174 ($self->{name}) = @{glGenTextures 1};
161 175
162 glBindTexture GL_TEXTURE_2D, $self->{name}; 176 glBindTexture GL_TEXTURE_2D, $self->{name};
163 177
164 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 178 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
165 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; 179 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR;
166 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 180 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
167 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 181 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
168 182
169 if (defined $data) { 183 if (defined $data) {
170 glTexImage2D GL_TEXTURE_2D, 0, 184 glTexImage2D GL_TEXTURE_2D, 0,
171 GL_RGBA8, 185 $self->{internalformat},
172 $self->{width}, $self->{height}, 186 $self->{width}, $self->{height},
173 0, 187 0,
174 GL_RGBA, 188 $self->{format},
175 GL_UNSIGNED_BYTE, 189 GL_UNSIGNED_BYTE,
176 $data; 190 $data;
177 } else { 191 } else {
178 glCopyTexImage2D GL_TEXTURE_2D, 0, 192 glCopyTexImage2D GL_TEXTURE_2D, 0,
179 GL_RGBA8, 193 $self->{internalformat},
180 0, 0, 194 0, 0,
181 $self->{width}, $self->{height}, 195 $self->{width}, $self->{height},
182 0; 196 0;
197 glPopmatrix;
198 #SDL::GLSwapBuffers;
199 #sleep 1;
183 } 200 }
184} 201}
185 202
186sub DESTROY { 203sub DESTROY {
187 my ($self) = @_; 204 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines