ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.7 by elmex, Thu Apr 6 21:43:17 2006 UTC vs.
Revision 1.11 by elmex, Fri Apr 7 16:08:01 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use strict; 3use strict;
4 4
5use Crossfire;
5use Crossfire::Client; 6use Crossfire::Client;
6use Crossfire::Protocol; 7use Crossfire::Protocol;
7 8
9use Client::Util;
10
8package Crossfire::Client; # uh, yeah 11package Crossfire::Client; # uh, yeah
9 12
10use strict; 13use strict;
14
15our $CFG;
16our $VERSION = '0.1';
11 17
12use SDL; 18use SDL;
13use SDL::App; 19use SDL::App;
14use SDL::Event; 20use SDL::Event;
15use SDL::Surface; 21use 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
52sub refresh { 60sub 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
150sub conn::face_update { 161sub 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
190use Event; 199use Event;
200
201Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
191 202
192glinit; 203glinit;
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
204Event::loop; 215Event::loop;
205 216
206

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines