… | |
… | |
1461 | glNewList $self->{list}, GL_COMPILE; |
1461 | glNewList $self->{list}, GL_COMPILE; |
1462 | |
1462 | |
1463 | my $sw = int $::WIDTH / 32; |
1463 | my $sw = int $::WIDTH / 32; |
1464 | my $sh = int $::HEIGHT / 32; |
1464 | my $sh = int $::HEIGHT / 32; |
1465 | |
1465 | |
1466 | $::MAP->draw (0, 0, $sw, $sh) if $::MAP; |
|
|
1467 | |
|
|
1468 | if (0) { |
1466 | if ($::MAP) { |
|
|
1467 | my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); |
1469 | |
1468 | |
1470 | my $mx = $::CONN->{mapx}; |
1469 | if ($::CFG->{fow_enable}) { |
1471 | my $my = $::CONN->{mapy}; |
1470 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1472 | |
1471 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1473 | my $map = $::CONN->{map}; |
1472 | glConvolutionFilter2D |
1474 | |
1473 | GL_CONVOLUTION_2D, |
1475 | my ($xofs, $yofs); |
1474 | GL_ALPHA, |
1476 | |
1475 | 3, 3, |
1477 | my $sw = 1 + int $::WIDTH / 32; |
1476 | GL_ALPHA, GL_FLOAT, |
1478 | my $sh = 1 + int $::HEIGHT / 32; |
1477 | pack "f*", |
1479 | |
1478 | 0.1, 0.1, 0.1, |
1480 | if ($::CONN->{mapw} > $sw) { |
1479 | 0.1, 0.2, 0.1, |
1481 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
1480 | 0.1, 0.1, 0.1, |
1482 | } else { |
|
|
1483 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
|
|
1484 | } |
|
|
1485 | |
|
|
1486 | if ($::CONN->{maph} > $sh) { |
|
|
1487 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
|
|
1488 | } else { |
|
|
1489 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
|
|
1490 | } |
|
|
1491 | |
|
|
1492 | glEnable GL_TEXTURE_2D; |
|
|
1493 | glEnable GL_BLEND; |
|
|
1494 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1495 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1496 | glColor 1, 1, 1, 1; |
|
|
1497 | |
|
|
1498 | my $sw4 = ($sw + 3) & ~3; |
|
|
1499 | my $darkness = "\x00" x ($sw4 * $sh); |
|
|
1500 | |
|
|
1501 | for my $x (0 .. $sw - 1) { |
|
|
1502 | my $row = $map->[$x + $xofs]; |
|
|
1503 | for my $y (0 .. $sh - 1) { |
|
|
1504 | |
|
|
1505 | my $cell = $row->[$y + $yofs] |
|
|
1506 | or next; |
1481 | ; |
1507 | |
1482 | glEnable GL_CONVOLUTION_2D; |
1508 | my $dark = $cell->[0]; |
|
|
1509 | if ($dark < 0) { |
|
|
1510 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
1511 | } else { |
|
|
1512 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
|
|
1513 | } |
1483 | } |
1514 | |
1484 | |
1515 | for my $num (grep $_, @$cell[1,2,3]) { |
1485 | my $tex = new CFClient::Texture |
1516 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1486 | w => $w, |
1517 | |
1487 | h => $h, |
1518 | my ($w, $h) = @$tex{qw(w h)}; |
1488 | data => $data, |
|
|
1489 | internalformat => GL_ALPHA, |
|
|
1490 | format => GL_ALPHA; |
1519 | |
1491 | |
1520 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1492 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1521 | } |
1493 | |
|
|
1494 | glEnable GL_BLEND; |
|
|
1495 | glEnable GL_TEXTURE_2D; |
|
|
1496 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1497 | |
|
|
1498 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1499 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1500 | |
|
|
1501 | glDisable GL_TEXTURE_2D; |
|
|
1502 | glDisable GL_BLEND; |
1522 | } |
1503 | } |
1523 | } |
|
|
1524 | |
|
|
1525 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1526 | |
|
|
1527 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1528 | my @conv = ( |
|
|
1529 | 0.1, 0.1, 0.1, |
|
|
1530 | 0.1, 0.2, 0.1, |
|
|
1531 | 0.1, 0.1, 0.1, |
|
|
1532 | ); |
|
|
1533 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1534 | glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1535 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1536 | pack "f*", @conv; |
|
|
1537 | glEnable GL_CONVOLUTION_2D; |
|
|
1538 | } |
|
|
1539 | |
|
|
1540 | $darkness = new CFClient::Texture |
|
|
1541 | w => $sw4, |
|
|
1542 | h => $sh, |
|
|
1543 | data => $darkness, |
|
|
1544 | internalformat => GL_ALPHA, |
|
|
1545 | format => GL_ALPHA; |
|
|
1546 | |
|
|
1547 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1548 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1549 | |
|
|
1550 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
|
|
1551 | |
|
|
1552 | glDisable GL_TEXTURE_2D; |
|
|
1553 | glDisable GL_BLEND; |
|
|
1554 | } |
1504 | } |
1555 | |
1505 | |
1556 | glEndList; |
1506 | glEndList; |
1557 | } |
1507 | } |
1558 | |
1508 | |