<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Display "Hello World" Example - ClanLib SDK</title> <link rel="stylesheet" media="screen" type="text/css" href="clanlib.css"/> <link rel="icon" href="gfx/favicon.png" type="image/png"/> </head> <body> <div id="content"> <h1><a href="."><img src="gfx/clanlib.png" alt="ClanLib SDK" /></a></h1> <!-- <div style="float: right;"> <a href="download.html">Download</a> : <a href="docs.html">Documentation</a> : <a href="development.html">Development</a> : <a href="donations.html">Donations</a> : <a href="http://www.rtsoft.com/clanlib">Forum</a> : <a href="contributions.html">Contributions</a> </div> --> <h2> <img src="gfx/overview.png"/>Display "Hello World" Example </h2> <p>A very simple example using clanCore, clanApplication, clanDisplay and clanGL:</p> <pre> #include <ClanLib/core.h> #include <ClanLib/display.h> #include <ClanLib/gl.h> #include <ClanLib/application.h> class DisplayProgram { public: static int main(const std::vector<CL_String> &args); }; // Create global application object: // You MUST include this line or the application start-up will fail to // locate your application object. CL_ClanApplication app(&DisplayProgram::main); int DisplayProgram::main(const std::vector<CL_String> &args) { // Setup clanlib modules: CL_SetupCore setup_core; CL_SetupDisplay setup_display; CL_SetupGL setup_gl; try { // Create a window: CL_DisplayWindow window("Hello World", 640, 480); // Retrieve some commonly used objects: CL_GraphicContext gc = window.get_gc(); CL_InputDevice keyboard = window.get_ic().get_keyboard(); CL_Font font(gc, "Tahoma", 30); // Loop until user hits escape: while (!keyboard.get_keycode(CL_KEY_ESCAPE)) { // Draw some text and lines: gc.clear(CL_Colorf::cadetblue); CL_Draw::line(gc, 0, 110, 640, 110, CL_Colorf::yellow); font.draw_text(gc, 100, 100, "Hello World!", CL_Colorf::lightseagreen); // Make the stuff visible: window.flip(); // Read messages from the windowing system message queue, // if any are available: CL_KeepAlive::process(); // Avoid using 100% CPU in the loop: CL_System::sleep(10); } } catch(CL_Exception &exception) { // Create a console window for text-output if not available CL_ConsoleWindow console("Console", 80, 160); CL_Console::write_line("Exception caught: " + exception.get_message_and_stack_trace()); console.display_close_message(); return -1; } return 0; } </pre> <p>To build this example with Visual C++:</p> <ol> <li>Create a new Win32 project.</li> <li>Add the source file to the project.</li> <li>Change the threading model to <i>Multithreaded Debug</i> (or just <i>Multithreaded</i> for release builds) in the project settings' C/C++ Code Generation section.</li> <li>Change the character set to <i>Multi-Byte Character Set</i> in the project settings General section, if you did not build the Unicode version of ClanLib.</li> </ol> </div> </body> </html>