… | |
… | |
25 | |
25 | |
26 | our $SDL_TIMER; |
26 | our $SDL_TIMER; |
27 | our $SDL_APP; |
27 | our $SDL_APP; |
28 | our $SDL_EV = new SDL::Event; |
28 | our $SDL_EV = new SDL::Event; |
29 | our %SDL_CB; |
29 | our %SDL_CB; |
|
|
30 | our @GL_INIT; |
30 | |
31 | |
31 | sub init_screen { |
32 | sub init_screen { |
32 | # nuke all gl context data |
|
|
33 | |
|
|
34 | $SDL_APP = new SDL::App |
33 | $SDL_APP = new SDL::App |
35 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
34 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
36 | -title => "Crossfire+ Client", |
35 | -title => "Crossfire+ Client", |
37 | -width => $CFG->{width}, |
36 | -width => $CFG->{width}, |
38 | -height => $CFG->{height}, |
37 | -height => $CFG->{height}, |
… | |
… | |
53 | |
52 | |
54 | glMatrixMode GL_PROJECTION; |
53 | glMatrixMode GL_PROJECTION; |
55 | glLoadIdentity; |
54 | glLoadIdentity; |
56 | glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1; |
55 | glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1; |
57 | |
56 | |
58 | # re-bind all textures |
57 | $_->() for @GL_INIT; |
59 | } |
58 | } |
60 | |
59 | |
61 | sub start_game { |
60 | sub start_game { |
62 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
61 | $SDL_TIMER = add Glib::Timeout 1000/20, sub { |
63 | while ($SDL_EV->poll) { |
62 | while ($SDL_EV->poll) { |
… | |
… | |
143 | } |
142 | } |
144 | |
143 | |
145 | sub conn::face_update { |
144 | sub conn::face_update { |
146 | my ($self, $num, $face) = @_; |
145 | my ($self, $num, $face) = @_; |
147 | |
146 | |
148 | my $pb = new Gtk2::Gdk::PixbufLoader; |
|
|
149 | $pb->write ($face->{image}); |
|
|
150 | $pb->close; |
|
|
151 | |
|
|
152 | $pb = $pb->get_pixbuf; |
|
|
153 | $pb = $pb->add_alpha (0, 0, 0, 0); |
|
|
154 | |
|
|
155 | glGetError(); |
|
|
156 | my ($tex) = @{glGenTextures 1}; |
|
|
157 | |
|
|
158 | $face->{texture} = $tex; |
|
|
159 | |
|
|
160 | glBindTexture GL_TEXTURE_2D, $tex; |
|
|
161 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
|
|
162 | |
|
|
163 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
164 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
|
|
165 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
|
|
166 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
|
|
167 | |
|
|
168 | glTexImage2D GL_TEXTURE_2D, 0, |
|
|
169 | GL_RGBA8, |
|
|
170 | $pb->get_width, $pb->get_height, |
|
|
171 | 0, |
|
|
172 | GL_RGBA, |
|
|
173 | GL_UNSIGNED_BYTE, |
|
|
174 | $pb->get_pixels; |
|
|
175 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
|
|
176 | } |
147 | } |
177 | |
148 | |
178 | ############################################################################# |
149 | ############################################################################# |
179 | |
150 | |
180 | my $mapwidget = Client::MapWidget->new; |
151 | my $mapwidget = Client::MapWidget->new; |