--- deliantra/Deliantra-Client/DC.pm 2006/04/07 20:13:13 1.5 +++ deliantra/Deliantra-Client/DC.pm 2006/04/09 00:12:58 1.15 @@ -55,6 +55,7 @@ or return; { + require Data::Dumper; local $Data::Dumper::Purity = 1; $::CFG->{VERSION} = $::VERSION; print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); @@ -71,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_RGBA, + %data, + }, $class; push @textures, $self; Scalar::Util::weaken $textures[-1]; @@ -87,7 +92,7 @@ sub new_from_image { my ($class, $image) = @_; - $class->_new (image => $image) + $class->new (image => $image) } sub new_from_file { @@ -100,16 +105,36 @@ $class->new_from_image (<$fh>) } -sub new_from_surface { - my ($class, $surface) = @_; +#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, + ) +} - $surface->rgba; +sub new_from_opengl { + my ($class, $w, $h, $cb) = @_; - $class->_new ( - data => $surface->pixels, - width => $surface->width, - height => $surface->height, - ) + $class->new (width => $w, height => $h, rendercb => $cb) } sub upload { @@ -117,10 +142,21 @@ return unless $SDL::App::USING_OPENGL; - my ($data, $width, $height); + my $data; if (exists $self->{data}) { - ($data, $width, $height) = ($self->{data}, $self->{width}, $self->{height}); + $data = $self->{data}; + } elsif (exists $self->{rendercb}) { + glViewport 0, 0, $self->{width}, $self->{height}; + glMatrixMode GL_PROJECTION; + glLoadIdentity; + glOrtho 0, $self->{width}, 0, $self->{height}, -100, 100; + glMatrixMode GL_MODELVIEW; + glPushmatrix; + glLoadIdentity; + glClear GL_COLOR_BUFFER_BIT; + + $self->{rendercb}->($self, $self->{width}, $self->{height}); } else { my $pb = new Gtk2::Gdk::PixbufLoader; $pb->write ($self->{image}); @@ -129,25 +165,39 @@ $pb = $pb->get_pixbuf; $pb = $pb->add_alpha (0, 0, 0, 0); - ($data, $width, $height) = ($pb->get_pixels, $pb->get_width, $pb->get_height); + $self->{width} = $pb->get_width; + $self->{height} = $pb->get_height; + + $data = $pb->get_pixels; } ($self->{name}) = @{glGenTextures 1}; glBindTexture GL_TEXTURE_2D, $self->{name}; - glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; - glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; + glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST; + glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST;#_MIPMAP_LINEAR; glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; - glTexImage2D GL_TEXTURE_2D, 0, - GL_RGBA8, - $width, $height, - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - $data; + if (defined $data) { + glTexImage2D GL_TEXTURE_2D, 0, + $self->{internalformat}, + $self->{width}, $self->{height}, + 0, + $self->{format}, + GL_UNSIGNED_BYTE, + $data; + } else { + glCopyTexImage2D GL_TEXTURE_2D, 0, + $self->{internalformat}, + 0, 0, + $self->{width}, $self->{height}, + 0; + glPopmatrix; + #SDL::GLSwapBuffers; + #sleep 1; + } } sub DESTROY {