Display "Hello World" Example
A very simple example using clanCore, clanApplication, clanDisplay and clanGL:
#include <ClanLib/core.h>
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
#include <ClanLib/application.h>
class DisplayApplication : public CL_ClanApplication
{
public:
int main(int argc, CL_String::char_type** argv);
};
// Create global application object:
// You MUST include this line or the application start-up will fail to
// locate your application object.
DisplayApplication app;
int DisplayApplication::main(int argc, CL_String::char_type** argv)
{
// Setup clanlib modules:
CL_SetupCore setup_core;
CL_SetupDisplay setup_display;
CL_SetupGL setup_gl;
// Create a window:
CL_DisplayWindow window(cl_text("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, cl_text("Tahoma"), 20);
// Loop until user hits escape:
while (!keyboard.get_keycode(CL_KEY_ESCAPE))
{
// Draw some text and lines:
gc.clear(CL_Colord::cadetblue);
gc.set_font(font);
CL_Draw::line(gc, 0, 0, 640, 480, CL_Colord::yellow);
gc.draw_text(10, 10, cl_text("Hello World!"), CL_Colord::lightseagreen);
// Make the stuff visible:
window.flip();
// Read messages from the windowing system message queue,
// if any are available:
if (CL_DisplayMessageQueue::has_messages())
CL_DisplayMessageQueue::process();
// Avoid using 100% CPU in the loop:
CL_System::sleep(10);
}
return 0;
}
To build this example with Visual C++:
- Create a new Win32 project.
- Add the source file to the project.
- Change the threading model to Multithreaded Debug (or just Multithreaded for release builds) in the project settings' C/C++ Code Generation section.
- Change the character set to Multi-Byte Character Set in the project settings General section, if you did not build the Unicode version of ClanLib.
