… | |
… | |
110 | width => $surface->width, |
110 | width => $surface->width, |
111 | height => $surface->height, |
111 | height => $surface->height, |
112 | ) |
112 | ) |
113 | } |
113 | } |
114 | |
114 | |
|
|
115 | sub new_from_ttf { |
|
|
116 | my ($class, $ttf, $text) = @_; |
|
|
117 | |
|
|
118 | utf8::upgrade $text; |
|
|
119 | |
|
|
120 | my $surface = SDL::TTFRenderUTF8Blended $ttf, $text, |
|
|
121 | (new SDL::Color -r => 255, -g => 255, -b => 255); |
|
|
122 | |
|
|
123 | $class->new_from_surface ($surface) |
|
|
124 | } |
|
|
125 | |
115 | sub upload { |
126 | sub upload { |
116 | my ($self) = @_; |
127 | my ($self) = @_; |
117 | |
128 | |
118 | return unless $SDL::App::USING_OPENGL; |
129 | return unless $SDL::App::USING_OPENGL; |
119 | |
130 | |
120 | my ($data, $width, $height); |
131 | my $data; |
121 | |
132 | |
122 | if (exists $self->{data}) { |
133 | if (exists $self->{data}) { |
123 | ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); |
134 | $data = $self->{data}; |
124 | } else { |
135 | } else { |
125 | my $pb = new Gtk2::Gdk::PixbufLoader; |
136 | my $pb = new Gtk2::Gdk::PixbufLoader; |
126 | $pb->write ($self->{image}); |
137 | $pb->write ($self->{image}); |
127 | $pb->close; |
138 | $pb->close; |
128 | |
139 | |
129 | $pb = $pb->get_pixbuf; |
140 | $pb = $pb->get_pixbuf; |
130 | $pb = $pb->add_alpha (0, 0, 0, 0); |
141 | $pb = $pb->add_alpha (0, 0, 0, 0); |
131 | |
142 | |
132 | ($data, $width, $height) = ($pb->get_pixels, $pb->get_width, $pb->get_height); |
143 | $self->{width} = $pb->get_width; |
|
|
144 | $self->{height} = $pb->get_height; |
|
|
145 | |
|
|
146 | $data = $pb->get_pixels; |
133 | } |
147 | } |
134 | |
148 | |
135 | ($self->{name}) = @{glGenTextures 1}; |
149 | ($self->{name}) = @{glGenTextures 1}; |
136 | |
150 | |
137 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
151 | glBindTexture GL_TEXTURE_2D, $self->{name}; |
… | |
… | |
141 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
155 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
142 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
156 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
143 | |
157 | |
144 | glTexImage2D GL_TEXTURE_2D, 0, |
158 | glTexImage2D GL_TEXTURE_2D, 0, |
145 | GL_RGBA8, |
159 | GL_RGBA8, |
146 | $width, $height, |
160 | $self->{width}, $self->{height}, |
147 | 0, |
161 | 0, |
148 | GL_RGBA, |
162 | GL_RGBA, |
149 | GL_UNSIGNED_BYTE, |
163 | GL_UNSIGNED_BYTE, |
150 | $data; |
164 | $data; |
151 | } |
165 | } |