--- deliantra/Deliantra-Client/DC/Texture.pm 2007/07/19 21:02:02 1.18 +++ deliantra/Deliantra-Client/DC/Texture.pm 2007/07/24 00:11:18 1.22 @@ -142,6 +142,8 @@ # 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}) { # use only part of the texture @@ -149,10 +151,12 @@ #$rh >>= 1 while $rh > $th; $rw = min $dw, $tw; $rh = min $dh, $th; + ++$render; } else { if ($self->{wrap} || $tw < $dw || $th < $dh) { # scale to the full texture size ($rw, $rh) = ($tw, $th); + ++$render; } else { # pad pad $data, $dw, $dh, $tw, $th; @@ -161,12 +165,13 @@ } } - # rendering means we need to scale in some way - my $render = $self->{render_cb} || $rw != $dw || $th != $dh; - if ($render) { - glViewport 0, 0, $tw, $th; - glClear 0, 0, 0, 0; + $ox = int .5 * ($::WIDTH - $tw); + $oy = int .5 * ($::HEIGHT - $th); + + glViewport $ox, $oy, $tw, $th; + #glScissor 0, 0, $tw, $th; + #glEnable GL_SCISSOR_TEST; glMatrixMode GL_PROJECTION; glLoadIdentity; glOrtho 0, $tw, 0, $th, -10000, 10000; @@ -177,7 +182,10 @@ glScale $rw / $dw, $rh / $dh; $self->{render_cb}->($self, $rw, $rh); } else { + 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}, @@ -214,11 +222,13 @@ 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", $tw, $th, $self->{internalformat}; + + #glDisable GL_SCISSOR_TEST; } else { glTexImage2D GL_TEXTURE_2D, 0, $self->{internalformat},