… | |
… | |
131 | sub render_chld { |
131 | sub render_chld { |
132 | my ($self) = @_; |
132 | my ($self) = @_; |
133 | my $chld = $self->get; |
133 | my $chld = $self->get; |
134 | my ($w, $h) = $self->size_request; |
134 | my ($w, $h) = $self->size_request; |
135 | |
135 | |
|
|
136 | $w = $h = 256; |
|
|
137 | |
136 | $self->{texture} = |
138 | $self->{texture} = |
137 | Crossfire::Client::Texture->new_from_opengl ( |
139 | Crossfire::Client::Texture->new_from_opengl ( |
138 | $w, $h, sub { |
140 | $w, $h, sub { |
139 | my ($txt, $w, $h) = @_; |
141 | glPushMatrix; |
|
|
142 | glLoadIdentity; |
140 | $chld->_draw; |
143 | $chld->_draw; |
|
|
144 | glPopMatrix; |
141 | } |
145 | } |
142 | ); |
146 | ); |
143 | $self->{texture}->upload; |
147 | $self->{texture}->upload; |
144 | } |
148 | } |
145 | |
149 | |
… | |
… | |
151 | } |
155 | } |
152 | |
156 | |
153 | sub _draw { |
157 | sub _draw { |
154 | my ($self) = @_; |
158 | my ($self) = @_; |
155 | |
159 | |
|
|
160 | my ($w, $h) = $self->size_request; |
156 | my $tex = $self->{texture} |
161 | my $tex = $self->{texture} |
157 | or return; |
162 | or return; |
158 | |
163 | |
159 | warn "DRAW TEX: $tex->{width} $tex->{height}\n"; |
|
|
160 | glEnable GL_BLEND; |
164 | glEnable GL_BLEND; |
161 | glEnable GL_TEXTURE_2D; |
165 | glEnable GL_TEXTURE_2D; |
162 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
166 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
163 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
167 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
164 | |
168 | |
165 | glColor 1, 1, 1; |
169 | glColor 1, 1, 1; |
166 | |
170 | |
167 | glBegin GL_QUADS; |
171 | glBegin GL_QUADS; |
168 | glTexCoord 0, 0; glVertex 0 , 0; |
172 | glTexCoord 0, 0; glVertex 0 , 0; |
169 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
173 | glTexCoord 0, 1; glVertex 0 , $h; |
170 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
174 | glTexCoord 1, 1; glVertex $w , $h; |
171 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
175 | glTexCoord 1, 0; glVertex $w , 0; |
172 | glEnd; |
176 | glEnd; |
173 | |
177 | |
174 | glDisable GL_BLEND; |
178 | glDisable GL_BLEND; |
175 | glDisable GL_TEXTURE_2D; |
179 | glDisable GL_TEXTURE_2D; |
176 | } |
180 | } |
… | |
… | |
421 | |
425 | |
422 | sub key_up { |
426 | sub key_up { |
423 | } |
427 | } |
424 | |
428 | |
425 | sub _draw { |
429 | sub _draw { |
|
|
430 | my ($self) = @_; |
|
|
431 | |
426 | glEnable GL_TEXTURE_2D; |
432 | glEnable GL_TEXTURE_2D; |
427 | glEnable GL_BLEND; |
433 | glEnable GL_BLEND; |
428 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
434 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
429 | |
435 | |
430 | my $map = $::CONN->{map}; |
436 | my $map = $::CONN->{map}; |
431 | |
437 | |
432 | for my $x (0 .. $::CONN->{mapw} - 1) { |
438 | for my $x (0 .. int $::WIDTH / 32) { |
433 | for my $y (0 .. $::CONN->{maph} - 1) { |
439 | for my $y (0 .. int $::HEIGHT / 32) { |
434 | |
440 | |
435 | my $cell = $map->[$x][$y] |
441 | my $cell = $map->[$x + $::CONN->{mapx}] |
|
|
442 | [$y + $::CONN->{mapy}] |
436 | or next; |
443 | or next; |
437 | |
444 | |
438 | my $darkness = $cell->[3] * (1 / 255); |
445 | my $darkness = $cell->[0] * (1 / 255); |
|
|
446 | if ($darkness < 0) { |
|
|
447 | $darkness = 0.5; |
|
|
448 | } |
439 | glColor $darkness, $darkness, $darkness; |
449 | glColor $darkness, $darkness, $darkness; |
440 | |
450 | |
441 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
451 | for my $num (grep $_, @$cell[1,2,3]) { |
442 | my $tex = $::CONN->{face}[$num]{texture} || next; |
452 | my $tex = $::CONN->{face}[$num]{texture} || next; |
443 | |
453 | |
444 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
454 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
445 | |
455 | |
446 | my $w = $tex->{width}; |
456 | my $w = $tex->{width}; |