Debian Codegraph @

Tests/Disp2Test/main.cpp

raw
1 #include <ClanLib/application.h>
2 #include <ClanLib/core.h>
3 #include <ClanLib/display.h>
4 #include <ClanLib/gl.h>
5 #include <GL/gl.h>
6 #include <GL/glu.h>
7
8 // #include "C:\Program Files\Rational\Quantify\pure.h"
9
10 /////////////////////////////////////////////////////////////////////////////
11 // Application class
12
13 class Application : public CL_ClanApplication
14 {
15 public:
16 int main(int argc, char** argv);
17
18 void layered_test();
19 void stencil_test();
20 void tesselate_test();
21 void viewport_test();
22
23 void resolution_test(CL_DisplayWindow &window);
24 void opengl_test(CL_OpenGLWindow &window, CL_OpenGLWindow &window2);
25 void gc_test(CL_DisplayWindow &window);
26 void gradient_test(CL_DisplayWindow &window);
27 void texture_test(CL_DisplayWindow &window);
28 void surface_test(CL_DisplayWindow &window);
29 void alpha_test(CL_DisplayWindow &window);
30 void sprite_cutter_detail_test(CL_DisplayWindow &window);
31 void sysfont_cutter_test(CL_DisplayWindow &window);
32 void surface_size_test(CL_DisplayWindow &window);
33 void font_test(CL_DisplayWindow &window);
34 void sprite_gpmfuchs_test(CL_DisplayWindow &window);
35 void surfaceandfont_test(CL_DisplayWindow &window);
36 void joystick_test(CL_DisplayWindow &window);
37 void surface_gc_test(CL_DisplayWindow &window);
38
39 void onKeyDown(const CL_InputEvent &key);
40
41 bool quit;
42 } app;
43
44 /////////////////////////////////////////////////////////////////////////////
45 // Application main entry point:
46
47 void log_to_cout(const std::string &channel, int level, const std::string &message)
48 {
49 std::cout << "[" << channel.c_str() << "] " << message.c_str() << std::endl;
50 }
51
52 int Application::main(int argc, char** argv)
53 {
54 // QuantifyStopRecordingData();
55
56 CL_ConsoleWindow debug_console("Debug console");
57 debug_console.redirect_stdio();
58
59 CL_Slot slot_log = CL_Log::sig_log().connect(&log_to_cout);
60
61 try
62 {
63 CL_SetupCore setup_init;
64 CL_SetupDisplay setup_display;
65 CL_SetupGL setup_gl;
66
67 // layered_test();
68 // return 0;
69
70 // stencil_test();
71 // return 0;
72
73 // tesselate_test();
74 // viewport_test();
75
76 CL_DisplayWindow window("ClanLib clanDisplay 2.0 test program", 320, 200, false, true);
77 // CL_DisplayWindow window2("ClanLib clanDisplay 2.0 test program", 640, 480);
78 // window.set_position(0, 0);
79 // window2.set_position(640, 480);
80
81 quit = false;
82 CL_Slot slot = CL_Keyboard::sig_key_down().connect(this, &Application::onKeyDown);
83
84 // opengl_test(window, window2);
85 // resolution_test(window);
86 // gradient_test(window);
87 gc_test(window);
88 // texture_test(window);
89 // surface_test(window);|
90 // alpha_test(window);
91 // surface_size_test(window);
92 // font_test(window);
93 // sprite_cutter_detail_test(window);
94 // sprite_gpmfuchs_test(window);
95 // surfaceandfont_test(window);
96 // joystick_test(window);
97 // surface_gc_test(window);
98 }
99 catch (CL_Error error)
100 {
101 std::cout << "Uncaught error: " << error.message.c_str() << std::endl;
102 }
103 debug_console.display_close_message();
104
105 return 0;
106 }
107
108 void Application::onKeyDown(const CL_InputEvent &key)
109 {
110 if(key.id == CL_KEY_ESCAPE)
111 quit = true;
112 }
113
114 void Application::layered_test()
115 {
116 #ifdef WIN32
117 CL_DisplayWindowDescription desc;
118 desc.set_title("ClanLib Layered Test Window");
119 desc.set_position(CL_Rect(100, 100, 260, 200));
120 desc.set_layered(true);
121
122 CL_DisplayWindow window(desc);
123
124 quit = false;
125 CL_Slot slot = CL_Keyboard::sig_key_down().connect(this, &Application::onKeyDown);
126
127 GLfloat rtri = 0.0f; // Angle For The Triangle
128 GLfloat rquad = 0.0f; // Angle For The Quad
129 int width = desc.get_size().width;
130 int height = desc.get_size().height;
131 int x = 100;
132 int y = 100;
133
134 CL_OpenGLState gl_state(window.get_gc());
135 gl_state.set_active();
136
137 while (!quit)
138 {
139 x = x + (CL_Mouse::get_x() - width/2)/10;
140 y = y + (CL_Mouse::get_y() - height/2)/10;
141 window.set_position(x, y);
142
143 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
144 glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
145 glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
146 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
147 glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
148
149 glMatrixMode(GL_PROJECTION);
150 glLoadIdentity(); // Reset The Projection Matrix
151
152 gluPerspective(45.0f,(GLfloat) width/(GLfloat)height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window
153
154 glMatrixMode(GL_MODELVIEW);
155
156 glViewport(0, 0, width, height); // Reset The Current Viewport And Perspective Transformation
157
158 glMatrixMode(GL_PROJECTION);
159 glLoadIdentity();
160
161 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
162 glMatrixMode(GL_MODELVIEW);
163
164
165 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
166 glLoadIdentity(); // Reset The View
167 glTranslatef(-1.5f,0.0f,-6.0f); // Move Into The Screen And Left
168
169 glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y Axis
170
171 glBegin(GL_POLYGON); // Start Drawing A Polygon
172 glColor4f(1.0f,0.0f,0.0f,1.0f); // Red
173 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
174 glColor4f(0.0f,1.0f,0.0f,1.0f); // Green
175 glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
176 glColor4f(0.0f,0.0f,1.0f,1.0f); // Blue
177 glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
178
179 glColor3f(1.0f,0.0f,0.0f); // Red
180 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
181 glColor3f(0.0f,0.0f,1.0f); // Blue
182 glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
183 glColor3f(0.0f,1.0f,0.0f); // Green
184 glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
185
186 glColor3f(1.0f,0.0f,0.0f); // Red
187 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
188 glColor3f(0.0f,1.0f,0.0f); // Green
189 glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
190 glColor3f(0.0f,0.0f,1.0f); // Blue
191 glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)
192
193 glColor3f(1.0f,0.0f,0.0f); // Red
194 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
195 glColor3f(0.0f,0.0f,1.0f); // Blue
196 glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
197 glColor3f(0.0f,1.0f,0.0f); // Green
198 glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
199 glEnd(); // Done Drawing The Polygon
200
201 glLoadIdentity();
202 glTranslatef(1.5f,0.0f,-7.0f); // Move Right 1.5 Units
203 glRotatef(rquad,1.0f,1.0f,1.0f); // Rotate The Quad On X,Y & Z
204
205
206 glBegin(GL_QUADS); // Start Drawing A Quad
207 glColor3f(0.0f,1.0f,0.0f); // Blue
208 glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
209 glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
210 glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
211 glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
212
213 glColor3f(1.0f,0.5f,0.0f); // Orange
214 glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
215 glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
216 glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
217 glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
218
219 glColor3f(1.0f,0.0f,0.0f); // Red
220 glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
221 glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
222 glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
223 glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
224
225 glColor3f(1.0f,1.0f,0.0f); // Yellow
226 glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
227 glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
228 glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
229 glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
230
231 glColor3f(0.0f,0.0f,1.0f); // Blue
232 glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
233 glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
234 glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
235 glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
236
237 glColor3f(1.0f,0.0f,1.0f); // Violet
238 glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
239 glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
240 glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
241 glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
242 glEnd(); // Done Drawing The Quad
243
244 rtri+=5.0f; // Increase Rotation Variable For The Triangle
245 rquad-=5.0f; // Decrease Rotation Variable For The Quad
246
247 window.flip();
248 CL_System::keep_alive(10);
249
250 gl_state.set_active();
251 }
252
253 quit = false;
254 #endif
255 }
256
257 void Application::resolution_test(CL_DisplayWindow &window)
258 {
259 /*
260 CL_System::keep_alive(2000);
261 window.set_fullscreen(640, 480, 16);
262 CL_System::keep_alive(2000);
263 window.set_windowed();
264 CL_System::keep_alive(5000);
265 */
266 }
267
268 void Application::opengl_test(CL_OpenGLWindow &window, CL_OpenGLWindow &window2)
269 {
270 GLfloat rtri = 0.0f; // Angle For The Triangle
271 GLfloat rquad = 0.0f; // Angle For The Quad
272 int width = 640;
273 int height = 480;
274
275 CL_OpenGLState gl_state_w1(window.get_gc());
276 CL_OpenGLState gl_state_w2(window2.get_gc());
277
278 for (int i=0; i<500; i++)
279 {
280 if (i%2) gl_state_w1.set_active();
281 else gl_state_w2.set_active();
282
283 glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
284 glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
285 glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
286 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
287 glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
288
289 glMatrixMode(GL_PROJECTION);
290 glLoadIdentity(); // Reset The Projection Matrix
291
292 gluPerspective(45.0f,(GLfloat) width/(GLfloat)height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window
293
294 glMatrixMode(GL_MODELVIEW);
295
296 glViewport(0, 0, width, height); // Reset The Current Viewport And Perspective Transformation
297
298 glMatrixMode(GL_PROJECTION);
299 glLoadIdentity();
300
301 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
302 glMatrixMode(GL_MODELVIEW);
303
304
305 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
306 glLoadIdentity(); // Reset The View
307 glTranslatef(-1.5f,0.0f,-6.0f); // Move Into The Screen And Left
308
309 glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y Axis
310
311 glBegin(GL_POLYGON); // Start Drawing A Polygon
312 glColor3f(1.0f,0.0f,0.0f); // Red
313 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
314 glColor3f(0.0f,1.0f,0.0f); // Green
315 glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
316 glColor3f(0.0f,0.0f,1.0f); // Blue
317 glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
318
319 glColor3f(1.0f,0.0f,0.0f); // Red
320 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
321 glColor3f(0.0f,0.0f,1.0f); // Blue
322 glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
323 glColor3f(0.0f,1.0f,0.0f); // Green
324 glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
325
326 glColor3f(1.0f,0.0f,0.0f); // Red
327 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
328 glColor3f(0.0f,1.0f,0.0f); // Green
329 glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
330 glColor3f(0.0f,0.0f,1.0f); // Blue
331 glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)
332
333 glColor3f(1.0f,0.0f,0.0f); // Red
334 glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
335 glColor3f(0.0f,0.0f,1.0f); // Blue
336 glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
337 glColor3f(0.0f,1.0f,0.0f); // Green
338 glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
339 glEnd(); // Done Drawing The Polygon
340
341 glLoadIdentity();
342 glTranslatef(1.5f,0.0f,-7.0f); // Move Right 1.5 Units
343 glRotatef(rquad,1.0f,1.0f,1.0f); // Rotate The Quad On X,Y & Z
344
345
346 glBegin(GL_QUADS); // Start Drawing A Quad
347 glColor3f(0.0f,1.0f,0.0f); // Blue
348 glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
349 glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
350 glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
351 glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
352
353 glColor3f(1.0f,0.5f,0.0f); // Orange
354 glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
355 glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
356 glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
357 glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
358
359 glColor3f(1.0f,0.0f,0.0f); // Red
360 glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
361 glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
362 glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
363 glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
364
365 glColor3f(1.0f,1.0f,0.0f); // Yellow
366 glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
367 glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
368 glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
369 glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
370
371 glColor3f(0.0f,0.0f,1.0f); // Blue
372 glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
373 glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
374 glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
375 glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
376
377 glColor3f(1.0f,0.0f,1.0f); // Violet
378 glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
379 glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
380 glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
381 glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
382 glEnd(); // Done Drawing The Quad
383
384 rtri+=5.0f; // Increase Rotation Variable For The Triangle
385 rquad-=5.0f; // Decrease Rotation Variable For The Quad
386
387 if (i%2) window.flip();
388 if (i%2) window2.flip();
389 CL_System::keep_alive(10);
390 }
391
392 quit = false;
393 }
394
395 void Application::gradient_test(CL_DisplayWindow &window)
396 {
397 CL_GraphicContext *gc = window.get_gc();
398
399 while (!quit)
400 {
401 gc->clear();
402 gc->fill_rect(CL_Rect(10,10,100,100), CL_Gradient(CL_Color::white, CL_Color::green, CL_Color::red, CL_Color::blue));
403 window.flip();
404 CL_System::keep_alive(10);
405 }
406
407 quit = false;
408 }
409
410 void Application::texture_test(CL_DisplayWindow &window)
411 {
412 /* CL_GraphicContext *gc = window.get_gc();
413
414 CL_OpenGLSurface texture("images/test32_alpha.tga");
415
416 std::cout << "Texture (mem) width: " << texture.get_texture_width() << std::endl;
417 std::cout << "Texture (mem) height: " << texture.get_texture_height() << std::endl;
418 std::cout << "Texture (screen) width: " << texture.get_width() << std::endl;
419 std::cout << "Texture (screen) height: " << texture.get_height() << std::endl;
420
421 while (!quit)
422 {
423 gc->clear();
424
425 window.flip();
426 CL_System::keep_alive(10);
427 }
428
429 quit = false;
430 */
431 }
432
433 void Application::gc_test(CL_DisplayWindow &window)
434 {
435 CL_GraphicContext *gc = window.get_gc();
436
437 while (!quit)
438 {
439 gc->clear();
440
441 gc->draw_rect(CL_Rect(0,0,gc->get_width(),gc->get_height()), CL_Color(255,255,255));
442
443 // gc->draw_line(0, 0, 640, 480, CL_Color(255, 255, 255));
444 // gc->draw_rect(CL_Rect(10, 10, 40, 40), CL_Color(0, 0, 255));
445 // gc->fill_rect(CL_Rect(50, 50, 70, 70), CL_Color(255, 0, 0));
446
447 window.flip();
448 CL_System::keep_alive(10);
449 }
450
451 quit = false;
452 }
453
454 void Application::surface_test(CL_DisplayWindow &window)
455 {
456 /* CL_Surface surface(new CL_TargaProvider("images/test32_alpha.tga"), true);
457 // CL_Surface surface(new CL_PCXProvider("images/test8.pcx"), true);
458 // CL_Surface surface(new CL_PNGProvider("images/test8.png"), true);
459 // CL_Surface surface(new CL_JPEGProvider("images/test24.jpg"), true);
460
461 float angle = 0.0f;
462 float angle2 = 0.5f;
463
464 CL_GraphicContext *gc = window.get_gc();
465
466 while (!quit)
467 {
468 gc->fill_rect(CL_Rect(0, 0, 1024, 768), CL_Color(0,0,0));
469
470 /////////////////////////////////////////////
471 // Draw 4 fading, scaling and rotating surfaces in center of the screen
472
473 angle += 0.5f;
474
475 surface.set_angle(angle);
476 surface.set_alpha(1.0f - ((360.0f - surface.get_angle()) / 360.0f));
477 surface.set_scale(1.0f - ((360.0f - surface.get_angle()) / 360.0f), 1.0f - ((360.0f - surface.get_angle()) / 360.0f));
478
479 surface.set_alignment(origin_top_left);
480 surface.set_rotation_hotspot(origin_top_left);
481 surface.draw(512, 384, gc);
482
483 surface.set_alignment(origin_bottom_right);
484 surface.set_rotation_hotspot(origin_bottom_right);
485 surface.draw(512, 384, gc);
486
487 surface.set_angle(-angle);
488 surface.set_alpha(surface.get_angle() / 360.0f);
489 surface.set_scale(surface.get_angle() / 360.0f, surface.get_angle() / 360.0f);
490
491 surface.set_alignment(origin_top_right);
492 surface.set_rotation_hotspot(origin_top_right);
493 surface.draw(512, 384, gc);
494
495 surface.set_alignment(origin_bottom_left);
496 surface.set_rotation_hotspot(origin_bottom_left);
497 surface.draw(512, 384, gc);
498
499 /////////////////////////////////////////////
500 // Draw 4 rotating surfaces in the corners
501
502 angle2 -= 2.0f;
503
504 surface.set_alpha(1.0f);
505 surface.set_scale(0.3f, 0.3f);
506 surface.set_rotation_hotspot(origin_center);
507
508 surface.set_angle(-angle2);
509
510 surface.set_alignment(origin_top_left);
511 surface.draw(0, 0, gc);
512
513 surface.set_alignment(origin_bottom_right);
514 surface.draw(1024, 768, gc);
515
516 surface.set_angle(angle2);
517
518 surface.set_alignment(origin_top_right);
519 surface.draw(1024, 0, gc);
520
521 surface.set_alignment(origin_bottom_left);
522 surface.draw(0, 768, gc);
523
524 surface.draw(
525 CL_Rect(
526 CL_Point(100, 200),
527 CL_Size(surface.get_pixelbuffer().get_width() / 2, surface.get_pixelbuffer().get_height() / 2)),
528 gc);
529 surface.draw(
530 CL_Rect(
531 CL_Point(0, 0),
532 CL_Size(surface.get_pixelbuffer().get_width() / 2, surface.get_pixelbuffer().get_height() / 2)),
533 CL_Rect(
534 CL_Point(100, 300),
535 CL_Size(surface.get_pixelbuffer().get_width(), surface.get_pixelbuffer().get_height())),
536 gc);
537
538 gc->draw_line(512, 0, 512, 768, CL_Color(255, 0, 0, 100));
539 gc->draw_line(0, 384, 1024, 384, CL_Color(255, 0, 0, 100));
540
541 window.flip();
542 CL_System::keep_alive(10);
543
544 GLenum error;
545 while ((error = glGetError()) != GL_NO_ERROR)
546 std::cout << gluErrorString(error) << std::endl;
547 }
548
549 quit = false;
550 */
551 }
552
553 void Application::alpha_test(CL_DisplayWindow &window)
554 {
555 // Set a cursor:
556 /* CL_SpriteDescription desc;
557 desc.add_frame(new CL_TargaProvider("images/manwalk_0001.tga"), true);
558 desc.add_frame(new CL_TargaProvider("images/manwalk_0002.tga"), true);
559 desc.add_frame(new CL_TargaProvider("images/manwalk_0003.tga"), true);
560 desc.add_frame(new CL_TargaProvider("images/manwalk_0004.tga"), true);
561 desc.add_frame(new CL_TargaProvider("images/manwalk_0005.tga"), true);
562 desc.add_frame(new CL_TargaProvider("images/manwalk_0006.tga"), true);
563 desc.add_frame(new CL_TargaProvider("images/manwalk_0007.tga"), true);
564 desc.add_frame(new CL_TargaProvider("images/manwalk_0008.tga"), true);
565 desc.add_frame(new CL_TargaProvider("images/manwalk_0009.tga"), true);
566 desc.add_frame(new CL_TargaProvider("images/manwalk_0010.tga"), true);
567 desc.add_frame(new CL_TargaProvider("images/manwalk_0011.tga"), true);
568 desc.add_frame(new CL_TargaProvider("images/manwalk_0012.tga"), true);
569 desc.add_frame(new CL_TargaProvider("images/manwalk_0013.tga"), true);
570 desc.add_frame(new CL_TargaProvider("images/manwalk_0014.tga"), true);
571 desc.add_frame(new CL_TargaProvider("images/manwalk_0015.tga"), true);
572 desc.add_frame(new CL_TargaProvider("images/manwalk_0016.tga"), true);
573 desc.add_frame(new CL_TargaProvider("images/manwalk_0017.tga"), true);
574 desc.add_frame(new CL_TargaProvider("images/manwalk_0018.tga"), true);
575 desc.add_frame(new CL_TargaProvider("images/manwalk_0019.tga"), true);
576 desc.add_frame(new CL_TargaProvider("images/manwalk_0020.tga"), true);
577 desc.add_frame(new CL_TargaProvider("images/manwalk_0021.tga"), true);
578 desc.add_frame(new CL_TargaProvider("images/manwalk_0022.tga"), true);
579 desc.add_frame(new CL_TargaProvider("images/manwalk_0023.tga"), true);
580 desc.add_frame(new CL_TargaProvider("images/manwalk_0024.tga"), true);
581 desc.add_frame(new CL_TargaProvider("images/manwalk_0025.tga"), true);
582 desc.add_frame(new CL_TargaProvider("images/manwalk_0026.tga"), true);
583 desc.add_frame(new CL_TargaProvider("images/manwalk_0027.tga"), true);
584 desc.add_frame(new CL_TargaProvider("images/manwalk_0028.tga"), true);
585 desc.add_frame(new CL_TargaProvider("images/manwalk_0029.tga"), true);
586
587 CL_Sprite sprite(desc);
588 sprite.set_alignment(origin_center);
589 window.set_cursor(sprite);
590
591 static int col = 0;
592 static int col_delta = 1;
593
594 std::list<CL_Surface> images;
595 std::list<std::string> text;
596
597 images.push_back(CL_Surface(new CL_PCXProvider("images/test8.pcx"), true)); text.push_back("test8.pcx");
598 images.push_back(CL_Surface(new CL_PNGProvider("images/test8.png"), true)); text.push_back("test8.png");
599 images.push_back(CL_Surface(new CL_TargaProvider("images/test8.tga"), true)); text.push_back("test8.tga");
600 images.push_back(CL_Surface(new CL_PNGProvider("images/test8_alpha.png"), true)); text.push_back("test8_alpha.png");
601 images.push_back(CL_Surface(new CL_TargaProvider("images/test16.tga"), true)); text.push_back("test16.tga");
602 images.push_back(CL_Surface(new CL_JPEGProvider("images/test24.jpg"), true)); text.push_back("test24.jpg");
603 images.push_back(CL_Surface(new CL_PCXProvider("images/test24.pcx"), true)); text.push_back("test24.pcx");
604 images.push_back(CL_Surface(new CL_PNGProvider("images/test24.png"), true)); text.push_back("test24.png");
605 images.push_back(CL_Surface(new CL_TargaProvider("images/test24.tga"), true)); text.push_back("images/test24.tga");
606 images.push_back(CL_Surface(new CL_PNGProvider("images/test32.png"), true)); text.push_back("images/test32.png");
607 images.push_back(CL_Surface(new CL_TargaProvider("images/test32.tga"), true)); text.push_back("images/test32.tga");
608 images.push_back(CL_Surface(new CL_PNGProvider("images/test32_alpha.png"), true)); text.push_back("images/test32_alpha.png");
609 images.push_back(CL_Surface(new CL_TargaProvider("images/test32_alpha.tga"), true)); text.push_back("images/test32_alpha.tga");
610
611 CL_GraphicContext *gc = window.get_gc();
612
613 CL_Font sysfont("Comic Sans MS", 15);
614 sysfont.set_alignment(origin_center);
615
616 while (!quit)
617 {
618 // Clear screen
619 CL_Display::clear(CL_Color(col, col, 0));
620
621 // Fade background between black and white
622 col += col_delta;
623 if(col > 255 || col < 0)
624 {
625 col_delta = -col_delta;
626 col += col_delta;
627 }
628
629 gc->draw_line(200, 0, 200, 600, CL_Color(100,100,100));
630 gc->draw_line(600, 0, 600, 600, CL_Color(100,100,100));
631
632 gc->draw_line(0, 150, 800, 150, CL_Color(100,100,100));
633 gc->draw_line(0, 450, 800, 450, CL_Color(100,100,100));
634
635 gc->draw_line(400, 0, 400, 600, CL_Color(255,255,255));
636 gc->draw_line(0, 300, 800, 300, CL_Color(255,255,255));
637
638 int x = 0;
639 int y = 0;
640 std::list<CL_Surface>::iterator i1;
641 std::list<std::string>::iterator i2;
642 for(i1 = images.begin(), i2 = text.begin(); i1 != images.end(); ++i1, ++i2)
643 {
644 (*i1).set_scale(0.37f, 0.37f);
645 (*i1).draw(x + 5, y + 5);
646 sysfont.draw(x + 100, y + 140, (*i2));
647
648 x += 200;
649 if(x == 800)
650 {
651 x = 0;
652 y += 150;
653 }
654 }
655
656 window.flip();
657 CL_System::keep_alive(10);
658 }
659
660 quit = false;
661
662 window.set_cursor(CL_Sprite());
663 */}
664
665 void Application::surface_size_test(CL_DisplayWindow &window)
666 {
667 /* CL_Surface surface(new CL_TargaProvider("images/wacked.tga"), true);
668
669 CL_GraphicContext *gc = window.get_gc();
670
671 surface.set_rotation_hotspot(origin_bottom_right);
672
673 while (!quit)
674 {
675 gc->fill_rect(CL_Rect(0, 0, 1024, 768), CL_Color(0,0,0));
676
677 surface.rotate(1.0f);
678
679 surface.draw(0, 0, gc);
680 surface.draw(CL_Rect(0, 100, 300, 300), gc);
681
682 window.flip();
683 CL_System::keep_alive(10);
684 }
685
686 quit = false;
687 */}
688
689 void Application::font_test(CL_DisplayWindow &window)
690 {
691 /* CL_GraphicContext *gc = window.get_gc();
692
693 CL_SpriteDescription desc;
694 desc.add_paletteclipped_frames(
695 new CL_PCXProvider("images/clanfont.pcx"), 129, 209, true);
696
697 CL_Sprite sprite(desc);
698 CL_Font bitfont(
699 sprite,
700 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
701 10);
702 bitfont.set_alignment(origin_center);
703 bitfont.set_color(0.0f, 1.0f, 0.0f, 1.0f);
704
705 CL_Font sysfont("Comic Sans MS", 141);
706 sysfont.set_alignment(origin_center);
707 // CL_Sprite glyphs = sysfont.get_glyphs();
708
709 while (!quit)
710 {
711 gc->fill_rect(CL_Rect(0, 0, 1024, 768), CL_Color(0,0,0));
712
713 // This grid is to test that coordinate system is sane:
714 for (int y=0; y<600; y+=3)
715 {
716 gc->draw_line(0, y, 800, y, CL_Color(255,255,255));
717 }
718 for (int x=0; x<800; x+=3)
719 {
720 gc->draw_line(x, 0, x, 600, CL_Color(255,255,255));
721 }
722
723 bitfont.draw(window.get_width()/2, 100, "Bitmap font", gc);
724 sysfont.draw(window.get_width()/2, 200, "System font", gc);
725
726 window.flip();
727 CL_System::keep_alive(10);
728 }
729
730 quit = false;
731 */}
732
733 void Application::sprite_cutter_detail_test(CL_DisplayWindow &window)
734 {
735 /* CL_SpriteDescription desc;
736
737 // desc.add_frame(new CL_TargaProvider("images/frameman.tga"), true);
738 desc.add_gridclipped_frames(
739 new CL_TargaProvider("images/fire.tga"),
740 0, 0,
741 29, 59,
742 8, 1,
743 1, 0,
744 true);
745
746 CL_Sprite sprite1(desc);
747
748 CL_GraphicContext *gc = window.get_gc();
749
750 float last_time = (float)CL_System::get_time();
751
752 sprite1.set_rotation_hotspot(origin_center, 0, 70);
753
754 float d = 0;
755 while (!quit)
756 {
757 // Calculate amount of time since last frame
758 float delta_time = (CL_System::get_time() - last_time) / 1000.0f;
759 last_time = (float)CL_System::get_time();
760
761 d += delta_time * 10;
762
763 gc->fill_rect(CL_Rect(0, 0, 1024, 768), CL_Color(0,0,0));
764
765 sprite1.update(delta_time);
766
767 for(float x = 0; x < 360; x += 15)
768 {
769 sprite1.set_angle(x + d);
770 sprite1.draw(400, 350, gc);
771 }
772
773 window.flip();
774 CL_System::keep_alive(10);
775 }
776
777 quit = false;
778 */}
779
780 void Application::sprite_gpmfuchs_test(CL_DisplayWindow &window)
781 {
782 /* CL_SpriteDescription desc;
783
784 desc.add_frame(new CL_TargaProvider("images/manwalk_0001.tga"), true);
785 desc.add_frame(new CL_TargaProvider("images/manwalk_0002.tga"), true);
786 desc.add_frame(new CL_TargaProvider("images/manwalk_0003.tga"), true);
787 desc.add_frame(new CL_TargaProvider("images/manwalk_0004.tga"), true);
788 desc.add_frame(new CL_TargaProvider("images/manwalk_0005.tga"), true);
789 desc.add_frame(new CL_TargaProvider("images/manwalk_0006.tga"), true);
790 desc.add_frame(new CL_TargaProvider("images/manwalk_0007.tga"), true);
791 desc.add_frame(new CL_TargaProvider("images/manwalk_0008.tga"), true);
792 desc.add_frame(new CL_TargaProvider("images/manwalk_0009.tga"), true);
793 desc.add_frame(new CL_TargaProvider("images/manwalk_0010.tga"), true);
794 desc.add_frame(new CL_TargaProvider("images/manwalk_0011.tga"), true);
795 desc.add_frame(new CL_TargaProvider("images/manwalk_0012.tga"), true);
796 desc.add_frame(new CL_TargaProvider("images/manwalk_0013.tga"), true);
797 desc.add_frame(new CL_TargaProvider("images/manwalk_0014.tga"), true);
798 desc.add_frame(new CL_TargaProvider("images/manwalk_0015.tga"), true);
799 desc.add_frame(new CL_TargaProvider("images/manwalk_0016.tga"), true);
800 desc.add_frame(new CL_TargaProvider("images/manwalk_0017.tga"), true);
801 desc.add_frame(new CL_TargaProvider("images/manwalk_0018.tga"), true);
802 desc.add_frame(new CL_TargaProvider("images/manwalk_0019.tga"), true);
803 desc.add_frame(new CL_TargaProvider("images/manwalk_0020.tga"), true);
804 desc.add_frame(new CL_TargaProvider("images/manwalk_0021.tga"), true);
805 desc.add_frame(new CL_TargaProvider("images/manwalk_0022.tga"), true);
806 desc.add_frame(new CL_TargaProvider("images/manwalk_0023.tga"), true);
807 desc.add_frame(new CL_TargaProvider("images/manwalk_0024.tga"), true);
808 desc.add_frame(new CL_TargaProvider("images/manwalk_0025.tga"), true);
809 desc.add_frame(new CL_TargaProvider("images/manwalk_0026.tga"), true);
810 desc.add_frame(new CL_TargaProvider("images/manwalk_0027.tga"), true);
811 desc.add_frame(new CL_TargaProvider("images/manwalk_0028.tga"), true);
812 desc.add_frame(new CL_TargaProvider("images/manwalk_0029.tga"), true);
813
814 CL_Sprite sprite(desc);
815 sprite.set_alignment(origin_center);
816
817 CL_GraphicContext *gc = window.get_gc();
818 float last_time = (float)CL_System::get_time();
819 float cur_spr = 0;
820 float time_elapsed = 0.0f;
821
822 while (!quit)
823 {
824 float delta_time = (CL_System::get_time() - last_time) / 1000.0f;
825 last_time = (float)CL_System::get_time();
826
827 cur_spr += delta_time*25;
828 while (cur_spr >= 29.0f) cur_spr -= 29.0f;
829 time_elapsed += delta_time*5;
830
831 gc->clear(CL_Color::white);
832
833 for (int objnr = 0; objnr < 800; objnr++)
834 {
835 float angle = time_elapsed + objnr*20%360;
836 sprite.set_angle((float) angle);
837 sprite.set_frame((int) cur_spr);
838 sprite.set_color(rand()%255 / 255.0f,rand()%255 / 255.0f,rand()%255 / 255.0f);
839 int x = objnr*30;
840 int y = x/1000*30;
841 x %= 1000;
842 sprite.draw(20+x, 20+y, gc);
843 }
844
845 window.flip();
846 CL_System::keep_alive(1);
847 }
848
849 quit = false;
850 */}
851
852 void Application::surfaceandfont_test(CL_DisplayWindow &window)
853 {
854 /* CL_GraphicContext *gc = window.get_gc();
855
856 CL_SpriteDescription font_desc;
857 font_desc.add_paletteclipped_frames(
858 new CL_PCXProvider("images/clanfont.pcx"), 129, 209, true);
859 CL_Sprite font_sprite(font_desc);
860 CL_Font font(
861 font_sprite,
862 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
863 10);
864
865 CL_Surface surface(new CL_TargaProvider("images/manwalk_0001.tga"), true);
866
867 CL_SpriteDescription desc;
868 desc.add_frame(new CL_TargaProvider("images/manwalk_0001.tga"), true);
869 desc.add_frame(new CL_TargaProvider("images/manwalk_0002.tga"), true);
870 desc.add_frame(new CL_TargaProvider("images/manwalk_0003.tga"), true);
871 desc.add_frame(new CL_TargaProvider("images/manwalk_0004.tga"), true);
872 desc.add_frame(new CL_TargaProvider("images/manwalk_0005.tga"), true);
873 desc.add_frame(new CL_TargaProvider("images/manwalk_0006.tga"), true);
874 desc.add_frame(new CL_TargaProvider("images/manwalk_0007.tga"), true);
875 desc.add_frame(new CL_TargaProvider("images/manwalk_0008.tga"), true);
876 desc.add_frame(new CL_TargaProvider("images/manwalk_0009.tga"), true);
877 desc.add_frame(new CL_TargaProvider("images/manwalk_0010.tga"), true);
878 desc.add_frame(new CL_TargaProvider("images/manwalk_0011.tga"), true);
879 desc.add_frame(new CL_TargaProvider("images/manwalk_0012.tga"), true);
880 desc.add_frame(new CL_TargaProvider("images/manwalk_0013.tga"), true);
881 desc.add_frame(new CL_TargaProvider("images/manwalk_0014.tga"), true);
882 desc.add_frame(new CL_TargaProvider("images/manwalk_0015.tga"), true);
883 desc.add_frame(new CL_TargaProvider("images/manwalk_0016.tga"), true);
884 desc.add_frame(new CL_TargaProvider("images/manwalk_0017.tga"), true);
885 desc.add_frame(new CL_TargaProvider("images/manwalk_0018.tga"), true);
886 desc.add_frame(new CL_TargaProvider("images/manwalk_0019.tga"), true);
887 desc.add_frame(new CL_TargaProvider("images/manwalk_0020.tga"), true);
888 desc.add_frame(new CL_TargaProvider("images/manwalk_0021.tga"), true);
889 desc.add_frame(new CL_TargaProvider("images/manwalk_0022.tga"), true);
890 desc.add_frame(new CL_TargaProvider("images/manwalk_0023.tga"), true);
891 desc.add_frame(new CL_TargaProvider("images/manwalk_0024.tga"), true);
892 desc.add_frame(new CL_TargaProvider("images/manwalk_0025.tga"), true);
893 desc.add_frame(new CL_TargaProvider("images/manwalk_0026.tga"), true);
894 desc.add_frame(new CL_TargaProvider("images/manwalk_0027.tga"), true);
895 desc.add_frame(new CL_TargaProvider("images/manwalk_0028.tga"), true);
896 desc.add_frame(new CL_TargaProvider("images/manwalk_0029.tga"), true);
897 CL_Sprite sprite(desc);
898
899 int width = CL_Display::get_width();
900 int height = CL_Display::get_height();
901
902 int start_time = CL_System::get_time();
903 int fps_result = 0;
904 int fps_counter = 0;
905 int total_time = 0;
906
907 // QuantifyStartRecordingData();
908
909 while (!quit)
910 {
911 int cur_time = CL_System::get_time();
912 int delta_time = cur_time - start_time;
913 start_time = cur_time;
914
915 total_time += delta_time;
916 if(total_time >= 1000)// One second has passed
917 {
918 fps_result = fps_counter + 1;
919 fps_counter = total_time = 0;
920 }
921 fps_counter++;// Increase fps
922
923 gc->clear(CL_Color::black);
924
925 for(int i=1; i<10000;i++)
926 {
927 // Surface test:
928 // for(int j = 0; j < 10; j++)
929 // surface.draw(width % i + j, height % i + j, gc);
930
931 // Sprite test:
932 // for(int j = 0; j < 10; j++)
933 // sprite.draw(width % i + j, height % i + j, gc);
934
935 // Font test:
936 font.draw(width % i, height % i, "Bitmap font", gc);
937 }
938
939 font.draw(900, 0, CL_String::from_int(fps_result) + " fps");
940
941 window.flip();
942 CL_System::keep_alive();
943 }
944
945 // QuantifyStopRecordingData();
946
947 quit = false;
948 */}
949
950 void Application::joystick_test(CL_DisplayWindow &window)
951 {
952 CL_GraphicContext *gc = window.get_gc();
953
954 int width = CL_Display::get_width();
955 int height = CL_Display::get_height();
956
957 if (window.get_ic()->get_joystick_count() == 0)
958 {
959 std::cout << "No joysticks found!" << std::endl;
960 return;
961 }
962 CL_InputDevice joystick = window.get_ic()->get_joystick();
963
964 while (!quit)
965 {
966 gc->clear(CL_Color::black);
967
968 double x_axis = joystick.get_x()/double(0xffff/2);
969 double y_axis = joystick.get_y()/double(0xffff/2);
970
971 int x = int(width/2+x_axis*width/2);
972 int y = int(height/2+y_axis*height/2);
973 CL_Rect rect(x-10, y-10, x+10, y+10);
974 CL_Color color = CL_Color::white;
975 if (joystick.get_keycode(0)) color = CL_Color::blue;
976 if (joystick.get_keycode(1)) color = CL_Color::burlywood;
977 if (joystick.get_keycode(2)) color = CL_Color::cornflowerblue;
978 if (joystick.get_keycode(3)) color = CL_Color::gainsboro;
979 if (joystick.get_keycode(4)) color = CL_Color::indianred;
980 if (joystick.get_keycode(5)) color = CL_Color::lightskyblue;
981 if (joystick.get_keycode(6)) color = CL_Color::lime;
982 if (joystick.get_keycode(7)) color = CL_Color::orange;
983 gc->fill_rect(rect, color);
984
985 window.flip();
986 CL_System::keep_alive();
987 }
988
989 quit = false;
990 }
991
992 void Application::surface_gc_test(CL_DisplayWindow &window)
993 {
994 /* CL_GraphicContext *gc = window.get_gc();
995
996 CL_Surface surface(new CL_TargaProvider("images/manwalk_0016.tga"), true);
997 CL_Surface surface2(new CL_TargaProvider("images/manwalk_0002.tga"), true);
998 CL_Surface surface3(new CL_TargaProvider("images/manwalk_0002.tga"), true);
999
1000 surface.set_color(1.0f, 1.0f, 0.25f);
1001
1002 CL_Canvas canvas(surface3);
1003 surface.draw(0, 0, canvas.get_gc());
1004 canvas.get_gc()->fill_rect(CL_Rect(0,0,20,20), CL_Color::yellow);
1005
1006 while (!quit)
1007 {
1008 gc->clear(CL_Color::black);
1009 surface2.draw(0, 0, gc);
1010 surface.draw(0, 0, gc);
1011 surface3.draw(64, 0, gc);
1012 window.flip();
1013 CL_System::keep_alive();
1014 }
1015
1016 quit = false;
1017 */
1018 }
1019
1020 void Application::stencil_test()
1021 {
1022 CL_OpenGLWindowDescription desc;
1023 desc.set_title("ClanLib clanDisplay 2.0 test program");
1024 desc.set_size(CL_Size(800,600));
1025 desc.set_stencil_size(8);
1026 desc.set_fullscreen(false);
1027
1028 CL_DisplayWindow window(desc);
1029
1030 quit = false;
1031 CL_Slot slot = CL_Keyboard::sig_key_down().connect(this, &Application::onKeyDown);
1032
1033 CL_Surface text("images/stencil_text.png");
1034 CL_Surface highlight("images/stencil_highlight.png");
1035
1036 CL_GraphicContext *gc = window.get_gc();
1037 CL_OpenGLState gl_state(gc);
1038 gl_state.set_active();
1039 gl_state.setup_2d();
1040
1041 glClearStencil(0);
1042 glStencilMask(1);
1043 glEnable(GL_STENCIL_TEST);
1044
1045 // discard pixels with alpha < 0.5 (quad drawn otherwise)
1046 // when GL_ALPHA_TEST is enabled
1047 glAlphaFunc(GL_GEQUAL,0.5f);
1048
1049 int width = CL_Display::get_width();
1050 int height = CL_Display::get_height();
1051
1052 float sin_count = 0;
1053
1054 while (!quit)
1055 {
1056 sin_count += float(M_PI)/180.0f;
1057
1058 gl_state.set_active();
1059
1060 glClear( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1061
1062 glDisable(GL_STENCIL_TEST);
1063
1064 int a=int(255.f*fabs(sin(sin_count)));
1065 int b=int(255.f*fabs(sin(sin_count+(0.25*M_PI))));
1066 int c=int(255.f*fabs(sin(sin_count+(0.5*M_PI))));
1067
1068 CL_Display::fill_rect(CL_Rect(0,0,1024,768),
1069 CL_Gradient(
1070 CL_Color(a,b,c,a),
1071 CL_Color(b,c,a,b),
1072 CL_Color(c,b,a,c),
1073 CL_Color(c,a,b,a)));
1074
1075 gl_state.set_active();
1076 glEnable(GL_STENCIL_TEST);
1077
1078 glStencilFunc(GL_ALWAYS, 1, 1);
1079 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); // increment when test passed
1080
1081 glColorMask(0,0,0,0); // disable color buf writing.
1082 glEnable(GL_ALPHA_TEST);
1083 text.draw(250,130); // draw to stencil buf (color buf disabled)
1084 gl_state.set_active();
1085 glDisable(GL_ALPHA_TEST);
1086 glColorMask(1,1,1,1); // enable color buf writing
1087
1088 // ----------------
1089 glStencilFunc(GL_EQUAL, 1, 1); // pass (draw pixel) if stencil buf content == 1
1090 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buf
1091
1092 highlight.draw(250,int(130+sin(sin_count)*100));
1093 gl_state.set_active();
1094
1095 window.flip();
1096 CL_System::keep_alive(20);
1097
1098 int error = glGetError();
1099 while( error != 0 )
1100 {
1101 std::cout << std::hex << "GLError: 0x" << error << std::endl;
1102 error = glGetError();
1103 }
1104 }
1105
1106 quit = false;
1107 }
1108
1109 struct Triangle { double x[3]; double y[3]; };
1110 std::vector<Triangle> triangles;
1111
1112 void on_tesselate_triangle(void *data1, void *data2, void *data3)
1113 {
1114 POINT *p1 = (POINT *) data1;
1115 POINT *p2 = (POINT *) data2;
1116 POINT *p3 = (POINT *) data3;
1117
1118 Triangle triangle;
1119 triangle.x[0] = p1->x;
1120 triangle.y[0] = p1->y;
1121 triangle.x[1] = p2->x;
1122 triangle.y[1] = p2->y;
1123 triangle.x[2] = p3->x;
1124 triangle.y[2] = p3->y;
1125 triangles.push_back(triangle);
1126 }
1127
1128 void Application::tesselate_test()
1129 {
1130 CL_OpenGLWindowDescription desc;
1131 desc.set_title("ClanLib clanDisplay 2.0 test program");
1132 desc.set_size(CL_Size(1024,768));
1133 desc.set_fullscreen(false);
1134
1135 CL_DisplayWindow window(desc);
1136
1137 HDC screen_dc = GetDC(0);
1138 BeginPath(screen_dc);
1139 HFONT font = CreateFont(400, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Comic Sans MS");
1140 HGDIOBJ old_font = SelectObject(screen_dc, font);
1141 int old_bkmode = SetBkMode(screen_dc, TRANSPARENT);
1142 TextOut(screen_dc, 10, 10, "4", 1);
1143 // TextOut(screen_dc, 10, 10, "ClanLib", 7);
1144 // TextOut(screen_dc, 10, 300, "123456", 6);
1145 SetBkMode(screen_dc, old_bkmode);
1146 SelectObject(screen_dc, old_font);
1147 EndPath(screen_dc);
1148 FlattenPath(screen_dc);
1149
1150 CL_OutlineTriangulator tesselator;
1151 // CL_Slot slot = tesselator.sig_triangle().connect(&on_tesselate_triangle);
1152
1153 int num_points = GetPath(screen_dc, 0, 0, 0);
1154 POINT *points = new POINT[num_points];
1155 BYTE *types = new BYTE[num_points];
1156 GetPath(screen_dc, points, types, num_points);
1157 POINT last_moveto = points[0];
1158 int last_moveto_index = 0;
1159 for (int i=0; i<num_points; i++)
1160 {
1161 if (types[i] == PT_MOVETO && i != 0)
1162 {
1163 tesselator.next_contour();
1164 last_moveto = points[i];
1165 last_moveto_index = i;
1166 }
1167 // If duplicate point. Skip it.
1168 // if (i < 1 || memcmp(points+i, points+i-1, sizeof(POINT)) != 0)
1169 tesselator.add_vertex(points[i].x, points[i].y, points+i);
1170
1171 if ((types[i] & PT_CLOSEFIGURE) == PT_CLOSEFIGURE)
1172 {
1173 // tesselator.add_vertex(last_moveto.x, last_moveto.y, points+last_moveto_index);
1174 tesselator.next_polygon();
1175 // break;
1176 }
1177 }
1178 tesselator.generate();
1179
1180 delete[] points;
1181 delete[] types;
1182
1183 int c = 0;
1184 while (CL_Keyboard::get_keycode(CL_KEY_ESCAPE) == false)
1185 {
1186 CL_Display::clear(CL_Color::black);
1187
1188 std::vector<Triangle>::size_type size_triangles, index_triangles;
1189 size_triangles = triangles.size();
1190 for (index_triangles = 0; index_triangles < size_triangles; index_triangles++)
1191 {
1192 Triangle &cur_triangle = triangles[index_triangles];
1193
1194 CL_Display::draw_line(
1195 cur_triangle.x[0], cur_triangle.y[0],
1196 cur_triangle.x[1], cur_triangle.y[1],
1197 CL_Color::grey);
1198
1199 CL_Display::draw_line(
1200 cur_triangle.x[1], cur_triangle.y[1],
1201 cur_triangle.x[2], cur_triangle.y[2],
1202 CL_Color::grey);
1203
1204 CL_Display::draw_line(
1205 cur_triangle.x[2], cur_triangle.y[2],
1206 cur_triangle.x[0], cur_triangle.y[0],
1207 CL_Color::grey);
1208 }
1209 /*
1210 Triangle &cur_triangle = triangles[c];
1211
1212 CL_Display::draw_line(
1213 cur_triangle.x[0], cur_triangle.y[0],
1214 cur_triangle.x[1], cur_triangle.y[1],
1215 CL_Color::yellow);
1216
1217 CL_Display::draw_line(
1218 cur_triangle.x[1], cur_triangle.y[1],
1219 cur_triangle.x[2], cur_triangle.y[2],
1220 CL_Color::yellow);
1221
1222 CL_Display::draw_line(
1223 cur_triangle.x[2], cur_triangle.y[2],
1224 cur_triangle.x[0], cur_triangle.y[0],
1225 CL_Color::yellow);
1226
1227 c++;
1228 if (c > size_triangles) c = 0;
1229 */
1230 CL_Display::flip();
1231 CL_System::keep_alive(10);
1232 }
1233 }
1234
1235 void Application::viewport_test()
1236 {
1237 /* CL_OpenGLWindowDescription desc;
1238 desc.set_title("ClanLib clanDisplay 2.0 test program");
1239 desc.set_size(CL_Size(640,480));
1240 desc.set_allow_resize(true);
1241 desc.set_fullscreen(false);
1242
1243 CL_DisplayWindow window(desc);
1244
1245 CL_Log::log("debug", "Size of viewport: %1 x %2", CL_Display::get_width(), CL_Display::get_height());
1246
1247 CL_PixelBuffer pb(101, 101, 101*4, CL_PixelFormat::rgba8888);
1248 pb.lock();
1249 unsigned int *pdata = (unsigned int *) pb.get_data();
1250 for (int i=0; i<101*101; i++) pdata[i] = 0x000000ff;
1251 int xx, yy;
1252 for (yy = 0; yy < 101; yy += 2)
1253 {
1254 for (xx = 0; xx < 101; xx++)
1255 {
1256 pdata[yy*101+xx] = 0xffffffff;
1257 }
1258 }
1259 for (xx = 0; xx < 101; xx += 2)
1260 {
1261 for (yy = 0; yy < 101; yy++)
1262 {
1263 pdata[yy*101+xx] = 0xffffffff;
1264 }
1265 }
1266 pb.unlock();
1267
1268 CL_Surface surf(&pb);
1269
1270 while (CL_Keyboard::get_keycode(CL_KEY_ESCAPE) == false)
1271 {
1272 CL_Display::clear(CL_Color::black);
1273
1274 for (int x = 0; x < CL_Display::get_width(); x+=2)
1275 {
1276 CL_Display::draw_line(x, 0, x, CL_Display::get_height(), CL_Color::white);
1277 }
1278
1279 for (int y = 0; y < CL_Display::get_height(); y+=2)
1280 {
1281 CL_Display::draw_line(0, y, CL_Display::get_width(), y, CL_Color::white);
1282 }
1283
1284 CL_Display::draw_line(CL_Display::get_width()-1, 0, CL_Display::get_width()-1, CL_Display::get_height()-1, CL_Color::blue);
1285 CL_Display::draw_line(0, CL_Display::get_height()-1, CL_Display::get_width()-1, CL_Display::get_height()-1, CL_Color::blue);
1286 CL_Display::draw_line(0, 0, CL_Display::get_width()-1, 0, CL_Color::blue);
1287 CL_Display::draw_line(0, 0, 0, CL_Display::get_height()-1, CL_Color::blue);
1288
1289 surf.draw((rand()%(CL_Display::get_width()/2))*2, (rand()%(CL_Display::get_height()/2))*2);
1290
1291 CL_Display::flip();
1292 CL_System::keep_alive(100);
1293 }
1294 */
1295 }