A simple Ogre application( 一个&#316

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
mythma
Gnoblar
Posts: 2
Joined: Sun May 15, 2005 2:54 am

A simple Ogre application( 一个&#316

Post by mythma »

:arrow:
/*
----------------------------------------------------------------
This is a mini Ogre Application. It does nothing.
by Mythma (mythma@126.com)
----------------------------------------------------------------
*/
#include "stdafx.h"
#include "Ogre.h"
#include "OgreFrameListener.h"
#include "OgreEventListeners.h"
#include "OgreKeyEvent.h"


using namespace Ogre;

//////////////////////////////////////////////////////////////////////////
// class CSimpleFrameListener
//////////////////////////////////////////////////////////////////////////
class CSimpleFrameListener : public FrameListener
{
public:
CSimpleFrameListener(InputReader* inputReader)
{
m_InputReader = inputReader;
}
bool frameStarted(const FrameEvent& evt)
{
m_InputReader->capture();
//exit if key KC_ESCAPE pressed
if(m_InputReader->isKeyDown(KC_ESCAPE))
return false;

return true;
}

bool frameEnded(const FrameEvent& evt)
{
return true;
}
private:
InputReader* m_InputReader;
};

//////////////////////////////////////////////////////////////////////////
// class CSimpleKeyListener
//////////////////////////////////////////////////////////////////////////
class CSimpleKeyListener : public KeyListener
{
public:
void keyClicked(KeyEvent* e){}

void keyPressed(KeyEvent* e){}

void keyReleased(KeyEvent* e){}
};


//////////////////////////////////////////////////////////////////////////
// class main
//////////////////////////////////////////////////////////////////////////

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
#else
int main(int argc, char **argv)
#endif
{
//----------------------------------------------------
//1 enter ogre
//-----------------------------------------------------

Root* root = new Root;

//----------------------------------------------------
// 2 Configures the application
//------------------------------------------------------

root->showConfigDialog();
root->initialise(true, "Simple Ogre App");

//------------------------------------------------------
// 3 Create the camera
//------------------------------------------------------

SceneManager* sceneMgr = root->getSceneManager(ST_GENERIC);
Camera* camera = sceneMgr->createCamera("SimpleCamera");

//------------------------------------------------------
// 4 Create one viewport, entire window
//------------------------------------------------------

Viewport* viewPort = root->getAutoCreatedWindow()->addViewport(camera);

//---------------------------------------------------
// 5 add event processor
//--------------------------------------------------

EventProcessor* eventProcessor = new EventProcessor();
eventProcessor->initialise(root->getAutoCreatedWindow());
eventProcessor->startProcessingEvents();
CSimpleKeyListener* keyListener = new CSimpleKeyListener();
eventProcessor->addKeyListener(keyListener);
CSimpleFrameListener* frameListener = new CSimpleFrameListener(
eventProcessor->getInputReader());
root->addFrameListener(frameListener);

//---------------------------------------------------
// 6 start rendering
//--------------------------------------------------

root->startRendering();

//------------------------------------------------
// 7 clean
//---------------------------------------------------

delete frameListener;
delete keyListener;
delete eventProcessor;
delete root; :wink: :wink: :wink:

return 0;
}

:P
User avatar
:wumpus:
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3067
Joined: Tue Feb 10, 2004 12:53 pm
Location: The Netherlands
x 1

Post by :wumpus: »

That can be useful, a minimal application that does nothing, wiki it please :)
stodge
Goblin
Posts: 217
Joined: Thu Oct 24, 2002 4:12 am
x 1
Contact:

Post by stodge »

It's a good starting point for people who want to move away from the example applications.
What does the debugger tell you? You *are* using a debugger, right??
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

to be honest when I started the example app just confused me. Obviously I'm a little scetchy still with OOP :) This is the main reason Irrlicht people think Ogre is harder I think (because it's not)
Raine3D
Gnoblar
Posts: 15
Joined: Mon Jul 25, 2005 3:22 am
x 1

