Doing several FLTK windows + the irrlicht one

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Doing several FLTK windows + the irrlicht one

Post by hendu »

Just thought I'd share the code for this experiment.

Simply put, FLTK does what it does much better than the builtin GUI possibilities. One can fairly easily pop FLTK windows and have them affect Irrlicht properties, as demonstrated.

Code: Select all

#include <irrlicht.h>
#include <cstdio>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;

void btn_pressed(Fl_Widget*, void *data) {

	ISceneNode *ptr = (ISceneNode *) data;

	vector3df pos = ptr->getPosition();
	pos.Y++;
	ptr->setPosition(pos);
}

int main() {
	IrrlichtDevice *device =
		createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
			false, false, false, 0);

	if (!device)
		return 1;

	IVideoDriver *driver = device->getVideoDriver();
	ISceneManager *smgr = device->getSceneManager();
	ITimer *timer = device->getTimer();

	IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
	if (!mesh) {
		device->drop();
		return 1;
	}
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

	if (node) {
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation(scene::EMAT_STAND);
		node->setMaterialTexture( 0, driver->getTexture("sydney.png") );
	}

	ISceneNode *cam = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

	int width, a;
	Fl::screen_xywh(a,a,width,a);
	// Yes, we could get screen width via Irrlicht too.

	Fl_Window *window = new Fl_Window(width-300,0,300,180,"Edit properties");
	Fl_Button *btn = new Fl_Button(20,40,260,100,"Go higher!");
	btn->user_data(cam);
	btn->callback(btn_pressed);
	window->end();
	window->show();

	int fps=-1, lastfps= -1;
	long long time, lasttime = timer->getTime(), timediff;
	wchar_t cfps[7];

	while(device->run()) {
		driver->beginScene(true, true, SColor(255,100,101,140));
		smgr->drawAll();
		driver->endScene();

		fps = driver->getFPS();
		if (fps != lastfps) {
			swprintf(cfps,7,L"%d",fps);
			cfps[6] = L'\0';
			// Why this and not stringw + whatever?
			// Think of it the next time you meditate.
			device->setWindowCaption(cfps);
			lastfps = fps;
		}

		Fl::check(); // This keeps our FLTK windows interactive.

		time = timer->getTime();
		timediff = 16-(time-lasttime);
		if (timediff > 0) device->sleep(timediff);
		// Yes, this is unrelated to FLTK.
		// I just prefer all my projects to be efficient.

		lasttime = timer->getTime();
	}

	device->drop();

	return 0;
}
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Post by hendu »

Image
yaten
Posts: 41
Joined: Tue Nov 16, 2010 4:57 pm
Location: /home/yaten on a server somewhere East of Asia
Contact:

Post by yaten »

wow nice sir hendu! now we have wx+irrlicht and FLTK+irrlicht, lots of options ^_^ thanks for sharing sir.

EDIT:
some info about FLTK:
FLTK (pronounced "fulltick") is a cross-platform C++ GUI toolkit for UNIX®/Linux® (X11), Microsoft® Windows®, and MacOS® X. FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation.
FLTK website
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yaten wrote:now we have wx+irrlicht and FLTK+irrlicht
we have it already for a long time... :lol:
just check out my homepage and you'll find my HDC-Widget for FLTK(2) !!! ;)
with it it's possible to integrate an Irrlicht screen in any FLTK widget, with all FLTK features, like resizing... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
yaten
Posts: 41
Joined: Tue Nov 16, 2010 4:57 pm
Location: /home/yaten on a server somewhere East of Asia
Contact:

Post by yaten »

Acki wrote:
yaten wrote:now we have wx+irrlicht and FLTK+irrlicht
we have it already for a long time... :lol:
just check out my homepage and you'll find my HDC-Widget for FLTK(2) !!! ;)
with it it's possible to integrate an Irrlicht screen in any FLTK widget, with all FLTK features, like resizing... ;)
oh sowee ^_^ i didn't know there was irrlicht+FLTK already, I'm just new to irrlicht myself ehehe. Now at least we have 2 references for irrlicht+FLTK now ^_^ more reference, more chance of understanding it ^_^ thanks for pointing it out sir acki ^_^
Post Reply