… | |
… | |
125 | } |
125 | } |
126 | |
126 | |
127 | sub new_from_opengl { |
127 | sub new_from_opengl { |
128 | my ($class, $w, $h, $cb) = @_; |
128 | my ($class, $w, $h, $cb) = @_; |
129 | |
129 | |
130 | $class->_new (width => $w, height => $h, render => $cb) |
130 | $class->_new (width => $w, height => $h, rendercb => $cb) |
131 | } |
131 | } |
132 | |
132 | |
133 | sub upload { |
133 | sub upload { |
134 | my ($self) = @_; |
134 | my ($self) = @_; |
135 | |
135 | |
… | |
… | |
139 | |
139 | |
140 | if (exists $self->{data}) { |
140 | if (exists $self->{data}) { |
141 | $data = $self->{data}; |
141 | $data = $self->{data}; |
142 | } elsif (exists $self->{rendercb}) { |
142 | } elsif (exists $self->{rendercb}) { |
143 | 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}, $self->{height}, 0, -100, 100; |
|
|
147 | glMatrixMode GL_MODELVIEW; |
|
|
148 | glPushmatrix; |
|
|
149 | glLoadIdentity; |
144 | glClear GL_COLOR_BUFFER_BIT; |
150 | glClear GL_COLOR_BUFFER_BIT; |
145 | |
151 | |
146 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
152 | $self->{rendercb}->($self, $self->{width}, $self->{height}); |
147 | } else { |
153 | } else { |
148 | my $pb = new Gtk2::Gdk::PixbufLoader; |
154 | my $pb = new Gtk2::Gdk::PixbufLoader; |
… | |
… | |
174 | 0, |
180 | 0, |
175 | GL_RGBA, |
181 | GL_RGBA, |
176 | GL_UNSIGNED_BYTE, |
182 | GL_UNSIGNED_BYTE, |
177 | $data; |
183 | $data; |
178 | } 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 | |
179 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
190 | glCopyTexImage2D GL_TEXTURE_2D, 0, |
180 | GL_RGBA8, |
191 | GL_RGBA8, |
181 | 0, 0, |
192 | 0, 0, |
182 | $self->{width}, $self->{height}, |
193 | $self->{width}, $self->{height}, |
183 | 0; |
194 | 0; |
|
|
195 | glPopmatrix; |
|
|
196 | warn "ERR: ". (glGetError). "\n"; |
|
|
197 | sleep 1; |
184 | } |
198 | } |
185 | } |
199 | } |
186 | |
200 | |
187 | sub DESTROY { |
201 | sub DESTROY { |
188 | my ($self) = @_; |
202 | my ($self) = @_; |