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.8 by root, Fri Apr 7 08:42:56 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_MODULATE; 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 glBlendFunc GL_SRC_ALPHA, GL_ZERO;
46 glEnable GL_BLEND;
47
48 glLoadIdentity; 54 glLoadIdentity;
49 glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1; 55 glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1;
50 56
51 # re-bind all textures 57 # re-bind all textures
52} 58}
61 for my $y (0 .. $conn->{maph} - 1) { 67 for my $y (0 .. $conn->{maph} - 1) {
62 68
63 my $cell = $map->[$x][$y] 69 my $cell = $map->[$x][$y]
64 or next; 70 or next;
65 71
66# my $darkness = $cell->[3] * (1 / 255); 72 my $darkness = $cell->[3] * (1 / 255);
73 my $darkness = 0.8 + 0.2*rand;
67# glColor $darkness, $darkness, $darkness; 74 glColor $darkness, $darkness, $darkness;
68 75
69 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { 76 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
70 my $tex = $conn->{face}[$num]{texture} || 0; 77 my $tex = $conn->{face}[$num]{texture} || 0;
71 78
72 glBindTexture GL_TEXTURE_2D, $tex; 79 glBindTexture GL_TEXTURE_2D, $tex;
153 160
154sub conn::face_update { 161sub conn::face_update {
155 my ($self, $num, $face) = @_; 162 my ($self, $num, $face) = @_;
156 163
157 warn "up face $self,$num,$face\n";#d# 164 warn "up face $self,$num,$face\n";#d#
158 #TODO 165 use Gtk2;
159 open my $fh, ">:raw", "/tmp/x~"; 166
167 my $pb = new Gtk2::Gdk::PixbufLoader;
160 syswrite $fh, $face->{image}; 168 $pb->write ($face->{image});
161 close $fh; 169 $pb->close;
162 170
163 my $surface = new SDL::Surface -name => "/tmp/x~"; 171 $pb = $pb->get_pixbuf;
172 $pb = $pb->add_alpha (0, 0, 0, 0);
164 173
165 unlink "/tmp/x~"; 174 glGetError();
166
167 my ($tex) = @{glGenTextures 1}; 175 my ($tex) = @{glGenTextures 1};
168 glGetError();
169 176
170 $face->{texture} = $tex; 177 $face->{texture} = $tex;
171 178
172 glBindTexture GL_TEXTURE_2D, $tex; 179 glBindTexture GL_TEXTURE_2D, $tex;
173 my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; 180 my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr;
175 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; 182 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
176 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;
177 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; 184 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
178 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; 185 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
179 186
180 $surface->rgba;
181
182 glTexImage2D GL_TEXTURE_2D, 0, 187 glTexImage2D GL_TEXTURE_2D, 0,
183 4, # components 188 GL_RGBA8,
184 $surface->width, $surface->height, 189 $pb->get_width, $pb->get_height,
185 0, 190 0,
186 GL_RGBA, 191 GL_RGBA,
187 GL_UNSIGNED_BYTE, 192 GL_UNSIGNED_BYTE,
188 $surface->pixels; 193 $pb->get_pixels;
189 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;
190} 195}
191 196
192############################################################################# 197#############################################################################
193 198
194use Event; 199use Event;
200
201Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
195 202
196glinit; 203glinit;
197 204
198$conn = new conn 205$conn = new conn
199 host => "cf.schmorp.de", 206 host => "cf.schmorp.de",
205 } 212 }
206}); 213});
207 214
208Event::loop; 215Event::loop;
209 216
210

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines