ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.7
Committed: Thu Apr 6 21:43:17 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.6: +2 -2 lines
Log Message:
pixels are bunt without MIPMAP

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3 root 1.2 use strict;
4    
5     use Crossfire::Client;
6     use Crossfire::Protocol;
7    
8     package Crossfire::Client; # uh, yeah
9    
10     use strict;
11    
12 root 1.1 use SDL;
13     use SDL::App;
14     use SDL::Event;
15     use SDL::Surface;
16 root 1.2 use SDL::OpenGL;
17     use SDL::OpenGL::Constants;
18 root 1.1
19     my $conn;
20 root 1.2 my $app;
21    
22     my $WIDTH = 640;
23     my $HEIGHT = 480;
24    
25     sub glinit {
26     # nuke all gl context data
27    
28     $app = new SDL::App
29 root 1.5 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
30     -title => "Crossfire+ Client",
31     -width => $WIDTH,
32     -height => $HEIGHT,
33     -opengl => 1,
34     -red_size => 8,
35     -green_size => 8,
36     -blue_size => 8,
37 root 1.2 -double_buffer => 1,
38 root 1.5 -resizeable => 0;
39 root 1.2
40     glEnable GL_TEXTURE_2D;
41 root 1.5 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL;
42 root 1.2 glShadeModel GL_FLAT;
43     glDisable GL_DEPTH_TEST;
44     glMatrixMode GL_PROJECTION;
45    
46 root 1.4 glLoadIdentity;
47     glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1;
48    
49 root 1.2 # re-bind all textures
50     }
51    
52     sub refresh {
53     glClearColor 0.5, 0.5, 0.7, 0;
54 root 1.5 glClear GL_COLOR_BUFFER_BIT;
55 root 1.2
56     my $map = $conn->{map};
57 root 1.1
58 root 1.2 for my $x (0 .. $conn->{mapw} - 1) {
59     for my $y (0 .. $conn->{maph} - 1) {
60 root 1.1
61 root 1.2 my $cell = $map->[$x][$y]
62     or next;
63    
64     for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
65 root 1.3 my $tex = $conn->{face}[$num]{texture} || 0;
66 root 1.2
67     glBindTexture GL_TEXTURE_2D, $tex;
68    
69 elmex 1.7 glColor 1,0,1;
70 root 1.2 glBegin GL_QUADS;
71     glTexCoord 0, 0; glVertex $x, $y;
72 root 1.5 glTexCoord 0, 1; glVertex $x, $y + 0.9;
73     glTexCoord 1, 1; glVertex $x + 0.9, $y + 0.9;
74 root 1.4 glTexCoord 1, 0; glVertex $x + 0.9, $y;
75 root 1.2 glEnd;
76     }
77     }
78     }
79 root 1.1
80 root 1.2 SDL::GLSwapBuffers;
81 root 1.1 }
82    
83     my $ev = new SDL::Event;
84     my %ev_cb;
85    
86     sub event(&$) {
87     $ev_cb{$_[0]->()} = $_[1];
88     }
89    
90     sub does(&) { shift }
91    
92     event {SDL_QUIT} does {
93     exit;
94     };
95    
96     event {SDL_VIDEORESIZE} does {
97     print "resize\n";
98     };
99    
100 root 1.4 event {SDL_VIDEOEXPOSE} does {
101     refresh;
102     };
103    
104 root 1.1 event {SDL_KEYDOWN} does {
105     print "keypress\n";
106     };
107    
108     event {SDL_KEYUP} does {
109     print "keyup\n";#d#
110     };
111    
112     event {SDL_MOUSEMOTION} does {
113     print "motion\n";
114     };
115    
116     event {SDL_MOUSEBUTTONDOWN} does {
117     print "button\n";
118     };
119    
120     event {SDL_MOUSEBUTTONUP} does {
121     print "buttup\n";
122     };
123    
124     event {SDL_ACTIVEEVENT} does {
125     print "active\n";
126     };
127    
128 root 1.2 package Crossfire::Client;
129 root 1.1
130 root 1.2 @conn::ISA = Crossfire::Protocol::;
131 root 1.1
132 root 1.2 sub conn::map_update {
133 root 1.1 my ($self, $dirty) = @_;
134    
135 root 1.2 refresh;
136 root 1.1 }
137    
138 root 1.2 sub conn::map_scroll {
139 root 1.1 my ($self, $dx, $dy) = @_;
140    
141 root 1.2 refresh;
142 root 1.1 }
143    
144 root 1.2 sub conn::map_clear {
145 root 1.1 my ($self) = @_;
146    
147 root 1.2 refresh;
148 root 1.1 }
149    
150 root 1.2 sub conn::face_update {
151 root 1.1 my ($self, $num, $face) = @_;
152    
153     warn "up face $self,$num,$face\n";#d#
154     #TODO
155     open my $fh, ">:raw", "/tmp/x~";
156     syswrite $fh, $face->{image};
157     close $fh;
158    
159 root 1.2 my $surface = new SDL::Surface -name => "/tmp/x~";
160 root 1.1
161     unlink "/tmp/x~";
162    
163 root 1.2 my ($tex) = @{glGenTextures 1};
164     glGetError();
165 root 1.1
166 root 1.2 $face->{texture} = $tex;
167    
168     glBindTexture GL_TEXTURE_2D, $tex;
169     my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr;
170    
171 root 1.5 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
172 elmex 1.7 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
173 root 1.6 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
174     glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
175 root 1.2
176     $surface->rgba;
177    
178     glTexImage2D GL_TEXTURE_2D, 0,
179     4, # components
180     $surface->width, $surface->height,
181     0,
182     GL_RGBA,
183     GL_UNSIGNED_BYTE,
184     $surface->pixels;
185     my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr;
186 root 1.1 }
187    
188     #############################################################################
189    
190     use Event;
191    
192 root 1.2 glinit;
193    
194 root 1.1 $conn = new conn
195     host => "cf.schmorp.de",
196     port => 13327;
197    
198     Event->timer (after => 0, interval => 1/20, hard => 1, cb => sub {
199     while ($ev->poll) {
200     ($ev_cb{$ev->type} || sub { warn "unhandled event ", $ev->type })->();
201     }
202     });
203    
204     Event::loop;
205    
206