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 » Tue Aug 04, 2009 3:17 pm

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!
0 x
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: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Re: Ogre as an FLTK2 Widget

Post by sinbad » Thu Aug 06, 2009 5:23 pm

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)
0 x

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 » Thu Aug 13, 2009 1:59 am

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 >.<
0 x
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 » Mon Aug 17, 2009 1:53 am

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.
0 x
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
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe » Mon Aug 17, 2009 3:00 am

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
0 x
/* 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 » Tue Aug 18, 2009 1:23 am

Yep, sure have.
Thanks for the links again though. Always good to go back to the beginning to move forward. ;)
0 x
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 » Sat Aug 22, 2009 11:08 pm

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
BadPixelFormat.png
Bad Pixel Format?
BadPixelFormat.png (111.86 KiB) Viewed 3232 times
0 x
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 » Sun Aug 23, 2009 2:06 am

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...
0 x
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 » Mon Aug 24, 2009 1:11 am

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?
0 x
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 » Wed Sep 02, 2009 2:10 am

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! :)
0 x
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
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe » Wed Sep 02, 2009 2:28 am

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

Keep us updated. :wink:
0 x
/* 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 » Wed Sep 02, 2009 3:07 am

How rude of me, I forgot to include a screenshot!
Attachments
AetherOgreEditorPlugin.png
Working, with a settings tab!
AetherOgreEditorPlugin.png (86.93 KiB) Viewed 3187 times
0 x
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
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe » Sat May 29, 2010 2:44 am

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.
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

dermont
Orc Shaman
Posts: 772
Joined: Thu Dec 09, 2004 2:51 am
x 8

Re: Ogre as an FLTK2 Widget

Post by dermont » Wed Jun 09, 2010 11:39 am

@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.
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe » Wed Jun 09, 2010 11:49 am

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:
0 x
/* 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 » Thu Jul 15, 2010 8:04 pm

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!
0 x
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
Contact:

Re: Ogre as an FLTK2 Widget

Post by jacmoe » Fri Jul 30, 2010 12:29 pm

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.
0 x
/* 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 » Fri Jul 30, 2010 5:45 pm

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! :)
0 x
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