--- deliantra/Deliantra-Client/DC.pm 2006/04/08 22:23:57 1.13 +++ deliantra/Deliantra-Client/DC.pm 2006/04/09 00:06:09 1.14 @@ -72,10 +72,14 @@ my @textures; -sub _new { +sub new { my ($class, %data) = @_; - my $self = bless \%data, $class; + my $self = bless { + internalFormat => GL_RGBA, + format => GL_RGBA8, + %data, + }, $class; push @textures, $self; Scalar::Util::weaken $textures[-1]; @@ -88,7 +92,7 @@ sub new_from_image { my ($class, $image) = @_; - $class->_new (image => $image) + $class->new (image => $image) } sub new_from_file { @@ -101,33 +105,36 @@ $class->new_from_image (<$fh>) } -sub new_from_surface { - my ($class, $surface) = @_; - - $surface->rgba; - - $class->_new ( - data => $surface->pixels, - width => $surface->width, - height => $surface->height, +#sub new_from_surface { +# my ($class, $surface) = @_; +# +# $surface->rgba; +# +# $class->new ( +# data => $surface->pixels, +# width => $surface->width, +# height => $surface->height, +# ) +#} + +sub new_from_text { + my ($class, $text, $height) = @_; + + my ($w, $h, $data) = Crossfire::Client::font_render $text, $height; + + $class->new ( + width => $w, + height => $h, + data => $data, + internalFormat => GL_ALPHA8, + format => GL_ALPHA, ) } -sub new_from_ttf { - my ($class, $ttf, $text) = @_; - - utf8::encode $text; - - my $surface = SDL::TTFRenderUTF8Blended $ttf, $text, - (new SDL::Color -r => 0, -g => 0, -b => 0); - - $class->new_from_surface (bless \$surface, SDL::Surface::) -} - sub new_from_opengl { my ($class, $w, $h, $cb) = @_; - $class->_new (width => $w, height => $h, rendercb => $cb) + $class->new (width => $w, height => $h, rendercb => $cb) } sub upload { @@ -175,27 +182,21 @@ if (defined $data) { glTexImage2D GL_TEXTURE_2D, 0, - GL_RGBA8, + $self->{internalFormat}, $self->{width}, $self->{height}, 0, - GL_RGBA, + $self->{format}, GL_UNSIGNED_BYTE, $data; } else { - warn "I{DTEDRAW TEX: $self->{width} $self->{height} \n"; - warn "ERR: ". (glGetError). "\n"; - my ($bd, $br) = (glGet (GL_DRAW_BUFFER), glGet (GL_READ_BUFFER)); - warn "BUF:[$bd $br]\n"; - glCopyTexImage2D GL_TEXTURE_2D, 0, - GL_RGBA8, + $self->{internalFormat}, 0, 0, $self->{width}, $self->{height}, 0; glPopmatrix; - warn "ERR: ". (glGetError). "\n"; - SDL::GLSwapBuffers; - sleep 1; + #SDL::GLSwapBuffers; + #sleep 1; } }