2012年7月18日 星期三

Orge 1.6 & 1.7 with vs2008

http://www.ogre3d.org/download/sdk下載Orge 1.6 for vc90

環境Path變數加入
;%OGRE_HOME%/bin/debug;%OGRE_HOME%/bin/release

在VS2008中的工具->選項中找到"專案和方案"->"VC++目錄"
在「Include 檔案」中,加入 $(OGRE_HOME)/include
在「程式庫檔」中,加入 $(OGRE_HOME)/lib

Orge 1.7 :
Include 檔案
OgreSDK_vc9_v1-7-4\include
OgreSDK_vc9_v1-7-4\boost_1_48

Lib檔案
OgreSDK_vc9_v1-7-4\lib\Debug      或    OgreSDK_vc9_v1-7-4\lib\Release
OgreSDK_vc9_v1-7-4\boost_1_48/lib



記得要加入
OgreMain.lib OIS.lib 或 OgreMain_d.lib OIS_d.lib

輸出目錄放
OgreMain.dll OIS.dll 或 OgreMain_d.dll OIS_d.dll
RenderSystem_Direct3D9.dll
d3dx9_43.dll
RenderSystem_GL.dll



main.cpp


目前ogre1.7用codeblock只能跑release mode
記得在Toolchain executable 中的Additional paths中加上$(CODEBLOCKS)\build\vs2008\Microsoft Visual Studio 9.0\Common7\IDE
#include <Ogre.h>
using namespace Ogre;

int main(int argc, char *argv[])
{
    // start the Ogre application
    Root *root = new Root( "", "" );

    // load a plugin(DLL) of the render system
#ifdef _DEBUG
    root->loadPlugin( "RenderSystem_Direct3D9_d" );     // for a debug build
   //  root->loadPlugin("RenderSystem_GL_d");
#else
    root->loadPlugin( "RenderSystem_Direct3D9" );       // for a release build
    // root->loadPlugin("RenderSystem_GL");
#endif

    // select the Direct3D renderer
//------------------------------------------------------------------------------------
//   RenderSystemList *render_sys_list = root->getAvailableRenderers(); //for 1.6
//   RenderSystemList::iterator it_rs( render_sys_list->begin() );      //for 1.6
//   while ( it_rs != render_sys_list->end() )                          //for 1.6
//------------------------------------------------------------------------------------
    const RenderSystemList &render_sys_list = root->getAvailableRenderers();//for 1.7
    RenderSystemList::const_iterator it_rs( render_sys_list.begin() );      //for 1.7
    while ( it_rs != render_sys_list.end() )                                //for 1.7
    {
        RenderSystem *render_sys = *(it_rs++);
      //if ( render_sys->getName().find( "OpenGL" ) != String::npos )
         if ( render_sys->getName().find( "Direct3D9" ) != String::npos )
        {
            root->setRenderSystem( render_sys );
            break;
        }
    }

    // end gracelessly if the preferred renderer is not available
    if ( root->getRenderSystem() == NULL )
    {
        delete root;
        return -1;
    }

    // initialize the root, and tell the root NOT to create a render window
    root->initialise( false );

    // manually create a render window
    RenderWindow* render_win = root->createRenderWindow( "Hello, Ogre!",   // window title
                              320,              // window (client area) width
                              240,              // window height
                              false );          // full screen mode
    // create the SceneManager, in this case a generic one
    SceneManager *scene_mgr = root->createSceneManager(ST_GENERIC, "my scene manager");
    // create the Camera
    Camera *camera = scene_mgr->createCamera( "MainCamera" );
    // create the Viewport
    Viewport *viewport = render_win->addViewport( camera );
     viewport->setBackgroundColour( ColourValue::Black ); // same as ColourValue( 0, 0, 0 )
     camera->setAspectRatio( Real( viewport->getActualWidth() ) / Real( viewport->getActualHeight() ) );
     camera->setNearClipDistance( 1 );
     camera->setFarClipDistance( 1000 );
     camera->setFOVy( Degree( 45 ) );
     camera->setPosition( 0, 0, 500 );
     // create a material with nothing and no lighting
     MaterialPtr mtl = MaterialManager::getSingleton().create( "Neo_MaterIal_NoLighting",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
     mtl->setLightingEnabled( false );
     // create the triangular face by using ManualObject
     ManualObject* manual = scene_mgr->createManualObject( "triangular_face" );
     manual->begin( "Neo_MaterIal_NoLighting", RenderOperation::OT_TRIANGLE_LIST );
     manual->position(-100.0,  100.0, 0.0);
     manual->colour( ColourValue::Red ); // ColourValue( 1, 0, 0 );
     manual->position(-100.0, -100.0, 0.0);
     manual->colour( ColourValue::Green ); // ColourValue( 0, 1, 0 );
     manual->position( 100.0, -100.0, 0.0);
     manual->colour( ColourValue::Blue ); // ColourValue( 0, 0, 1 );
     manual->end();
     // attach the object to the root node
     scene_mgr->getRootSceneNode()->attachObject( manual );

    // start the rendering loop
    root->startRendering();
    return 0;
}

沒有留言:

張貼留言