Post by Raine3D »

Vectrex wrote:to be honest when I started the example app just confused me. Obviously I'm a little scetchy still with OOP :) This is the main reason Irrlicht people think Ogre is harder I think (because it's not)
So true. At first I kept going back to Irrlicht, because it was so easy to set up a scene, but I kept trying to understand Ogre because its so praised. The ExampleApplication tutorial kept confusing me, and I learned more trying to create my app from scratch. A tutorial like this can be very helpful for newcomers.
User avatar
Gaffeghan
Greenskin
Posts: 110
Joined: Sat Nov 13, 2004 10:37 pm
Location: Ballston Spa, NY
Contact:

Post by Gaffeghan »

nice! so simple, even i can understand it lol. perfect wiki meterial.
User avatar
Tannayr
Gnoblar
Posts: 8
Joined: Tue Jun 21, 2005 12:09 am

Post by Tannayr »

Might would have been awesome if it worked. Kept getting these errors:

--------------------Configuration: test92 - Win32 Debug--------------------
Compiling...
source.cpp
C:\Documents and Settings\Rich\Desktop\test2\test92\source.cpp(1) : error C2143: syntax error : missing ';' before '--'
C:\Documents and Settings\Rich\Desktop\test2\test92\source.cpp(3) : error C2018: unknown character '0x40'
C:\Documents and Settings\Rich\Desktop\test2\test92\source.cpp(3) : error C2059: syntax error : 'bad suffix on number'
C:\Documents and Settings\Rich\Desktop\test2\test92\source.cpp(5) : warning C4138: '*/' found outside of comment
C:\Documents and Settings\Rich\Desktop\test2\test92\source.cpp(6) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
Error executing cl.exe.

source.obj - 4 error(s), 1 warning(s)


After spending the 2 straight weeks getting everything to work with v6 I have no energy to try to figure this out.
User avatar
SuprChikn
Bugbear
Posts: 863
Joined: Tue Apr 19, 2005 6:10 am
Location: Melbourne, Aus
Contact:

Post by SuprChikn »

It looks like you're missing the open-comments marker at the start of the file. ie: /*
That should take care of the first 3 errors and the warning at least.
Tyn
Gremlin
Posts: 195
Joined: Mon Jul 19, 2004 11:40 pm
Location: England
Contact:

Post by Tyn »

Also, remove the include stdafx.h line, it's not needed here. Should compile fine now.
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
Douglas Adams

http://www.spacecolonization.net
2080: Space Colonization
User avatar
Gaffeghan
Greenskin
Posts: 110
Joined: Sat Nov 13, 2004 10:37 pm
Location: Ballston Spa, NY
Contact:

Post by Gaffeghan »

dunno, i'm stumped, the code itself is really easy to understand, it's the cryptic error messages that stop me cold

Code: Select all

OgreDemo fatal error LNK1120: 8 unresolved externals
OgreDemo error LNK2020: unresolved token (0A000008) Ogre.FrameListener.__dtor
OgreDemo error LNK2020: unresolved token (0A000009) Ogre.EventProcessor.isKeyEnabled
OgreDemo error LNK2020: unresolved token (0A00002D) Ogre.EventProcessor.__dtor
OgreDemo error LNK2020: unresolved token (0A000030) Ogre.EventProcessor.processEvent
OgreDemo error LNK2020: unresolved token (0A000031) Ogre.EventProcessor.getTop
OgreDemo error LNK2020: unresolved token (0A000032) Ogre.EventProcessor.getLeft
OgreDemo error LNK2020: unresolved token (0A000033) Ogre.EventProcessor.getPositionTargetParent
OgreDemo error LNK2020: unresolved token (0A000036) __imp_?sMemManager@MemoryManager@Ogre@@2V12@A
any suggestions?

[edit] a thousand pardons for hijacking this thread, i'd like to see this demo application work too.[/edit]
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Post by johnhpus »

Gaffeghan: Are you linking against OgreMain_d.lib?

