… | |
… | |
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 | |
… | |
… | |
116 | my ($class, $ttf, $text) = @_; |
117 | my ($class, $ttf, $text) = @_; |
117 | |
118 | |
118 | utf8::encode $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 (bless \$surface, SDL::Surface::) |
124 | $class->new_from_surface (bless \$surface, SDL::Surface::) |
124 | } |
125 | } |
125 | |
126 | |
126 | sub new_from_opengl { |
127 | sub new_from_opengl { |
127 | my ($class, $w, $h, $cb) = @_; |
128 | my ($class, $w, $h, $cb) = @_; |
128 | |
129 | |
129 | $class->_new (width => $w, height => $h, render => $cb) |
130 | $class->_new (width => $w, height => $h, rendercb => $cb) |
130 | } |
131 | } |
131 | |
132 | |
132 | sub upload { |
133 | sub upload { |
133 | my ($self) = @_; |
134 | my ($self) = @_; |
134 | |
135 | |
… | |
… | |
138 | |
139 | |
139 | if (exists $self->{data}) { |
140 | if (exists $self->{data}) { |
140 | $data = $self->{data}; |
141 | $data = $self->{data}; |
141 | } elsif (exists $self->{rendercb}) { |
142 | } elsif (exists $self->{rendercb}) { |
142 | glViewport 0, 0, $self->{width}, $self->{height}; |
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; |
143 | glClear GL_COLOR_BUFFER_BIT; |
150 | glClear GL_COLOR_BUFFER_BIT; |
144 | |
151 | |
145 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
152 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
146 | } else { |
153 | } else { |
147 | my $pb = new Gtk2::Gdk::PixbufLoader; |
154 | my $pb = new Gtk2::Gdk::PixbufLoader; |
… | |
… | |
159 | |
166 | |
160 | ($self->{name}) = @{glGenTextures 1}; |
167 | ($self->{name}) = @{glGenTextures 1}; |
161 | |
168 | |
162 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
169 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
163 | |
170 | |
164 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
171 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; |
165 | 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; |
166 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
173 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
167 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
174 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
168 | |
175 | |
169 | if (defined $data) { |
176 | if (defined $data) { |
170 | glTexImage2D GL_TEXTURE_2D, 0, |
177 | glTexImage2D GL_TEXTURE_2D, 0, |
… | |
… | |
173 | 0, |
180 | 0, |
174 | GL_RGBA, |
181 | GL_RGBA, |
175 | GL_UNSIGNED_BYTE, |
182 | GL_UNSIGNED_BYTE, |
176 | $data; |
183 | $data; |
177 | } else { |
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 | |
178 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
190 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
179 | GL_RGBA8, |
191 | GL_RGBA8, |
180 | 0, 0, |
192 | 0, 0, |
181 | $self->{width}, $self->{height}, |
193 | $self->{width}, $self->{height}, |
182 | 0; |
194 | 0; |
|
|
195 | glPopmatrix; |
|
|
196 | warn "ERR: ". (glGetError). "\n"; |
|
|
197 | SDL::GLSwapBuffers; |
|
|
198 | sleep 1; |
183 | } |
199 | } |
184 | } |
200 | } |
185 | |
201 | |
186 | sub DESTROY { |
202 | sub DESTROY { |
187 | my ($self) = @_; |
203 | my ($self) = @_; |