1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
|
|
5 | use Crossfire; |
5 | use Crossfire::Client; |
6 | use Crossfire::Client; |
6 | use Crossfire::Protocol; |
7 | use Crossfire::Protocol; |
7 | |
8 | |
|
|
9 | use Client::Util; |
|
|
10 | |
8 | package Crossfire::Client; # uh, yeah |
11 | package Crossfire::Client; # uh, yeah |
9 | |
12 | |
10 | use strict; |
13 | use strict; |
|
|
14 | |
|
|
15 | our $CFG; |
|
|
16 | our $VERSION = '0.1'; |
11 | |
17 | |
12 | use SDL; |
18 | use SDL; |
13 | use SDL::App; |
19 | use SDL::App; |
14 | use SDL::Event; |
20 | use SDL::Event; |
15 | use SDL::Surface; |
21 | use SDL::Surface; |
… | |
… | |
36 | -blue_size => 8, |
42 | -blue_size => 8, |
37 | -double_buffer => 1, |
43 | -double_buffer => 1, |
38 | -resizeable => 0; |
44 | -resizeable => 0; |
39 | |
45 | |
40 | glEnable GL_TEXTURE_2D; |
46 | glEnable GL_TEXTURE_2D; |
41 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL; |
47 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
42 | glShadeModel GL_FLAT; |
48 | glShadeModel GL_FLAT; |
43 | glDisable GL_DEPTH_TEST; |
49 | glDisable GL_DEPTH_TEST; |
|
|
50 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
51 | glEnable GL_BLEND; |
|
|
52 | |
44 | glMatrixMode GL_PROJECTION; |
53 | glMatrixMode GL_PROJECTION; |
45 | |
|
|
46 | glLoadIdentity; |
54 | glLoadIdentity; |
47 | glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1; |
55 | glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1; |
48 | |
56 | |
49 | # re-bind all textures |
57 | # re-bind all textures |
50 | } |
58 | } |
51 | |
59 | |
52 | sub refresh { |
60 | sub refresh { |
53 | glClearColor 0.5, 0.5, 0.7, 0; |
61 | glClearColor 0, 0, 0, 0; |
54 | glClear GL_COLOR_BUFFER_BIT; |
62 | glClear GL_COLOR_BUFFER_BIT; |
55 | |
63 | |
56 | my $map = $conn->{map}; |
64 | my $map = $conn->{map}; |
57 | |
65 | |
58 | for my $x (0 .. $conn->{mapw} - 1) { |
66 | for my $x (0 .. $conn->{mapw} - 1) { |
59 | for my $y (0 .. $conn->{maph} - 1) { |
67 | for my $y (0 .. $conn->{maph} - 1) { |
60 | |
68 | |
61 | my $cell = $map->[$x][$y] |
69 | my $cell = $map->[$x][$y] |
62 | or next; |
70 | or next; |
|
|
71 | |
|
|
72 | my $darkness = $cell->[3] * (1 / 255); |
|
|
73 | my $darkness = 0.8 + 0.2*rand; |
|
|
74 | glColor $darkness, $darkness, $darkness; |
63 | |
75 | |
64 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
76 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
65 | my $tex = $conn->{face}[$num]{texture} || 0; |
77 | my $tex = $conn->{face}[$num]{texture} || 0; |
66 | |
78 | |
67 | glBindTexture GL_TEXTURE_2D, $tex; |
79 | glBindTexture GL_TEXTURE_2D, $tex; |
68 | |
80 | |
69 | glColor 1,0,1; |
|
|
70 | glBegin GL_QUADS; |
81 | glBegin GL_QUADS; |
71 | glTexCoord 0, 0; glVertex $x, $y; |
82 | glTexCoord 0, 0; glVertex $x, $y; |
72 | glTexCoord 0, 1; glVertex $x, $y + 0.9; |
83 | glTexCoord 0, 1; glVertex $x, $y + 1; |
73 | glTexCoord 1, 1; glVertex $x + 0.9, $y + 0.9; |
84 | glTexCoord 1, 1; glVertex $x + 1, $y + 1; |
74 | glTexCoord 1, 0; glVertex $x + 0.9, $y; |
85 | glTexCoord 1, 0; glVertex $x + 1, $y; |
75 | glEnd; |
86 | glEnd; |
76 | } |
87 | } |
77 | } |
88 | } |
78 | } |
89 | } |
79 | |
90 | |
… | |
… | |
149 | |
160 | |
150 | sub conn::face_update { |
161 | sub conn::face_update { |
151 | my ($self, $num, $face) = @_; |
162 | my ($self, $num, $face) = @_; |
152 | |
163 | |
153 | warn "up face $self,$num,$face\n";#d# |
164 | warn "up face $self,$num,$face\n";#d# |
154 | #TODO |
165 | use Gtk2; |
155 | open my $fh, ">:raw", "/tmp/x~"; |
166 | |
|
|
167 | my $pb = new Gtk2::Gdk::PixbufLoader; |
156 | syswrite $fh, $face->{image}; |
168 | $pb->write ($face->{image}); |
157 | close $fh; |
169 | $pb->close; |
158 | |
170 | |
159 | my $surface = new SDL::Surface -name => "/tmp/x~"; |
171 | $pb = $pb->get_pixbuf; |
|
|
172 | $pb = $pb->add_alpha (0, 0, 0, 0); |
160 | |
173 | |
161 | unlink "/tmp/x~"; |
174 | glGetError(); |
162 | |
|
|
163 | my ($tex) = @{glGenTextures 1}; |
175 | my ($tex) = @{glGenTextures 1}; |
164 | glGetError(); |
|
|
165 | |
176 | |
166 | $face->{texture} = $tex; |
177 | $face->{texture} = $tex; |
167 | |
178 | |
168 | glBindTexture GL_TEXTURE_2D, $tex; |
179 | glBindTexture GL_TEXTURE_2D, $tex; |
169 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
180 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
… | |
… | |
171 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
182 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
172 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
183 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
173 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
184 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
174 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
185 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
175 | |
186 | |
176 | $surface->rgba; |
|
|
177 | |
|
|
178 | glTexImage2D GL_TEXTURE_2D, 0, |
187 | glTexImage2D GL_TEXTURE_2D, 0, |
179 | 4, # components |
188 | GL_RGBA8, |
180 | $surface->width, $surface->height, |
189 | $pb->get_width, $pb->get_height, |
181 | 0, |
190 | 0, |
182 | GL_RGBA, |
191 | GL_RGBA, |
183 | GL_UNSIGNED_BYTE, |
192 | GL_UNSIGNED_BYTE, |
184 | $surface->pixels; |
193 | $pb->get_pixels; |
185 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
194 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
186 | } |
195 | } |
187 | |
196 | |
188 | ############################################################################# |
197 | ############################################################################# |
189 | |
198 | |
190 | use Event; |
199 | use Event; |
|
|
200 | |
|
|
201 | Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc"; |
191 | |
202 | |
192 | glinit; |
203 | glinit; |
193 | |
204 | |
194 | $conn = new conn |
205 | $conn = new conn |
195 | host => "cf.schmorp.de", |
206 | host => "cf.schmorp.de", |
… | |
… | |
201 | } |
212 | } |
202 | }); |
213 | }); |
203 | |
214 | |
204 | Event::loop; |
215 | Event::loop; |
205 | |
216 | |
206 | |
|
|