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.11 by elmex, Sat Apr 8 18:18:09 2006 UTC vs.
Revision 1.15 by root, Sun Apr 9 00:12:58 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_RGBA,
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 => 255, -g => 255, -b => 255);
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
139 146
140 if (exists $self->{data}) { 147 if (exists $self->{data}) {
141 $data = $self->{data}; 148 $data = $self->{data};
142 } elsif (exists $self->{rendercb}) { 149 } elsif (exists $self->{rendercb}) {
143 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;
144 glClear GL_COLOR_BUFFER_BIT; 157 glClear GL_COLOR_BUFFER_BIT;
145 158
146 $self->{rendercb}->($self, $self->{width}, $self->{height}); 159 $self->{rendercb}->($self, $self->{width}, $self->{height});
147 } else { 160 } else {
148 my $pb = new Gtk2::Gdk::PixbufLoader; 161 my $pb = new Gtk2::Gdk::PixbufLoader;
160 173
161 ($self->{name}) = @{glGenTextures 1}; 174 ($self->{name}) = @{glGenTextures 1};
162 175
163 glBindTexture GL_TEXTURE_2D, $self->{name}; 176 glBindTexture GL_TEXTURE_2D, $self->{name};
164 177
165 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 178 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST;
166 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;
167 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 180 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
168 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 181 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
169 182
170 if (defined $data) { 183 if (defined $data) {
171 glTexImage2D GL_TEXTURE_2D, 0, 184 glTexImage2D GL_TEXTURE_2D, 0,
172 GL_RGBA8, 185 $self->{internalformat},
173 $self->{width}, $self->{height}, 186 $self->{width}, $self->{height},
174 0, 187 0,
175 GL_RGBA, 188 $self->{format},
176 GL_UNSIGNED_BYTE, 189 GL_UNSIGNED_BYTE,
177 $data; 190 $data;
178 } else { 191 } else {
179 warn "I{DTEDRAW TEX: $self->{width} $self->{height} \n";
180 warn "ERR: ". (glGetError). "\n";
181 my ($bd, $br) = (glGet (GL_DRAW_BUFFER), glGet (GL_READ_BUFFER));
182 warn "BUF:[$bd $br]\n";
183
184 glCopyTexImage2D GL_TEXTURE_2D, 0, 192 glCopyTexImage2D GL_TEXTURE_2D, 0,
185 GL_RGBA8, 193 $self->{internalformat},
186 0, 0, 194 0, 0,
187 $self->{width}, $self->{height}, 195 $self->{width}, $self->{height},
188 0; 196 0;
189 warn "ERR: ". (glGetError). "\n"; 197 glPopmatrix;
198 #SDL::GLSwapBuffers;
199 #sleep 1;
190 } 200 }
191} 201}
192 202
193sub DESTROY { 203sub DESTROY {
194 my ($self) = @_; 204 my ($self) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines