Tutorial 01 Installing

From IndieLib
Jump to: navigation, search

Welcome to the first IndieLib Tutorial. In this tutorial you will learn how to create your first application using IndieLib from the very beginning.

Contents

Things you need before starting

If you haven't done it yet, you should read the FAQ before anything.

You just need a programming environment to work with Indielib, for example you can use Visual C++ 2012 Express Edition, this is a programming environment for c++ that you can download for free on Windows. If you use Mac you will be using XCode and over Linux only GNU tools are required, use the editor of your choice.

The last thing you need, of course, is the last Indielib SDK that includes all the tutorials files and engine binaries and documentation.

Win downloads:

Mac downloads:

Linux downloads:

Indielib SDK:


The folder tree of the SDK is as follows:

  • docs
  • Doxygen
  • html
  • tutorials
  • win/mac/linux - Project files for every platform, depending on download
  • Project files for platform, to build tutorials yourself
  • resources - assets used by test and tutorial apps
  • common
  • include IndieLib includes, to be referenced by your code
  • bin
-win/mac/linux - pre-built library for your use :) And pre-built tutorial apps for you to see how engine works

Start hacking with Indielib the easy way

Just download the SDK files, then go to tutorial folder (IndieLib_SDK\tutorials\win) and open the Visual Studio Solution.
Choose tutorial 01_Installing, by right-clicking on it and 'Set as Startup Project'
Build and run!
Just download the SDK files, then go to tutorial folder (IndieLib_SDK\tutorials\mac) and open the XCode workspace.
Select the target 01_Installing, and run on XCode


That's all, you can jump directly to next tutorial, for starting drawing some amazing graphics. Go to the next tutorial, please.

Using Indielib with your own project

In the following sections you will learn how to create an IndieLib project from the beginning using Visual Studio 2012. The process is really similar in OSX, a bit more different for Linux.
If you want to see examples of every platform, you can check the sources here Feel free to ask and to tamper with the test projects in any platform!

Visual Studio 2012: Creating the Project

Once you have downloaded the files of the previous section you are ready for creating your first project.

Well done, you have created your first Visual C++ 2012 Express Edition project. Now we have to create one file: Main.cpp. And we have to include a class (CIndieLib) that will help us to initialize the engine.

Very good. At this point you have created a VC++ 2012 project and included some files. Now we have to prepare the project in order it links with IndieLib.

And that's all. You can click on "File>Save All" in order to save your project. And you are ready now for writting your first IndieLib application.

Writing your first IndieLib application

IndieLib Initialization

The initialization of IndieLib is quite easy, but you need to know a little of C++ and Object Oriented Programming.

For all the tutorials we will use the same initialization class that is in "CIndieLib.cpp" and "CIndieLib.h" files. This is a singleton class, that means that you can use it globally from all the classes of your game and that there will be always only one instance of this class.


Here it is the code of the important methods:

/*
==================
Init singleton
==================
*/
CIndieLib* CIndieLib::pinstance = 0;// initialize pointer
CIndieLib* CIndieLib::Instance () 
{
	if (pinstance == 0)  // is it the first call?
	{  
		pinstance = new CIndieLib; // create sole instance
	}
	return pinstance; // address of sole instance
}
 
 
/*
==================
Init IndieLib
==================
*/
bool CIndieLib::init() {
	// IndieLib Initialization, a debug.log file will be created.
	IndieLib::init(IND_DEBUG_MODE);
 
	_input               =   new     IND_Input;
	_render              =   new     IND_Render;
	_imageManager        =   new     IND_ImageManager;
	_surfaceManager      =   new     IND_SurfaceManager;
	_animationManager    =   new     IND_AnimationManager;
	_fontManager         =   new     IND_FontManager;
	_entity2dManager     =   new     IND_Entity2dManager;
	_math                =   new     IND_Math;
 
	IND_WindowProperties props ("IndieLib", 800, 600, 32, 0, 0, 1);
	_window = _render        ->initRenderAndWindow(props);                                 
	if(!_window)                                                                 return 0;
	if (!_imageManager       ->init())                                           return 0;
	if (!_surfaceManager     ->init(_imageManager, _render))                     return 0;
	if (!_animationManager   ->init(_imageManager, _surfaceManager))             return 0;
	if (!_fontManager        ->init(_imageManager, _surfaceManager))             return 0;
	if (!_entity2dManager    ->init(_render))                                    return 0;
	if (!_input              ->init(_render))                                    return 0;
	if (!_math               ->init())                                           return 0;
 
	return 1;
}
 
 
/*
==================
Free Indielib managers
==================
*/
void CIndieLib::end() {
	// ----- Freeing objects -----
 
	_math                ->end();
	_input               ->end();
	_entity2dManager     ->end();
	_fontManager         ->end();
	_animationManager    ->end();
	_surfaceManager      ->end();
	_imageManager        ->end();
	_render              ->end();
 
	DISPOSE(_math);
	DISPOSE(_input);
	DISPOSE(_entity2dManager);
	DISPOSE(_fontManager);
	DISPOSE(_animationManager);
	DISPOSE(_surfaceManager);
    	DISPOSE(_imageManager);
	DISPOSE(_render);
 
	IndieLib::end();
 
    DISPOSE(_pinstance);
}

