Ogre as an FLTK2 Widget

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Ogre as an FLTK2 Widget

Post by Xypher »

Hello all!
After some deep searching and experimenting with Ogre as an FLTK::Window (FLTK2) I got it working.
I'll be glad to share code if anyone wants, but at the moment i'm at work.

My issue is this...
The way Ogre is drawing to the window is through the externalWindowHandle parameter, using my precreated FLTK window as its receiver.
The ogre RenderWindow ALWAYS draws on top of the window, no matter when I update Ogre.

I've had a couple of unsuccessful ideas regarding this, as I need the WHOLE window, as well as the widget to receive window events (Like mouse entered, left, moved, etc. within my superclass of FLTK::Window's handle(int evt) method.)

Anyone have ideas as to how I might put a transparent rectangle over the ogre RenderWindow, or HIDE the renderwindow and simply use the writeContentsToMemory method in conjunction with fltk's draw functions (Which I'm already trying, but can't seem to hide the renderwindow...and thats including moving it offscreen, it segfaults.)

Much appreciated!
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Re: Ogre as an FLTK2 Widget

Post by sinbad »

I'm not really aware of how FLTK works, but your options include:
- rendering OGRE to an RGBA texture and applying that in FLTK as an alpha-blended surface (or vice versa)
- telling OGRE viewport not to clear the colour buffer, just the depth buffer (see Viewport::setClearEveryFrame)
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Thanks for the ideas, Sinbad!
Unfortunately none of them seem to place the Ogre rendering surface beneath the content of the window...
I'll be looking into it until I bleed! lol

When i tell it not to clear the color buffer it doesn't display anything in the ogre window (I have the drawing rect and the render window next to each other)
However, I CAN get fltk to spit out an image from the data written to memory, though its offset improperly, but only when i resize the window.
I'll be happy to figure out why it does it only when I resize the window for now...then i'll need to figure out the rest.

I'm exporting from ogre using A8R8G8B8, and drawing that data in FLTK with its ARGB32 setting:
ARGB32 32-bit words containing 0xaarrggbb

Is there perhaps a way to get mouse events over the rendering surface from ogre and sending them using a listener? Thats really the only issue i'm having >.<
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Even using a RenderTargetListener doesn't allow me to draw on top of the ogre surface...

I did have a thought, though. Is it possible to initialize ogre without a RenderWindow, using a RenderTexture instead?
This cursed surface is the bane of my existance at the moment, lol.
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe »

I am sure you've seen them, the FLTK articles in our Wiki, but here they are anyway:
http://www.ogre3d.org/wiki/index.php/Us ... _with_FLTK
http://www.ogre3d.org/wiki/index.php/Us ... FLTK_FLUID
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Yep, sure have.
Thanks for the links again though. Always good to go back to the beginning to move forward. ;)
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

I've made some progress. Using the "externalWindowHandle" rather than the "parentWindowHandle" parameter seems to help a bit. Ogre doesn't claim any window events as its own, at least.
Now I'm having a bit of an issue with pixel formats as I described before. I'll be trying a few things but my main question is...how large should the buffer be?

For those of you using FLTK2 and are curious what i'm doing in my superclass fltk::Window::draw():

Code: Select all

		unsigned int wW, wH, wCD;
		int wL, wT;

		mRW->update();
		fltk::Group::draw();


		mRW->getMetrics(wW, wH, wCD, wL, wT);

		unsigned char* pData = new unsigned char[wW * wH * wCD];
		Ogre::PixelBox* pb = new Ogre::PixelBox(wW, wH, 1, Ogre::PF_A8R8G8B8, pData);

		mRW->copyContentsToMemory(*pb);

		fltk::drawimage(reinterpret_cast<unsigned char*>(pb->data), fltk::ARGB32, *this);

		delete pb;
		delete pData;

I'm using (Width * Height * ColorDepth) to determine the size of the buffer, but it results in this:
Attachments
Bad Pixel Format?
Bad Pixel Format?
BadPixelFormat.png (111.86 KiB) Viewed 4220 times
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Apparently I had to set an offset of 1600 to fltk:

