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