OGRE within typical GUI Window
-
- Gnoblar
- Posts: 8
- Joined: Fri Feb 25, 2005 12:46 am
- Location: Avila Beach, CA
OGRE within typical GUI Window
Could someone please refer me to a past discussion or sample code regarding the use of OGRE embedded in a parent window (similar to OgreMeshViewer)?
Since I'm rather new to OGRE, and computer graphics in general, I apologize if this quest seems silly!
Thanks ~ Jason
Since I'm rather new to OGRE, and computer graphics in general, I apologize if this quest seems silly!
Thanks ~ Jason
-
- Platinum Sponsor
- Posts: 1186
- Joined: Sat Apr 17, 2004 2:49 am
- x 3
Ogre can indeed be used just fine inside a "normal" windows program. I personally have successfully used Ogre in MFC, wxWidgets and a .NET Windows Forms application. MeshViewer uses WTL. There is a tutorial for ogre called something like "Using Ogre with wxWidgets". I've been working on one for MFC, but who knows when or if I'll even finish it.
As a side note you say your new to "graphics programming". If you've never worked with any graphics programming of any kind that I've got to recomend you spend some time with 2d graphics.
John
As a side note you say your new to "graphics programming". If you've never worked with any graphics programming of any kind that I've got to recomend you spend some time with 2d graphics.
John
-
- Gnoblar
- Posts: 8
- Joined: Fri Feb 25, 2005 12:46 am
- Location: Avila Beach, CA
Thanks John -
Like scores of other "I used to write app server code in Java" programmers, I've decided to take a leap towards sound and graphics.
Current reading material includes "3D Math Primer for Graphics and Game Development" soon to be followed by the classic "Computer Graphics: Principles and Practice in C". Knowing that the latter is somewhat out-of-date, once I feel initiated, "Real-Time Rendering (2nd Edition)" looks like a great source of info.
Re: 2D frameworks / platforms, any suggestions? SDL grabbed my attention, but... then... there... was... OGRE <eyes widen noticeably>
All bets were off at that moment.
Thanks again for your help and advice.
Cheers ~ Jason
Like scores of other "I used to write app server code in Java" programmers, I've decided to take a leap towards sound and graphics.
Current reading material includes "3D Math Primer for Graphics and Game Development" soon to be followed by the classic "Computer Graphics: Principles and Practice in C". Knowing that the latter is somewhat out-of-date, once I feel initiated, "Real-Time Rendering (2nd Edition)" looks like a great source of info.
Re: 2D frameworks / platforms, any suggestions? SDL grabbed my attention, but... then... there... was... OGRE <eyes widen noticeably>

Thanks again for your help and advice.
Cheers ~ Jason
-
- Kobold
- Posts: 35
- Joined: Wed Mar 10, 2004 12:10 pm
- Location: Bielefeld, Germany
-
- Platinum Sponsor
- Posts: 1186
- Joined: Sat Apr 17, 2004 2:49 am
- x 3
@apuhjee
As far as 2d engines go, www.allegro.cc is the only one I've used extensively. Its easy to learn and should make a fine primer for Ogre.
@DarkSun
No, I didn't use any kind of wrapper. I was actually suprised that it worked, considering that Ogre's classes aren't managed. I did run into scores of problems though, mainly trying to get std::string and System::String to play nice together.
As far as 2d engines go, www.allegro.cc is the only one I've used extensively. Its easy to learn and should make a fine primer for Ogre.
@DarkSun
No, I didn't use any kind of wrapper. I was actually suprised that it worked, considering that Ogre's classes aren't managed. I did run into scores of problems though, mainly trying to get std::string and System::String to play nice together.
-
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
@DarkSun:
If you want a .net version of Ogre, look into Axiom - this is a superb project!
If you want a .net version of Ogre, look into Axiom - this is a superb project!