Mythma: This is really cool, it should make it easier for people new to Ogre. I understand that your intention was to show as simply as possible what it takes to use Ogre, but did you leave out the resource loading stuff on purpose? As is, you can't use any of Ogre's normal media resources. That's probably going to confuse the people this is meant to help.
User avatar
Robomaniac
Hobgoblin
Posts: 508
Joined: Tue Feb 03, 2004 6:39 am

Post by Robomaniac »

phear hingo

My Webpage
User avatar
Gaffeghan
Greenskin
Posts: 110
Joined: Sat Nov 13, 2004 10:37 pm
Location: Ballston Spa, NY
Contact:

Post by Gaffeghan »

johnhpus wrote: ...but did you leave out the resource loading stuff on purpose? As is, you can't use any of Ogre's normal media resources. That's probably going to confuse the people this is meant to help.
i wish i read the rest of your post before going on and fixing the ogremain_d thing (seems the difference between ogremain.lib and _d.lib is one of the biggest issues in the community)... this explanes why i can't compile my attempt to load a car mesh into ogre. this took me most of the day to come back here and read that... so sad. still good wiki material, just have to add the resource loading stuff and it's nearly perfect
User avatar
bal
Greenskin
Posts: 100
Joined: Thu Dec 09, 2004 7:29 pm
Location: Geluwe, Belgium

Post by bal »

@ Gaffeghan;

Code: Select all

#include <OgreKeyEvent.h>
#include <OgreEventListeners.h>
This should fix your problem :).
Vectrex
Ogre Magi
Posts: 1266
Joined: Tue Aug 12, 2003 1:53 am
Location: Melbourne, Australia
x 1
Contact:

Post by Vectrex »

Just put this example on the wiki. I'm not sure about some of the fixes/problems so could you guys check it.

http://www.ogre3d.org/wiki/index.php/MinimalApplication
Sanguis
Gnoblar
Posts: 2
Joined: Tue Sep 27, 2005 7:15 pm

Post by Sanguis »

Should this thing also work at Dev-C++? Couse I can't seem to get anything working :(

Code: Select all

        ConfigFile cf;
        cf.load("resources.cfg");

        // Go through all sections & settings in the file
        ConfigFile::SectionIterator seci = cf.getSectionIterator();

        String secName, typeName, archName;
        while (seci.hasMoreElements())
        {
            secName = seci.peekNextKey();
            ConfigFile::SettingsMultiMap *settings = seci.getNext();
            ConfigFile::SettingsMultiMap::iterator i;
            for (i = settings->begin(); i != settings->end(); ++i)
            {
                typeName = i->first;
                archName = i->second;
                ResourceGroupManager::getSingleton().addResourceLocation(
                    archName, typeName, secName);
            }
        }

Makes it crash before i can couse the graphix type (opengl or d3d)
If I remove that code i can couse a video mode and get in apart from these two lines:

Code: Select all

eventProcessor->addKeyListener(keyListener);
root->addFrameListener(frameListener); 
leaving any one of these two in results in a a hard windows crash, commenting them both out results in a black screen (witch is good) but reading the lines you can guess it no input of keys or something like that. Am I doing something wrong? (its my first time with something like this) or is this code written for an other compiler and not supposed to work on Dev-C++?

EDIT: I might have found the root of my problem in this topic http://www.ogre3d.org/phpBB2/viewtopic. ... light=devc seems my Dev-C++ is to new :P
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

We don't officially support Dev-C++, use Code::Blocks if you want a decent free IDE.
User avatar
Morrog
Greenskin
Posts: 105
Joined: Wed Aug 24, 2005 11:24 pm

Post by Morrog »

I had the same problem. I was scared of Ogre because the code I needed to actually develop any decent app was too far. Had to spend a day or two going over the tutorials, and the cut down tutorials, to finally work it all out. I'm glad I finally did though. Irrlicht was a pain in the butt, so many little bugs and problems that weren't getting fixed.
Sanguis
Gnoblar
Posts: 2
Joined: Tue Sep 27, 2005 7:15 pm

