| 1 |
#include <ClanLib/application.h> |
| 2 |
#include <ClanLib/core.h> |
| 3 |
#include <ClanLib/display.h> |
| 4 |
#include <ClanLib/gl.h> |
| 5 |
|
| 6 |
///////////////////////////////////////////////////////////////////////////// |
| 7 |
// Application class |
| 8 |
|
| 9 |
class Application : public CL_ClanApplication |
| 10 |
{ |
| 11 |
public: |
| 12 |
int main(int argc, char** argv); |
| 13 |
} app; |
| 14 |
|
| 15 |
///////////////////////////////////////////////////////////////////////////// |
| 16 |
// Application main entry point: |
| 17 |
|
| 18 |
int Application::main(int argc, char** argv) |
| 19 |
{ |
| 20 |
CL_ConsoleWindow debug_console("Debug console"); |
| 21 |
debug_console.redirect_stdio(); |
| 22 |
|
| 23 |
try |
| 24 |
{ |
| 25 |
CL_SetupCore::init(); |
| 26 |
CL_SetupDisplay::init(); |
| 27 |
CL_SetupGL::init(); |
| 28 |
|
| 29 |
{ |
| 30 |
CL_DisplayWindow window("ClanLib Primitives Test", 320, 200, true); |
| 31 |
|
| 32 |
CL_Surface surface("images/primitives.png"); |
| 33 |
|
| 34 |
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 35 |
{ |
| 36 |
CL_Display::clear(); |
| 37 |
|
| 38 |
if(!CL_Keyboard::get_keycode(CL_KEY_SPACE)) |
| 39 |
surface.draw(); |
| 40 |
else |
| 41 |
{ |
| 42 |
CL_Display::draw_rect(CL_Rect(0, 0, 320, 200), CL_Color::white); |
| 43 |
|
| 44 |
CL_Display::draw_pixel(1, 1, CL_Color::red); |
| 45 |
CL_Display::draw_pixel(3, 3, CL_Color::red); |
| 46 |
CL_Display::draw_pixel(1, 198, CL_Color::red); |
| 47 |
CL_Display::draw_pixel(3, 196, CL_Color::red); |
| 48 |
CL_Display::draw_pixel(318, 1, CL_Color::red); |
| 49 |
CL_Display::draw_pixel(316, 3, CL_Color::red); |
| 50 |
CL_Display::draw_pixel(318, 198, CL_Color::red); |
| 51 |
CL_Display::draw_pixel(316, 196, CL_Color::red); |
| 52 |
|
| 53 |
CL_Display::draw_line(2, 2, 2, 198, CL_Color::yellow); |
| 54 |
CL_Display::draw_line(4, 4, 316, 4, CL_Color::yellow); |
| 55 |
CL_Display::draw_line(4, 195, 316, 195, CL_Color::yellow); |
| 56 |
CL_Display::draw_line(317, 2, 317, 198, CL_Color::yellow); |
| 57 |
|
| 58 |
CL_Display::fill_rect(CL_Rect(5, 5, 15, 15), CL_Color::blue); |
| 59 |
} |
| 60 |
|
| 61 |
CL_Display::flip(); |
| 62 |
CL_System::keep_alive(10); |
| 63 |
} |
| 64 |
|
| 65 |
while(CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 66 |
CL_System::keep_alive(10); |
| 67 |
} |
| 68 |
|
| 69 |
{ |
| 70 |
CL_DisplayWindow window("ClanLib Primitives Test", 640, 480, false); |
| 71 |
|
| 72 |
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 73 |
{ |
| 74 |
CL_Display::clear(); |
| 75 |
|
| 76 |
for(int y=0; y<480; ++y) |
| 77 |
for(int x=0; x<640; x+=4) |
| 78 |
CL_Display::draw_line(x, y, x + 2, y, CL_Color::white); |
| 79 |
|
| 80 |
CL_Display::flip(); |
| 81 |
CL_System::keep_alive(10); |
| 82 |
} |
| 83 |
|
| 84 |
while(CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 85 |
CL_System::keep_alive(10); |
| 86 |
} |
| 87 |
|
| 88 |
{ |
| 89 |
CL_DisplayWindow window("ClanLib Primitives Test", 480, 480, false); |
| 90 |
|
| 91 |
while(!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) |
| 92 |
{ |
| 93 |
CL_Display::clear(); |
| 94 |
|
| 95 |
for(int y=0; y<=480; ++y) |
| 96 |
CL_Display::draw_rect(CL_Rect(0, 0, y, y), CL_Color::white); |
| 97 |
|
| 98 |
CL_Display::flip(); |
| 99 |
CL_System::keep_alive(10); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
CL_SetupGL::deinit(); |
| 104 |
CL_SetupDisplay::deinit(); |
| 105 |
CL_SetupCore::deinit(); |
| 106 |
} |
| 107 |
catch (CL_Error error) |
| 108 |
{ |
| 109 |
std::cout << "Uncaught error: " << error.message.c_str() << std::endl; |
| 110 |
debug_console.display_close_message(); |
| 111 |
} |
| 112 |
|
| 113 |
return 0; |
| 114 |
} |