… | |
… | |
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 | |
… | |
… | |
113 | } |
114 | } |
114 | |
115 | |
115 | sub new_from_ttf { |
116 | sub new_from_ttf { |
116 | my ($class, $ttf, $text) = @_; |
117 | my ($class, $ttf, $text) = @_; |
117 | |
118 | |
118 | utf8::upgrade $text; |
119 | utf8::encode $text; |
119 | |
120 | |
120 | my $surface = SDL::TTFRenderUTF8Blended $ttf, $text, |
121 | my $surface = SDL::TTFRenderUTF8Blended $ttf, $text, |
121 | (new SDL::Color -r => 255, -g => 255, -b => 255); |
122 | (new SDL::Color -r => 0, -g => 0, -b => 0); |
122 | |
123 | |
123 | $class->new_from_surface ($surface) |
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) |
124 | } |
131 | } |
125 | |
132 | |
126 | sub upload { |
133 | sub upload { |
127 | my ($self) = @_; |
134 | my ($self) = @_; |
128 | |
135 | |
… | |
… | |
130 | |
137 | |
131 | my $data; |
138 | my $data; |
132 | |
139 | |
133 | if (exists $self->{data}) { |
140 | if (exists $self->{data}) { |
134 | $data = $self->{data}; |
141 | $data = $self->{data}; |
|
|
142 | } elsif (exists $self->{rendercb}) { |
|
|
143 | glViewport 0, 0, $self->{width}, $self->{height}; |
|
|
144 | glMatrixMode GL_PROJECTION; |
|
|
145 | glLoadIdentity; |
|
|
146 | glOrtho 0, $self->{width}, 0, $self->{height}, -100, 100; |
|
|
147 | glMatrixMode GL_MODELVIEW; |
|
|
148 | glPushmatrix; |
|
|
149 | glLoadIdentity; |
|
|
150 | glClear GL_COLOR_BUFFER_BIT; |
|
|
151 | |
|
|
152 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
135 | } else { |
153 | } else { |
136 | my $pb = new Gtk2::Gdk::PixbufLoader; |
154 | my $pb = new Gtk2::Gdk::PixbufLoader; |
137 | $pb->write ($self->{image}); |
155 | $pb->write ($self->{image}); |
138 | $pb->close; |
156 | $pb->close; |
139 | |
157 | |
… | |
… | |
148 | |
166 | |
149 | ($self->{name}) = @{glGenTextures 1}; |
167 | ($self->{name}) = @{glGenTextures 1}; |
150 | |
168 | |
151 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
169 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
152 | |
170 | |
153 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
171 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; |
154 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
172 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; |
155 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
173 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
156 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
174 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
157 | |
175 | |
|
|
176 | if (defined $data) { |
158 | glTexImage2D GL_TEXTURE_2D, 0, |
177 | glTexImage2D GL_TEXTURE_2D, 0, |
159 | GL_RGBA8, |
178 | GL_RGBA8, |
160 | $self->{width}, $self->{height}, |
179 | $self->{width}, $self->{height}, |
161 | 0, |
180 | 0, |
162 | GL_RGBA, |
181 | GL_RGBA, |
163 | GL_UNSIGNED_BYTE, |
182 | GL_UNSIGNED_BYTE, |
164 | $data; |
183 | $data; |
|
|
184 | } 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, |
|
|
191 | GL_RGBA8, |
|
|
192 | 0, 0, |
|
|
193 | $self->{width}, $self->{height}, |
|
|
194 | 0; |
|
|
195 | glPopmatrix; |
|
|
196 | warn "ERR: ". (glGetError). "\n"; |
|
|
197 | SDL::GLSwapBuffers; |
|
|
198 | sleep 1; |
|
|
199 | } |
165 | } |
200 | } |
166 | |
201 | |
167 | sub DESTROY { |
202 | sub DESTROY { |
168 | my ($self) = @_; |
203 | my ($self) = @_; |
169 | |
204 | |