--- deliantra/Deliantra-Client/DC/Texture.pm 2007/07/19 23:29:17 1.21 +++ deliantra/Deliantra-Client/DC/Texture.pm 2007/07/29 03:58:26 1.24 @@ -42,6 +42,9 @@ sub new_from_image { my ($class, $image, %arg) = @_; + Carp::confess "tried to create texture from undefined image" + unless defined $image; + $class->new (image => $image, internalformat => undef, %arg) } @@ -107,12 +110,14 @@ } elsif (exists $self->{render_cb}) { ($dw, $dh) = @$self{qw(w h)}; - } else { + } elsif (exists $self->{image}) { ($self->{w}, $self->{h}, $data, my $internalformat, $self->{format}, $self->{type}) = CFPlus::load_image_inline $self->{image}; $self->{internalformat} ||= $internalformat; ($dw, $dh) = @$self{qw(w h)}; + } else { + Carp::confess "tried to create texture that is not data, render or image"; } my ($tw, $th) = ($dw, $dh); @@ -142,6 +147,7 @@ # decide the amount of space used in the texture my ($rw, $rh); + my ($ox, $oy); # area shift to lessen effetc of buggy opengl implementations (nvida, ati) my $render; if ($self->{render_cb}) { @@ -165,7 +171,10 @@ } if ($render) { - glViewport 0, 0, $tw, $th; + $ox = int .5 * ($::WIDTH - $rw); + $oy = int .5 * ($::HEIGHT - $rh); + + glViewport $ox, $oy, $tw, $th; #glScissor 0, 0, $tw, $th; #glEnable GL_SCISSOR_TEST; glMatrixMode GL_PROJECTION; @@ -181,6 +190,7 @@ glClearColor 0, 0, 0, 0; glClear GL_COLOR_BUFFER_BIT; glPixelZoom $tw / $dw, $th / $dh; + glRasterPos 0, 0; glDrawPixels $dw, $dh, $self->{format}, $self->{type}, @@ -217,7 +227,7 @@ if ($render) { glCopyTexImage2D GL_TEXTURE_2D, 0, $self->{internalformat}, - 0, 0, + $ox, $oy, $tw, $th, 0; gl_check "copying to texture %dx%d if=%x",