/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
-
- Goblin
- Posts: 282
- Joined: Tue Jan 04, 2005 6:56 pm
- Location: The Netherlands
THIS POST WAS EDITED, READ BELOW
I've just been spending a few hours on it, but here's the code:
I'm using SDL, where SDL created the window for me, here's the code for that (including getWindowHandle()):
There's plenty of documentation about this subject, it's just that none of them mentions the crucial line "mWindow->setActive(true)" 
Maybe someone could edit http://grotsnik.ogre3d.org/wiki/index.php/AzathothNotes where this line is forgotten (I have to be logged in, but haven't looked into that yet
)
EDIT:
(Please note, my purpose for this code was never to run inside a window, but rather to get input using SDL. The above code can still be used to run Ogre inside a window)
I thought I had tested this more then enough, but it turns out OpenGL fullscreen didn't work and there was a bit of a problem with DirectX9 at the highest resolution (1024x768 for my laptop). I only ever test things in windowed 800x600 mode because it's easier for debugging, sorry people
The OpenGL fullscreen problem can be overcome, but the SDL initialization code needs to be changed. That means you have to dynamically check if OpenGL or D3D9 is being used, and whether it's fullscreen or not. I didn't want to do that and there was still the D3D9 problem to cope with.
I've switched to the code Motorsport uses in their project, which at first didn't give me input using D3D9 (I'm pretty sure anyway), but now works fine. I don't know what changed though, so for all I know a reboot could've fixed it last time I checked. I did make some changes to allow the window to be moved (in windowed mode). Here's the new code:
If you need anything else, let me know 
I've just been spending a few hours on it, but here's the code:
Code: Select all
NameValuePairList miscParams;
#ifdef WIN32
HWND hWnd = mSDL->getWindowHandle();
miscParams["externalWindowHandle"] = StringConverter::toString((size_t)hWnd);
#endif
mRoot->initialise(false);
mWindow = mRoot->createRenderWindow("OpenFRAG", 640, 480, false, &miscParams);
mWindow->setActive(true);
Code: Select all
void SDLEngine::initialise()
{
// You might want an #ifdef WIN32 here too... I'm not done yet :)
SetEnvironmentVariable("SDL_VIDEODRIVER", "directx");
_putenv("SDL_VIDEODRIVER=directx");
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
{
mLog->writeLog("Couldn't initialize SDL\n");
mLog->writeLog(SDL_GetError());
}
if(SDL_WasInit(SDL_INIT_VIDEO) != 0)
std::cout<<"\nSDL_VIDEO enabled \n";
SDL_SetVideoMode(800, 600, 16, 0); // Fullscreen = 0, always. Not
// sure if the BPP matter here,
// though
}
#ifdef WIN32
HWND SDLEngine::getWindowHandle()
{
// Read http://www.libsdl.org/cgi/docwiki.cgi/FAQ_20SDL_20and_20Direct3D?action=highlight&value=directx
// for an explanation on why this variable is
// static (or rather, an excuse :P).
static SDL_SysWMinfo pInfo;
SDL_VERSION(&pInfo.version);
SDL_GetWMInfo(&pInfo);
return pInfo.window;
}
#endif

Maybe someone could edit http://grotsnik.ogre3d.org/wiki/index.php/AzathothNotes where this line is forgotten (I have to be logged in, but haven't looked into that yet

EDIT:
(Please note, my purpose for this code was never to run inside a window, but rather to get input using SDL. The above code can still be used to run Ogre inside a window)
I thought I had tested this more then enough, but it turns out OpenGL fullscreen didn't work and there was a bit of a problem with DirectX9 at the highest resolution (1024x768 for my laptop). I only ever test things in windowed 800x600 mode because it's easier for debugging, sorry people

I've switched to the code Motorsport uses in their project, which at first didn't give me input using D3D9 (I'm pretty sure anyway), but now works fine. I don't know what changed though, so for all I know a reboot could've fixed it last time I checked. I did make some changes to allow the window to be moved (in windowed mode). Here's the new code:
Code: Select all
// Initialise Ogre
char tmp[64] = "OpenFRAG Window";
mWindow = mRoot->initialise(true, tmp);
// Initialise SDL
#ifdef WIN32
// Allow SDL to use the window Ogre just created
HWND hWnd = FindWindow(tmp, 0);
sprintf(tmp, "SDL_WINDOWID=%d", hWnd);
_putenv(tmp);
if (!mWindow->isFullScreen())
{
// This is necessary to allow the window to move
// on WIN32 systems. Without this, the window resets
// to the smallest possible size after moving.
mSDL->initialise(mWindow->getWidth(), mWindow->getHeight());
}
else
{
mSDL->initialise(0, 0);
}
#else
mSDL->initialise();
#endif
// And in SDLEngine (mSDL in the code above)
#ifdef WIN32
void SDLEngine::initialise(int width, int height)
#else
void SDLEngine::initialise()
#endif
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0)
{
mLog->writeLog("Couldn't initialize SDL:\n\t\t");
mLog->writeLine(SDL_GetError());
}
#ifdef WIN32
// TODO [Sander Bisschops]: Find out if this is necessary on Linux/Unix
if (width && height)
{
// if width = 0 and height = 0, the window is fullscreen
// This is necessary to allow the window to move
// on WIN32 systems. Without this, the window resets
// to the smallest possible size after moving.
SDL_SetVideoMode(width, height, 0, 0);
}
static SDL_SysWMinfo pInfo;
SDL_VERSION(&pInfo.version);
SDL_GetWMInfo(&pInfo);
// Also, SDL keeps an internal record of the window size
// and position. Because SDL does not own the window, it
// missed the WM_POSCHANGED message and has no record of
// either size or position. It defaults to {0, 0, 0, 0},
// which is then used to trap the mouse "inside the
// window". We have to fake a window-move to allow SDL
// to catch up, after which we can safely grab input.
RECT r;
GetWindowRect(pInfo.window, &r);
SetWindowPos(pInfo.window, 0, r.left, r.top, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
#endif
// Grab means: lock the mouse inside our window!
SDL_ShowCursor(SDL_DISABLE); // SDL_ENABLE to show the mouse cursor (default)
SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_GRAB_OFF to not grab input (default)

Last edited by BRAINLESS on Sat Apr 30, 2005 10:30 pm, edited 5 times in total.
Proud member of the OpenFRAG Game Development community
-
- Gnoblar
- Posts: 13
- Joined: Tue Nov 26, 2002 11:19 pm
- Location: Calgary, Alberta, Canada
I could really use something like this. How did you communicate between WinForms and Ogre? Any chance of sharing some code? Suggestions? Tips? Anything?johnhpus wrote:No, I didn't use any kind of wrapper. I was actually suprised that it worked, considering that Ogre's classes aren't managed. I did run into scores of problems though, mainly trying to get std::string and System::String to play nice together.
John Van Vliet
In-Turn Software
In-Turn Software
-
- Greenskin
- Posts: 135
- Joined: Wed Feb 23, 2005 1:28 pm
- Location: Tokyo, JAPAN
BTW, the wxWidgets tutorial needs a minor update. it doesn't compile with Ogre 1.0.0, at least not the last time I checked about a week ago. The method used to pass ogre the HWND has changed since that was written. Oh, and also the code seems to be assuming Win32/D3D renderer.johnhpus wrote: There is a tutorial for ogre called something like "Using Ogre with wxWidgets". I've been working on one for MFC, but who knows when or if I'll even finish it.
-
- Gnoblar
- Posts: 1
- Joined: Thu Apr 07, 2005 10:29 am
GUI integration with Ogre
Hello -
I'm brand new to Ogre, and for my project I need an integrated GUI. I've read a number of messages in the forums on this subject, but I am still confused. Certainly there seems to be a push to use "Crazy Eddie's" GUI system; unfortunately, I cannot really tell how mature that library is. It appears to be Beta, and CE himself has recently left the project. It's also a bit unclear how much this library has been integrated into Ogre so far; it seems clear enough that the current GUI is being abandoned in favor of CE's, but again it seems to be an incomplete/ongoing effort.
I'm familiar with wxWidgets, with is a mature/stable library, and I've read that it has been successfully integrated with Ogre, but only for Win32. To quote other threads:
"You'd have to get rid of Ogre's dependency on SDL for window creation in Linux."
"The best bet would be to actually take wxWindows and integrate it with Ogre's window creation routines and remove SDL altogether, then just use wxWindows on all platforms. "
"just to clarify, Ogre only uses SDL on Linux/OSX, in Windows the windowing code is native."
So, do these still hold? Has there been a GTK port, or is there still a dependency on SDL on Linux? Or is there more current advice on wxWidgets integration?
thanks!!
--craig
I'm brand new to Ogre, and for my project I need an integrated GUI. I've read a number of messages in the forums on this subject, but I am still confused. Certainly there seems to be a push to use "Crazy Eddie's" GUI system; unfortunately, I cannot really tell how mature that library is. It appears to be Beta, and CE himself has recently left the project. It's also a bit unclear how much this library has been integrated into Ogre so far; it seems clear enough that the current GUI is being abandoned in favor of CE's, but again it seems to be an incomplete/ongoing effort.
I'm familiar with wxWidgets, with is a mature/stable library, and I've read that it has been successfully integrated with Ogre, but only for Win32. To quote other threads:
"You'd have to get rid of Ogre's dependency on SDL for window creation in Linux."
"The best bet would be to actually take wxWindows and integrate it with Ogre's window creation routines and remove SDL altogether, then just use wxWindows on all platforms. "
"just to clarify, Ogre only uses SDL on Linux/OSX, in Windows the windowing code is native."
So, do these still hold? Has there been a GTK port, or is there still a dependency on SDL on Linux? Or is there more current advice on wxWidgets integration?
thanks!!
--craig
-
- Halfling
- Posts: 97
- Joined: Wed Aug 25, 2004 8:14 am
- Location: Germany
Hi craig,
i'm working on the linux port of the OgreToolbox project.
It is using wxWidgets/wxWindows and Ogre compiled with GLX support on linux.
I still working on it, but have first results, see this thread http://ogretoolbox.sourceforge.net/modu ... 2&start=10 for the process.
Greetings MadLion
i'm working on the linux port of the OgreToolbox project.
It is using wxWidgets/wxWindows and Ogre compiled with GLX support on linux.
I still working on it, but have first results, see this thread http://ogretoolbox.sourceforge.net/modu ... 2&start=10 for the process.
Greetings MadLion
-
- Halfling
- Posts: 95
- Joined: Sun Apr 03, 2005 6:58 pm
I would just like to thank BRAINLESS for figuring out how to get the HWND in SDL in the most elegant way =). Before I was doing the FindWindow Win32API. That little technique has been of a great use to me. I now can try out my DirectInput quite easily.
I recently also used that information as well as a reference to a method to use D3D in SDL, to successfully make a SDL program that uses D3D as the rendering api.
Thanks a bunch!
- Drew
I recently also used that information as well as a reference to a method to use D3D in SDL, to successfully make a SDL program that uses D3D as the rendering api.
Thanks a bunch!

- Drew