… | |
… | |
74 | |
74 | |
75 | sub new { |
75 | sub new { |
76 | my ($class, %data) = @_; |
76 | my ($class, %data) = @_; |
77 | |
77 | |
78 | my $self = bless { |
78 | my $self = bless { |
79 | internalFormat => GL_RGBA, |
79 | internalformat => GL_RGBA, |
80 | format => GL_RGBA8, |
80 | format => GL_RGBA, |
81 | %data, |
81 | %data, |
82 | }, $class; |
82 | }, $class; |
83 | |
83 | |
84 | push @textures, $self; |
84 | push @textures, $self; |
85 | Scalar::Util::weaken $textures[-1]; |
85 | Scalar::Util::weaken $textures[-1]; |
… | |
… | |
124 | |
124 | |
125 | $class->new ( |
125 | $class->new ( |
126 | width => $w, |
126 | width => $w, |
127 | height => $h, |
127 | height => $h, |
128 | data => $data, |
128 | data => $data, |
129 | internalFormat => GL_ALPHA8, |
129 | internalformat => GL_ALPHA4, |
130 | format => GL_ALPHA, |
130 | format => GL_ALPHA, |
131 | ) |
131 | ) |
132 | } |
132 | } |
133 | |
133 | |
134 | sub new_from_opengl { |
134 | sub new_from_opengl { |
… | |
… | |
148 | $data = $self->{data}; |
148 | $data = $self->{data}; |
149 | } elsif (exists $self->{rendercb}) { |
149 | } elsif (exists $self->{rendercb}) { |
150 | glViewport 0, 0, $self->{width}, $self->{height}; |
150 | glViewport 0, 0, $self->{width}, $self->{height}; |
151 | glMatrixMode GL_PROJECTION; |
151 | glMatrixMode GL_PROJECTION; |
152 | glLoadIdentity; |
152 | glLoadIdentity; |
153 | glOrtho 0, $self->{width}, 0, $self->{height}, -100, 100; |
153 | glOrtho 0, $self->{width}, 0, $self->{height}, -10000, 10000; |
154 | glMatrixMode GL_MODELVIEW; |
154 | glMatrixMode GL_MODELVIEW; |
155 | glPushmatrix; |
155 | glPushmatrix; |
156 | glLoadIdentity; |
156 | glLoadIdentity; |
157 | glClear GL_COLOR_BUFFER_BIT; |
157 | glClear GL_COLOR_BUFFER_BIT; |
158 | |
158 | |
… | |
… | |
178 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; |
178 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; |
179 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; |
179 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; |
180 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
180 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
181 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
181 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
182 | |
182 | |
|
|
183 | glGetError; |
183 | if (defined $data) { |
184 | if (defined $data) { |
184 | glTexImage2D GL_TEXTURE_2D, 0, |
185 | glTexImage2D GL_TEXTURE_2D, 0, |
185 | $self->{internalFormat}, |
186 | $self->{internalformat}, |
186 | $self->{width}, $self->{height}, |
187 | $self->{width}, $self->{height}, |
187 | 0, |
188 | 0, |
188 | $self->{format}, |
189 | $self->{format}, |
189 | GL_UNSIGNED_BYTE, |
190 | GL_UNSIGNED_BYTE, |
190 | $data; |
191 | $data; |
|
|
192 | glGetError and die; |
191 | } else { |
193 | } else { |
192 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
194 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
193 | $self->{internalFormat}, |
195 | $self->{internalformat}, |
194 | 0, 0, |
196 | 0, 0, |
195 | $self->{width}, $self->{height}, |
197 | $self->{width}, $self->{height}, |
196 | 0; |
198 | 0; |
197 | glPopmatrix; |
199 | glPopmatrix; |
198 | #SDL::GLSwapBuffers; |
|
|
199 | #sleep 1; |
|
|
200 | } |
200 | } |
201 | } |
201 | } |
202 | |
202 | |
203 | sub DESTROY { |
203 | sub DESTROY { |
204 | my ($self) = @_; |
204 | my ($self) = @_; |
… | |
… | |
206 | return unless exists $self->{name}; |
206 | return unless exists $self->{name}; |
207 | |
207 | |
208 | glDeleteTextures delete $self->{name}; |
208 | glDeleteTextures delete $self->{name}; |
209 | } |
209 | } |
210 | |
210 | |
211 | push @::GLINIT, sub { |
211 | push @::GL_INIT, sub { |
212 | $_->upload |
212 | $_->upload |
213 | for grep $_, @textures; |
213 | for grep $_, @textures; |
214 | }; |
214 | }; |
215 | |
215 | |
216 | 1; |
216 | 1; |