Delgine 3D Tools & Content DeleD Community Edition
Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Loading X Files Into Irrlicht

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Tutorials
View previous topic :: View next topic  
Author Message
EricTheAnteater
Member


Joined: 10 Feb 2005
Posts: 8

PostPosted: Thu Apr 07, 2005 7:34 pm    Post subject: Loading X Files Into Irrlicht Reply with quote

This shows how to load (DeleD) X Files (not the TV show :D ) into Irrlicht (although .dmf is better in most situations). It also shows how to setup a first level.
This is in the C++ version of Irrlicht:
If you use any of this code, give "Eric the Anteater" credit in the Special thanks or Programming
//////////INCLUDE//////////////////////////////////////////////////////////////
//We need to include the basics: stdio for I/O, Irrlicht for gfx, windows for windows, math for, umm, math, and MMsystem for sound.
#include <stdio.h>
#include <irrlicht.h>
#include <windows.h>
#include <math.h>
#include <mmsystem.h>

///////NAMESPACES//////////////////////////////////////////////////////////////
//Standard Irrlicht
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

///////////////////DEFINE INT VALUES///////////////////////////////////////////
//Some values: X Resolution/Y Res, internal 'switch', and a value for controling the title.
int resxset = 640;
int resyset = 480;
int globalswitch = 0;
int lvlstrt = 0;


///////////////////DEFINE FUNCTIONS////////////////////////////////////////////
/// None yet

/////////SET SOME POINTERS FOR WINDOW POSITION AND DEVICE//////////////////////
//Pointers because events happen before the main loop
IrrlichtDevice *deviceIrr = 0;
s32 cnt = 0;


/////////////////EVENTS////////////////////////////////////////////////////////
// Events for the title [screen].
class MenuEventR : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* guienv = deviceIrr->getGUIEnvironment();
switch (event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == 0000000004)
{
if (globalswitch == 0)
{
// No load... YET.
}
}
if (id == 0000000003)
{
if (globalswitch == 0)
{
IGUIWindow *window1 = guienv->addWindow(rect<s32>(cnt+200,cnt+250,cnt+400,cnt+400),false,L"HELP");
guienv->addStaticText(L"MyGame\n\nThis software is based in part on the work of the Independent JPEG Group.\n\nProgrammer........Eric Anteater\nSpecial Thanks....Guest",rect<s32>(20,25,180,130),1,1,window1);
JPEG group license agreement states that you need to say you used IJG code.
}
}
if (id == 0000000002)
{
if (globalswitch == 0)
{
globalswitch = 1;
}
}
if (id == 0000000001)
{
if (globalswitch == 0)
{
//Quit
deviceIrr->closeDevice();
return true;
}
}
break;
}
}
return false;
}
};




///MAIN////////////////////////////////////////////////////////////////////////
main()
{

///////////////////////////////CONSOLE/////////////////////////////////////////
//Put here for the heck of it. May use it later.
system ("pause");

////////////////START ENGINE///////////////////////////////////////////////////
deviceIrr =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(resxset, resyset), 32, true, true, true,0);
//Music. Better than some sound libs because it runs both RAW and MIDI formats.
mciSendString("play media/mid1.mid",NULL,0,NULL);

//////SET WINDOW CAPTION AND SET POINTERS//////////////////////////////////////
//Read the Irrlicht tutorials to understand this.
deviceIrr->setWindowCaption(L"GAME");
IVideoDriver* driver = deviceIrr->getVideoDriver();
ISceneManager* smgr = deviceIrr->getSceneManager();
IGUIEnvironment* guienv = deviceIrr->getGUIEnvironment();



///////////EVENT RECEIVER//////////////////////////////////////////////////////
//And this:
MenuEventR receiver1;
deviceIrr->setEventReceiver(&receiver1);

///////////////LOAD PK3 FILEs//////////////////////////////////////////////////
//Images and code
deviceIrr->getFileSystem()->addZipFileArchive("pak1.pk3");

////LOAD LEVELS////////////////////////////////////////////////////////////////
//This is the whole point of this post:
scene::IAnimatedMesh* level1mesh = smgr->getMesh("media/level1.x");
//DON'T PUT YOUR X FILE IN A PK3/ZIP! IT MESSES IT UP! THE TEXTURES WON'T WORK
scene::ISceneNode* level1node = 0;
//Collision
scene::ITriangleSelector* triselector1 = 0;
if (level1mesh)
{
level1node = smgr->addOctTreeSceneNode(level1mesh->getMesh(0));
level1node->setMaterialFlag(EMF_LIGHTING, false);
triselector1 = smgr->createOctTreeTriangleSelector(level1mesh->getMesh(0),level1node, 128);
level1node->setTriangleSelector(triselector1);
}


////////////////////////LOAD TEXTURES//////////////////////////////////////////
video:: ITexture* ericlogo1 = driver->getTexture("blah.bmp");

///////////////////ADD GUI BUTTONS/////////////////////////////////////////////
guienv->addStaticText (L"DEVELOPED BY ", rect<int>(0,2,195,12), false);
guienv->addButton (rect<s32>(160,420,240,445),0,0000000004,L"LOAD");
guienv->addButton (rect<s32>(400,390,480,415),0,0000000001,L"QUIT");
guienv->addButton (rect<s32>(160,390,240,415),0,0000000002,L"START");
guienv->addButton (rect<s32>(400,420,480,445),0,0000000003,L"ABOUT");
///GAMEPLAY////////////////////////////////////////////////////////////////////
///Not a very fun game yet:)

////////////DO EVERYTHING//////////////////////////////////////////////////////
while(deviceIrr->run())
{
driver->beginScene(true, true, SColor(0,255,255,255));

if (globalswitch == 0)
{
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

driver->draw2DImage(ericlogo1, core::position2d<s32>(0,0),
core::rect<s32>(0, 0, 640, 480), 0,
video::SColor(1, 255, 255, 255), true);
}
if (globalswitch == 1)
{
if (lvlstrt == 0)
{
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
//U need to see the level!
scene::ICameraSceneNode* camera1 =
smgr->addCameraSceneNodeFPS();
scene::ISceneNodeAnimator* camanim = smgr->createCollisionResponseAnimator(
triselector1, camera1, core::vector3df(30,50,30),
core::vector3df(0,-5,0),core::vector3df(0,60,0));
camera1->addAnimator(camanim);
lvlstrt = 1;
}
}
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
deviceIrr->drop();
return 0;
}

///////////////////END/////////////////////////////////////////////////////////

By the way, don't forget to make the project a 'Console Win32'
Created on DevC++.
Back to top
View user's profile Send private message
Daaark
DeleD PRO user


Joined: 01 Sep 2004
Posts: 2696
Location: Ottawa, Canada

PostPosted: Thu Apr 07, 2005 10:59 pm    Post subject: Reply with quote

the code tags would preserve your code formatting.
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    DeleD Community Edition Forum Index -> DeleD Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum