… | |
… | |
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 | |
… | |
… | |
858 | } |
813 | } |
859 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
814 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
860 | |
815 | |
861 | for my $num (grep $_, @$cell[1,2,3]) { |
816 | for my $num (grep $_, @$cell[1,2,3]) { |
862 | my $tex = $::CONN->{face}[$num]{texture} || next; |
817 | my $tex = $::CONN->{face}[$num]{texture} || next; |
863 | |
818 | |
864 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
865 | |
|
|
866 | my $w = $tex->{width}; |
819 | my $w = $tex->{width}; |
867 | my $h = $tex->{height}; |
820 | my $h = $tex->{height}; |
868 | |
821 | |
869 | my $px = ($x + 1) * 32 - $w; |
822 | my $px = ($x + 1) * 32 - $w; |
870 | my $py = ($y + 1) * 32 - $h; |
823 | my $py = ($y + 1) * 32 - $h; |
871 | |
824 | |
872 | glBegin GL_QUADS; |
825 | $tex->draw_quad ($px, $py, $w, $h); |
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 | } |
826 | } |
879 | } |
827 | } |
880 | } |
828 | } |
881 | |
829 | |
882 | # if (1) { # higher quality darkness |
830 | # if (1) { # higher quality darkness |
… | |
… | |
899 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
847 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
900 | glColor 0.45, 0.45, 0.45, 1; |
848 | glColor 0.45, 0.45, 0.45, 1; |
901 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
849 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
902 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
850 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
903 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
851 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
904 | glBegin GL_QUADS; |
852 | |
905 | glTexCoord 0, 0; glVertex 0 , 0; |
853 | $lighting->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
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 | |
854 | |
911 | glDisable GL_TEXTURE_2D; |
855 | glDisable GL_TEXTURE_2D; |
912 | glDisable GL_BLEND; |
856 | glDisable GL_BLEND; |
913 | } |
857 | } |
914 | |
858 | |
… | |
… | |
973 | |
917 | |
974 | sub moveto { |
918 | sub moveto { |
975 | my ($self, $x, $y) = @_; |
919 | my ($self, $x, $y) = @_; |
976 | |
920 | |
977 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
921 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
978 | $self->{speed} = 2; |
922 | $self->{speed} = 0.001; |
979 | $self->{time} = 1; |
923 | $self->{time} = 1; |
980 | |
924 | |
981 | ::animation_start $self; |
925 | ::animation_start $self; |
982 | } |
926 | } |
983 | |
927 | |
984 | sub animate { |
928 | sub animate { |
985 | my ($self, $interval) = @_; |
929 | my ($self, $interval) = @_; |
|
|
930 | |
|
|
931 | printf "%5.2f\n", 1 / $interval;#d# |
986 | |
932 | |
987 | $self->{time} -= $interval * $self->{speed}; |
933 | $self->{time} -= $interval * $self->{speed}; |
988 | if ($self->{time} <= 0) { |
934 | if ($self->{time} <= 0) { |
989 | $self->{time} = 0; |
935 | $self->{time} = 0; |
990 | ::animation_stop $self; |
936 | ::animation_stop $self; |