… | |
… | |
30 | |
30 | |
31 | our $WIDTH; |
31 | our $WIDTH; |
32 | our $HEIGHT; |
32 | our $HEIGHT; |
33 | our $FULLSCREEN; |
33 | our $FULLSCREEN; |
34 | |
34 | |
35 | our $UIFONT; |
35 | our $FONTSIZE; |
36 | |
36 | |
37 | our $SDL_TIMER; |
37 | our $SDL_TIMER; |
38 | our $SDL_APP; |
38 | our $SDL_APP; |
39 | our $SDL_EV = new SDL::Event; |
39 | our $SDL_EV = new SDL::Event; |
40 | our %SDL_CB; |
40 | our %SDL_CB; |
41 | |
41 | |
42 | our @GL_INIT; # hooks called on every gl init |
42 | our @GL_INIT; # hooks called on every gl init |
43 | |
43 | |
44 | our $ALT_ENTER_MESSAGE; |
44 | our $ALT_ENTER_MESSAGE; |
45 | |
45 | |
46 | our $tw; |
46 | our $tw; # Test widget #d# |
47 | |
47 | |
48 | sub init_screen { |
48 | sub init_screen { |
49 | $SDL_APP = new SDL::App |
49 | $SDL_APP = new SDL::App |
50 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
50 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
51 | -title => "Crossfire+ Client", |
51 | -title => "Crossfire+ Client", |
… | |
… | |
62 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
62 | %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; |
63 | |
63 | |
64 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
64 | $GL_EXT{GL_ARB_texture_non_power_of_two} |
65 | or warn "WARNING: non-power-of-two opengl extension required"; |
65 | or warn "WARNING: non-power-of-two opengl extension required"; |
66 | |
66 | |
67 | $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40 |
67 | $FONTSIZE = int $HEIGHT / 40; |
68 | or die "TTFOpenFont: $!"; |
|
|
69 | |
68 | |
70 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode"; |
69 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, "Alt-Enter toggles fullscreen mode"; |
71 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
70 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); |
72 | $ALT_ENTER_MESSAGE->activate; |
71 | $ALT_ENTER_MESSAGE->activate; |
73 | |
72 | |
|
|
73 | # Test code #d# |
|
|
74 | { |
|
|
75 | my $frm = new Crossfire::Client::Widget::Frame; |
74 | $tw = new Crossfire::Client::Widget::Window; |
76 | $tw = new Crossfire::Client::Widget::Window; |
75 | $tw->add (my $lbl = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"); |
77 | $frm->add (new Crossfire::Client::Widget::Label 0, 0, 10, $FONTSIZE, "Foo in the garden!"); |
76 | # $tw = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Foo in the garden!"; |
78 | $tw->add ($frm); |
77 | |
79 | |
78 | $tw->move (0, $HEIGHT - 50); |
80 | $tw->move (0, $HEIGHT - 120); |
79 | $tw->activate; |
81 | $tw->activate; |
|
|
82 | } |
80 | |
83 | |
81 | glClearColor 0, 0, 0, 0; |
84 | glClearColor 0, 0, 0, 0; |
82 | |
85 | |
83 | glEnable GL_TEXTURE_2D; |
86 | glEnable GL_TEXTURE_2D; |
|
|
87 | glEnable GL_COLOR_MATERIAL; |
84 | glShadeModel GL_FLAT; |
88 | glShadeModel GL_FLAT; |
85 | glDisable GL_DEPTH_TEST; |
89 | glDisable GL_DEPTH_TEST; |
86 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
90 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
87 | |
|
|
88 | glMatrixMode GL_PROJECTION; |
|
|
89 | glLoadIdentity; |
|
|
90 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
|
|
91 | |
|
|
92 | glMatrixMode GL_MODELVIEW; |
|
|
93 | |
91 | |
94 | $_->() for @GL_INIT; |
92 | $_->() for @GL_INIT; |
95 | } |
93 | } |
96 | |
94 | |
97 | sub start_game { |
95 | sub start_game { |
… | |
… | |
110 | |
108 | |
111 | $CONN = new conn |
109 | $CONN = new conn |
112 | host => $CFG->{host}, |
110 | host => $CFG->{host}, |
113 | port => $CFG->{port}, |
111 | port => $CFG->{port}, |
114 | user => $CFG->{user}, |
112 | user => $CFG->{user}, |
115 | pass => $CFG->{password}; |
113 | pass => $CFG->{password}, |
|
|
114 | mapw => 50, |
|
|
115 | maph => 37, |
|
|
116 | ; |
116 | } |
117 | } |
117 | |
118 | |
118 | sub stop_game { |
119 | sub stop_game { |
119 | remove Glib::Source $SDL_TIMER; |
120 | remove Glib::Source $SDL_TIMER; |
120 | |
121 | |
… | |
… | |
123 | } |
124 | } |
124 | |
125 | |
125 | |
126 | |
126 | sub force_refresh { |
127 | sub force_refresh { |
127 | glViewport 0, 0, $WIDTH, $HEIGHT; |
128 | glViewport 0, 0, $WIDTH, $HEIGHT; |
|
|
129 | |
|
|
130 | glMatrixMode GL_PROJECTION; |
|
|
131 | glLoadIdentity; |
|
|
132 | glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; |
|
|
133 | glMatrixMode GL_MODELVIEW; |
|
|
134 | |
128 | glClear GL_COLOR_BUFFER_BIT; |
135 | glClear GL_COLOR_BUFFER_BIT; |
129 | |
136 | |
130 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
137 | $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; |
131 | |
138 | |
132 | SDL::GLSwapBuffers; |
139 | SDL::GLSwapBuffers; |
… | |
… | |
310 | |
317 | |
311 | |
318 | |
312 | ############################################################################# |
319 | ############################################################################# |
313 | |
320 | |
314 | SDL::Init SDL_INIT_EVERYTHING; |
321 | SDL::Init SDL_INIT_EVERYTHING; |
315 | SDL::TTFInit; |
|
|
316 | |
322 | |
317 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
323 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
318 | |
324 | |
319 | $mapwidget->activate; |
325 | $mapwidget->activate; |
320 | $mapwidget->focus_in; |
326 | $mapwidget->focus_in; |