… | |
… | |
332 | or return; |
332 | or return; |
333 | |
333 | |
334 | glEnable GL_BLEND; |
334 | glEnable GL_BLEND; |
335 | glEnable GL_TEXTURE_2D; |
335 | glEnable GL_TEXTURE_2D; |
336 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
336 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
337 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
338 | |
337 | |
339 | glBegin GL_QUADS; |
338 | $tex->draw_quad (0, 0, $w, $h); |
340 | glTexCoord 0, 0; glVertex 0, 0; |
|
|
341 | glTexCoord 0, 1; glVertex 0, $h; |
|
|
342 | glTexCoord 1, 1; glVertex $w, $h; |
|
|
343 | glTexCoord 1, 0; glVertex $w, 0; |
|
|
344 | glEnd; |
|
|
345 | |
339 | |
346 | glDisable GL_BLEND; |
340 | glDisable GL_BLEND; |
347 | glDisable GL_TEXTURE_2D; |
341 | glDisable GL_TEXTURE_2D; |
348 | } |
342 | } |
349 | |
343 | |
… | |
… | |
382 | |
376 | |
383 | my ($w, $h) = $chld->size_request; |
377 | my ($w, $h) = $chld->size_request; |
384 | |
378 | |
385 | glBegin GL_QUADS; |
379 | glBegin GL_QUADS; |
386 | glColor 0, 0, 0; |
380 | glColor 0, 0, 0; |
387 | glTexCoord 0, 0; glVertex 0 , 0; |
381 | glVertex 0 , 0; |
388 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
382 | glVertex 0 , $h + 4; |
389 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
383 | glVertex $w + 4 , $h + 4; |
390 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
384 | glVertex $w + 4 , 0; |
391 | glEnd; |
385 | glEnd; |
392 | |
386 | |
393 | $chld->draw; |
387 | $chld->draw; |
394 | } |
388 | } |
395 | |
389 | |
… | |
… | |
445 | glEnable GL_TEXTURE_2D; |
439 | glEnable GL_TEXTURE_2D; |
446 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
440 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
447 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
441 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
448 | |
442 | |
449 | my $top = $tex[1]; |
443 | my $top = $tex[1]; |
450 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
444 | $top->draw_quad (0, 0, $w, $top->{height}); |
451 | |
|
|
452 | glBegin GL_QUADS; |
|
|
453 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
454 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
|
|
455 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
|
|
456 | glTexCoord 1, 0; glVertex $w , 0; |
|
|
457 | glEnd; |
|
|
458 | |
445 | |
459 | my $left = $tex[3]; |
446 | my $left = $tex[3]; |
460 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
447 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
461 | |
|
|
462 | glBegin GL_QUADS; |
|
|
463 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
|
|
464 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
|
|
465 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
|
|
466 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
|
|
467 | glEnd; |
|
|
468 | |
448 | |
469 | my $right = $tex[2]; |
449 | my $right = $tex[2]; |
470 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
450 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
471 | |
|
|
472 | glBegin GL_QUADS; |
|
|
473 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
|
|
474 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
|
|
475 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
|
|
476 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
|
|
477 | glEnd; |
|
|
478 | |
451 | |
479 | my $bottom = $tex[4]; |
452 | my $bottom = $tex[4]; |
480 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
453 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
481 | |
|
|
482 | glBegin GL_QUADS; |
|
|
483 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
|
|
484 | glTexCoord 0, 1; glVertex 0 , $h; |
|
|
485 | glTexCoord 1, 1; glVertex $w , $h; |
|
|
486 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
|
|
487 | glEnd; |
|
|
488 | |
454 | |
489 | my $bg = $tex[0]; |
455 | my $bg = $tex[0]; |
490 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
456 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
491 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
457 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
492 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
458 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
493 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
459 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
494 | |
460 | |
495 | my $rep_x = $cw / $bg->{width}; |
461 | my $rep_x = $cw / $bg->{width}; |
496 | my $rep_y = $ch / $bg->{height}; |
462 | my $rep_y = $ch / $bg->{height}; |
497 | |
463 | |
498 | glBegin GL_QUADS; |
464 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
499 | glTexCoord 0, 0; glVertex $left->{width}, $top->{height}; |
|
|
500 | glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch; |
|
|
501 | glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch; |
|
|
502 | glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height}; |
|
|
503 | glEnd; |
|
|
504 | |
465 | |
505 | glDisable GL_BLEND; |
466 | glDisable GL_BLEND; |
506 | glDisable GL_TEXTURE_2D; |
467 | glDisable GL_TEXTURE_2D; |
507 | |
468 | |
508 | $self->child->draw; |
469 | $self->child->draw; |
… | |
… | |
715 | |
676 | |
716 | glEnable GL_BLEND; |
677 | glEnable GL_BLEND; |
717 | glEnable GL_TEXTURE_2D; |
678 | glEnable GL_TEXTURE_2D; |
718 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
679 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
719 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
680 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
720 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
721 | |
681 | |
722 | glColor 1, 0, 0, 1; # TODO color |
682 | glColor 1, 0, 0, 1; # TODO color |
723 | |
683 | |
724 | glBegin GL_QUADS; |
684 | $tex->draw_quad (0, 0); |
725 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
726 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
|
|
727 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
|
|
728 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
|
|
729 | glEnd; |
|
|
730 | |
685 | |
731 | glDisable GL_BLEND; |
686 | glDisable GL_BLEND; |
732 | glDisable GL_TEXTURE_2D; |
687 | glDisable GL_TEXTURE_2D; |
733 | } |
688 | } |
734 | |
689 | |
… | |
… | |
842 | glEnable GL_TEXTURE_2D; |
797 | glEnable GL_TEXTURE_2D; |
843 | glEnable GL_BLEND; |
798 | glEnable GL_BLEND; |
844 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
799 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
845 | |
800 | |
846 | my $sw4 = ($sw + 3) & ~3; |
801 | my $sw4 = ($sw + 3) & ~3; |
847 | my $lighting = "\x00" x ($sw4 * $sh); |
802 | my $darkness = "\x00" x ($sw4 * $sh); |
848 | |
803 | |
849 | for my $x (0 .. $sw - 1) { |
804 | for my $x (0 .. $sw - 1) { |
|
|
805 | my $row = $map->[$x + $xofs]; |
850 | for my $y (0 .. $sh - 1) { |
806 | for my $y (0 .. $sh - 1) { |
851 | |
807 | |
852 | my $cell = $map->[$x + $xofs][$y + $yofs] |
808 | my $cell = $row->[$y + $yofs] |
853 | or next; |
809 | or next; |
854 | |
810 | |
855 | my $darkness = $cell->[0] * (1 / 255); |
811 | my $dark = $cell->[0]; |
856 | if ($darkness < 0) { |
812 | if ($dark < 0) { |
857 | $darkness = $cell->[1] ? 0.2 : 0; |
813 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
814 | } else { |
|
|
815 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
858 | } |
816 | } |
859 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
860 | |
817 | |
861 | for my $num (grep $_, @$cell[1,2,3]) { |
818 | for my $num (grep $_, @$cell[1,2,3]) { |
862 | my $tex = $::CONN->{face}[$num]{texture} || next; |
819 | my $tex = $::CONN->{face}[$num]{texture} || next; |
863 | |
820 | |
864 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
865 | |
|
|
866 | my $w = $tex->{width}; |
821 | my $w = $tex->{width}; |
867 | my $h = $tex->{height}; |
822 | my $h = $tex->{height}; |
868 | |
823 | |
869 | my $px = ($x + 1) * 32 - $w; |
824 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
870 | my $py = ($y + 1) * 32 - $h; |
|
|
871 | |
|
|
872 | glBegin GL_QUADS; |
|
|
873 | glTexCoord 0, 0; glVertex $px , $py; |
|
|
874 | glTexCoord 0, 1; glVertex $px , $py + $h; |
|
|
875 | glTexCoord 1, 1; glVertex $px + $w, $py + $h; |
|
|
876 | glTexCoord 1, 0; glVertex $px + $w, $py; |
|
|
877 | glEnd; |
|
|
878 | } |
825 | } |
879 | } |
826 | } |
880 | } |
827 | } |
881 | |
828 | |
882 | # if (1) { # higher quality darkness |
829 | # if (1) { # higher quality darkness |
… | |
… | |
887 | # |
834 | # |
888 | # $lighting = $pb->get_pixels; |
835 | # $lighting = $pb->get_pixels; |
889 | # $lighting =~ s/(.)../$1/gs; |
836 | # $lighting =~ s/(.)../$1/gs; |
890 | # } |
837 | # } |
891 | |
838 | |
|
|
839 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
840 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
841 | |
892 | $lighting = new Crossfire::Client::Texture |
842 | $darkness = new Crossfire::Client::Texture |
893 | width => $sw4, |
843 | width => $sw4, |
894 | height => $sh, |
844 | height => $sh, |
895 | data => $lighting, |
845 | data => $darkness, |
896 | internalformat => GL_ALPHA, |
846 | internalformat => GL_ALPHA, |
897 | format => GL_ALPHA; |
847 | format => GL_ALPHA; |
898 | |
848 | |
899 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
900 | glColor 0.5, 0.5, 0.5, 1; |
849 | glColor 0.45, 0.45, 0.45, 1; |
901 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
850 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
902 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
903 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
904 | glBegin GL_QUADS; |
|
|
905 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
906 | glTexCoord 0, 1; glVertex 0 , $sh * 32; |
|
|
907 | glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32; |
|
|
908 | glTexCoord 1, 0; glVertex $sw4 * 32, 0; |
|
|
909 | glEnd; |
|
|
910 | |
851 | |
911 | glDisable GL_TEXTURE_2D; |
852 | glDisable GL_TEXTURE_2D; |
912 | glDisable GL_BLEND; |
853 | glDisable GL_BLEND; |
913 | } |
854 | } |
914 | |
855 | |
… | |
… | |
973 | |
914 | |
974 | sub moveto { |
915 | sub moveto { |
975 | my ($self, $x, $y) = @_; |
916 | my ($self, $x, $y) = @_; |
976 | |
917 | |
977 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
918 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
978 | $self->{speed} = 2; |
919 | $self->{speed} = 0.001; |
979 | $self->{time} = 1; |
920 | $self->{time} = 1; |
980 | |
921 | |
981 | ::animation_start $self; |
922 | ::animation_start $self; |
982 | } |
923 | } |
983 | |
924 | |
984 | sub animate { |
925 | sub animate { |
985 | my ($self, $interval) = @_; |
926 | my ($self, $interval) = @_; |
|
|
927 | |
|
|
928 | printf "%5.2f\n", 1 / $interval if $interval;#d# |
986 | |
929 | |
987 | $self->{time} -= $interval * $self->{speed}; |
930 | $self->{time} -= $interval * $self->{speed}; |
988 | if ($self->{time} <= 0) { |
931 | if ($self->{time} <= 0) { |
989 | $self->{time} = 0; |
932 | $self->{time} = 0; |
990 | ::animation_stop $self; |
933 | ::animation_stop $self; |