Post by Sanguis »

Well after a day of trying I gave up Dev-C++ and tryed in Visual Studio and it worked in like 10 min so I'm gonna stick with this for now. Walking trugh the tutorials now. Great stuff I really this so keep up the good work :D
brog
Gnoblar
Posts: 1
Joined: Fri Apr 14, 2006 1:25 am

Post by brog »

in the line:
SceneManager* sceneMgr = root->getSceneManager(ST_GENERIC);
I get the error: C2664: 'Ogre::Root::getSceneManager' : cannot convert parameter 1 from 'Ogre::SceneType' to 'const Ogre::String &' Reason: cannot convert from 'Ogre::SceneType' to 'const Ogre::String'

I'm using visual studio 7.1, can anybody offer help?
smestorp
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

root->createSceneManager

This is a Dagon change. Use the search button, please! :wink:
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
vvv
Gnoblar
Posts: 8
Joined: Tue Apr 18, 2006 9:26 am

Post by vvv »

brog wrote:in the line:
SceneManager* sceneMgr = root->getSceneManager(ST_GENERIC);
I get the error: C2664: 'Ogre::Root::getSceneManager' : cannot convert parameter 1 from 'Ogre::SceneType' to 'const Ogre::String &' Reason: cannot convert from 'Ogre::SceneType' to 'const Ogre::String'

I'm using visual studio 7.1, can anybody offer help?
I had similar problem. All tutorials show that code, but it didn't work until I used a string argument "ST_GENERIC" instead of Ogre::ST_GENERIC. Compiler is happy cause its a string, but I have no idea if it is the right string :)

I just installed ogre so pls excuse me if I say (or if I already said :)) something dumb. When I run this simple app, or similar basic apps found elsewhere, the config window crashes when I click 'select one'. I am using Ubuntu linux. The problem is, I read somewhere, that X can not work with empty menu lists. What can I do about this?
Last edited by vvv on Tue Apr 18, 2006 10:00 am, edited 1 time in total.
vvv
Gnoblar
Posts: 8
Joined: Tue Apr 18, 2006 9:26 am

Post by vvv »

Code::Blocks project works just fine, no config dialog crash.
Avihay
Gnoblar
Posts: 16
Joined: Tue Oct 05, 2004 12:17 am

Post by Avihay »

Tell me, when you terminate the window by a windows command, namely Alt + F4, dose it kill the prosses or just the window?

I ask because I tryed to compile a modified ver of the newbe tutorial 2 with some modifications and, as it happens, I got an error on Ogre::PlatformManager::getSingleton().messagePump(window); that message pump isn't a member function.

I use an older ver of ogre that compiles with MSVC6 and that function hasn't been implemented.

so I went and copyed a simple message pump that someone posted on the wiki, that was supposed to intercept WM_QUIT messages and then tell ogre to quit so that the prosses will know when to die, but it didn't work. I also tryed WM_CLOSE and WM_DESTROY.

then I looked better at the code and found out that I was sending peekMessage() NULL insted of hWND, but I suck at MFC and generaly programing for windows, so i didn't know how to get it, and I thought maybe the renderWindow class has that kind of pointer, so I looked thru the docs, and found a method to know if the window is closed in the platform manager that is by definition cross platform.

Code: Select all

while (1)
     {
	//do stuff
        if(root->renderOneFrame() == false)
                 break;
        messagePump(window);
        if (window->isClosed())
			   break;//exit(0)//whatever
     }
The method RenderWindow::isClosed() is there for usefull to determin if you'r window has been closed by the OS, and so you'r prosses has no reason to live and therefor should terminate.

Any better, less expansive way to do it?
Tufty
Gnoblar
Posts: 3
Joined: Mon Jul 24, 2006 11:10 am

C#

Post by Tufty »

This looks like great! I'm using C# tho... :roll:
Has anyone converted this to C# yet?
Post Reply