Code: Select all

		fltk::drawimage(pData, fltk::RGB32, *this, 1600); 
Had to incrementally add to the value to figure out what a good value was...
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Another update for any of you who are following this, and a question...

Everything is now working nearly perfectly. It turns out the 1600 offset is related to the width of the viewport, or pixelbox which is being used, so it ends up being width * 4.

My question is this...
When using Ogre::RenderWindow::writeContentsToMemory(), does the PixelBox you provide determine the target area to copy from the buffer, or is it only the resulting dimensions of the buffer?

The doxy doesn't say, and the mindset i'm in thinks that it determines the area from which it copies the frame buffer.
If not, how might I accomplish this? Is there an easy way to trim the buffer if this is the case?
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Nevermind, figured it out.
Apparently I was correct. :)

Everything is now working, save for a flicker on the window, which will simply require me to figure out how to update the whole window without redrawing Ogre3D. This will likely require some trickery on my part, as the base window updates its child widgets whenever it is drawn...hmmmz...

Thanks for all your help! :)
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe »

Well, you did all the helping yourself - but I'm glad to hear you've got it working. :)

Keep us updated. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

How rude of me, I forgot to include a screenshot!
Attachments
Working, with a settings tab!
Working, with a settings tab!
AetherOgreEditorPlugin.png (86.93 KiB) Viewed 4175 times
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe »

Hi Xypher

I just downloaded FLTK because I wanted to check out the most lightweight cross platform GUI I know of - I hope I didn't do anything foolish. :P

However, some help would be appreciated - maybe some of that code of yours?
I've got FLTK-2.0.

Would be nice to not have to start from bare scratch. :)

I'll update the Ogre Wiki when (if) it happens.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
dermont
Bugbear
Posts: 808
Joined: Thu Dec 09, 2004 2:51 am
x 42

Re: Ogre as an FLTK2 Widget

Post by dermont »

@jacmoe I don't know what the problems the original poster encountered with embedding Ogre and fltk but if I remember correctly it was straightforward on Linux at least and similar to Qt/wxWidgets, i.e. an "externalWindowHandle" / fltk::Window and a shared context "currentGLContext" / fltk::GlWindow.

I'll try and dig out an example if you need it.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe »

I'll get back to this. :)
It was a pain to compile in Windows, so I gave it up.
I'll probably try it in Linux later.
I'll let you know. :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Sorry for the (VERY) late reply Jacmoe, I had to abandon the project for a while due to a dead PC.
However I still have the source. There was a couple of modifications I had to make to the FLTK2 code to get it compiling correctly in windows (damned if i can remember what it was at the moment, but I think I backed up that wiki page...).
If you're looking to jump back onto this the original idea was to build a pluggable editor designed differently than most have been. Including the ability to load up a game as the frontend and dive into editing from within the game.
Its still kind of backburner, but the code shouldn't be too difficult to resurrect.
I'm still not so sure I was slapping the renderer on top correctly, either. It flickers because FLTK insists on refreshing the whole window, then the renderer has to redraw on top of it, which sounds normal, but it flickers!
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe »

I just compiled FLTK2 rev.7680 using VC10 - success. :)
FLTK looks like shit, but it's lightweight..
I'll probably fire up Tk as well and compare the two.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Xypher
Gremlin
Posts: 180
Joined: Tue Jun 29, 2004 1:35 am
Location: Richmond, IN; USA
Contact:

Re: Ogre as an FLTK2 Widget

Post by Xypher »

Good deal, not sure if i'll be of much help in this department any more, but if you like I can rip out what code I have and wiki it or something. If i'm not mistaken it'll be an aggrivating feat getting it working with FLTK2 without cairo as you'll likely need to do things from the inside out.

And just a side note, still hoping to be able to use Ogre on Android, I can't even get it to compile yet! :)
Ubuntu Studio 13.04 64-bit
GCC 4.8.1
Ogre3D 1.8.1
AMD Athlon FX 8120 @4Ghz
16Gb G.Skill Ripjaws (PC3-12800)
EVGA GeForce 560 Ti FTW

http://www.hellbatgames.com
Post Reply