… | |
… | |
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 | |
… | |
… | |
110 | width => $surface->width, |
111 | width => $surface->width, |
111 | height => $surface->height, |
112 | height => $surface->height, |
112 | ) |
113 | ) |
113 | } |
114 | } |
114 | |
115 | |
|
|
116 | sub 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 | } |
|
|
126 | |
|
|
127 | sub new_from_opengl { |
|
|
128 | my ($class, $w, $h, $cb) = @_; |
|
|
129 | |
|
|
130 | $class->_new (width => $w, height => $h, rendercb => $cb) |
|
|
131 | } |
|
|
132 | |
115 | sub upload { |
133 | sub upload { |
116 | my ($self) = @_; |
134 | my ($self) = @_; |
117 | |
135 | |
118 | return unless $SDL::App::USING_OPENGL; |
136 | return unless $SDL::App::USING_OPENGL; |
119 | |
137 | |
120 | my ($data, $width, $height); |
138 | my $data; |
121 | |
139 | |
122 | if (exists $self->{data}) { |
140 | if (exists $self->{data}) { |
123 | ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); |
141 | $data = $self->{data}; |
|
|
142 | } elsif (exists $self->{rendercb}) { |
|
|
143 | glViewport 0, 0, $self->{width}, $self->{height}; |
|
|
144 | glClear GL_COLOR_BUFFER_BIT; |
|
|
145 | |
|
|
146 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
124 | } else { |
147 | } else { |
125 | my $pb = new Gtk2::Gdk::PixbufLoader; |
148 | my $pb = new Gtk2::Gdk::PixbufLoader; |
126 | $pb->write ($self->{image}); |
149 | $pb->write ($self->{image}); |
127 | $pb->close; |
150 | $pb->close; |
128 | |
151 | |
129 | $pb = $pb->get_pixbuf; |
152 | $pb = $pb->get_pixbuf; |
130 | $pb = $pb->add_alpha (0, 0, 0, 0); |
153 | $pb = $pb->add_alpha (0, 0, 0, 0); |
131 | |
154 | |
132 | ($data, $width, $height) = ($pb->get_pixels, $pb->get_width, $pb->get_height); |
155 | $self->{width} = $pb->get_width; |
|
|
156 | $self->{height} = $pb->get_height; |
|
|
157 | |
|
|
158 | $data = $pb->get_pixels; |
133 | } |
159 | } |
134 | |
160 | |
135 | ($self->{name}) = @{glGenTextures 1}; |
161 | ($self->{name}) = @{glGenTextures 1}; |
136 | |
162 | |
137 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
163 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
… | |
… | |
139 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
165 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
140 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
166 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
141 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
167 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
142 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
168 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
143 | |
169 | |
|
|
170 | if (defined $data) { |
144 | glTexImage2D GL_TEXTURE_2D, 0, |
171 | glTexImage2D GL_TEXTURE_2D, 0, |
145 | GL_RGBA8, |
172 | GL_RGBA8, |
146 | $width, $height, |
173 | $self->{width}, $self->{height}, |
147 | 0, |
174 | 0, |
148 | GL_RGBA, |
175 | GL_RGBA, |
149 | GL_UNSIGNED_BYTE, |
176 | GL_UNSIGNED_BYTE, |
150 | $data; |
177 | $data; |
|
|
178 | } 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, |
|
|
185 | GL_RGBA8, |
|
|
186 | 0, 0, |
|
|
187 | $self->{width}, $self->{height}, |
|
|
188 | 0; |
|
|
189 | warn "ERR: ". (glGetError). "\n"; |
|
|
190 | } |
151 | } |
191 | } |
152 | |
192 | |
153 | sub DESTROY { |
193 | sub DESTROY { |
154 | my ($self) = @_; |
194 | my ($self) = @_; |
155 | |
195 | |