Let's explain this methods.

In order to initialize the engine, you need to use the init() method. IND_DEBUG_MODE tells the engine that this is not the final release of our application. In debug mode a "debug.log" file with information about the execution of the IndieLib will be created in the root of your application. This debug file can be very useful because it will inform you about possible errors about initialization, loading / saving resources, etc. When your IndieLib application will be ready for release, use IND_RELEASE_MODE instead.

// IndieLib Initialization in Debug Mode
IndieLib::init(IND_DEBUG_MODE);

After this line, all the managers are created and initialized. Changing the initialization line of the IND_Window object, you can change the size and aspect of the application window. The parameters are: window title, width, height, bpp, vsync, fullscreen. For having full color quality use 32 bits, but you can also chose 16. If "vsync" is equal to "true", the vertical synchronization will be activated. If "fullscreen" is equal to "true", then the application window will be full-screen.

In this line, we create a 800x600 non fullscreen window, with no title text and vsync deactivated using 32 bpp.

IND_WindowProperties props ("IndieLib", 800, 600, 32, 0, 0, 1);
_window = _render->initRenderAndWindow(props);

The rest of the sourcecode it's easy to understand. We have an End() method that destroys all the managers and frees the memory. And we also have the variable members of the class, that are the IndieLib Managers that we are going to use for developing our application.

You could reimplement CIndielib or not use it at all in your project. The API in the library are the managers contained by CIndielib. We included this class to have all access in one part of your code, but it can be changed as needed.

Main Loop

So, everything it's ready in order to create our game :). We will just create a IndieLib application that shows a grey window (nothing else!). You will be able to exit by clicking on "ESC" key or by closing the window. So, double click in your previously add "Main.cpp" file in your project and copy this source code (you can also download it from here):

/*****************************************************************************************
/* Desc: Tutorial a) 01 Installing
/*****************************************************************************************/
 
#include "CIndieLib.h"
 
/*
==================
Main
==================
*/
int IndieLib()		
{
	// ----- IndieLib intialization -----
 
	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;	
 
	// ----- Main Loop -----
 
	while (!mI->_input->onKeyPress (IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input Update ----
 
		mI->_input->update();
 
		// -------- Render -------
 
		mI->_render->clearViewPort(60, 60, 60);
		mI->_render->beginScene();
		mI->_render->endScene();
	}
 
	// ----- Indielib End -----
 
	mI->end();
 
	return 0;
}

Let's explain the source code

It seems easy to understand, isn't it? The first important line is the calling to the initialization method of the class we talked about in the previous section. This will initialize the IndieLib engine. For getting the pointer to our singleton IndieLib class, we use the method Instance(). You can do this from each class in wich you want to use IndieLib.

CIndieLib *mI = CIndieLib::instance();
if (!mI->init()) return 0;

After that, we have the game loop. The source code inside the while will be running until you press IND_ESCAPE (esc key) or the windows is closed. Both methods are given by the Input class that we will study later in another tutorial.

while (!mI->_input->onKeyPress (IND_ESCAPE) && !mI->_input->quit())

Inside the loop, we call to several importat methods:

mI->_input->update();
mI->_render->clearViewPort(60, 60, 60);
mI->_render->beginScene();
mI->_render->endScene();

Finally, after the loop, we call to our end() method in order to free all the memory used.

mI->end ();

Compiling and executing

So, quite everything it's ready for running your first IndieLib application. You only have to do three steps more:

You now are ready to start drawing some stuff. Go to the next tutorial, please.

Template:Category Tutorials

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox