--- deliantra/Deliantra-Client/DC.pm 2006/04/08 16:34:46 1.9 +++ 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 => 255, -g => 255, -b => 255); - - $class->new_from_surface (bless \$surface, SDL::Surface::) -} - sub new_from_opengl { my ($class, $w, $h, $cb) = @_; - $class->_new (width => $w, height => $h, render => $cb) + $class->new (width => $w, height => $h, rendercb => $cb) } sub upload { @@ -141,6 +148,12 @@ $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}); @@ -162,25 +175,28 @@ 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; 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 { glCopyTexImage2D GL_TEXTURE_2D, 0, - GL_RGBA8, + $self->{internalFormat}, 0, 0, $self->{width}, $self->{height}, 0; + glPopmatrix; + #SDL::GLSwapBuffers; + #sleep 1; } }