NOGDUS

Articles, Tutorials, and other things. => ClanLib Game Programming => Topic started by: Richard Marks on March 14, 2009, 10:04:03 AM



Title: Getting started with ClanLib - Part II
Post by: Richard Marks on March 14, 2009, 10:04:03 AM
Getting started with ClanLib - Part II

In this article I'm going to show you how to load and draw images on your newly created window.

I am going to assume that you have already read the first article (http://ccpssolutions.com/nogdusforums/index.php?topic=392.0), and will not re-post the code that is in it here.
I am just going to show you the changes to the code.

I duplicated the first article's project files in a new project directory, and then started editing.

First thing was to edit the comments :D
Code:
// Project: ClanLib Test Project #2 (CLTEST2)

and update the namespace
Code:
namespace CLTEST2

now do a search replace and change the class name from CLTest1Application to CLTest2Application.

after we create the main window, we add this code to give us a pointer to the graphics context of the window for drawing on:
Code:
// get the graphics context of the window
CL_GraphicContext* graphicsContext = mainWindow.get_gc();

and right after we add this code for loading our image:
Code:
// load the title screen image
CL_Surface title("data/graphics/title.png");

Now, in the main loop, right after we clear the screen, we draw our title screen image
Code:
// draw the title screen image on the graphics context
title.draw(0, 0, graphicsContext);

last change is the instance creation at the end:
Code:
// create the application instance
CLTEST2::CLTest2Application globalApplicationInstance;

Ok. thats it! After you build your project, you should see your image (don't forget to create one!)

Thanks for reading! 8)