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.13 by elmex, Sat Apr 8 22:23:57 2006 UTC vs.
Revision 1.14 by root, Sun Apr 9 00:06:09 2006 UTC

70 70
71use SDL::OpenGL; 71use SDL::OpenGL;
72 72
73my @textures; 73my @textures;
74 74
75sub _new { 75sub new {
76 my ($class, %data) = @_; 76 my ($class, %data) = @_;
77 77
78 my $self = bless \%data, $class; 78 my $self = bless {
79 internalFormat => GL_RGBA,
80 format => GL_RGBA8,
81 %data,
82 }, $class;
79 83
80 push @textures, $self; 84 push @textures, $self;
81 Scalar::Util::weaken $textures[-1]; 85 Scalar::Util::weaken $textures[-1];
82 86
83 $self->upload; 87 $self->upload;
86} 90}
87 91
88sub new_from_image { 92sub new_from_image {
89 my ($class, $image) = @_; 93 my ($class, $image) = @_;
90 94
91 $class->_new (image => $image) 95 $class->new (image => $image)
92} 96}
93 97
94sub new_from_file { 98sub new_from_file {
95 my ($class, $path) = @_; 99 my ($class, $path) = @_;
96 100
99 103
100 local $/; 104 local $/;
101 $class->new_from_image (<$fh>) 105 $class->new_from_image (<$fh>)
102} 106}
103 107
104sub new_from_surface { 108#sub new_from_surface {
105 my ($class, $surface) = @_; 109# my ($class, $surface) = @_;
106 110#
107 $surface->rgba; 111# $surface->rgba;
108 112#
109 $class->_new ( 113# $class->new (
110 data => $surface->pixels, 114# data => $surface->pixels,
111 width => $surface->width, 115# width => $surface->width,
112 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,
113 ) 131 )
114}
115
116sub new_from_ttf {
117 my ($class, $ttf, $text) = @_;
118
119 utf8::encode $text;
120
121 my $surface = SDL::TTFRenderUTF8Blended $ttf, $text,
122 (new SDL::Color -r => 0, -g => 0, -b => 0);
123
124 $class->new_from_surface (bless \$surface, SDL::Surface::)
125} 132}
126 133
127sub new_from_opengl { 134sub new_from_opengl {
128 my ($class, $w, $h, $cb) = @_; 135 my ($class, $w, $h, $cb) = @_;
129 136
130 $class->_new (width => $w, height => $h, rendercb => $cb) 137 $class->new (width => $w, height => $h, rendercb => $cb)
131} 138}
132 139
133sub upload { 140sub upload {
134 my ($self) = @_; 141 my ($self) = @_;
135 142
173 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 180 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
174 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 181 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
175 182
176 if (defined $data) { 183 if (defined $data) {
177 glTexImage2D GL_TEXTURE_2D, 0, 184 glTexImage2D GL_TEXTURE_2D, 0,
178 GL_RGBA8, 185 $self->{internalFormat},
179 $self->{width}, $self->{height}, 186 $self->{width}, $self->{height},
180 0, 187 0,
181 GL_RGBA, 188 $self->{format},
182 GL_UNSIGNED_BYTE, 189 GL_UNSIGNED_BYTE,
183 $data; 190 $data;
184 } else { 191 } else {
185 warn "I{DTEDRAW TEX: $self->{width} $self->{height} \n";
186 warn "ERR: ". (glGetError). "\n";
187 my ($bd, $br) = (glGet (GL_DRAW_BUFFER), glGet (GL_READ_BUFFER));
188 warn "BUF:[$bd $br]\n";
189
190 glCopyTexImage2D GL_TEXTURE_2D, 0, 192 glCopyTexImage2D GL_TEXTURE_2D, 0,
191 GL_RGBA8, 193 $self->{internalFormat},
192 0, 0, 194 0, 0,
193 $self->{width}, $self->{height}, 195 $self->{width}, $self->{height},
194 0; 196 0;
195 glPopmatrix; 197 glPopmatrix;
196 warn "ERR: ". (glGetError). "\n";
197 SDL::GLSwapBuffers; 198 #SDL::GLSwapBuffers;
198 sleep 1; 199 #sleep 1;
199 } 200 }
200} 201}
201 202
202sub DESTROY { 203sub DESTROY {
203 my ($self) = @_; 204 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines