Locking FPS
Locking FPS
is there any way to lock the FPS?
if so, How?
Thanks,
catron
if so, How?
Thanks,
catron
ok i've impemented it, but it gives me:
im using Dev-cpp
Code: Select all
In function `int main()':
'class irr::video::IVideoDriver' has no member named 'getTimer'
'class irr::video::IVideoDriver' has no member named 'getTimer'
[Build Error] [mainmenu.o] Error 1
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
now it crashes as sonn as it loads.
mainmenu.cpp:
mainmenu.h:
mainmenu.cpp:
Code: Select all
#include "mainmenu.h"
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
" (d) Software Renderer\n (e) Apfelbaum Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_DIRECT3D8;break;
case 'c': driverType = video::EDT_OPENGL; break;
case 'd': driverType = video::EDT_SOFTWARE; break;
case 'e': driverType = video::EDT_SOFTWARE2;break;
case 'f': driverType = video::EDT_NULL; break;
default: return 1;
}
// create device and exit if creation failed
device = createDevice(driverType, core::dimension2d<s32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
/* The creation was successful, now we set the event receiver and
store pointers to the driver and to the gui environment. */
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
device->setWindowCaption(L"Game");
gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
ISoundEngine* engine = createIrrKlangDevice();
video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
scene::ISceneManager* smgr = device->getSceneManager();
IrrlichtDevice* videoDevice;
/*
We add three buttons. The first one closes the engine. The second
creates a window and the third opens a file open dialog. The third
parameter is the id of the button, with which we can easily identify
the button in the event receiver.
*/
env->addButton(rect<s32>(10, 10, 110, 60), 0, 101, L"Start Game");
env->addButton(rect<s32>(120, 10, 220, 60), 0, 103, L"Load Game");
env->addButton(rect<s32>(230, 10, 330, 60), 0, 101, L"Credits");
/*
To make the font a little bit nicer, we load an external font
and set it as new font in the skin. An at last, we create a
nice Irrlicht Engine logo in the top left corner.
*/
scene::ICameraSceneNode* camera =
smgr->addCameraSceneNodeFPS(0,100.0f,1200.0f);
camera->setPosition(core::vector3df(1900*2,255*2,3700*2));
camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
camera->setFarValue(12000.0f);
//background
video::ITexture* images = driver->getTexture("media/backdrop.bmp");
driver->makeColorKeyTexture(images, 0);
//loading background
video::ITexture* loading = driver->getTexture("media/loading.bmp");
driver->makeColorKeyTexture(loading, 0);
//bar (might not use)
video::ITexture* bar = driver->getTexture("media/bar.bmp");
driver->makeColorKeyTexture(bar, 1);
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"media/terrain-heightmap.bmp");
terrain->setScale(core::vector3df(40, 4.4f, 40));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
//terrain->setMaterialTexture(0, driver->getTexture("media/terrain-texture.jpg"));
//terrain->setMaterialTexture(1, driver->getTexture("media/detailmap3.jpg"));
//terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 20.0f);
/*
Now, we add a static text and a scrollbar, which modifies the
transparency of all gui elements. We set the maximum value of
the scrollbar to 255, because that's the maximal value for
a color value.
Then we create an other static text and a list box.
*/
//env->addStaticText(L"Transparent Control:", rect<s32>(150,20,350,40), true);
//IGUIScrollBar* scrollbar = env->addScrollBar(true, rect<s32>(150, 45, 350, 60), 0, 104);
//scrollbar->setMax(255);
// set scrollbar position to alpha value of an arbitrary element
//scrollbar->setPos(env->getSkin()->getColor((EGUI_DEFAULT_COLOR)0).getAlpha());
//env->addStaticText(L"Logging ListBox:", rect<s32>(50,80,250,100), true);
//listbox = env->addListBox(rect<s32>(50, 110, 250, 180));
//env->addEditBox(L"Editable Text", rect<s32>(350, 80, 550, 100));
/*
That's all, we only have to draw everything.
*/
engine->play2D("media/MAINTHEMEFORGAME.wav", true);
int x;
while(device->run() && driver)
if (device->isWindowActive())
{
start = videoDevice->getTimer()->getTime();
driver->beginScene(true, true, 0);
if(start1 == false) {
driver->draw2DImage(images, core::position2d<s32>(0,0),
core::rect<s32>(0,0,640,480), 0,
video::SColor(255,255,255,255), true);
} else {
driver->draw2DImage(loading, core::position2d<s32>(0,0),
core::rect<s32>(0,0,640,480), 0,
video::SColor(255,255,255,255), true);
}
if(start1 == false) {
env->drawAll();
} else {
smgr->drawAll();
device->getCursorControl()->setVisible(false);
}
driver->endScene();
}
end = videoDevice->getTimer()->getTime();
elapsed = end-start;
if(elapsed < frame)
{
#ifdef LINUX
usleep(1000* (frame - elapsed));
#endif
#ifdef WINDOWS
Sleep(frame - elapsed);
#endif
}
device->drop();
return 0;
}
Code: Select all
#include <irr/irrlicht.h>
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <irrKlang.h>
#include <windows.h>
using namespace irr;
using namespace audio;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "irrKlang.lib")
IrrlichtDevice *device = 0;
s32 cnt = 0;
IGUIListBox* listbox = 0;
bool start1;
u32 start, end, elapsed, frame = 10; // 10 millisec per frame = 100 hz
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
/*
If a scrollbar changed its scroll position, and it is 'our'
scrollbar (the one with id 104), then we change the
transparency of all gui elements. This is a very easy task:
There is a skin object, in which all color settings are stored.
We simply go through all colors stored in the skin and change
their alpha value.
*/
case EGET_SCROLL_BAR_CHANGED:
if (id == 104)
{
s32 pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
for (s32 i=0; i<EGDC_COUNT ; ++i)
{
SColor col = env->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
col.setAlpha(pos);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
}
}
break;
/*
If a button was clicked, it could be one of 'our'
three buttons. If it is the first, we shut down the engine.
If it is the second, we create a little window with some
text on it. We also add a string to the list box to log
what happened. And if it is the third button, we create
a file open dialog, and add also this as string to the list box.
That's all for the event receiver.
*/
case EGET_BUTTON_CLICKED:
if (id == 101)
{
start = true;
}
if (id == 102)
{
device->closeDevice();
return true;
}
if (id == 103)
{
listbox->addItem(L"File open");
env->addFileOpenDialog(L"Please choose a file.");
return true;
}
break;
}
}
return false;
}
};
it must compile, device must be of irr::IrrlichtDevice type, you have it at the beginning of code, and everywhere it says videoDevice replace with device and I don't see why it shouldn't compile. I guess you defined new variable named 'videoDevice' of irr::IrrlichtDevice type but you haven't initialized it, and than you get run-time error of course. I don't know what else could be a problem.