LogoScene.h
Code: Select all
/*
Everything is declared and defined
for Logo scene as it is simple and small
and thus deemed pointless giving it an
implementation file
*/
#ifndef LOGO_H // header guard
#define LOGO_H
#include <irrlicht.h>
#include <irrKlang.h>
class LogoScene
{
protected:
//for sound declaration used in both methods
irrklang::ISound* snd;
//temp int for both methods
int introSceneCount;
public:
void createIntroScene()
{
device->setWindowCaption(L"Displaying company logo and playing music");
//play a sound, with params no loop and tracking enabled
snd = engine->play2D("THE SOUND FILE",false,false,true);
//create Logo Image
irr::gui::IGUIImage* img = env->addImage(driver->getTexture("COMPANY IMAGE")
,irr::core::position2d<irr::s32>(0,10));
//disable mouse visibillity
device->getCursorControl()->setVisible(false);
}
//used to check if the sound is finished [to be used in main render loop]
void checkIntroSceneFinishParams()
{
//used as a reference counter
/*
Wait for logo rendering/music
to finish and then call the menu state
*/
if(snd->isFinished() && introSceneCount == 0)
{
env->clear();
device->getCursorControl()->setVisible(true);
//Code for menu state here
//break loop condition so loop is executed 1 time
introSceneCount = 1;
}
}
}Logo;
#endif
main.cpp
Code: Select all
//Other includes
#include <iostream>
#include "LogoScene.h"
#pragma comment(lib, "Irrlicht.lib") //link with irrlicht.dll
#pragma comment(lib, "irrKlang.lib") // link with irrKlang.dll
//----remove console if desireable----
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
//********************main****************
int main()
{
std::cout<<"Initializing essentials...\n";
//create rendering device
device = irr::createDevice( irr::video::EDT_DIRECT3D9,
irr::core::dimension2d<irr::s32>(800, 600), 32, false ,true,false,0);
//check if rendering device created
if(!device)
{
std::cout<<"Could not create device"<<std::endl;
return false;
}
//create irrklang engine init
engine = irrklang::createIrrKlangDevice();
//check if engine device was initialized
if(!engine)
{
std::cout<<"Could not initialize IrrKlang device"<<std::endl;
return false;
}
//get driver
driver = device->getVideoDriver();
//check if driver was retrieved
if(!driver)
{
std::cout<<"Could not locate driver"<<std::endl;
return false;
}
//get scene manager
smgr = device->getSceneManager();
//check if smgr was retrieved
if(!smgr)
{
std::cout<<"Could not retrieve Scene Manager"<<std::endl;
return false;
}
//get GUI environment
env = device->getGUIEnvironment();
//check env was retrieved
if(!env)
{
std::cout<<"Could not get GUIEnvironment"<<std::endl;
return false;
}
std::cout<<"Everything initialized\n";
///////////////////////create logo screen//////////////////////
Logo.createIntroScene();
while(device->run() && driver)
{
//////////////check logo scene finish parameters///////////////////
Logo.checkIntroSceneFinishParams();
driver->beginScene(true, true, irr::video::SColor(255,120,120,120));
smgr->drawAll();
env->drawAll();
driver->endScene();
}
device->drop();
engine->drop();
return 0;
}